From 66d5b5d5716012382c9805dbcc476c840aedf412 Mon Sep 17 00:00:00 2001 From: Rafael Santos Date: Mon, 16 Jan 2017 10:25:26 +1300 Subject: [PATCH] update test to test only the block param --- .../association_matchers/model_reflection_spec.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb b/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb index 52551275e..d47b0894d 100644 --- a/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb @@ -104,18 +104,19 @@ expect(actual_sql).to eq expected_sql end - it 'executes the block in the context of an empty scope parametrised by association source' do + it 'pass instance of association source to block' do + spy = spy('spy') define_model(:country, mood: :string) - person_model = define_model(:person, country_id: :integer, spirit: :string) do - belongs_to :country, -> (person) { where(mood: person.spirit) } + person_model = define_model(:person, country_id: :integer) do + belongs_to :country, ->(person) { spy.who(person) } end person_instance = person_model.new(spirit: 'nice') delegate_reflection = person_model.reflect_on_association(:country) reflection = described_class.new(delegate_reflection) - actual_sql = reflection.association_relation(person_instance).to_sql - expected_sql = Country.where(mood: 'nice').to_sql - expect(actual_sql).to eq expected_sql + reflection.association_relation(person_instance) + + expect(spy).to have_received(:who).with(person_instance) end end