mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Tests refactor
This commit is contained in:
parent
b6f9c5ee43
commit
45453f638b
@ -1,23 +1,23 @@
|
|||||||
require 'newbase/test_helper'
|
require 'newbase/test_helper'
|
||||||
require 'newbase/active_model/serializer'
|
require 'newbase/active_model/serializer'
|
||||||
|
|
||||||
module SerializerTest
|
module ActiveModel
|
||||||
module Attributes
|
class Serializer
|
||||||
class Model
|
class AttributesTest < ActiveModel::TestCase
|
||||||
def initialize(hash={})
|
class Model
|
||||||
@attributes = hash
|
def initialize(hash={})
|
||||||
|
@attributes = hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_attribute_for_serialization(name)
|
||||||
|
@attributes[name]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_attribute_for_serialization(name)
|
class ModelSerializer < ActiveModel::Serializer
|
||||||
@attributes[name]
|
attributes :attr1, :attr2
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class ModelSerializer < ActiveModel::Serializer
|
|
||||||
attributes :attr1, :attr2
|
|
||||||
end
|
|
||||||
|
|
||||||
class Test < ActiveModel::TestCase
|
|
||||||
def setup
|
def setup
|
||||||
model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
|
model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
|
||||||
@model_serializer = ModelSerializer.new(model)
|
@model_serializer = ModelSerializer.new(model)
|
||||||
@ -1,19 +1,19 @@
|
|||||||
require 'newbase/test_helper'
|
require 'newbase/test_helper'
|
||||||
require 'newbase/active_model/serializer'
|
require 'newbase/active_model/serializer'
|
||||||
|
|
||||||
module SerializerTest
|
module ActiveModel
|
||||||
module Root
|
class Serializer
|
||||||
class Model
|
|
||||||
def initialize(hash={})
|
|
||||||
@attributes = hash
|
|
||||||
end
|
|
||||||
|
|
||||||
def read_attribute_for_serialization(name)
|
|
||||||
@attributes[name]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class RootAsOptionTest < ActiveModel::TestCase
|
class RootAsOptionTest < ActiveModel::TestCase
|
||||||
|
class Model
|
||||||
|
def initialize(hash={})
|
||||||
|
@attributes = hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_attribute_for_serialization(name)
|
||||||
|
@attributes[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class ModelSerializer < ActiveModel::Serializer
|
class ModelSerializer < ActiveModel::Serializer
|
||||||
attributes :attr1, :attr2
|
attributes :attr1, :attr2
|
||||||
end
|
end
|
||||||
@ -58,6 +58,16 @@ module SerializerTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
class RootInSerializerTest < ActiveModel::TestCase
|
class RootInSerializerTest < ActiveModel::TestCase
|
||||||
|
class Model
|
||||||
|
def initialize(hash={})
|
||||||
|
@attributes = hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_attribute_for_serialization(name)
|
||||||
|
@attributes[name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class ModelSerializer < ActiveModel::Serializer
|
class ModelSerializer < ActiveModel::Serializer
|
||||||
root :in_serializer
|
root :in_serializer
|
||||||
attributes :attr1, :attr2
|
attributes :attr1, :attr2
|
||||||
@ -1,22 +1,22 @@
|
|||||||
require 'newbase/test_helper'
|
require 'newbase/test_helper'
|
||||||
require 'newbase/active_model/serializer'
|
require 'newbase/active_model/serializer'
|
||||||
|
|
||||||
module SerializerTest
|
module ActiveModel
|
||||||
module Scope
|
class Serializer
|
||||||
class Model
|
class ScopeTest < ActiveModel::TestCase
|
||||||
def initialize(hash={})
|
class Model
|
||||||
@attributes = hash
|
def initialize(hash={})
|
||||||
|
@attributes = hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_attribute_for_serialization(name)
|
||||||
|
@attributes[name]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_attribute_for_serialization(name)
|
class ModelSerializer < ActiveModel::Serializer
|
||||||
@attributes[name]
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class ModelSerializer < ActiveModel::Serializer
|
|
||||||
end
|
|
||||||
|
|
||||||
class Test < ActiveModel::TestCase
|
|
||||||
def setup
|
def setup
|
||||||
@serializer = ModelSerializer.new(nil, scope: current_user)
|
@serializer = ModelSerializer.new(nil, scope: current_user)
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue
Block a user