From 614c07aab894515f394855af76edbda1bd0c4cee Mon Sep 17 00:00:00 2001 From: Sean Devine Date: Tue, 31 May 2016 18:50:26 -0400 Subject: [PATCH] fix polymorphic_type for ToOne relationships --- lib/jsonapi/relationship.rb | 2 +- test/unit/resource/relationship_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/unit/resource/relationship_test.rb diff --git a/lib/jsonapi/relationship.rb b/lib/jsonapi/relationship.rb index 74c739bc8..0108e8985 100644 --- a/lib/jsonapi/relationship.rb +++ b/lib/jsonapi/relationship.rb @@ -74,7 +74,7 @@ def belongs_to? end def polymorphic_type - "#{type.to_s.singularize}_type" if polymorphic? + "#{name}_type" if polymorphic? end end diff --git a/test/unit/resource/relationship_test.rb b/test/unit/resource/relationship_test.rb new file mode 100644 index 000000000..8208933e4 --- /dev/null +++ b/test/unit/resource/relationship_test.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../../test_helper', __FILE__) + +class HasOneRelationshipTest < ActiveSupport::TestCase + + def test_polymorphic_type + relationship = JSONAPI::Relationship::ToOne.new("imageable", + polymorphic: true + ) + assert_equal(relationship.polymorphic_type, "imageable_type") + end + +end