mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Use Minitest::Test instead of ActiveModel::TestCase
This commit is contained in:
parent
cec7980208
commit
1ec499bd64
2
Gemfile
2
Gemfile
@ -22,4 +22,4 @@ platforms :rbx do
|
|||||||
gem 'racc', '~> 1.4.10'
|
gem 'racc', '~> 1.4.10'
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'rails', "~> 4.0.0"
|
gem 'rails', '~> 4.0.0'
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'fixtures/active_record'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class ActiveRecordTest < ActiveModel::TestCase
|
class ActiveRecordTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@post = ARPost.first
|
@post = ARPost.first
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,6 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||||||
run_generator
|
run_generator
|
||||||
|
|
||||||
assert_file 'app/controllers/accounts_controller.rb' do |content|
|
assert_file 'app/controllers/accounts_controller.rb' do |content|
|
||||||
|
|
||||||
assert_instance_method :index, content do |m|
|
assert_instance_method :index, content do |m|
|
||||||
assert_match /@accounts = Account\.all/, m
|
assert_match /@accounts = Account\.all/, m
|
||||||
assert_match /format.html/, m
|
assert_match /format.html/, m
|
||||||
@ -60,8 +59,6 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||||||
|
|
||||||
assert_match(/def account_params/, content)
|
assert_match(/def account_params/, content)
|
||||||
assert_match(/params\.require\(:account\)\.permit\(:name, :description, :business_id\)/, content)
|
assert_match(/params\.require\(:account\)\.permit\(:name, :description, :business_id\)/, content)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,6 +4,9 @@ require 'minitest/autorun'
|
|||||||
require 'active_model_serializers'
|
require 'active_model_serializers'
|
||||||
require 'fixtures/poro'
|
require 'fixtures/poro'
|
||||||
|
|
||||||
|
# Ensure backward compatibility with Minitest 4
|
||||||
|
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
||||||
|
|
||||||
module TestHelper
|
module TestHelper
|
||||||
Routes = ActionDispatch::Routing::RouteSet.new
|
Routes = ActionDispatch::Routing::RouteSet.new
|
||||||
Routes.draw do
|
Routes.draw do
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'active_model/serializer'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class ArraySerializer
|
class ArraySerializer
|
||||||
class MetaTest < ActiveModel::TestCase
|
class MetaTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
@profile2 = Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
|
@profile2 = Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class ArraySerializer
|
class ArraySerializer
|
||||||
class RootAsOptionTest < ActiveModel::TestCase
|
class RootAsOptionTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@old_root = ArraySerializer._root
|
@old_root = ArraySerializer._root
|
||||||
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
@ -50,7 +50,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RootInSerializerTest < ActiveModel::TestCase
|
class RootInSerializerTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@old_root = ArraySerializer._root
|
@old_root = ArraySerializer._root
|
||||||
ArraySerializer._root = :in_serializer
|
ArraySerializer._root = :in_serializer
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class ArraySerializer
|
class ArraySerializer
|
||||||
class ScopeTest < ActiveModel::TestCase
|
class ScopeTest < Minitest::Test
|
||||||
def test_array_serializer_pass_options_to_items_serializers
|
def test_array_serializer_pass_options_to_items_serializers
|
||||||
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||||
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
||||||
|
|||||||
@ -2,10 +2,10 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class ArraySerializer
|
class ArraySerializer
|
||||||
class BasicObjectsSerializationTest < ActiveModel::TestCase
|
class BasicObjectsSerializationTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
array = [1, 2, 3]
|
array = [1, 2, 3]
|
||||||
@serializer = ActiveModel::Serializer.serializer_for(array).new(array)
|
@serializer = Serializer.serializer_for(array).new(array)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_serializer_for_array_returns_appropriate_type
|
def test_serializer_for_array_returns_appropriate_type
|
||||||
@ -18,7 +18,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ModelSerializationTest < ActiveModel::TestCase
|
class ModelSerializationTest < Minitest::Test
|
||||||
def test_array_serializer_serializes_models
|
def test_array_serializer_serializes_models
|
||||||
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||||
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class DefaultSerializer
|
class DefaultSerializer
|
||||||
class Test < ActiveModel::TestCase
|
class Test < Minitest::Test
|
||||||
def test_serialize_objects
|
def test_serialize_objects
|
||||||
assert_equal(nil, DefaultSerializer.new(nil).serializable_object)
|
assert_equal(nil, DefaultSerializer.new(nil).serializable_object)
|
||||||
assert_equal(1, DefaultSerializer.new(1).serializable_object)
|
assert_equal(1, DefaultSerializer.new(1).serializable_object)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'test_helper'
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class Association
|
class Association
|
||||||
class BuildSerializerTest < ActiveModel::TestCase
|
class BuildSerializerTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@association = Association::HasOne.new('post', serializer: PostSerializer)
|
@association = Association::HasOne.new('post', serializer: PostSerializer)
|
||||||
@post = Post.new({ title: 'Title 1', body: 'Body 1', date: '1/1/2000' })
|
@post = Post.new({ title: 'Title 1', body: 'Body 1', date: '1/1/2000' })
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class AssociationsTest < ActiveModel::TestCase
|
class AssociationsTest < Minitest::Test
|
||||||
def test_associations_inheritance
|
def test_associations_inheritance
|
||||||
inherited_serializer_klass = Class.new(PostSerializer) do
|
inherited_serializer_klass = Class.new(PostSerializer) do
|
||||||
has_many :users
|
has_many :users
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class AttributesTest < ActiveModel::TestCase
|
class AttributesTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
@profile_serializer = ProfileSerializer.new(@profile)
|
@profile_serializer = ProfileSerializer.new(@profile)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'test_helper'
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class Config
|
class Config
|
||||||
class Test < ActiveModel::TestCase
|
class Test < Minitest::Test
|
||||||
def test_config_const_is_an_instance_of_config
|
def test_config_const_is_an_instance_of_config
|
||||||
assert_kind_of Config, CONFIG
|
assert_kind_of Config, CONFIG
|
||||||
end
|
end
|
||||||
@ -30,9 +30,9 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ConfigTest < ActiveModel::TestCase
|
class ConfigTest < Minitest::Test
|
||||||
def test_setup
|
def test_setup
|
||||||
ActiveModel::Serializer.setup do |config|
|
Serializer.setup do |config|
|
||||||
config.a = 'v1'
|
config.a = 'v1'
|
||||||
config.b = 'v2'
|
config.b = 'v2'
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_config_accessors
|
def test_config_accessors
|
||||||
ActiveModel::Serializer.setup do |config|
|
Serializer.setup do |config|
|
||||||
config.foo = 'v1'
|
config.foo = 'v1'
|
||||||
config.bar = 'v2'
|
config.bar = 'v2'
|
||||||
end
|
end
|
||||||
@ -63,7 +63,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ApplyConfigTest < ActiveModel::TestCase
|
class ApplyConfigTest < Minitest::Test
|
||||||
def test_apply_config_to_associations
|
def test_apply_config_to_associations
|
||||||
CONFIG.embed = :ids
|
CONFIG.embed = :ids
|
||||||
CONFIG.embed_in_root = true
|
CONFIG.embed_in_root = true
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class FilterAttributesTest < ActiveModel::TestCase
|
class FilterAttributesTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
@profile_serializer = ProfileSerializer.new(@profile)
|
@profile_serializer = ProfileSerializer.new(@profile)
|
||||||
@ -20,7 +20,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FilterAssociationsTest < ActiveModel::TestCase
|
class FilterAssociationsTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@association = PostSerializer._associations[:comments]
|
@association = PostSerializer._associations[:comments]
|
||||||
@old_association = @association.dup
|
@old_association = @association.dup
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class HasManyTest < ActiveModel::TestCase
|
class HasManyTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@association = PostSerializer._associations[:comments]
|
@association = PostSerializer._associations[:comments]
|
||||||
@old_association = @association.dup
|
@old_association = @association.dup
|
||||||
@ -128,7 +128,7 @@ module ActiveModel
|
|||||||
def test_associations_using_a_given_serializer
|
def test_associations_using_a_given_serializer
|
||||||
@association.embed = :ids
|
@association.embed = :ids
|
||||||
@association.embed_in_root = true
|
@association.embed_in_root = true
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::Serializer) do
|
@association.serializer_from_options = Class.new(Serializer) do
|
||||||
def content
|
def content
|
||||||
object.read_attribute_for_serialization(:content) + '!'
|
object.read_attribute_for_serialization(:content) + '!'
|
||||||
end
|
end
|
||||||
@ -145,7 +145,7 @@ module ActiveModel
|
|||||||
def test_associations_embedding_ids_using_a_given_array_serializer
|
def test_associations_embedding_ids_using_a_given_array_serializer
|
||||||
@association.embed = :ids
|
@association.embed = :ids
|
||||||
@association.embed_in_root = true
|
@association.embed_in_root = true
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::ArraySerializer) do
|
@association.serializer_from_options = Class.new(ArraySerializer) do
|
||||||
def serializable_object
|
def serializable_object
|
||||||
{ my_content: ['fake'] }
|
{ my_content: ['fake'] }
|
||||||
end
|
end
|
||||||
@ -158,7 +158,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_associations_embedding_objects_using_a_given_array_serializer
|
def test_associations_embedding_objects_using_a_given_array_serializer
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::ArraySerializer) do
|
@association.serializer_from_options = Class.new(ArraySerializer) do
|
||||||
def serializable_object
|
def serializable_object
|
||||||
{ my_content: ['fake'] }
|
{ my_content: ['fake'] }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class HasOneTest < ActiveModel::TestCase
|
class HasOneTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@association = UserSerializer._associations[:profile]
|
@association = UserSerializer._associations[:profile]
|
||||||
@old_association = @association.dup
|
@old_association = @association.dup
|
||||||
@ -119,7 +119,7 @@ module ActiveModel
|
|||||||
def test_associations_embedding_ids_using_a_given_serializer
|
def test_associations_embedding_ids_using_a_given_serializer
|
||||||
@association.embed = :ids
|
@association.embed = :ids
|
||||||
@association.embed_in_root = true
|
@association.embed_in_root = true
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::Serializer) do
|
@association.serializer_from_options = Class.new(Serializer) do
|
||||||
def name
|
def name
|
||||||
'fake'
|
'fake'
|
||||||
end
|
end
|
||||||
@ -134,7 +134,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_associations_embedding_objects_using_a_given_serializer
|
def test_associations_embedding_objects_using_a_given_serializer
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::Serializer) do
|
@association.serializer_from_options = Class.new(Serializer) do
|
||||||
def name
|
def name
|
||||||
'fake'
|
'fake'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class MetaTest < ActiveModel::TestCase
|
class MetaTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class RootAsOptionTest < ActiveModel::TestCase
|
class RootAsOptionTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@old_root = ProfileSerializer._root
|
@old_root = ProfileSerializer._root
|
||||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||||
@ -70,7 +70,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RootInSerializerTest < ActiveModel::TestCase
|
class RootInSerializerTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@old_root = ProfileSerializer._root
|
@old_root = ProfileSerializer._root
|
||||||
ProfileSerializer._root = :in_serializer
|
ProfileSerializer._root = :in_serializer
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class ScopeTest < ActiveModel::TestCase
|
class ScopeTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@serializer = ProfileSerializer.new(nil, scope: current_user)
|
@serializer = ProfileSerializer.new(nil, scope: current_user)
|
||||||
end
|
end
|
||||||
@ -18,7 +18,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NestedScopeTest < ActiveModel::TestCase
|
class NestedScopeTest < Minitest::Test
|
||||||
def setup
|
def setup
|
||||||
@association = UserSerializer._associations[:profile]
|
@association = UserSerializer._associations[:profile]
|
||||||
@old_association = @association.dup
|
@old_association = @association.dup
|
||||||
@ -31,7 +31,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_scope_passed_through
|
def test_scope_passed_through
|
||||||
@association.serializer_from_options = Class.new(ActiveModel::Serializer) do
|
@association.serializer_from_options = Class.new(Serializer) do
|
||||||
def name
|
def name
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user