From 01477e9c5b4d09b0a4d92034fd55a4c54cf0c2c9 Mon Sep 17 00:00:00 2001 From: Kyle Reeves Date: Tue, 3 Jul 2018 15:18:52 -0500 Subject: [PATCH] fix relationship id_hash method --- lib/fast_jsonapi/relationship.rb | 4 ++-- spec/lib/serialization_core_spec.rb | 18 ------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/lib/fast_jsonapi/relationship.rb b/lib/fast_jsonapi/relationship.rb index 15b381c..0b3a101 100644 --- a/lib/fast_jsonapi/relationship.rb +++ b/lib/fast_jsonapi/relationship.rb @@ -77,11 +77,11 @@ module FastJsonapi id_hash(ids, record_type) # ids variable is just a single id here end - def id_hash(id, associated_record_type, default_return=false) + def id_hash(id, record_type, default_return=false) if id.present? { id: id.to_s, type: record_type } else - default_return ? { id: nil, type: associated_record_type } : nil + default_return ? { id: nil, type: record_type } : nil end end diff --git a/spec/lib/serialization_core_spec.rb b/spec/lib/serialization_core_spec.rb index 385c36e..d161e3f 100644 --- a/spec/lib/serialization_core_spec.rb +++ b/spec/lib/serialization_core_spec.rb @@ -17,24 +17,6 @@ describe FastJsonapi::ObjectSerializer do expect(result_hash).to be nil end - # it 'returns the correct hash when ids_hash_from_record_and_relationship is called for a polymorphic association' do - # relationship = { name: :groupees, relationship_type: :has_many, object_method_name: :groupees, polymorphic: {} } - # results = GroupSerializer.send :ids_hash_from_record_and_relationship, group, relationship - # expect(results).to include({ id: "1", type: :person }, { id: "2", type: :group }) - # end - - # it 'returns correct hash when ids_hash is called' do - # inputs = [{ids: %w(1 2 3), record_type: :movie}, {ids: %w(x y z), record_type: 'person'}] - # inputs.each do |hash| - # results = MovieSerializer.send(:ids_hash, hash[:ids], hash[:record_type]) - # expect(results.map{|h| h[:id]}).to eq hash[:ids] - # expect(results[0][:type]).to eq hash[:record_type] - # end - - # result = MovieSerializer.send(:ids_hash, [], 'movie') - # expect(result).to be_empty - # end - it 'returns correct hash when attributes_hash is called' do attributes_hash = MovieSerializer.send(:attributes_hash, movie) attribute_names = attributes_hash.keys.sort