mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Move models and serializers in test to fixtures.rb file
This commit is contained in:
parent
0d3b56e9cf
commit
a25c352525
24
test/fixtures.rb
Normal file
24
test/fixtures.rb
Normal file
@ -0,0 +1,24 @@
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
|
||||
def attr2
|
||||
attr2 = object.read_attribute_for_serialization(:attr2)
|
||||
if scope
|
||||
attr2 + '-' + scope
|
||||
else
|
||||
attr2
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -4,22 +4,6 @@ require 'newbase/active_model_serializers'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class ImplicitSerializerTest < ActionController::TestCase
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
end
|
||||
|
||||
class MyController < ActionController::Base
|
||||
def render_using_implicit_serializer
|
||||
render :json => Model.new(attr1: 'value1', attr2: 'value2', attr3: 'value3')
|
||||
@ -36,32 +20,12 @@ module ActionController
|
||||
end
|
||||
|
||||
class ImplicitSerializerScopeTest < ActionController::TestCase
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
|
||||
def attr2
|
||||
object.read_attribute_for_serialization(:attr2) + '-' + scope
|
||||
end
|
||||
end
|
||||
|
||||
class MyController < ActionController::Base
|
||||
def render_using_implicit_serializer_and_scope
|
||||
render :json => Model.new(attr1: 'value1', attr2: 'value2', attr3: 'value3')
|
||||
end
|
||||
|
||||
protected
|
||||
private
|
||||
|
||||
def current_user
|
||||
'current_user'
|
||||
@ -78,26 +42,6 @@ module ActionController
|
||||
end
|
||||
|
||||
class ExplicitSerializerScopeTest < ActionController::TestCase
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
|
||||
def attr2
|
||||
object.read_attribute_for_serialization(:attr2) + '-' + scope
|
||||
end
|
||||
end
|
||||
|
||||
class MyController < ActionController::Base
|
||||
def render_using_implicit_serializer_and_explicit_scope
|
||||
render json: Model.new(attr1: 'value1', attr2: 'value2', attr3: 'value3'), scope: current_admin
|
||||
@ -124,26 +68,6 @@ module ActionController
|
||||
end
|
||||
|
||||
class OverridingSerializationScopeTest < ActionController::TestCase
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
|
||||
def attr2
|
||||
object.read_attribute_for_serialization(:attr2) + '-' + scope
|
||||
end
|
||||
end
|
||||
|
||||
class MyController < ActionController::Base
|
||||
def render_overriding_serialization_scope
|
||||
render json: Model.new(attr1: 'value1', attr2: 'value2', attr3: 'value3')
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
require 'bundler/setup'
|
||||
require 'newbase/active_model_serializers'
|
||||
require 'test/unit'
|
||||
require 'newbase/fixtures'
|
||||
|
||||
module TestHelper
|
||||
Routes = ActionDispatch::Routing::RouteSet.new
|
||||
|
||||
@ -4,20 +4,6 @@ require 'newbase/active_model/serializer'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AttributesTest < ActiveModel::TestCase
|
||||
class Model
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
attributes :attr1, :attr2
|
||||
end
|
||||
|
||||
def setup
|
||||
model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
|
||||
@model_serializer = ModelSerializer.new(model)
|
||||
|
||||
@ -4,24 +4,16 @@ require 'newbase/active_model/serializer'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
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
|
||||
attributes :attr1, :attr2
|
||||
end
|
||||
ModelSerializer.root = true
|
||||
|
||||
def setup
|
||||
@old_root = ModelSerializer._root
|
||||
@model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
|
||||
@serializer = ModelSerializer.new(@model, root: 'initialize')
|
||||
ModelSerializer._root = true
|
||||
end
|
||||
|
||||
def teardown
|
||||
ModelSerializer._root = @old_root
|
||||
end
|
||||
|
||||
def test_root_is_not_displayed_using_serializable_hash
|
||||
|
||||
@ -4,19 +4,6 @@ require 'newbase/active_model/serializer'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class ScopeTest < ActiveModel::TestCase
|
||||
class Model
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def setup
|
||||
@serializer = ModelSerializer.new(nil, scope: current_user)
|
||||
end
|
||||
|
||||
@ -4,13 +4,6 @@ require 'newbase/active_model/serializer_support'
|
||||
module ActiveModel
|
||||
module SerializerSupport
|
||||
class Test < ActiveModel::TestCase
|
||||
class Model
|
||||
include ActiveModel::SerializerSupport
|
||||
end
|
||||
|
||||
class ModelSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def test_active_model_returns_its_serializer
|
||||
assert_equal ModelSerializer, Model.new.active_model_serializer
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user