mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
do not generate id method (was for 1.8 only)
see https://github.com/rails-api/active_model_serializers/issues/127 for original motivation
This commit is contained in:
parent
2c563eaace
commit
143e5d9866
@ -13,9 +13,6 @@ module Rails
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def generate_id_method
|
|
||||||
RUBY_VERSION =~ /1\.8/
|
|
||||||
end
|
|
||||||
|
|
||||||
def attributes_names
|
def attributes_names
|
||||||
[:id] + attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
|
[:id] + attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
|
||||||
|
|||||||
@ -4,16 +4,5 @@ class <%= class_name %>Serializer < <%= parent_class_name %>
|
|||||||
<% association_names.each do |attribute| -%>
|
<% association_names.each do |attribute| -%>
|
||||||
has_one :<%= attribute %>
|
has_one :<%= attribute %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if generate_id_method %>
|
|
||||||
|
|
||||||
# due to the difference between 1.8 and 1.9 with respect to #id and
|
|
||||||
# #object_id, we recommend that if you wish to serialize id columns, you
|
|
||||||
# do this. Feel free to remove this if you don't feel that it's appropriate.
|
|
||||||
#
|
|
||||||
# For more: https://github.com/rails-api/active_model_serializers/issues/127
|
|
||||||
def id
|
|
||||||
object.read_attribute_for_serialization(:id)
|
|
||||||
end
|
|
||||||
<% end -%>
|
|
||||||
end
|
end
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|||||||
@ -36,18 +36,6 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
|
|||||||
Object.send :remove_const, :ApplicationSerializer
|
Object.send :remove_const, :ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_serializer_gets_id
|
|
||||||
run_generator
|
|
||||||
|
|
||||||
assert_file "app/serializers/account_serializer.rb" do |content|
|
|
||||||
if RUBY_VERSION =~ /1.8/
|
|
||||||
assert_match /def id/, content
|
|
||||||
else
|
|
||||||
assert_no_match /def id/, content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# def test_uses_namespace_application_serializer_if_one_exists
|
# def test_uses_namespace_application_serializer_if_one_exists
|
||||||
# Object.const_set(:SerializerNamespace, Module.new)
|
# Object.const_set(:SerializerNamespace, Module.new)
|
||||||
# SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
|
# SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user