diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index 05ae73a4..9cdf055a 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -6,15 +6,16 @@ ActiveRecord::Base.establish_connection( ) ActiveRecord::Schema.define do - create_table :ar_models, :force => true do |t| - t.string :attr1 - t.string :attr2 + create_table :ar_profiles, :force => true do |t| + t.string :name + t.string :description + t.string :comments end end -class ARModel < ActiveRecord::Base +class ARProfile < ActiveRecord::Base end -class ARModelSerializer < ActiveModel::Serializer - attributes :attr1, :attr2 +class ARProfileSerializer < ActiveModel::Serializer + attributes :name, :description end diff --git a/test/integration/active_record/active_record_test.rb b/test/integration/active_record/active_record_test.rb new file mode 100644 index 00000000..9529da1e --- /dev/null +++ b/test/integration/active_record/active_record_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' +require 'fixtures/active_record' +require 'active_model/serializer' + +module ActiveModel + class Serializer + class ActiveRecordTest < ActiveModel::TestCase + def setup + @profile = ARProfile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) + @profile_serializer = ARProfileSerializer.new(@profile) + end + + def test_attributes_definition + assert_equal(['name', 'description'], + @profile_serializer.class._attributes) + end + + def test_attributes_serialization_using_serializable_hash + assert_equal({ + 'name' => 'Name 1', 'description' => 'Description 1' + }, @profile_serializer.serializable_hash) + end + + def test_attributes_serialization_using_as_json + assert_equal({ + 'name' => 'Name 1', 'description' => 'Description 1' + }, @profile_serializer.as_json) + end + end + end +end