为Analytics Ahoy gem创建种子数据

时间:2016-02-21 03:09:47

标签: ruby-on-rails ahoy

我想为演示

Ahoy Analytics Gem创建一些种子数据

我如何模拟页面访问,还会更改数据库中记录的日期以模拟过去的访问者数据?

感谢任何帮助谢谢

2 个答案:

答案 0 :(得分:0)

可以部分模拟水豚,也可以改变水豚常规的价值

另外,https://github.com/jnicklas/capybara/以防可能感兴趣

答案 1 :(得分:0)

我手动创建了Ahoy::VisitsAhoy::Events

# use the Faker gem for fake data

request = OpenStruct.new(
  params: { },
  referer: Faker::Internet.url,
  remote_ip: Faker::Internet.public_ip_v4_address,
  user_agent: Faker::Internet.user_agent,
  original_url: Rails.application.routes.url_helpers.root_url,
)

visit_properties = Ahoy::VisitProperties.new(request, api: nil)
properties = visit_properties.generate.select { |_, v| v }

example_visit = Ahoy::Visit.create!(properties.merge(
  visit_token: SecureRandom.uuid,
  visitor_token: SecureRandom.uuid,
  started_at: Time.current
))

example_event = Ahoy::Event.create!(
  visit: example_visit,
  name: 'example_event',
  properties: 'example properties',
  time: Time.current
)