Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Event < ApplicationRecord
- ...
- belongs_to :organization
- ...
- end
- class Organization < ApplicationRecord
- ...
- has_many :events, :dependent => :destroy
- ...
- end
- FactoryGirl.define do
- factory :organization do
- organization_name { Faker::Company.name }
- end
- factory :invalid_organization, class: Organization do
- organization_name ''
- end
- end
- FactoryGirl.define do
- factory :event do
- event_description { Faker::Lorem.sentence(3) }
- host_name { Faker::Internet.domain_name }
- organization = build(:organization)
- organization_id = organization.id
- end
- end
- require 'rails_helper'
- RSpec.describe Event, type: :model do
- it "has a valid factory" do
- event = build(:event)
- expect(event).to be_valid
- end
- it { is_expected.to validate_presence_of(:event_description) }
- it { is_expected.to validate_presence_of(:host_name) }
- it { is_expected.to validate_presence_of(:organization_id) }
- it { is_expected.to belong_to(:organization) }
- end
- /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)
- FactoryGirl.define do
- factory :event do
- event_description { Faker::Lorem.sentence(3) }
- host_name { Faker::Internet.domain_name }
- organization { build(:organization) }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement