1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/factory_bot/attribute/association_spec.rb

39 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

describe FactoryBot::Attribute::Association do
let(:name) { :author }
let(:factory) { :user }
let(:overrides) { {first_name: "John"} }
2017-06-01 12:54:02 -04:00
let(:association) { double("association") }
2009-04-11 11:27:23 -04:00
subject { FactoryBot::Attribute::Association.new(name, factory, overrides) }
before do
# Define an '#association' instance method allowing it to be mocked.
# Usually this is determined via '#method_missing'
missing_methods = Module.new {
def association(*args)
end
}
subject.extend(missing_methods)
allow(subject)
.to receive(:association).with(any_args).and_return association
2017-06-01 12:54:02 -04:00
end
2009-04-11 11:27:23 -04:00
it { should be_association }
2013-01-18 13:27:57 -05:00
its(:name) { should eq name }
it "builds the association when calling the proc" do
2013-01-18 13:27:57 -05:00
expect(subject.to_proc.call).to eq association
end
it "builds the association when calling the proc" do
subject.to_proc.call
2013-01-18 13:27:57 -05:00
expect(subject).to have_received(:association).with(factory, overrides)
2009-04-11 11:27:23 -04:00
end
end
2009-04-11 11:27:23 -04:00
describe FactoryBot::Attribute::Association, "with a string name" do
subject { FactoryBot::Attribute::Association.new("name", :user, {}) }
2013-01-18 13:27:57 -05:00
its(:name) { should eq :name }
2009-04-11 11:27:23 -04:00
end