Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. class Event < ApplicationRecord
  2. ...
  3. belongs_to :organization
  4. ...
  5. end
  6.  
  7. class Organization < ApplicationRecord
  8. ...
  9. has_many :events, :dependent => :destroy
  10. ...
  11. end
  12.  
  13. FactoryGirl.define do
  14. factory :organization do
  15. organization_name { Faker::Company.name }
  16. end
  17. factory :invalid_organization, class: Organization do
  18. organization_name ''
  19. end
  20. end
  21.  
  22. FactoryGirl.define do
  23. factory :event do
  24. event_description { Faker::Lorem.sentence(3) }
  25. host_name { Faker::Internet.domain_name }
  26. organization = build(:organization)
  27. organization_id = organization.id
  28. end
  29. end
  30.  
  31. require 'rails_helper'
  32.  
  33. RSpec.describe Event, type: :model do
  34. it "has a valid factory" do
  35. event = build(:event)
  36. expect(event).to be_valid
  37. end
  38. it { is_expected.to validate_presence_of(:event_description) }
  39. it { is_expected.to validate_presence_of(:host_name) }
  40. it { is_expected.to validate_presence_of(:organization_id) }
  41. it { is_expected.to belong_to(:organization) }
  42. end
  43.  
  44. /Users/levi/ror/events-handler/spec/factories/events.rb:6:in `block (2 levels) in <top (required)>': undefined method `id' for #<FactoryGirl::Declaration::Static:0x007febc03db798> (NoMethodError)
  45.  
  46. FactoryGirl.define do
  47. factory :event do
  48. event_description { Faker::Lorem.sentence(3) }
  49. host_name { Faker::Internet.domain_name }
  50. organization { build(:organization) }
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement