active_model_serializers 0.8.3 → 0.10.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +19 -20
- data/CHANGELOG.md +8 -67
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +14 -1
- data/{MIT-LICENSE.txt → LICENSE.txt} +3 -2
- data/README.md +166 -495
- data/Rakefile +6 -12
- data/active_model_serializers.gemspec +21 -19
- data/lib/action_controller/serialization.rb +28 -27
- data/lib/active_model/serializer/adapter/fragment_cache.rb +78 -0
- data/lib/active_model/serializer/adapter/json/fragment_cache.rb +15 -0
- data/lib/active_model/serializer/adapter/json.rb +52 -0
- data/lib/active_model/serializer/adapter/json_api/fragment_cache.rb +22 -0
- data/lib/active_model/serializer/adapter/json_api.rb +152 -0
- data/lib/active_model/serializer/adapter/null.rb +11 -0
- data/lib/active_model/serializer/adapter.rb +87 -0
- data/lib/active_model/serializer/array_serializer.rb +32 -0
- data/lib/active_model/serializer/configuration.rb +13 -0
- data/lib/active_model/serializer/fieldset.rb +40 -0
- data/lib/active_model/{serializers → serializer}/version.rb +1 -1
- data/lib/active_model/serializer.rb +179 -436
- data/lib/active_model_serializers.rb +9 -86
- data/lib/generators/serializer/USAGE +0 -3
- data/lib/generators/serializer/serializer_generator.rb +1 -6
- data/lib/generators/serializer/templates/serializer.rb +2 -13
- data/test/action_controller/adapter_selector_test.rb +51 -0
- data/test/action_controller/explicit_serializer_test.rb +110 -0
- data/test/action_controller/json_api_linked_test.rb +173 -0
- data/test/{serialization_scope_name_test.rb → action_controller/serialization_scope_name_test.rb} +7 -11
- data/test/action_controller/serialization_test.rb +365 -0
- data/test/adapter/fragment_cache_test.rb +27 -0
- data/test/adapter/json/belongs_to_test.rb +41 -0
- data/test/adapter/json/collection_test.rb +59 -0
- data/test/adapter/json/has_many_test.rb +36 -0
- data/test/adapter/json_api/belongs_to_test.rb +147 -0
- data/test/adapter/json_api/collection_test.rb +89 -0
- data/test/adapter/json_api/has_many_embed_ids_test.rb +45 -0
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +98 -0
- data/test/adapter/json_api/has_many_test.rb +106 -0
- data/test/adapter/json_api/has_one_test.rb +59 -0
- data/test/adapter/json_api/linked_test.rb +257 -0
- data/test/adapter/json_test.rb +34 -0
- data/test/adapter/null_test.rb +25 -0
- data/test/adapter_test.rb +43 -0
- data/test/array_serializer_test.rb +21 -67
- data/test/fixtures/poro.rb +206 -0
- data/test/serializers/adapter_for_test.rb +50 -0
- data/test/serializers/associations_test.rb +106 -0
- data/test/serializers/attribute_test.rb +23 -0
- data/test/serializers/attributes_test.rb +28 -0
- data/test/serializers/cache_test.rb +128 -0
- data/test/serializers/configuration_test.rb +15 -0
- data/test/serializers/fieldset_test.rb +26 -0
- data/test/{generators_test.rb → serializers/generators_test.rb} +1 -27
- data/test/serializers/meta_test.rb +78 -0
- data/test/serializers/options_test.rb +21 -0
- data/test/serializers/serializer_for_test.rb +56 -0
- data/test/serializers/urls_test.rb +26 -0
- data/test/test_helper.rb +22 -13
- metadata +101 -42
- data/DESIGN.textile +0 -586
- data/Gemfile.edge +0 -9
- data/bench/perf.rb +0 -43
- data/cruft.md +0 -19
- data/lib/active_model/array_serializer.rb +0 -104
- data/lib/active_model/serializer/associations.rb +0 -233
- data/lib/active_record/serializer_override.rb +0 -16
- data/lib/generators/resource_override.rb +0 -13
- data/test/association_test.rb +0 -592
- data/test/caching_test.rb +0 -96
- data/test/no_serialization_scope_test.rb +0 -34
- data/test/serialization_test.rb +0 -392
- data/test/serializer_support_test.rb +0 -51
- data/test/serializer_test.rb +0 -1465
- data/test/test_fakes.rb +0 -217
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
module ActiveModel
|
3
|
+
class Serializer
|
4
|
+
class CacheTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
ActionController::Base.cache_store.clear
|
7
|
+
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
8
|
+
@blog = Blog.new(id: 999, name: "Custom blog")
|
9
|
+
@post = Post.new(title: 'New Post', body: 'Body')
|
10
|
+
@bio = Bio.new(id: 1, content: 'AMS Contributor')
|
11
|
+
@author = Author.new(name: 'Joao M. D. Moura')
|
12
|
+
@role = Role.new(name: 'Great Author')
|
13
|
+
@location = Location.new(lat: '-23.550520', lng: '-46.633309')
|
14
|
+
@place = Place.new(name: 'Amazing Place')
|
15
|
+
@author.posts = [@post]
|
16
|
+
@author.roles = [@role]
|
17
|
+
@role.author = @author
|
18
|
+
@author.bio = @bio
|
19
|
+
@bio.author = @author
|
20
|
+
@post.comments = [@comment]
|
21
|
+
@post.author = @author
|
22
|
+
@comment.post = @post
|
23
|
+
@comment.author = @author
|
24
|
+
@post.blog = @blog
|
25
|
+
@location.place = @place
|
26
|
+
|
27
|
+
@location_serializer = LocationSerializer.new(@location)
|
28
|
+
@bio_serializer = BioSerializer.new(@bio)
|
29
|
+
@role_serializer = RoleSerializer.new(@role)
|
30
|
+
@post_serializer = PostSerializer.new(@post)
|
31
|
+
@author_serializer = AuthorSerializer.new(@author)
|
32
|
+
@comment_serializer = CommentSerializer.new(@comment)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_cache_definition
|
36
|
+
assert_equal(ActionController::Base.cache_store, @post_serializer.class._cache)
|
37
|
+
assert_equal(ActionController::Base.cache_store, @author_serializer.class._cache)
|
38
|
+
assert_equal(ActionController::Base.cache_store, @comment_serializer.class._cache)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_cache_key_definition
|
42
|
+
assert_equal('post', @post_serializer.class._cache_key)
|
43
|
+
assert_equal('writer', @author_serializer.class._cache_key)
|
44
|
+
assert_equal(nil, @comment_serializer.class._cache_key)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_cache_key_interpolation_with_updated_at
|
48
|
+
author = render_object_with_cache(@author)
|
49
|
+
assert_equal(nil, ActionController::Base.cache_store.fetch(@author.cache_key))
|
50
|
+
assert_equal(@author_serializer.attributes.to_json, ActionController::Base.cache_store.fetch("#{@author_serializer.class._cache_key}/#{@author_serializer.object.id}-#{@author_serializer.object.updated_at}").to_json)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_default_cache_key_fallback
|
54
|
+
comment = render_object_with_cache(@comment)
|
55
|
+
assert_equal(@comment_serializer.attributes.to_json, ActionController::Base.cache_store.fetch(@comment.cache_key).to_json)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_cache_options_definition
|
59
|
+
assert_equal({expires_in: 0.1}, @post_serializer.class._cache_options)
|
60
|
+
assert_equal(nil, @author_serializer.class._cache_options)
|
61
|
+
assert_equal({expires_in: 1.day}, @comment_serializer.class._cache_options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_fragment_cache_definition
|
65
|
+
assert_equal([:name], @role_serializer.class._cache_only)
|
66
|
+
assert_equal([:content], @bio_serializer.class._cache_except)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_associations_separately_cache
|
70
|
+
ActionController::Base.cache_store.clear
|
71
|
+
assert_equal(nil, ActionController::Base.cache_store.fetch(@post.cache_key))
|
72
|
+
assert_equal(nil, ActionController::Base.cache_store.fetch(@comment.cache_key))
|
73
|
+
|
74
|
+
post = render_object_with_cache(@post)
|
75
|
+
|
76
|
+
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
|
77
|
+
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_associations_cache_when_updated
|
81
|
+
# Clean the Cache
|
82
|
+
ActionController::Base.cache_store.clear
|
83
|
+
|
84
|
+
# Generate a new Cache of Post object and each objects related to it.
|
85
|
+
render_object_with_cache(@post)
|
86
|
+
|
87
|
+
# Check if if cache the objects separately
|
88
|
+
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
|
89
|
+
assert_equal(@comment_serializer.attributes, ActionController::Base.cache_store.fetch(@comment.cache_key))
|
90
|
+
|
91
|
+
# Simulating update on comments relationship with Post
|
92
|
+
new_comment = Comment.new(id: 2, body: 'ZOMG A NEW COMMENT')
|
93
|
+
new_comment_serializer = CommentSerializer.new(new_comment)
|
94
|
+
@post.comments = [new_comment]
|
95
|
+
|
96
|
+
# Ask for the serialized object
|
97
|
+
render_object_with_cache(@post)
|
98
|
+
|
99
|
+
# Check if the the new comment was cached
|
100
|
+
assert_equal(new_comment_serializer.attributes, ActionController::Base.cache_store.fetch(new_comment.cache_key))
|
101
|
+
assert_equal(@post_serializer.attributes, ActionController::Base.cache_store.fetch(@post.cache_key))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_fragment_fetch_with_virtual_associations
|
105
|
+
expected_result = {
|
106
|
+
id: @location.id,
|
107
|
+
lat: @location.lat,
|
108
|
+
lng: @location.lng,
|
109
|
+
place: 'Nowhere'
|
110
|
+
}
|
111
|
+
|
112
|
+
hash = render_object_with_cache(@location)
|
113
|
+
|
114
|
+
assert_equal(hash, expected_result)
|
115
|
+
assert_equal({place: 'Nowhere'}, ActionController::Base.cache_store.fetch(@location.cache_key))
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
def render_object_with_cache(obj)
|
120
|
+
serializer_class = ActiveModel::Serializer.serializer_for(obj)
|
121
|
+
serializer = serializer_class.new(obj)
|
122
|
+
adapter = ActiveModel::Serializer.adapter.new(serializer)
|
123
|
+
adapter.serializable_hash
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class ConfigurationTest < Minitest::Test
|
6
|
+
def test_array_serializer
|
7
|
+
assert_equal ActiveModel::Serializer::ArraySerializer, ActiveModel::Serializer.config.array_serializer
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_default_adapter
|
11
|
+
assert_equal :json, ActiveModel::Serializer.config.adapter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class FieldsetTest < Minitest::Test
|
6
|
+
|
7
|
+
def test_fieldset_with_hash
|
8
|
+
fieldset = ActiveModel::Serializer::Fieldset.new({'post' => ['id', 'title'], 'coment' => ['body']})
|
9
|
+
|
10
|
+
assert_equal(
|
11
|
+
{:post=>[:id, :title], :coment=>[:body]},
|
12
|
+
fieldset.fields
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_fieldset_with_array_of_fields_and_root_name
|
17
|
+
fieldset = ActiveModel::Serializer::Fieldset.new(['title'], 'post')
|
18
|
+
|
19
|
+
assert_equal(
|
20
|
+
{:post => [:title]},
|
21
|
+
fieldset.fields
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
1
|
class Foo < Rails::Application
|
4
2
|
if Rails.version.to_s.start_with? '4'
|
5
3
|
config.eager_load = false
|
@@ -36,30 +34,6 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
|
|
36
34
|
Object.send :remove_const, :ApplicationSerializer
|
37
35
|
end
|
38
36
|
|
39
|
-
def test_serializer_gets_id
|
40
|
-
run_generator
|
41
|
-
|
42
|
-
assert_file "app/serializers/account_serializer.rb" do |content|
|
43
|
-
if RUBY_VERSION =~ /1.8/
|
44
|
-
assert_match /def id/, content
|
45
|
-
else
|
46
|
-
assert_no_match /def id/, content
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# def test_uses_namespace_application_serializer_if_one_exists
|
52
|
-
# Object.const_set(:SerializerNamespace, Module.new)
|
53
|
-
# SerializerNamespace.const_set(:ApplicationSerializer, Class.new)
|
54
|
-
# Rails::Generators.namespace = SerializerNamespace
|
55
|
-
# run_generator
|
56
|
-
# assert_file "app/serializers/serializer_namespace/account_serializer.rb",
|
57
|
-
# /module SerializerNamespace\n class AccountSerializer < ApplicationSerializer/
|
58
|
-
# ensure
|
59
|
-
# Object.send :remove_const, :SerializerNamespace
|
60
|
-
# Rails::Generators.namespace = nil
|
61
|
-
# end
|
62
|
-
|
63
37
|
def test_uses_given_parent
|
64
38
|
Object.const_set(:ApplicationSerializer, Class.new)
|
65
39
|
run_generator ["Account", "--parent=MySerializer"]
|
@@ -72,7 +46,7 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
|
|
72
46
|
run_generator
|
73
47
|
assert_file "app/serializers/account_serializer.rb" do |serializer|
|
74
48
|
assert_match(/^ attributes :id, :name, :description$/, serializer)
|
75
|
-
assert_match(/^
|
49
|
+
assert_match(/^ attribute :business$/, serializer)
|
76
50
|
end
|
77
51
|
end
|
78
52
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class MetaTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
ActionController::Base.cache_store.clear
|
8
|
+
@blog = Blog.new(id: 1,
|
9
|
+
name: 'AMS Hints',
|
10
|
+
writer: Author.new(id: 2, name: "Steve"),
|
11
|
+
articles: [Post.new(id: 3, title: "AMS")])
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_meta_is_present_with_root
|
15
|
+
adapter = load_adapter(root: "blog", meta: {total: 10})
|
16
|
+
expected = {
|
17
|
+
"blog" => {
|
18
|
+
id: 1,
|
19
|
+
title: "AMS Hints"
|
20
|
+
},
|
21
|
+
"meta" => {
|
22
|
+
total: 10
|
23
|
+
}
|
24
|
+
}
|
25
|
+
assert_equal expected, adapter.as_json
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_meta_is_not_included_when_root_is_missing
|
29
|
+
adapter = load_adapter(meta: {total: 10})
|
30
|
+
expected = {
|
31
|
+
id: 1,
|
32
|
+
title: "AMS Hints"
|
33
|
+
}
|
34
|
+
assert_equal expected, adapter.as_json
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_meta_key_is_used
|
38
|
+
adapter = load_adapter(root: "blog", meta: {total: 10}, meta_key: "haha_meta")
|
39
|
+
expected = {
|
40
|
+
"blog" => {
|
41
|
+
id: 1,
|
42
|
+
title: "AMS Hints"
|
43
|
+
},
|
44
|
+
"haha_meta" => {
|
45
|
+
total: 10
|
46
|
+
}
|
47
|
+
}
|
48
|
+
assert_equal expected, adapter.as_json
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_meta_is_not_used_on_arrays
|
52
|
+
serializer = ArraySerializer.new([@blog], root: "blog", meta: {total: 10}, meta_key: "haha_meta")
|
53
|
+
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
54
|
+
expected = [{
|
55
|
+
id: 1,
|
56
|
+
name: "AMS Hints",
|
57
|
+
writer: {
|
58
|
+
id: 2,
|
59
|
+
name: "Steve"
|
60
|
+
},
|
61
|
+
articles: [{
|
62
|
+
id: 3,
|
63
|
+
title: "AMS",
|
64
|
+
body: nil
|
65
|
+
}]
|
66
|
+
}]
|
67
|
+
assert_equal expected, adapter.as_json
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def load_adapter(options)
|
73
|
+
serializer = AlternateBlogSerializer.new(@blog, options)
|
74
|
+
ActiveModel::Serializer::Adapter::Json.new(serializer)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class OptionsTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@profile = Profile.new(name: 'Name 1', description: 'Description 1')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_options_are_accessible
|
11
|
+
@profile_serializer = ProfileSerializer.new(@profile, my_options: :accessible)
|
12
|
+
assert @profile_serializer.arguments_passed_in?
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_no_option_is_passed_in
|
16
|
+
@profile_serializer = ProfileSerializer.new(@profile)
|
17
|
+
refute @profile_serializer.arguments_passed_in?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class SerializerForTest < Minitest::Test
|
6
|
+
class ArraySerializerTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@array = [1, 2, 3]
|
9
|
+
@previous_array_serializer = ActiveModel::Serializer.config.array_serializer
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
ActiveModel::Serializer.config.array_serializer = @previous_array_serializer
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_serializer_for_array
|
17
|
+
serializer = ActiveModel::Serializer.serializer_for(@array)
|
18
|
+
assert_equal ActiveModel::Serializer.config.array_serializer, serializer
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_overwritten_serializer_for_array
|
22
|
+
new_array_serializer = Class.new
|
23
|
+
ActiveModel::Serializer.config.array_serializer = new_array_serializer
|
24
|
+
serializer = ActiveModel::Serializer.serializer_for(@array)
|
25
|
+
assert_equal new_array_serializer, serializer
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class SerializerTest < Minitest::Test
|
30
|
+
class MyProfile < Profile
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup
|
34
|
+
@profile = Profile.new
|
35
|
+
@my_profile = MyProfile.new
|
36
|
+
@model = ::Model.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_serializer_for_existing_serializer
|
40
|
+
serializer = ActiveModel::Serializer.serializer_for(@profile)
|
41
|
+
assert_equal ProfileSerializer, serializer
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_serializer_for_not_existing_serializer
|
45
|
+
serializer = ActiveModel::Serializer.serializer_for(@model)
|
46
|
+
assert_equal nil, serializer
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_serializer_inherited_serializer
|
50
|
+
serializer = ActiveModel::Serializer.serializer_for(@my_profile)
|
51
|
+
assert_equal ProfileSerializer, serializer
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
data/test/test_helper.rb
CHANGED
@@ -1,32 +1,41 @@
|
|
1
|
-
require
|
2
|
-
require "bundler/setup"
|
1
|
+
require 'bundler/setup'
|
3
2
|
|
4
|
-
require
|
3
|
+
require 'rails'
|
4
|
+
require 'action_controller'
|
5
|
+
require 'action_controller/test_case'
|
6
|
+
require 'action_controller/railtie'
|
7
|
+
require 'active_support/json'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
# Ensure backward compatibility with Minitest 4
|
10
|
+
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
11
|
+
|
12
|
+
class Foo < Rails::Application
|
13
|
+
if Rails.version.to_s.start_with? '4'
|
14
|
+
config.action_controller.perform_caching = true
|
15
|
+
ActionController::Base.cache_store = :memory_store
|
16
|
+
end
|
17
|
+
end
|
5
18
|
|
6
19
|
require "active_model_serializers"
|
7
|
-
require "active_support/json"
|
8
|
-
require "minitest/autorun"
|
9
20
|
|
10
|
-
require '
|
21
|
+
require 'fixtures/poro'
|
11
22
|
|
12
23
|
module TestHelper
|
13
24
|
Routes = ActionDispatch::Routing::RouteSet.new
|
14
25
|
Routes.draw do
|
15
|
-
resource :hypermedia
|
16
26
|
get ':controller(/:action(/:id))'
|
17
27
|
get ':controller(/:action)'
|
18
28
|
end
|
19
29
|
|
20
30
|
ActionController::Base.send :include, Routes.url_helpers
|
21
|
-
ActiveModel::Serializer.send :include, Routes.url_helpers
|
22
31
|
end
|
23
32
|
|
24
|
-
|
25
|
-
setup
|
26
|
-
@routes =
|
33
|
+
ActionController::TestCase.class_eval do
|
34
|
+
def setup
|
35
|
+
@routes = TestHelper::Routes
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
|
-
|
31
|
-
|
39
|
+
def def_serializer(&block)
|
40
|
+
Class.new(ActiveModel::Serializer, &block)
|
32
41
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Yehuda Katz
|
7
|
+
- Steve Klabnik
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activemodel
|
@@ -17,44 +16,44 @@ dependencies:
|
|
17
16
|
requirements:
|
18
17
|
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
19
|
+
version: '4.0'
|
21
20
|
type: :runtime
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
24
|
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
26
|
+
version: '4.0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: rails
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
31
|
- - ">="
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
33
|
+
version: '4.0'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
38
|
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
40
|
+
version: '4.0'
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
42
|
+
name: bundler
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
|
-
- - "
|
45
|
+
- - "~>"
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
47
|
+
version: '1.6'
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
|
-
- - "
|
52
|
+
- - "~>"
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
54
|
+
version: '1.6'
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
56
|
+
name: rake
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
59
|
- - ">="
|
@@ -67,10 +66,10 @@ dependencies:
|
|
67
66
|
- - ">="
|
68
67
|
- !ruby/object:Gem::Version
|
69
68
|
version: '0'
|
70
|
-
description:
|
69
|
+
description: ActiveModel::Serializers allows you to generate your JSON in an object-oriented
|
70
|
+
and convention-driven manner.
|
71
71
|
email:
|
72
|
-
-
|
73
|
-
- wycats@gmail.com
|
72
|
+
- steve@steveklabnik.com
|
74
73
|
executables: []
|
75
74
|
extensions: []
|
76
75
|
extra_rdoc_files: []
|
@@ -78,39 +77,66 @@ files:
|
|
78
77
|
- ".gitignore"
|
79
78
|
- ".travis.yml"
|
80
79
|
- CHANGELOG.md
|
81
|
-
-
|
80
|
+
- CONTRIBUTING.md
|
82
81
|
- Gemfile
|
83
|
-
-
|
84
|
-
- MIT-LICENSE.txt
|
82
|
+
- LICENSE.txt
|
85
83
|
- README.md
|
86
84
|
- Rakefile
|
87
85
|
- active_model_serializers.gemspec
|
88
|
-
- bench/perf.rb
|
89
|
-
- cruft.md
|
90
86
|
- lib/action_controller/serialization.rb
|
91
|
-
- lib/active_model/array_serializer.rb
|
92
87
|
- lib/active_model/serializer.rb
|
93
|
-
- lib/active_model/serializer/
|
94
|
-
- lib/active_model/
|
88
|
+
- lib/active_model/serializer/adapter.rb
|
89
|
+
- lib/active_model/serializer/adapter/fragment_cache.rb
|
90
|
+
- lib/active_model/serializer/adapter/json.rb
|
91
|
+
- lib/active_model/serializer/adapter/json/fragment_cache.rb
|
92
|
+
- lib/active_model/serializer/adapter/json_api.rb
|
93
|
+
- lib/active_model/serializer/adapter/json_api/fragment_cache.rb
|
94
|
+
- lib/active_model/serializer/adapter/null.rb
|
95
|
+
- lib/active_model/serializer/array_serializer.rb
|
96
|
+
- lib/active_model/serializer/configuration.rb
|
97
|
+
- lib/active_model/serializer/fieldset.rb
|
98
|
+
- lib/active_model/serializer/version.rb
|
95
99
|
- lib/active_model_serializers.rb
|
96
|
-
- lib/active_record/serializer_override.rb
|
97
|
-
- lib/generators/resource_override.rb
|
98
100
|
- lib/generators/serializer/USAGE
|
99
101
|
- lib/generators/serializer/serializer_generator.rb
|
100
102
|
- lib/generators/serializer/templates/serializer.rb
|
103
|
+
- test/action_controller/adapter_selector_test.rb
|
104
|
+
- test/action_controller/explicit_serializer_test.rb
|
105
|
+
- test/action_controller/json_api_linked_test.rb
|
106
|
+
- test/action_controller/serialization_scope_name_test.rb
|
107
|
+
- test/action_controller/serialization_test.rb
|
108
|
+
- test/adapter/fragment_cache_test.rb
|
109
|
+
- test/adapter/json/belongs_to_test.rb
|
110
|
+
- test/adapter/json/collection_test.rb
|
111
|
+
- test/adapter/json/has_many_test.rb
|
112
|
+
- test/adapter/json_api/belongs_to_test.rb
|
113
|
+
- test/adapter/json_api/collection_test.rb
|
114
|
+
- test/adapter/json_api/has_many_embed_ids_test.rb
|
115
|
+
- test/adapter/json_api/has_many_explicit_serializer_test.rb
|
116
|
+
- test/adapter/json_api/has_many_test.rb
|
117
|
+
- test/adapter/json_api/has_one_test.rb
|
118
|
+
- test/adapter/json_api/linked_test.rb
|
119
|
+
- test/adapter/json_test.rb
|
120
|
+
- test/adapter/null_test.rb
|
121
|
+
- test/adapter_test.rb
|
101
122
|
- test/array_serializer_test.rb
|
102
|
-
- test/
|
103
|
-
- test/
|
104
|
-
- test/
|
105
|
-
- test/
|
106
|
-
- test/
|
107
|
-
- test/
|
108
|
-
- test/
|
109
|
-
- test/
|
110
|
-
- test/
|
123
|
+
- test/fixtures/poro.rb
|
124
|
+
- test/serializers/adapter_for_test.rb
|
125
|
+
- test/serializers/associations_test.rb
|
126
|
+
- test/serializers/attribute_test.rb
|
127
|
+
- test/serializers/attributes_test.rb
|
128
|
+
- test/serializers/cache_test.rb
|
129
|
+
- test/serializers/configuration_test.rb
|
130
|
+
- test/serializers/fieldset_test.rb
|
131
|
+
- test/serializers/generators_test.rb
|
132
|
+
- test/serializers/meta_test.rb
|
133
|
+
- test/serializers/options_test.rb
|
134
|
+
- test/serializers/serializer_for_test.rb
|
135
|
+
- test/serializers/urls_test.rb
|
111
136
|
- test/test_helper.rb
|
112
137
|
homepage: https://github.com/rails-api/active_model_serializers
|
113
|
-
licenses:
|
138
|
+
licenses:
|
139
|
+
- MIT
|
114
140
|
metadata: {}
|
115
141
|
post_install_message:
|
116
142
|
rdoc_options: []
|
@@ -123,14 +149,47 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
149
|
version: '0'
|
124
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
151
|
requirements:
|
126
|
-
- - "
|
152
|
+
- - ">"
|
127
153
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
154
|
+
version: 1.3.1
|
129
155
|
requirements: []
|
130
156
|
rubyforge_project:
|
131
157
|
rubygems_version: 2.2.2
|
132
158
|
signing_key:
|
133
159
|
specification_version: 4
|
134
|
-
summary:
|
135
|
-
|
136
|
-
|
160
|
+
summary: Conventions-based JSON generation for Rails.
|
161
|
+
test_files:
|
162
|
+
- test/action_controller/adapter_selector_test.rb
|
163
|
+
- test/action_controller/explicit_serializer_test.rb
|
164
|
+
- test/action_controller/json_api_linked_test.rb
|
165
|
+
- test/action_controller/serialization_scope_name_test.rb
|
166
|
+
- test/action_controller/serialization_test.rb
|
167
|
+
- test/adapter/fragment_cache_test.rb
|
168
|
+
- test/adapter/json/belongs_to_test.rb
|
169
|
+
- test/adapter/json/collection_test.rb
|
170
|
+
- test/adapter/json/has_many_test.rb
|
171
|
+
- test/adapter/json_api/belongs_to_test.rb
|
172
|
+
- test/adapter/json_api/collection_test.rb
|
173
|
+
- test/adapter/json_api/has_many_embed_ids_test.rb
|
174
|
+
- test/adapter/json_api/has_many_explicit_serializer_test.rb
|
175
|
+
- test/adapter/json_api/has_many_test.rb
|
176
|
+
- test/adapter/json_api/has_one_test.rb
|
177
|
+
- test/adapter/json_api/linked_test.rb
|
178
|
+
- test/adapter/json_test.rb
|
179
|
+
- test/adapter/null_test.rb
|
180
|
+
- test/adapter_test.rb
|
181
|
+
- test/array_serializer_test.rb
|
182
|
+
- test/fixtures/poro.rb
|
183
|
+
- test/serializers/adapter_for_test.rb
|
184
|
+
- test/serializers/associations_test.rb
|
185
|
+
- test/serializers/attribute_test.rb
|
186
|
+
- test/serializers/attributes_test.rb
|
187
|
+
- test/serializers/cache_test.rb
|
188
|
+
- test/serializers/configuration_test.rb
|
189
|
+
- test/serializers/fieldset_test.rb
|
190
|
+
- test/serializers/generators_test.rb
|
191
|
+
- test/serializers/meta_test.rb
|
192
|
+
- test/serializers/options_test.rb
|
193
|
+
- test/serializers/serializer_for_test.rb
|
194
|
+
- test/serializers/urls_test.rb
|
195
|
+
- test/test_helper.rb
|