active_model_serializers_rails_2.3 0.9.0.alpha1 → 0.9.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +11 -55
- data/lib/active_model/array_serializer.rb +9 -34
- data/lib/active_model/as_json_overrides.rb +6 -0
- data/lib/active_model/default_serializer.rb +3 -12
- data/lib/active_model/serializable.rb +5 -9
- data/lib/active_model/serializer/associations.rb +15 -53
- data/lib/active_model/serializer/railtie.rb +2 -2
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +29 -56
- data/lib/active_model_serializers.rb +2 -18
- data/test/coverage_setup.rb +9 -12
- data/test/fixtures/active_record.rb +3 -3
- data/test/integration/active_record/active_record_test.rb +21 -23
- data/test/test_app.rb +1 -4
- data/test/test_helper.rb +0 -3
- data/test/unit/active_model/array_serializer/meta_test.rb +1 -1
- data/test/unit/active_model/array_serializer/root_test.rb +2 -2
- data/test/unit/active_model/array_serializer/scope_test.rb +1 -1
- data/test/unit/active_model/array_serializer/serialize_test.rb +45 -0
- data/test/unit/active_model/default_serializer_test.rb +6 -4
- data/test/unit/active_model/serializer/attributes_test.rb +1 -13
- data/test/unit/active_model/serializer/config_test.rb +5 -5
- data/test/unit/active_model/serializer/filter_test.rb +2 -2
- data/test/unit/active_model/serializer/has_many_test.rb +6 -30
- data/test/unit/active_model/serializer/has_one_test.rb +5 -19
- data/test/unit/active_model/serializer/meta_test.rb +1 -1
- data/test/unit/active_model/serializer/root_test.rb +2 -16
- data/test/unit/active_model/serializer/scope_test.rb +1 -29
- metadata +11 -21
- data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +0 -14
- data/lib/active_model/serializer/generators/serializer/templates/controller.rb +0 -93
- data/test/unit/active_model/array_serializer/serialization_test.rb +0 -182
- data/test/unit/active_model/serializer/associations/build_serializer_test.rb +0 -21
- data/test/unit/active_model/serializer/associations_test.rb +0 -19
data/test/test_app.rb
CHANGED
@@ -3,9 +3,6 @@ class TestApp < Rails::Application
|
|
3
3
|
config.eager_load = false
|
4
4
|
config.secret_key_base = 'abc123'
|
5
5
|
end
|
6
|
-
|
7
|
-
# Set up a logger to avoid creating a log directory on every run.
|
8
|
-
config.logger = Logger.new(nil)
|
9
6
|
end
|
10
7
|
|
11
|
-
TestApp.
|
8
|
+
TestApp.load_generators
|
data/test/test_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_model/serializer'
|
|
3
3
|
|
4
4
|
module ActiveModel
|
5
5
|
class ArraySerializer
|
6
|
-
class MetaTest <
|
6
|
+
class MetaTest < ActiveRecord::TestCase
|
7
7
|
def setup
|
8
8
|
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
9
9
|
@profile2 = Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class ArraySerializer
|
5
|
-
class RootAsOptionTest <
|
5
|
+
class RootAsOptionTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
7
7
|
@old_root = ArraySerializer._root
|
8
8
|
@profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@@ -50,7 +50,7 @@ module ActiveModel
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
class RootInSerializerTest <
|
53
|
+
class RootInSerializerTest < ActiveRecord::TestCase
|
54
54
|
def setup
|
55
55
|
@old_root = ArraySerializer._root
|
56
56
|
ArraySerializer._root = :in_serializer
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class ArraySerializer
|
5
|
-
class ScopeTest <
|
5
|
+
class ScopeTest < ActiveRecord::TestCase
|
6
6
|
def test_array_serializer_pass_options_to_items_serializers
|
7
7
|
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
8
8
|
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class ArraySerializer
|
5
|
+
class SerializeTest < ActiveRecord::TestCase
|
6
|
+
def setup
|
7
|
+
array = [1, 2, 3]
|
8
|
+
@serializer = ActiveModel::Serializer.serializer_for(array).new(array)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_serializer_for_array_returns_appropriate_type
|
12
|
+
assert_kind_of ArraySerializer, @serializer
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_array_serializer_serializes_simple_objects
|
16
|
+
assert_equal [1, 2, 3], @serializer.serializable_array
|
17
|
+
assert_equal [1, 2, 3], @serializer.as_json
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_array_serializer_serializes_models
|
21
|
+
array = [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
22
|
+
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
23
|
+
serializer = ArraySerializer.new(array)
|
24
|
+
|
25
|
+
expected = [{ name: 'Name 1', description: 'Description 1' },
|
26
|
+
{ name: 'Name 2', description: 'Description 2' }]
|
27
|
+
|
28
|
+
assert_equal expected, serializer.serializable_array
|
29
|
+
assert_equal expected, serializer.as_json
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_array_serializers_each_serializer
|
33
|
+
array = [::Model.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
34
|
+
::Model.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })]
|
35
|
+
serializer = ArraySerializer.new(array, each_serializer: ProfileSerializer)
|
36
|
+
|
37
|
+
expected = [{ name: 'Name 1', description: 'Description 1' },
|
38
|
+
{ name: 'Name 2', description: 'Description 2' }]
|
39
|
+
|
40
|
+
assert_equal expected, serializer.serializable_array
|
41
|
+
assert_equal expected, serializer.as_json
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -2,11 +2,13 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class DefaultSerializer
|
5
|
-
class Test <
|
5
|
+
class Test < ActiveRecord::TestCase
|
6
6
|
def test_serialize_objects
|
7
|
-
assert_equal(nil, DefaultSerializer.new(nil).
|
8
|
-
assert_equal(1, DefaultSerializer.new(1).
|
9
|
-
assert_equal('hi', DefaultSerializer.new('hi').
|
7
|
+
assert_equal(nil, DefaultSerializer.new(nil).serializable_hash)
|
8
|
+
assert_equal(1, DefaultSerializer.new(1).serializable_hash)
|
9
|
+
assert_equal('hi', DefaultSerializer.new('hi').serializable_hash)
|
10
|
+
obj = Struct.new(:a, :b).new(1, 2)
|
11
|
+
assert_equal({ a: 1, b: 2 }, DefaultSerializer.new(obj).serializable_hash)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class AttributesTest <
|
5
|
+
class AttributesTest < ActiveRecord::TestCase
|
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)
|
@@ -24,18 +24,6 @@ module ActiveModel
|
|
24
24
|
'profile' => { name: 'Name 1', description: 'Description 1' }
|
25
25
|
}, @profile_serializer.as_json)
|
26
26
|
end
|
27
|
-
|
28
|
-
def test_attributes_inheritance
|
29
|
-
inherited_serializer_klass = Class.new(ProfileSerializer) do
|
30
|
-
attributes :comments
|
31
|
-
end
|
32
|
-
another_inherited_serializer_klass = Class.new(ProfileSerializer)
|
33
|
-
|
34
|
-
assert_equal([:name, :description, :comments],
|
35
|
-
inherited_serializer_klass._attributes)
|
36
|
-
assert_equal([:name, :description],
|
37
|
-
another_inherited_serializer_klass._attributes)
|
38
|
-
end
|
39
27
|
end
|
40
28
|
end
|
41
29
|
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
5
|
class Config
|
6
|
-
class Test <
|
6
|
+
class Test < ActiveRecord::TestCase
|
7
7
|
def test_config_const_is_an_instance_of_config
|
8
8
|
assert_kind_of Config, CONFIG
|
9
9
|
end
|
@@ -30,9 +30,9 @@ module ActiveModel
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
class ConfigTest <
|
33
|
+
class ConfigTest < ActiveRecord::TestCase
|
34
34
|
def test_setup
|
35
|
-
Serializer.setup do |config|
|
35
|
+
ActiveModel::Serializer.setup do |config|
|
36
36
|
config.a = 'v1'
|
37
37
|
config.b = 'v2'
|
38
38
|
end
|
@@ -44,7 +44,7 @@ module ActiveModel
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_config_accessors
|
47
|
-
Serializer.setup do |config|
|
47
|
+
ActiveModel::Serializer.setup do |config|
|
48
48
|
config.foo = 'v1'
|
49
49
|
config.bar = 'v2'
|
50
50
|
end
|
@@ -63,7 +63,7 @@ module ActiveModel
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
class ApplyConfigTest <
|
66
|
+
class ApplyConfigTest < ActiveRecord::TestCase
|
67
67
|
def test_apply_config_to_associations
|
68
68
|
CONFIG.embed = :ids
|
69
69
|
CONFIG.embed_in_root = true
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class FilterAttributesTest <
|
5
|
+
class FilterAttributesTest < ActiveRecord::TestCase
|
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)
|
@@ -20,7 +20,7 @@ module ActiveModel
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
class FilterAssociationsTest <
|
23
|
+
class FilterAssociationsTest < ActiveRecord::TestCase
|
24
24
|
def setup
|
25
25
|
@association = PostSerializer._associations[:comments]
|
26
26
|
@old_association = @association.dup
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class HasManyTest <
|
5
|
+
class HasManyTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
7
7
|
@association = PostSerializer._associations[:comments]
|
8
8
|
@old_association = @association.dup
|
@@ -21,18 +21,6 @@ module ActiveModel
|
|
21
21
|
assert_equal 'comments', @association.name
|
22
22
|
end
|
23
23
|
|
24
|
-
def test_associations_inheritance
|
25
|
-
inherited_serializer_klass = Class.new(PostSerializer) do
|
26
|
-
has_many :some_associations
|
27
|
-
end
|
28
|
-
another_inherited_serializer_klass = Class.new(PostSerializer)
|
29
|
-
|
30
|
-
assert_equal(PostSerializer._associations.length + 1,
|
31
|
-
inherited_serializer_klass._associations.length)
|
32
|
-
assert_equal(PostSerializer._associations.length,
|
33
|
-
another_inherited_serializer_klass._associations.length)
|
34
|
-
end
|
35
|
-
|
36
24
|
def test_associations_embedding_ids_serialization_using_serializable_hash
|
37
25
|
@association.embed = :ids
|
38
26
|
|
@@ -129,9 +117,9 @@ module ActiveModel
|
|
129
117
|
def test_associations_using_a_given_serializer
|
130
118
|
@association.embed = :ids
|
131
119
|
@association.embed_in_root = true
|
132
|
-
@association.
|
120
|
+
@association.serializer_class = Class.new(ActiveModel::Serializer) do
|
133
121
|
def content
|
134
|
-
|
122
|
+
'fake'
|
135
123
|
end
|
136
124
|
|
137
125
|
attributes :content
|
@@ -139,14 +127,14 @@ module ActiveModel
|
|
139
127
|
|
140
128
|
assert_equal({
|
141
129
|
'post' => { title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id } },
|
142
|
-
comments: [{ content: '
|
130
|
+
comments: [{ content: 'fake' }, { content: 'fake' }]
|
143
131
|
}, @post_serializer.as_json)
|
144
132
|
end
|
145
133
|
|
146
|
-
def
|
134
|
+
def test_associations_using_a_given_array_serializer
|
147
135
|
@association.embed = :ids
|
148
136
|
@association.embed_in_root = true
|
149
|
-
@association.
|
137
|
+
@association.serializer_class = Class.new(ActiveModel::ArraySerializer) do
|
150
138
|
def serializable_object
|
151
139
|
{ my_content: ['fake'] }
|
152
140
|
end
|
@@ -157,18 +145,6 @@ module ActiveModel
|
|
157
145
|
comments: { my_content: ['fake'] }
|
158
146
|
}, @post_serializer.as_json)
|
159
147
|
end
|
160
|
-
|
161
|
-
def test_associations_embedding_objects_using_a_given_array_serializer
|
162
|
-
@association.serializer_from_options = Class.new(ArraySerializer) do
|
163
|
-
def serializable_object
|
164
|
-
{ my_content: ['fake'] }
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
assert_equal({
|
169
|
-
'post' => { title: 'Title 1', body: 'Body 1', comments: { my_content: ['fake'] } }
|
170
|
-
}, @post_serializer.as_json)
|
171
|
-
end
|
172
148
|
end
|
173
149
|
end
|
174
150
|
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class HasOneTest <
|
5
|
+
class HasOneTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
7
7
|
@association = UserSerializer._associations[:profile]
|
8
8
|
@old_association = @association.dup
|
@@ -112,14 +112,14 @@ module ActiveModel
|
|
112
112
|
|
113
113
|
assert_equal({
|
114
114
|
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id },
|
115
|
-
|
115
|
+
profile: { name: 'N1', description: 'D1' }
|
116
116
|
}, @user_serializer.as_json)
|
117
117
|
end
|
118
118
|
|
119
|
-
def
|
119
|
+
def test_associations_using_a_given_serializer
|
120
120
|
@association.embed = :ids
|
121
121
|
@association.embed_in_root = true
|
122
|
-
@association.
|
122
|
+
@association.serializer_class = Class.new(ActiveModel::Serializer) do
|
123
123
|
def name
|
124
124
|
'fake'
|
125
125
|
end
|
@@ -129,21 +129,7 @@ module ActiveModel
|
|
129
129
|
|
130
130
|
assert_equal({
|
131
131
|
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id },
|
132
|
-
|
133
|
-
}, @user_serializer.as_json)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_associations_embedding_objects_using_a_given_serializer
|
137
|
-
@association.serializer_from_options = Class.new(Serializer) do
|
138
|
-
def name
|
139
|
-
'fake'
|
140
|
-
end
|
141
|
-
|
142
|
-
attributes :name
|
143
|
-
end
|
144
|
-
|
145
|
-
assert_equal({
|
146
|
-
'user' => { name: 'Name 1', email: 'mail@server.com', profile: { name: 'fake' } }
|
132
|
+
profile: { name: 'fake' }
|
147
133
|
}, @user_serializer.as_json)
|
148
134
|
end
|
149
135
|
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class RootAsOptionTest <
|
5
|
+
class RootAsOptionTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
7
7
|
@old_root = ProfileSerializer._root
|
8
8
|
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
@@ -54,23 +54,9 @@ module ActiveModel
|
|
54
54
|
name: 'Name 1', description: 'Description 1'
|
55
55
|
}, @serializer.as_json)
|
56
56
|
end
|
57
|
-
|
58
|
-
def test_root_inheritance
|
59
|
-
ProfileSerializer._root = 'profile'
|
60
|
-
|
61
|
-
inherited_serializer_klass = Class.new(ProfileSerializer)
|
62
|
-
inherited_serializer_klass._root = 'inherited_profile'
|
63
|
-
|
64
|
-
another_inherited_serializer_klass = Class.new(ProfileSerializer)
|
65
|
-
|
66
|
-
assert_equal('inherited_profile',
|
67
|
-
inherited_serializer_klass._root)
|
68
|
-
assert_equal('profile',
|
69
|
-
another_inherited_serializer_klass._root)
|
70
|
-
end
|
71
57
|
end
|
72
58
|
|
73
|
-
class RootInSerializerTest <
|
59
|
+
class RootInSerializerTest < ActiveRecord::TestCase
|
74
60
|
def setup
|
75
61
|
@old_root = ProfileSerializer._root
|
76
62
|
ProfileSerializer._root = :in_serializer
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class ScopeTest <
|
5
|
+
class ScopeTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
7
7
|
@serializer = ProfileSerializer.new(nil, scope: current_user)
|
8
8
|
end
|
@@ -17,33 +17,5 @@ module ActiveModel
|
|
17
17
|
'user'
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
class NestedScopeTest < Minitest::Test
|
22
|
-
def setup
|
23
|
-
@association = UserSerializer._associations[:profile]
|
24
|
-
@old_association = @association.dup
|
25
|
-
@user = User.new({ name: 'Name 1', email: 'mail@server.com', gender: 'M' })
|
26
|
-
@user_serializer = UserSerializer.new(@user, scope: 'user')
|
27
|
-
end
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
UserSerializer._associations[:profile] = @old_association
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_scope_passed_through
|
34
|
-
@association.serializer_from_options = Class.new(Serializer) do
|
35
|
-
def name
|
36
|
-
scope
|
37
|
-
end
|
38
|
-
|
39
|
-
attributes :name
|
40
|
-
end
|
41
|
-
|
42
|
-
assert_equal({
|
43
|
-
name: 'Name 1', email: 'mail@server.com', profile: { name: 'user' }
|
44
|
-
}, @user_serializer.serializable_hash)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
20
|
end
|
49
21
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers_rails_2.3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0.
|
5
|
-
prerelease: 6
|
4
|
+
version: 0.9.0.pre1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- José Valim
|
@@ -11,12 +10,11 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date:
|
13
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: rails
|
18
17
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
18
|
requirements:
|
21
19
|
- - ~>
|
22
20
|
- !ruby/object:Gem::Version
|
@@ -24,7 +22,6 @@ dependencies:
|
|
24
22
|
type: :development
|
25
23
|
prerelease: false
|
26
24
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
25
|
requirements:
|
29
26
|
- - ~>
|
30
27
|
- !ruby/object:Gem::Version
|
@@ -44,12 +41,11 @@ files:
|
|
44
41
|
- DESIGN.textile
|
45
42
|
- MIT-LICENSE
|
46
43
|
- lib/active_model/array_serializer.rb
|
44
|
+
- lib/active_model/as_json_overrides.rb
|
47
45
|
- lib/active_model/default_serializer.rb
|
48
46
|
- lib/active_model/serializable.rb
|
49
47
|
- lib/active_model/serializer/associations.rb
|
50
48
|
- lib/active_model/serializer/config.rb
|
51
|
-
- lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb
|
52
|
-
- lib/active_model/serializer/generators/serializer/templates/controller.rb
|
53
49
|
- lib/active_model/serializer/railtie.rb
|
54
50
|
- lib/active_model/serializer/version.rb
|
55
51
|
- lib/active_model/serializer.rb
|
@@ -64,10 +60,8 @@ files:
|
|
64
60
|
- test/unit/active_model/array_serializer/meta_test.rb
|
65
61
|
- test/unit/active_model/array_serializer/root_test.rb
|
66
62
|
- test/unit/active_model/array_serializer/scope_test.rb
|
67
|
-
- test/unit/active_model/array_serializer/
|
63
|
+
- test/unit/active_model/array_serializer/serialize_test.rb
|
68
64
|
- test/unit/active_model/default_serializer_test.rb
|
69
|
-
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
70
|
-
- test/unit/active_model/serializer/associations_test.rb
|
71
65
|
- test/unit/active_model/serializer/attributes_test.rb
|
72
66
|
- test/unit/active_model/serializer/config_test.rb
|
73
67
|
- test/unit/active_model/serializer/filter_test.rb
|
@@ -76,30 +70,29 @@ files:
|
|
76
70
|
- test/unit/active_model/serializer/meta_test.rb
|
77
71
|
- test/unit/active_model/serializer/root_test.rb
|
78
72
|
- test/unit/active_model/serializer/scope_test.rb
|
79
|
-
homepage: https://github.com/rails-
|
73
|
+
homepage: https://github.com/fivetanley/active_model_serializers_rails/tree/rails-2.3
|
80
74
|
licenses:
|
81
75
|
- MIT
|
76
|
+
metadata: {}
|
82
77
|
post_install_message:
|
83
78
|
rdoc_options: []
|
84
79
|
require_paths:
|
85
80
|
- lib
|
86
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
82
|
requirements:
|
89
|
-
- -
|
83
|
+
- - '>='
|
90
84
|
- !ruby/object:Gem::Version
|
91
85
|
version: 1.9.3
|
92
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
87
|
requirements:
|
95
|
-
- -
|
88
|
+
- - '>'
|
96
89
|
- !ruby/object:Gem::Version
|
97
90
|
version: 1.3.1
|
98
91
|
requirements: []
|
99
92
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
101
94
|
signing_key:
|
102
|
-
specification_version:
|
95
|
+
specification_version: 4
|
103
96
|
summary: Bringing consistency and object orientation to model serialization. Works
|
104
97
|
great for client-side MVC frameworks!
|
105
98
|
test_files:
|
@@ -112,10 +105,8 @@ test_files:
|
|
112
105
|
- test/unit/active_model/array_serializer/meta_test.rb
|
113
106
|
- test/unit/active_model/array_serializer/root_test.rb
|
114
107
|
- test/unit/active_model/array_serializer/scope_test.rb
|
115
|
-
- test/unit/active_model/array_serializer/
|
108
|
+
- test/unit/active_model/array_serializer/serialize_test.rb
|
116
109
|
- test/unit/active_model/default_serializer_test.rb
|
117
|
-
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
118
|
-
- test/unit/active_model/serializer/associations_test.rb
|
119
110
|
- test/unit/active_model/serializer/attributes_test.rb
|
120
111
|
- test/unit/active_model/serializer/config_test.rb
|
121
112
|
- test/unit/active_model/serializer/filter_test.rb
|
@@ -124,4 +115,3 @@ test_files:
|
|
124
115
|
- test/unit/active_model/serializer/meta_test.rb
|
125
116
|
- test/unit/active_model/serializer/root_test.rb
|
126
117
|
- test/unit/active_model/serializer/scope_test.rb
|
127
|
-
has_rdoc:
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Generators
|
6
|
-
class ScaffoldControllerGenerator
|
7
|
-
if Rails::VERSION::MAJOR >= 4
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
hook_for :serializer, default: true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
<% if namespaced? -%>
|
2
|
-
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
|
-
|
4
|
-
<% end -%>
|
5
|
-
<% module_namespacing do -%>
|
6
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
|
8
|
-
|
9
|
-
# GET <%= route_url %>
|
10
|
-
# GET <%= route_url %>.json
|
11
|
-
def index
|
12
|
-
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
13
|
-
|
14
|
-
respond_to do |format|
|
15
|
-
format.html # index.html.erb
|
16
|
-
format.json { render json: <%= "@#{plural_table_name}" %> }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# GET <%= route_url %>/1
|
21
|
-
# GET <%= route_url %>/1.json
|
22
|
-
def show
|
23
|
-
respond_to do |format|
|
24
|
-
format.html # show.html.erb
|
25
|
-
format.json { render json: <%= "@#{singular_table_name}" %> }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# GET <%= route_url %>/new
|
30
|
-
def new
|
31
|
-
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
32
|
-
end
|
33
|
-
|
34
|
-
# GET <%= route_url %>/1/edit
|
35
|
-
def edit
|
36
|
-
end
|
37
|
-
|
38
|
-
# POST <%= route_url %>
|
39
|
-
# POST <%= route_url %>.json
|
40
|
-
def create
|
41
|
-
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
42
|
-
|
43
|
-
respond_to do |format|
|
44
|
-
if @<%= orm_instance.save %>
|
45
|
-
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
|
46
|
-
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created }
|
47
|
-
else
|
48
|
-
format.html { render action: 'new' }
|
49
|
-
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# PATCH/PUT <%= route_url %>/1
|
55
|
-
# PATCH/PUT <%= route_url %>/1.json
|
56
|
-
def update
|
57
|
-
respond_to do |format|
|
58
|
-
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
59
|
-
format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
60
|
-
format.json { head :no_content }
|
61
|
-
else
|
62
|
-
format.html { render action: 'edit' }
|
63
|
-
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# DELETE <%= route_url %>/1
|
69
|
-
# DELETE <%= route_url %>/1.json
|
70
|
-
def destroy
|
71
|
-
@<%= orm_instance.destroy %>
|
72
|
-
respond_to do |format|
|
73
|
-
format.html { redirect_to <%= index_helper %>_url }
|
74
|
-
format.json { head :no_content }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
# Use callbacks to share common setup or constraints between actions.
|
80
|
-
def set_<%= singular_table_name %>
|
81
|
-
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
82
|
-
end
|
83
|
-
|
84
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
85
|
-
def <%= "#{singular_table_name}_params" %>
|
86
|
-
<%- if attributes_names.empty? -%>
|
87
|
-
params[<%= ":#{singular_table_name}" %>]
|
88
|
-
<%- else -%>
|
89
|
-
params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
90
|
-
<%- end -%>
|
91
|
-
end
|
92
|
-
end
|
93
|
-
<% end -%>
|