Skip to content

Commit

Permalink
use model name to determine the type
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Sylvester committed Jun 12, 2015
1 parent 460150f commit a9f9c95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def id
end

def type
object.class.to_s.demodulize.underscore.pluralize
object.class.model_name.plural
end

def attributes(options = {})
Expand Down
4 changes: 2 additions & 2 deletions test/adapter/json_api/linked_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_include_multiple_posts_and_linked
assert_equal expected, alt_adapter.serializable_hash[:included]
end

def test_ignore_model_namespace_for_linked_resource_type
def test_underscore_model_namespace_for_linked_resource_type
spammy_post = Post.new(id: 123)
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
serializer = SpammyPostSerializer.new(spammy_post)
Expand All @@ -212,7 +212,7 @@ def test_ignore_model_namespace_for_linked_resource_type
expected = {
related: {
data: [{
type: 'unrelated_links',
type: 'spam_unrelated_links',
id: '456'
}]
}
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/poro.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class Model

def self.model_name
@_model_name ||= ActiveModel::Name.new(self)
end

def initialize(hash={})
@attributes = hash
end
Expand Down

0 comments on commit a9f9c95

Please sign in to comment.