mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add AR integration tests
This commit is contained in:
parent
4c7599cfff
commit
fa61314d0e
13
test/fixtures/active_record.rb
vendored
13
test/fixtures/active_record.rb
vendored
@ -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
|
||||
|
||||
31
test/integration/active_record/active_record_test.rb
Normal file
31
test/integration/active_record/active_record_test.rb
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user