Generate id method on Ruby 1.8.

Because object_id and id went through some flux, it's best to tell 1.8
specifically what we mean.

Closes #127.
This commit is contained in:
Steve Klabnik
2013-03-19 14:53:08 -07:00
parent 145b6d499d
commit c129ae2016
4 changed files with 32 additions and 3 deletions

View File

@@ -36,6 +36,18 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
Object.send :remove_const, :ApplicationSerializer
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
# Object.const_set(:SerializerNamespace, Module.new)
# SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
@@ -66,6 +78,8 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
def test_with_no_attributes_does_not_add_extra_space
run_generator ["account"]
assert_file "app/serializers/account_serializer.rb", /class AccountSerializer < ActiveModel::Serializer\n attributes :id\nend/
assert_file "app/serializers/account_serializer.rb" do |content|
assert_no_match /\n\nend/, content
end
end
end