cheap_ams 0.10.5 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +315 -0
- data/.simplecov +99 -0
- data/.travis.yml +8 -0
- data/Gemfile +10 -1
- data/README.md +4 -16
- data/Rakefile +29 -2
- data/cheap_ams.gemspec +3 -2
- data/docs/README.md +1 -0
- data/docs/general/configuration_options.md +11 -0
- data/lib/action_controller/serialization.rb +2 -2
- data/lib/active_model/serializable_resource.rb +0 -2
- data/lib/active_model/serializer/adapter/fragment_cache.rb +3 -4
- data/lib/active_model/serializer/adapter/json/fragment_cache.rb +0 -2
- data/lib/active_model/serializer/adapter/json.rb +0 -1
- data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +2 -4
- data/lib/active_model/serializer/adapter/json_api.rb +87 -93
- data/lib/active_model/serializer/adapter.rb +4 -4
- data/lib/active_model/serializer/array_serializer.rb +11 -12
- data/lib/active_model/serializer/association.rb +0 -1
- data/lib/active_model/serializer/fieldset.rb +2 -4
- data/lib/active_model/serializer/lint.rb +2 -4
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +0 -25
- data/lib/active_model_serializers.rb +0 -1
- data/lib/generators/serializer/serializer_generator.rb +7 -7
- data/lib/generators/serializer/templates/{serializer.rb → serializer.rb.erb} +0 -0
- data/lib/tasks/rubocop.rake +0 -0
- data/test/action_controller/adapter_selector_test.rb +3 -3
- data/test/action_controller/explicit_serializer_test.rb +9 -9
- data/test/action_controller/json_api/linked_test.rb +28 -28
- data/test/action_controller/json_api/pagination_test.rb +24 -24
- data/test/action_controller/serialization_test.rb +73 -79
- data/test/adapter/fragment_cache_test.rb +2 -2
- data/test/adapter/json/belongs_to_test.rb +4 -4
- data/test/adapter/json/collection_test.rb +15 -15
- data/test/adapter/json/has_many_test.rb +5 -5
- data/test/adapter/json_api/belongs_to_test.rb +37 -37
- data/test/adapter/json_api/collection_test.rb +22 -23
- data/test/adapter/json_api/has_many_embed_ids_test.rb +2 -2
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +4 -4
- data/test/adapter/json_api/has_many_test.rb +25 -25
- data/test/adapter/json_api/has_one_test.rb +10 -10
- data/test/adapter/json_api/json_api_test.rb +6 -7
- data/test/adapter/json_api/linked_test.rb +69 -69
- data/test/adapter/json_api/pagination_links_test.rb +8 -8
- data/test/adapter/json_api/resource_type_config_test.rb +14 -14
- data/test/adapter/json_test.rb +7 -7
- data/test/adapter_test.rb +2 -2
- data/test/array_serializer_test.rb +11 -7
- data/test/capture_warnings.rb +8 -7
- data/test/fixtures/active_record.rb +0 -1
- data/test/fixtures/poro.rb +7 -12
- data/test/generators/scaffold_controller_generator_test.rb +1 -2
- data/test/generators/serializer_generator_test.rb +10 -10
- data/test/lint_test.rb +0 -7
- data/test/serializers/adapter_for_test.rb +0 -1
- data/test/serializers/associations_test.rb +4 -4
- data/test/serializers/attribute_test.rb +7 -7
- data/test/serializers/attributes_test.rb +8 -14
- data/test/serializers/cache_test.rb +8 -7
- data/test/serializers/fieldset_test.rb +3 -4
- data/test/serializers/meta_test.rb +23 -23
- data/test/serializers/root_test.rb +1 -3
- data/test/serializers/serializer_for_test.rb +1 -1
- data/test/support/serialization_testing.rb +13 -0
- data/test/support/simplecov.rb +6 -0
- data/test/support/stream_capture.rb +2 -2
- data/test/test_helper.rb +14 -2
- metadata +13 -6
- data/test/serializers/urls_test.rb +0 -26
data/test/lint_test.rb
CHANGED
@@ -7,27 +7,21 @@ module ActiveModel
|
|
7
7
|
|
8
8
|
class CompliantResource
|
9
9
|
def serializable_hash(options = nil)
|
10
|
-
|
11
10
|
end
|
12
11
|
|
13
12
|
def read_attribute_for_serialization(name)
|
14
|
-
|
15
13
|
end
|
16
14
|
|
17
15
|
def as_json(options = nil)
|
18
|
-
|
19
16
|
end
|
20
17
|
|
21
18
|
def to_json(options = nil)
|
22
|
-
|
23
19
|
end
|
24
20
|
|
25
21
|
def cache_key
|
26
|
-
|
27
22
|
end
|
28
23
|
|
29
24
|
def id
|
30
|
-
|
31
25
|
end
|
32
26
|
|
33
27
|
def self.model_name
|
@@ -38,7 +32,6 @@ module ActiveModel
|
|
38
32
|
def setup
|
39
33
|
@resource = CompliantResource.new
|
40
34
|
end
|
41
|
-
|
42
35
|
end
|
43
36
|
end
|
44
37
|
end
|
@@ -4,7 +4,7 @@ module ActiveModel
|
|
4
4
|
class Serializer
|
5
5
|
class AssociationsTest < Minitest::Test
|
6
6
|
class Model
|
7
|
-
def initialize(hash={})
|
7
|
+
def initialize(hash = {})
|
8
8
|
@attributes = hash
|
9
9
|
end
|
10
10
|
|
@@ -29,7 +29,7 @@ module ActiveModel
|
|
29
29
|
@author.roles = []
|
30
30
|
@blog = Blog.new({ name: 'AMS Blog' })
|
31
31
|
@post = Post.new({ title: 'New Post', body: 'Body' })
|
32
|
-
@tag = Tag.new({name: '#hashtagged'})
|
32
|
+
@tag = Tag.new({ name: '#hashtagged' })
|
33
33
|
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
34
34
|
@post.comments = [@comment]
|
35
35
|
@post.tags = [@tag]
|
@@ -39,7 +39,7 @@ module ActiveModel
|
|
39
39
|
@post.author = @author
|
40
40
|
@author.posts = [@post]
|
41
41
|
|
42
|
-
@post_serializer = PostSerializer.new(@post, {custom_options: true})
|
42
|
+
@post_serializer = PostSerializer.new(@post, { custom_options: true })
|
43
43
|
@author_serializer = AuthorSerializer.new(@author)
|
44
44
|
@comment_serializer = CommentSerializer.new(@comment)
|
45
45
|
end
|
@@ -74,7 +74,7 @@ module ActiveModel
|
|
74
74
|
|
75
75
|
assert_equal key, :tags
|
76
76
|
assert_equal serializer, nil
|
77
|
-
assert_equal [{ attributes: { name:
|
77
|
+
assert_equal [{ attributes: { name: '#hashtagged' } }].to_json, options[:virtual_value].to_json
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -4,25 +4,25 @@ module ActiveModel
|
|
4
4
|
class Serializer
|
5
5
|
class AttributeTest < Minitest::Test
|
6
6
|
def setup
|
7
|
-
@blog = Blog.new({ id: 1, name: 'AMS Hints', type:
|
7
|
+
@blog = Blog.new({ id: 1, name: 'AMS Hints', type: 'stuff' })
|
8
8
|
@blog_serializer = AlternateBlogSerializer.new(@blog)
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_attributes_definition
|
12
12
|
assert_equal([:id, :title],
|
13
|
-
|
13
|
+
@blog_serializer.class._attributes)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_json_serializable_hash
|
17
17
|
adapter = ActiveModel::Serializer::Adapter::Json.new(@blog_serializer)
|
18
|
-
assert_equal({blog: { id:1, title:
|
18
|
+
assert_equal({ blog: { id: 1, title: 'AMS Hints' } }, adapter.serializable_hash)
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_attribute_inheritance_with_key
|
22
22
|
inherited_klass = Class.new(AlternateBlogSerializer)
|
23
23
|
blog_serializer = inherited_klass.new(@blog)
|
24
24
|
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(blog_serializer)
|
25
|
-
assert_equal({:id=>1, :title=>
|
25
|
+
assert_equal({ :id => 1, :title => 'AMS Hints' }, adapter.serializable_hash)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_multiple_calls_with_the_same_attribute
|
@@ -40,7 +40,7 @@ module ActiveModel
|
|
40
40
|
end
|
41
41
|
|
42
42
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer.new(@blog))
|
43
|
-
assert_equal({ blog: { id:
|
43
|
+
assert_equal({ blog: { id: 'AMS Hints' } }, adapter.serializable_hash)
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_type_attribute
|
@@ -52,10 +52,10 @@ module ActiveModel
|
|
52
52
|
end
|
53
53
|
|
54
54
|
adapter = ActiveModel::Serializer::Adapter::Json.new(attribute_serializer.new(@blog))
|
55
|
-
assert_equal({ blog: { type: 1} }, adapter.serializable_hash)
|
55
|
+
assert_equal({ blog: { type: 1 } }, adapter.serializable_hash)
|
56
56
|
|
57
57
|
adapter = ActiveModel::Serializer::Adapter::Json.new(attributes_serializer.new(@blog))
|
58
|
-
assert_equal({ blog: { type:
|
58
|
+
assert_equal({ blog: { type: 'stuff' } }, adapter.serializable_hash)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -6,7 +6,7 @@ module ActiveModel
|
|
6
6
|
def setup
|
7
7
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
8
8
|
@profile_serializer = ProfileSerializer.new(@profile)
|
9
|
-
@comment = Comment.new(id: 1, body:
|
9
|
+
@comment = Comment.new(id: 1, body: 'ZOMG!!', date: '2015')
|
10
10
|
@serializer_klass = Class.new(CommentSerializer)
|
11
11
|
@serializer_klass_with_new_attributes = Class.new(CommentSerializer) do
|
12
12
|
attributes :date, :likes
|
@@ -15,18 +15,12 @@ module ActiveModel
|
|
15
15
|
|
16
16
|
def test_attributes_definition
|
17
17
|
assert_equal([:name, :description],
|
18
|
-
|
18
|
+
@profile_serializer.class._attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_attributes_with_fields_option
|
22
|
-
assert_equal({name: 'Name 1'},
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_required_fields
|
27
|
-
assert_equal({name: 'Name 1', description: 'Description 1'},
|
28
|
-
@profile_serializer.attributes(fields: [:name, :description], required_fields: [:name]))
|
29
|
-
|
22
|
+
assert_equal({ name: 'Name 1' },
|
23
|
+
@profile_serializer.attributes(fields: [:name]))
|
30
24
|
end
|
31
25
|
|
32
26
|
def test_attributes_inheritance_definition
|
@@ -35,8 +29,8 @@ module ActiveModel
|
|
35
29
|
|
36
30
|
def test_attributes_inheritance
|
37
31
|
serializer = @serializer_klass.new(@comment)
|
38
|
-
assert_equal({id: 1, body:
|
39
|
-
|
32
|
+
assert_equal({ id: 1, body: 'ZOMG!!' },
|
33
|
+
serializer.attributes)
|
40
34
|
end
|
41
35
|
|
42
36
|
def test_attribute_inheritance_with_new_attribute_definition
|
@@ -46,8 +40,8 @@ module ActiveModel
|
|
46
40
|
|
47
41
|
def test_attribute_inheritance_with_new_attribute
|
48
42
|
serializer = @serializer_klass_with_new_attributes.new(@comment)
|
49
|
-
assert_equal({id: 1, body:
|
50
|
-
|
43
|
+
assert_equal({ id: 1, body: 'ZOMG!!', date: '2015', likes: nil },
|
44
|
+
serializer.attributes)
|
51
45
|
end
|
52
46
|
|
53
47
|
def test_multiple_calls_with_the_same_attribute
|
@@ -9,7 +9,7 @@ module ActiveModel
|
|
9
9
|
@post = Post.new(title: 'New Post', body: 'Body')
|
10
10
|
@bio = Bio.new(id: 1, content: 'AMS Contributor')
|
11
11
|
@author = Author.new(name: 'Joao M. D. Moura')
|
12
|
-
@blog = Blog.new(id: 999, name:
|
12
|
+
@blog = Blog.new(id: 999, name: 'Custom blog', writer: @author, articles: [])
|
13
13
|
@role = Role.new(name: 'Great Author')
|
14
14
|
@location = Location.new(lat: '-23.550520', lng: '-46.633309')
|
15
15
|
@place = Place.new(name: 'Amazing Place')
|
@@ -58,9 +58,9 @@ module ActiveModel
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_cache_options_definition
|
61
|
-
assert_equal({expires_in: 0.1, skip_digest: true}, @post_serializer.class._cache_options)
|
61
|
+
assert_equal({ expires_in: 0.1, skip_digest: true }, @post_serializer.class._cache_options)
|
62
62
|
assert_equal(nil, @blog_serializer.class._cache_options)
|
63
|
-
assert_equal({expires_in: 1.day, skip_digest: true}, @comment_serializer.class._cache_options)
|
63
|
+
assert_equal({ expires_in: 1.day, skip_digest: true }, @comment_serializer.class._cache_options)
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_fragment_cache_definition
|
@@ -118,7 +118,7 @@ module ActiveModel
|
|
118
118
|
hash = render_object_with_cache(@location)
|
119
119
|
|
120
120
|
assert_equal(hash, expected_result)
|
121
|
-
assert_equal({place: 'Nowhere'}, ActionController::Base.cache_store.fetch(@location.cache_key))
|
121
|
+
assert_equal({ place: 'Nowhere' }, ActionController::Base.cache_store.fetch(@location.cache_key))
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_uses_file_digest_in_cache_key
|
@@ -131,20 +131,20 @@ module ActiveModel
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def test_serializer_file_path_on_nix
|
134
|
-
path =
|
134
|
+
path = '/Users/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb'
|
135
135
|
caller_line = "#{path}:1:in `<top (required)>'"
|
136
136
|
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_serializer_file_path_on_windows
|
140
|
-
path =
|
140
|
+
path = 'c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb'
|
141
141
|
caller_line = "#{path}:1:in `<top (required)>'"
|
142
142
|
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_digest_caller_file
|
146
146
|
contents = "puts 'AMS rocks'!"
|
147
|
-
file = Tempfile.new(
|
147
|
+
file = Tempfile.new('some_ruby.rb')
|
148
148
|
file.write(contents)
|
149
149
|
path = file.path
|
150
150
|
caller_line = "#{path}:1:in `<top (required)>'"
|
@@ -155,6 +155,7 @@ module ActiveModel
|
|
155
155
|
end
|
156
156
|
|
157
157
|
private
|
158
|
+
|
158
159
|
def render_object_with_cache(obj)
|
159
160
|
ActiveModel::SerializableResource.new(obj).serializable_hash
|
160
161
|
end
|
@@ -3,12 +3,11 @@ require 'test_helper'
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
5
|
class FieldsetTest < Minitest::Test
|
6
|
-
|
7
6
|
def test_fieldset_with_hash
|
8
|
-
fieldset = ActiveModel::Serializer::Fieldset.new({'post' =>
|
7
|
+
fieldset = ActiveModel::Serializer::Fieldset.new({ 'post' => %w(id title), 'coment' => ['body'] })
|
9
8
|
|
10
9
|
assert_equal(
|
11
|
-
{:post=>[:id, :title], :coment=>[:body]},
|
10
|
+
{ :post => [:id, :title], :coment => [:body] },
|
12
11
|
fieldset.fields
|
13
12
|
)
|
14
13
|
end
|
@@ -17,7 +16,7 @@ module ActiveModel
|
|
17
16
|
fieldset = ActiveModel::Serializer::Fieldset.new(['title'], 'post')
|
18
17
|
|
19
18
|
assert_equal(
|
20
|
-
{:post => [:title]},
|
19
|
+
{ :post => [:title] },
|
21
20
|
fieldset.fields
|
22
21
|
)
|
23
22
|
end
|
@@ -7,19 +7,19 @@ module ActiveModel
|
|
7
7
|
ActionController::Base.cache_store.clear
|
8
8
|
@blog = Blog.new(id: 1,
|
9
9
|
name: 'AMS Hints',
|
10
|
-
writer: Author.new(id: 2, name:
|
11
|
-
articles: [Post.new(id: 3, title:
|
10
|
+
writer: Author.new(id: 2, name: 'Steve'),
|
11
|
+
articles: [Post.new(id: 3, title: 'AMS')])
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_meta_is_present_with_root
|
15
|
-
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
|
15
|
+
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 })
|
16
16
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
17
17
|
expected = {
|
18
18
|
blog: {
|
19
19
|
id: 1,
|
20
|
-
title:
|
20
|
+
title: 'AMS Hints'
|
21
21
|
},
|
22
|
-
|
22
|
+
'meta' => {
|
23
23
|
total: 10
|
24
24
|
}
|
25
25
|
}
|
@@ -28,23 +28,23 @@ module ActiveModel
|
|
28
28
|
|
29
29
|
def test_meta_is_not_included_when_root_is_missing
|
30
30
|
# load_adapter uses FlattenJson Adapter
|
31
|
-
adapter = load_adapter(meta: {total: 10})
|
31
|
+
adapter = load_adapter(meta: { total: 10 })
|
32
32
|
expected = {
|
33
33
|
id: 1,
|
34
|
-
title:
|
34
|
+
title: 'AMS Hints'
|
35
35
|
}
|
36
36
|
assert_equal expected, adapter.as_json
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_meta_key_is_used
|
40
|
-
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key:
|
40
|
+
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 }, meta_key: 'haha_meta')
|
41
41
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
42
42
|
expected = {
|
43
43
|
blog: {
|
44
44
|
id: 1,
|
45
|
-
title:
|
45
|
+
title: 'AMS Hints'
|
46
46
|
},
|
47
|
-
|
47
|
+
'haha_meta' => {
|
48
48
|
total: 10
|
49
49
|
}
|
50
50
|
}
|
@@ -52,33 +52,33 @@ module ActiveModel
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_meta_key_is_used_with_json_api
|
55
|
-
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key:
|
55
|
+
serializer = AlternateBlogSerializer.new(@blog, meta: { total: 10 }, meta_key: 'haha_meta')
|
56
56
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
57
57
|
expected = {
|
58
58
|
data: {
|
59
|
-
id:
|
60
|
-
type:
|
61
|
-
attributes: { title:
|
59
|
+
id: '1',
|
60
|
+
type: 'blogs',
|
61
|
+
attributes: { title: 'AMS Hints' }
|
62
62
|
},
|
63
|
-
|
63
|
+
'haha_meta' => { total: 10 }
|
64
64
|
}
|
65
65
|
assert_equal expected, adapter.as_json
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_meta_is_not_present_on_arrays_without_root
|
69
|
-
serializer = ArraySerializer.new([@blog], meta: {total: 10})
|
69
|
+
serializer = ArraySerializer.new([@blog], meta: { total: 10 })
|
70
70
|
# FlattenJSON doesn't have support to root
|
71
71
|
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer)
|
72
72
|
expected = [{
|
73
73
|
id: 1,
|
74
|
-
name:
|
74
|
+
name: 'AMS Hints',
|
75
75
|
writer: {
|
76
76
|
id: 2,
|
77
|
-
name:
|
77
|
+
name: 'Steve'
|
78
78
|
},
|
79
79
|
articles: [{
|
80
80
|
id: 3,
|
81
|
-
title:
|
81
|
+
title: 'AMS',
|
82
82
|
body: nil
|
83
83
|
}]
|
84
84
|
}]
|
@@ -86,20 +86,20 @@ module ActiveModel
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_meta_is_present_on_arrays_with_root
|
89
|
-
serializer = ArraySerializer.new([@blog], meta: {total: 10}, meta_key:
|
89
|
+
serializer = ArraySerializer.new([@blog], meta: { total: 10 }, meta_key: 'haha_meta')
|
90
90
|
# JSON adapter adds root by default
|
91
91
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
92
92
|
expected = {
|
93
93
|
blogs: [{
|
94
94
|
id: 1,
|
95
|
-
name:
|
95
|
+
name: 'AMS Hints',
|
96
96
|
writer: {
|
97
97
|
id: 2,
|
98
|
-
name:
|
98
|
+
name: 'Steve'
|
99
99
|
},
|
100
100
|
articles: [{
|
101
101
|
id: 3,
|
102
|
-
title:
|
102
|
+
title: 'AMS',
|
103
103
|
body: nil
|
104
104
|
}]
|
105
105
|
}],
|
@@ -3,13 +3,12 @@ require 'test_helper'
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
5
|
class RootTest < Minitest::Test
|
6
|
-
|
7
6
|
def setup
|
8
7
|
@virtual_value = VirtualValue.new(id: 1)
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_overwrite_root
|
12
|
-
serializer = VirtualValueSerializer.new(@virtual_value, {root: 'smth'})
|
11
|
+
serializer = VirtualValueSerializer.new(@virtual_value, { root: 'smth' })
|
13
12
|
assert_equal('smth', serializer.json_key)
|
14
13
|
end
|
15
14
|
|
@@ -17,7 +16,6 @@ module ActiveModel
|
|
17
16
|
serializer = VirtualValueSerializer.new(@virtual_value)
|
18
17
|
assert_equal('virtual_value', serializer.json_key)
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Minitest::Test
|
2
|
+
def before_setup
|
3
|
+
ActionController::Base.cache_store.clear
|
4
|
+
end
|
5
|
+
|
6
|
+
def with_adapter(adapter)
|
7
|
+
old_adapter = ActiveModel::Serializer.config.adapter
|
8
|
+
ActiveModel::Serializer.config.adapter = adapter
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
ActiveModel::Serializer.config.adapter = old_adapter
|
12
|
+
end
|
13
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Use cleaner stream testing interface from Rails 5 if available
|
2
2
|
# see https://github.com/rails/rails/blob/29959eb59d/activesupport/lib/active_support/testing/stream.rb
|
3
3
|
begin
|
4
|
-
require
|
4
|
+
require 'active_support/testing/stream'
|
5
5
|
rescue LoadError
|
6
6
|
module ActiveSupport
|
7
7
|
module Testing
|
@@ -29,7 +29,7 @@ rescue LoadError
|
|
29
29
|
def capture(stream)
|
30
30
|
stream = stream.to_s
|
31
31
|
captured_stream = Tempfile.new(stream)
|
32
|
-
stream_io = eval("$#{stream}")
|
32
|
+
stream_io = eval("$#{stream}") # rubocop:disable Lint/Eval
|
33
33
|
origin_stream = stream_io.dup
|
34
34
|
stream_io.reopen(captured_stream)
|
35
35
|
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
# HACK: till https://github.com/colszowka/simplecov/pull/400 is merged and released.
|
6
|
+
# Otherwise you may get:
|
7
|
+
# simplecov-0.10.0/lib/simplecov/defaults.rb:50: warning: global variable `$ERROR_INFO' not initialized
|
8
|
+
require 'support/simplecov'
|
9
|
+
AppCoverage.start
|
10
|
+
rescue LoadError
|
11
|
+
STDERR.puts 'Running without SimpleCov'
|
12
|
+
end
|
13
|
+
|
3
14
|
require 'timecop'
|
4
15
|
require 'rails'
|
5
16
|
require 'action_controller'
|
@@ -13,7 +24,6 @@ require 'minitest/autorun'
|
|
13
24
|
# Ensure backward compatibility with Minitest 4
|
14
25
|
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
15
26
|
|
16
|
-
|
17
27
|
require 'capture_warnings'
|
18
28
|
@capture_warnings = CaptureWarnings.new(fail_build = true)
|
19
29
|
@capture_warnings.before_tests
|
@@ -23,7 +33,7 @@ if Minitest.respond_to?(:after_run)
|
|
23
33
|
end
|
24
34
|
else
|
25
35
|
at_exit do
|
26
|
-
STDOUT.puts
|
36
|
+
STDOUT.puts 'Minitest.after_run not available.'
|
27
37
|
@capture_warnings.after_tests
|
28
38
|
end
|
29
39
|
end
|
@@ -36,6 +46,8 @@ require 'support/rails_app'
|
|
36
46
|
|
37
47
|
require 'support/test_case'
|
38
48
|
|
49
|
+
require 'support/serialization_testing'
|
50
|
+
|
39
51
|
require 'fixtures/active_record'
|
40
52
|
|
41
53
|
require 'fixtures/poro'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheap_ams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -117,6 +117,9 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".rubocop_todo.yml"
|
122
|
+
- ".simplecov"
|
120
123
|
- ".travis.yml"
|
121
124
|
- CHANGELOG.md
|
122
125
|
- CONTRIBUTING.md
|
@@ -128,6 +131,7 @@ files:
|
|
128
131
|
- cheap_ams.gemspec
|
129
132
|
- docs/README.md
|
130
133
|
- docs/general/adapters.md
|
134
|
+
- docs/general/configuration_options.md
|
131
135
|
- docs/general/getting_started.md
|
132
136
|
- docs/howto/add_pagination_links.md
|
133
137
|
- docs/howto/add_root_key.md
|
@@ -161,7 +165,8 @@ files:
|
|
161
165
|
- lib/generators/serializer/USAGE
|
162
166
|
- lib/generators/serializer/resource_override.rb
|
163
167
|
- lib/generators/serializer/serializer_generator.rb
|
164
|
-
- lib/generators/serializer/templates/serializer.rb
|
168
|
+
- lib/generators/serializer/templates/serializer.rb.erb
|
169
|
+
- lib/tasks/rubocop.rake
|
165
170
|
- test/action_controller/adapter_selector_test.rb
|
166
171
|
- test/action_controller/explicit_serializer_test.rb
|
167
172
|
- test/action_controller/json_api/linked_test.rb
|
@@ -206,12 +211,13 @@ files:
|
|
206
211
|
- test/serializers/options_test.rb
|
207
212
|
- test/serializers/root_test.rb
|
208
213
|
- test/serializers/serializer_for_test.rb
|
209
|
-
- test/serializers/urls_test.rb
|
210
214
|
- test/support/rails_app.rb
|
215
|
+
- test/support/serialization_testing.rb
|
216
|
+
- test/support/simplecov.rb
|
211
217
|
- test/support/stream_capture.rb
|
212
218
|
- test/support/test_case.rb
|
213
219
|
- test/test_helper.rb
|
214
|
-
homepage:
|
220
|
+
homepage: https://github.com/rails-api/active_model_serializers
|
215
221
|
licenses:
|
216
222
|
- MIT
|
217
223
|
metadata: {}
|
@@ -280,8 +286,9 @@ test_files:
|
|
280
286
|
- test/serializers/options_test.rb
|
281
287
|
- test/serializers/root_test.rb
|
282
288
|
- test/serializers/serializer_for_test.rb
|
283
|
-
- test/serializers/urls_test.rb
|
284
289
|
- test/support/rails_app.rb
|
290
|
+
- test/support/serialization_testing.rb
|
291
|
+
- test/support/simplecov.rb
|
285
292
|
- test/support/stream_capture.rb
|
286
293
|
- test/support/test_case.rb
|
287
294
|
- test/test_helper.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActiveModel
|
4
|
-
class Serializer
|
5
|
-
class UrlsTest < Minitest::Test
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
9
|
-
@post = Post.new({ title: 'New Post', body: 'Body' })
|
10
|
-
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
11
|
-
@post.comments = [@comment]
|
12
|
-
|
13
|
-
@profile_serializer = ProfileSerializer.new(@profile)
|
14
|
-
@post_serializer = PostSerializer.new(@post)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_urls_definition
|
18
|
-
assert_equal([:posts, :comments], @profile_serializer.class._urls)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_url_definition
|
22
|
-
assert_equal([:comments], @post_serializer.class._urls)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|