Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use model name to determine the type #953

Merged
merged 1 commit into from
Jun 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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
4 changes: 4 additions & 0 deletions test/fixtures/poro.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Model
FILE_DIGEST = Digest::MD5.hexdigest(File.open(__FILE__).read)

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

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