Open DArrigoni opened 10 years ago
You probably have already found a solution to this by now, but i implemented the same way you did and it worked fine.
@product = FactoryGirl.build(:product, :with_views)
trait :with_views do
after(:build) do |impressionable|
impressionable.impressions = build_list :impression, 3, impressionable: impressionable
end
end
FactoryGirl.define do
factory :impression do
impressionable_type { impressionable.class.name }
impressionable_id { impressionable.id }
user_id { nil }
controller_name 'impressionables'
action_name 'show'
view_name nil
request_hash { SecureRandom.hex }
ip_address Faker::Internet.ip_v4_address
session_hash { SecureRandom.hex }
message nil
referrer nil
end
end
I'm not sure how best to create impressions on my model in a test setup so as to test at an integration level. I'm using FactoryGirl and RSpec. Here was my first rough crack at it and the error I received:
Any suggestions on the correct way to set up impressions on models in testing would be appreciated! I will happily format what I learn into a documentation pull request. :)