Tests refactor

This commit is contained in:
Santiago Pastorino 2013-07-02 14:30:42 -07:00
parent b6f9c5ee43
commit 45453f638b
3 changed files with 47 additions and 37 deletions

View File

@ -1,23 +1,23 @@
require 'newbase/test_helper'
require 'newbase/active_model/serializer'
module SerializerTest
module Attributes
class Model
def initialize(hash={})
@attributes = hash
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
def read_attribute_for_serialization(name)
@attributes[name]
class ModelSerializer < ActiveModel::Serializer
attributes :attr1, :attr2
end
end
class ModelSerializer < ActiveModel::Serializer
attributes :attr1, :attr2
end
class Test < ActiveModel::TestCase
def setup
model = Model.new({ :attr1 => 'value1', :attr2 => 'value2', :attr3 => 'value3' })
@model_serializer = ModelSerializer.new(model)

View File

@ -1,19 +1,19 @@
require 'newbase/test_helper'
require 'newbase/active_model/serializer'
module SerializerTest
module Root
class Model
def initialize(hash={})
@attributes = hash
end
def read_attribute_for_serialization(name)
@attributes[name]
end
end
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
@ -58,6 +58,16 @@ module SerializerTest
end
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
root :in_serializer
attributes :attr1, :attr2

View File

@ -1,22 +1,22 @@
require 'newbase/test_helper'
require 'newbase/active_model/serializer'
module SerializerTest
module Scope
class Model
def initialize(hash={})
@attributes = hash
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
def read_attribute_for_serialization(name)
@attributes[name]
class ModelSerializer < ActiveModel::Serializer
end
end
class ModelSerializer < ActiveModel::Serializer
end
class Test < ActiveModel::TestCase
def setup
@serializer = ModelSerializer.new(nil, scope: current_user)
end