collection_json_serializer 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a38b7d4dc38ed5c1bed4033818d2e69968be6720
4
- data.tar.gz: b52f5ce2efdc98b2ed6c18a75d634c61592ffff4
3
+ metadata.gz: 120a86d520ebce948248bd32a6c3e894ff46661c
4
+ data.tar.gz: 7cd6a7fadbc9b783e3da6c95e95e1bedcb079e50
5
5
  SHA512:
6
- metadata.gz: 56aa051a9b31a5b8da6e218c62a75dde366d1a92fdffe55ba55340fe480954a74c212aea2715f3379a308e549f60cec1ecfad4736cb7671b2132d6954adf9d7f
7
- data.tar.gz: 4946c642a0ed91dca00879ef01bf5d73c998912747434be345d7bc5c1dc7137e1673f8b4700e3b5966713964b196dd7305e94f8897ac2e5ff6880c84d499b9cd
6
+ metadata.gz: 15949ebd3af294d4f58fda0b7779f77ef70b88ef269c2bdabc035c5c5f0c88c9ffa01282765cd1dfcb7d0f5152605c9c3d4f115afa7ce8ac42a92403dd7ae690
7
+ data.tar.gz: 2295bf1900c61c5b1f5691bb0d18b4e689c80db69e2dbd5e461971299edb2af7a88c0006e74fe2f8f3d0a7412862b5b8b0c804d19a3e47a0f9ca90e07358cac1
data/README.md CHANGED
@@ -149,17 +149,23 @@ Please, notice that placeholders can _only_ be used within the `items` block.
149
149
 
150
150
  #### Open Attributes Policy
151
151
 
152
- Collection+JSON serializer has an __open attributes policy__, which means that objects' attributes can be extended at will. That is good if you want to use many of the [extensions available](https://github.com/collection-json/extensions), and also if you need to add custom extensions to suit your particular needs. Be aware that, [as the specs say](https://github.com/collection-json/spec#7-extensibility), you must only extend attributes in a way that won't break clients that are not aware of them.
152
+ Collection+JSON Serializer introduces an __open attributes policy__, which means that objects' attributes can be extended at will. This makes it easy to add custom extensions to suit your particular needs. Be aware that, [as the specs say](https://github.com/collection-json/spec#7-extensibility), you must only extend attributes in a way that won't break clients that are not aware of them.
153
+
154
+ In order to use the Open Attributes policy, it must be declared as an extension.
153
155
 
154
156
  ```ruby
155
157
  class UserSerializer < CollectionJson::Serializer
158
+ # Add Open Attrs as an extension
159
+ extensions :open_attrs
160
+
161
+ # Now you can use your crazy properties everywhere
156
162
  items do
157
163
  attributes :id, name: { css_class: "people" }
158
164
  end
159
165
 
160
166
  template name: { regex: "/\A[a-zA-Z0-9_]*\z/" }
161
167
 
162
- links profile: { css_class: "button" }
168
+ links profile: { on_click: "reboot_universe" }
163
169
  end
164
170
  ```
165
171
 
@@ -7,7 +7,7 @@ require "collection_json_serializer/support"
7
7
 
8
8
  require "collection_json_serializer/serializer"
9
9
  require "collection_json_serializer/items"
10
-
10
+ require "collection_json_serializer/spec"
11
11
  require "collection_json_serializer/builder"
12
12
 
13
13
  require "collection_json_serializer/validator"
@@ -1,4 +1,11 @@
1
1
  class Hash
2
+ # Extract params
3
+ # Returns a two-key hash where the first key is :name and the second is
4
+ # :properties, being the latter a hash itself.
5
+ #
6
+ # hash = { hi: { prompt: "My prompt", value: "Hello!" } }
7
+ # hash.extract_params
8
+ # => { name: "hi", properties: { prompt: "My prompt", value: "Hello!" } }
2
9
  def extract_params
3
10
  params = {}
4
11
  params[:name] = keys.first
@@ -19,6 +19,10 @@ module CollectionJson
19
19
  @query[:prompt] = @resource[:prompt] if @resource[:prompt]
20
20
  @query[:data] = add_data if @resource[:data]
21
21
 
22
+ if @serializer.uses?(:open_attrs)
23
+ @resource.each { |k, v| @query[k] = v unless @query.key?(k) }
24
+ end
25
+
22
26
  @query
23
27
  end
24
28
 
@@ -30,7 +34,10 @@ module CollectionJson
30
34
 
31
35
  def add_data
32
36
  @resource[:data].each_with_object([]) do |attr, data|
33
- data << { name: attr[:name], value: nil.to_s }
37
+ h = Hash.new
38
+ attr.keys.each { |k| h[k] = attr[k] }
39
+ h[:value] = nil.to_s unless h[:value]
40
+ data << h
34
41
  end
35
42
  end
36
43
 
@@ -1,6 +1,7 @@
1
1
  module CollectionJson
2
2
  class Serializer
3
3
  class << self
4
+ attr_accessor :extensions
4
5
  attr_accessor :href
5
6
  attr_accessor :template
6
7
  attr_accessor :links
@@ -9,12 +10,17 @@ module CollectionJson
9
10
  end
10
11
 
11
12
  def self.inherited(base)
13
+ base.extensions = []
12
14
  base.href = []
13
15
  base.template = []
14
16
  base.links = []
15
17
  base.queries = []
16
18
  end
17
19
 
20
+ def self.extensions(*attrs)
21
+ @extensions.concat attrs
22
+ end
23
+
18
24
  def self.href(*attrs)
19
25
  @href.concat attrs
20
26
  end
@@ -46,6 +52,10 @@ module CollectionJson
46
52
  end
47
53
  end
48
54
 
55
+ def extensions
56
+ self.class.extensions
57
+ end
58
+
49
59
  def href
50
60
  self.class.href.first
51
61
  end
@@ -82,6 +92,10 @@ module CollectionJson
82
92
  self.class._items.present?
83
93
  end
84
94
 
95
+ def uses?(extension)
96
+ extensions.include?(extension)
97
+ end
98
+
85
99
  def invalid?
86
100
  Validator.new(self).invalid?
87
101
  end
@@ -0,0 +1,50 @@
1
+ module CollectionJson
2
+ module Spec
3
+ DEFINITION = {
4
+ href: {},
5
+ links: {
6
+ href: {},
7
+ rel: {},
8
+ name: {},
9
+ prompt: {},
10
+ render: {}
11
+ },
12
+ items: {
13
+ href: {},
14
+ data: {
15
+ name: {},
16
+ value: {},
17
+ prompt: {}
18
+ },
19
+ links: {
20
+ href: {},
21
+ rel: {},
22
+ name: {},
23
+ prompt: {},
24
+ remder: {}
25
+ }
26
+ },
27
+ template: {
28
+ name: {},
29
+ value: {},
30
+ prompt: {}
31
+ },
32
+ queries: {
33
+ href: {},
34
+ rel: {},
35
+ name: {},
36
+ prompt: {},
37
+ data: {
38
+ name: {},
39
+ value: {}
40
+ }
41
+ },
42
+ error: {
43
+ title: {},
44
+ code: {},
45
+ message: {}
46
+ }
47
+ }
48
+ end
49
+ end
50
+
@@ -23,7 +23,7 @@ module CollectionJson
23
23
 
24
24
  def validate
25
25
  [
26
- :attributes,
26
+ :items,
27
27
  :href,
28
28
  :links,
29
29
  :template,
@@ -31,24 +31,58 @@ module CollectionJson
31
31
  ].each { |m| send("validate_#{m}") }
32
32
  end
33
33
 
34
- def validate_attributes
34
+ def validate_items
35
+ validate_items_attributes if attributes?
36
+ validate_items_links if links?
37
+ end
38
+
39
+ def validate_items_attributes
35
40
  @serializer.items.attributes.each do |attr|
36
41
  params = attr.extract_params
42
+ validate_attributes_values(@serializer.resources, params)
43
+ validate_attributes_properties(params) if params[:properties]
44
+ end if @serializer.items? && @serializer.items.attributes?
45
+ end
37
46
 
38
- @serializer.resources.each do |resource|
39
- val = extract_value_from(resource, params[:name])
40
- if value_is_invalid? val
41
- error_for :value, root: :attributes, path: [params[:name]]
42
- end
47
+ def validate_attributes_values(resources, params)
48
+ resources.each do |resource|
49
+ val = extract_value_from(resource, params[:name])
50
+ if value_is_invalid?(val)
51
+ error_for :value, root: :attributes, path: [params[:name]]
43
52
  end
53
+ end
54
+ end
44
55
 
45
- params[:properties].each do |key, value|
46
- if value_is_invalid? value
47
- error_for :value, root: :attributes, path: [params[:name], key]
48
- end
49
- end if params[:properties]
56
+ def validate_attributes_properties(params)
57
+ params[:properties].each do |key, value|
58
+ unless definition[:items][:data].keys.include?(key.to_sym)
59
+ error_for(
60
+ :unknown_attribute,
61
+ root: :attributes,
62
+ path: [params[:name], key]
63
+ )
64
+ next
65
+ end unless @serializer.uses?(:open_attrs)
66
+
67
+ if value_is_invalid?(value)
68
+ error_for :value, root: :attributes, path: [params[:name], key]
69
+ end
70
+ end
71
+ end
50
72
 
51
- end if @serializer.items && @serializer.items.attributes.any?
73
+ def validate_items_links
74
+ @serializer.items.links.each do |attr|
75
+ params = attr.extract_params
76
+ params[:properties].keys.each do |key|
77
+ unless definition[:items][:links].keys.include?(key.to_sym)
78
+ error_for(
79
+ :unknown_attribute,
80
+ root: :items,
81
+ path: [:links, params[:name], key]
82
+ )
83
+ end unless @serializer.uses?(:open_attrs)
84
+ end
85
+ end
52
86
  end
53
87
 
54
88
  def validate_href
@@ -72,6 +106,11 @@ module CollectionJson
72
106
  end
73
107
 
74
108
  link.each do |key, value|
109
+ unless definition[:links].keys.include?(key.to_sym)
110
+ error_for :unknown_attribute, root: :links, path: [key]
111
+ next
112
+ end unless @serializer.uses?(:open_attrs)
113
+
75
114
  case key
76
115
  when :href
77
116
  if url_is_invalid? link[:href]
@@ -91,7 +130,16 @@ module CollectionJson
91
130
  params = attr.extract_params
92
131
 
93
132
  params[:properties].each do |key, value|
94
- if value_is_invalid? value
133
+ unless definition[:template].keys.include?(key.to_sym)
134
+ error_for(
135
+ :unknown_attribute,
136
+ root: :template,
137
+ path: [params[:name], key]
138
+ )
139
+ next
140
+ end unless @serializer.uses?(:open_attrs)
141
+
142
+ if value_is_invalid?(value)
95
143
  error_for :value, root: :template, path: [params[:name], key]
96
144
  end
97
145
  end if params[:properties]
@@ -103,7 +151,7 @@ module CollectionJson
103
151
  @serializer.queries.each do |query|
104
152
  params = query.extract_params
105
153
 
106
- unless params[:properties].key? :href
154
+ unless params[:properties].key?(:href)
107
155
  error_for :missing_attribute,
108
156
  root: :queries,
109
157
  path: [params[:name], "href"]
@@ -111,12 +159,19 @@ module CollectionJson
111
159
  next
112
160
  end
113
161
 
114
- if url_is_invalid? params[:properties][:href]
162
+ if url_is_invalid?(params[:properties][:href])
115
163
  error_for :url, root: :queries, path: [params[:name], "href"]
116
164
  end
117
165
 
118
166
  params[:properties].each do |key, value|
119
167
  next if key == :data || key == :href
168
+ unless definition[:queries].keys.include?(key.to_sym)
169
+ error_for(
170
+ :unknown_attribute,
171
+ root: :queries,
172
+ path: [params[:name], key]
173
+ )
174
+ end unless @serializer.uses?(:open_attrs)
120
175
 
121
176
  if value_is_invalid?(value)
122
177
  error_for :value, root: :queries, path: [params[:name], key]
@@ -125,6 +180,16 @@ module CollectionJson
125
180
 
126
181
  if params[:properties].key?(:data)
127
182
  params[:properties][:data].each do |hash|
183
+ hash.keys.each do |key|
184
+ unless definition[:queries][:data].keys.include?(key)
185
+ error_for(
186
+ :unknown_attribute,
187
+ root: :queries,
188
+ path: [params[:name], :data, key]
189
+ )
190
+ end unless @serializer.uses?(:open_attrs)
191
+ end
192
+
128
193
  if value_is_invalid?(hash[:name])
129
194
  error_for :value,
130
195
  root: :queries,
@@ -153,6 +218,8 @@ module CollectionJson
153
218
  ending = " is an invalid value"
154
219
  when :missing_attribute
155
220
  ending = " is missing"
221
+ when :unknown_attribute
222
+ ending = " is an unknown attribute"
156
223
  else
157
224
  ending = " is an invalid value"
158
225
  end
@@ -163,6 +230,18 @@ module CollectionJson
163
230
  e << ending
164
231
  @errors[root] << e
165
232
  end
233
+
234
+ def definition
235
+ CollectionJson::Spec::DEFINITION
236
+ end
237
+
238
+ def attributes?
239
+ @serializer.items? && @serializer.items.attributes?
240
+ end
241
+
242
+ def links?
243
+ @serializer.items? && @serializer.items.links?
244
+ end
166
245
  end
167
246
  end
168
247
  end
@@ -1,5 +1,5 @@
1
1
  module CollectionJson
2
2
  class Serializer
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -153,25 +153,6 @@ module CollectionJson
153
153
  assert_equal expected.to_json, builder.to_json
154
154
  end
155
155
 
156
- def test_that_any_attributes_can_be_passed_to_template
157
- custom_serializer = CustomTemplateSerializer.new(@user1)
158
- builder = Builder.new(custom_serializer)
159
-
160
- expected = {
161
- collection: {
162
- version: "1.0",
163
- template: {
164
- data: [
165
- { name: "name", value: "" },
166
- { name: "email", value: "", prompt: "My email", anything: "at all", whatever: "really" }
167
- ]
168
- }
169
- }
170
- }
171
-
172
- assert_equal expected.to_json, builder.to_json
173
- end
174
-
175
156
  def test_that_an_invalid_serializer_raises_an_error
176
157
  invalid_serializer = InvalidSerializer.new(@user1)
177
158
  builder = Builder.new(invalid_serializer)
@@ -0,0 +1,118 @@
1
+ require "minitest_helper"
2
+
3
+ module CollectionJson
4
+ class Serializer
5
+ class TestOpenAttrs < Minitest::Test
6
+ include TestHelper
7
+
8
+ def setup
9
+ @user = User.new(name: "Carles Jove", email: "hola@carlus.cat")
10
+ @serializer = empty_serializer_for(@user)
11
+ @serializer.class.extensions = [:open_attrs]
12
+ @serializer.class.template = [
13
+ email: {
14
+ prompt: "My email",
15
+ anything: "at all"
16
+ }
17
+ ]
18
+ @serializer.items.attributes = [
19
+ name:
20
+ {
21
+ anything: "at all"
22
+ }
23
+ ]
24
+ @serializer.items.links = [
25
+ dashboard: {
26
+ # TODO
27
+ # This URL shouldn't validate!
28
+ href: "/my-dashboard",
29
+ anything: "at all"
30
+ }
31
+ ]
32
+ @serializer.class.links = [
33
+ dashboard: {
34
+ href: "http://example.com/my-dashboard",
35
+ anything: "at all"
36
+ }
37
+ ]
38
+ @serializer.class.queries = [
39
+ search: {
40
+ href: "http://example.com/search",
41
+ rel: "search",
42
+ whatever: "doesn't matter",
43
+ data: [
44
+ name: "required",
45
+ anything: "at all"
46
+ ]
47
+ }
48
+ ]
49
+ end
50
+
51
+ def test_that_serializer_is_valid_using_open_attrs
52
+ assert @serializer.valid?, "#{@serializer} should be valid"
53
+ end
54
+
55
+ def test_that_a_collection_can_be_built_using_open_attrs
56
+ builder = Builder.new(@serializer)
57
+ expected = {
58
+ collection: {
59
+ version: "1.0",
60
+ items: [
61
+ {
62
+ data: [
63
+ {
64
+ name: "name",
65
+ value: "Carles Jove",
66
+ anything: "at all"
67
+ }
68
+ ],
69
+ links: [
70
+ {
71
+ rel: "dashboard",
72
+ href: "/my-dashboard",
73
+ name: "dashboard",
74
+ anything: "at all",
75
+ }
76
+ ]
77
+ }
78
+ ],
79
+ links: [
80
+ {
81
+ rel: "dashboard",
82
+ href: "http://example.com/my-dashboard",
83
+ name: "dashboard",
84
+ anything: "at all",
85
+ }
86
+ ],
87
+ template: {
88
+ data: [
89
+ {
90
+ name: "email",
91
+ value: "",
92
+ prompt: "My email",
93
+ anything: "at all"
94
+ }
95
+ ]
96
+ },
97
+ queries: [
98
+ {
99
+ href: "http://example.com/search",
100
+ name: "search",
101
+ whatever: "doesn't matter",
102
+ rel: "search",
103
+ data: [
104
+ name: "required",
105
+ anything: "at all",
106
+ value: ""
107
+ ]
108
+ }
109
+ ]
110
+ }
111
+ }
112
+
113
+ assert_equal JSON(expected.to_json), JSON(builder.to_json)
114
+ end
115
+ end
116
+ end
117
+ end
118
+
@@ -13,6 +13,7 @@ require "active_support/inflector"
13
13
  module TestHelper
14
14
  def empty_serializer_for(object)
15
15
  serializer = CollectionJson::Serializer.new(object)
16
+ serializer.class.extensions = []
16
17
  serializer.class.href = []
17
18
  serializer.class.links = []
18
19
  serializer.class.template = []
@@ -68,38 +68,6 @@ module CollectionJson
68
68
  assert_equal expected.to_json, item.create.to_json
69
69
  end
70
70
 
71
- def test_that_an_item_can_be_build_with_random_attributes
72
- custom_serializer = CustomItemSerializer.new(@user1)
73
- item = Item.new(custom_serializer)
74
-
75
- expected = {
76
- data: [{
77
- name: "name",
78
- value: "Carles Jove",
79
- anything: "at all",
80
- whatever: "really"
81
- }]
82
- }
83
- assert_equal expected.to_json, item.create.to_json
84
- end
85
-
86
- def test_that_an_item_link_can_be_build_with_unlimited_attributes
87
- custom_serializer = CustomItemLinksSerializer.new(@user1)
88
- item = Item.new(custom_serializer)
89
-
90
- expected = {
91
- links: [{
92
- rel: "dashboard",
93
- name: "dashboard",
94
- href: "/my-dashboard",
95
- anything: "at all",
96
- whatever: "really"
97
- }]
98
- }
99
-
100
- assert_equal expected[:links], item.create[:links]
101
- end
102
-
103
71
  def test_that_unknown_attributes_are_silently_ignored
104
72
  serializer = empty_serializer_for(@user1)
105
73
  serializer.items.attributes(:unknown)
@@ -0,0 +1,28 @@
1
+ require "minitest_helper"
2
+
3
+ module CollectionJson
4
+ class Serializer
5
+ class TestDSL < Minitest::Test
6
+ def setup
7
+ @user = User.new(name: "Carles Jove", email: "hola@carlus.cat")
8
+ @serializer = Serializer.new(@user)
9
+ end
10
+
11
+ def test_top_level_dsl
12
+ assert @serializer.respond_to?(:href)
13
+ assert @serializer.respond_to?(:links)
14
+ assert @serializer.respond_to?(:template)
15
+ assert @serializer.respond_to?(:queries)
16
+ assert @serializer.respond_to?(:items)
17
+ assert @serializer.respond_to?(:extensions)
18
+ end
19
+
20
+ def test_items_dsl
21
+ assert_equal Items, @serializer.items.class
22
+ assert @serializer.items.respond_to?(:attributes)
23
+ assert @serializer.items.respond_to?(:links)
24
+ assert @serializer.items.respond_to?(:href)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -11,19 +11,6 @@ module CollectionJson
11
11
  def test_attributes_properties
12
12
  assert_equal [:name, :email], @user_serializer.items.attributes
13
13
  end
14
-
15
- def test_that_any_attributes_can_be_passed
16
- custom_serializer = CustomItemSerializer.new(@user)
17
- expected = [
18
- name:
19
- {
20
- anything: "at all",
21
- whatever: "really"
22
- }
23
- ]
24
-
25
- assert_equal expected, custom_serializer.items.attributes
26
- end
27
14
  end
28
15
  end
29
16
  end
@@ -14,18 +14,6 @@ module CollectionJson
14
14
  expected = [dashboard: { href: "http://example.com/my-dashboard" }]
15
15
  assert_equal expected, @user_serializer.class.links
16
16
  end
17
-
18
- def test_item_links_attributes_can_take_unlimited_properties
19
- custom_serializer = empty_serializer_for(@user)
20
- links = { dashboard: {
21
- href: "/my-dashboard",
22
- anything: "at all",
23
- whatever: "really"
24
- } }
25
- custom_serializer.class.links links
26
-
27
- assert_equal [links], custom_serializer.class.links
28
- end
29
17
  end
30
18
  end
31
19
  end
@@ -0,0 +1,24 @@
1
+ require "minitest_helper"
2
+
3
+ # Here we test Serializer's stuff _other_ than the DSL and Validations
4
+ # - For the DSL tests, check serializer/dsl_test.rb
5
+ # - For validation tests, check validator/validator_test.rb
6
+ module CollectionJson
7
+ class Serializer
8
+ class TestSerializer < Minitest::Test
9
+ include TestHelper
10
+
11
+ def setup
12
+ @user = User.new(name: "Carles Jove", email: "hola@carlus.cat")
13
+ @serializer = empty_serializer_for(@user)
14
+ end
15
+
16
+ def test_uses_method
17
+ @serializer.class.extensions(:open_attrs, :another_ext)
18
+ assert @serializer.uses?(:open_attrs)
19
+ assert @serializer.uses?(:another_ext)
20
+ refute @serializer.uses?(:unexistent_ext)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ require "minitest_helper"
2
+
3
+ module CollectionJson
4
+ module Spec
5
+ class TestSpec < Minitest::Test
6
+ include TestHelper
7
+
8
+ def test_that_random_attributes_cannot_be_passed
9
+ serializer = empty_serializer_for(@user)
10
+ serializer.items.attributes = [
11
+ name: { unknown: "this should not be valid" }
12
+ ]
13
+ serializer.items.links = serializer.class.links = [
14
+ dashboard: {
15
+ href: "http://example.com",
16
+ unknown: "this should not be valid"
17
+ }
18
+ ]
19
+ serializer.class.template = [
20
+ name: { whatever: "this should not be valid" }
21
+ ]
22
+ serializer.class.queries = [
23
+ name: {
24
+ href: "http://example.com",
25
+ whatever: "this should be invalid",
26
+ data: [
27
+ unknown: "this should be invalid"
28
+ ]
29
+ }
30
+ ]
31
+
32
+ assert serializer.invalid?,
33
+ "#{serializer.inspect} should be invalid"
34
+
35
+ # Items attributes
36
+ assert serializer.errors.key?(:attributes),
37
+ "#{serializer.errors.inspect} should have key attributes"
38
+ assert serializer.errors[:attributes][0].
39
+ include?("attributes:name:unknown is an unknown attribute"),
40
+ "#{serializer.errors[:attributes]} should include 'unknown attribute'"
41
+
42
+ # Items links
43
+ assert serializer.errors.key?(:items),
44
+ "#{serializer.errors.inspect} should have key attributes"
45
+ assert serializer.errors[:items][0].
46
+ include?("items:links:dashboard:unknown is an unknown attribute")
47
+
48
+ # Links
49
+ assert serializer.errors.key?(:links), "should have error for 'links'"
50
+ assert serializer.errors[:links][0].
51
+ include?("links:unknown is an unknown attribute")
52
+
53
+ # Template
54
+ assert serializer.errors.key?(:template),
55
+ "should have error for 'template'"
56
+ assert serializer.errors[:template][0].
57
+ include?("template:name:whatever is an unknown attribute")
58
+
59
+ # Queries
60
+ assert serializer.errors.key?(:queries),
61
+ "should have error for 'queries'"
62
+ assert serializer.errors[:queries][0].
63
+ include?("queries:name:whatever is an unknown attribute")
64
+ assert serializer.errors[:queries][1].
65
+ include?("queries:name:data:unknown is an unknown attribute")
66
+ end
67
+ end
68
+ end
69
+ end
70
+
@@ -11,20 +11,6 @@ module CollectionJson
11
11
  def test_template_attributes
12
12
  assert_equal [:name, email: { prompt: "My email" }], @user_serializer.class.template
13
13
  end
14
-
15
- def test_that_any_attributes_can_be_passed
16
- custom_serializer = CustomTemplateSerializer.new(@user)
17
- expected = [
18
- :name,
19
- email: {
20
- prompt: "My email",
21
- anything: "at all",
22
- whatever: "really"
23
- }
24
- ]
25
-
26
- assert_equal expected, custom_serializer.class.template
27
- end
28
14
  end
29
15
  end
30
16
  end
@@ -94,8 +94,7 @@ module CollectionJson
94
94
  @invalid_value_types.each do |invalidate|
95
95
  @invalid.items.attributes = [
96
96
  name: {
97
- prompt: invalidate,
98
- test: invalidate
97
+ prompt: invalidate
99
98
  }
100
99
  ]
101
100
 
@@ -105,8 +104,6 @@ module CollectionJson
105
104
  "#{invalidate} should be invalid"
106
105
  assert @invalid.errors[:attributes][0].
107
106
  include? "attributes:name:prompt is an invalid value"
108
- assert @invalid.errors[:attributes][1].
109
- include? "attributes:name:test is an invalid value"
110
107
  end
111
108
  end
112
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collection_json_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carles Jove i Buxeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-10 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -90,12 +90,14 @@ files:
90
90
  - lib/collection_json_serializer/objects/query.rb
91
91
  - lib/collection_json_serializer/objects/template.rb
92
92
  - lib/collection_json_serializer/serializer.rb
93
+ - lib/collection_json_serializer/spec.rb
93
94
  - lib/collection_json_serializer/support.rb
94
95
  - lib/collection_json_serializer/validator.rb
95
96
  - lib/collection_json_serializer/validator/url.rb
96
97
  - lib/collection_json_serializer/validator/value.rb
97
98
  - lib/collection_json_serializer/version.rb
98
99
  - test/builder/builder_test.rb
100
+ - test/extensions/open_attrs_test.rb
99
101
  - test/fixtures/models.rb
100
102
  - test/fixtures/poro.rb
101
103
  - test/fixtures/serializers/custom_item_links_serializer.rb
@@ -108,13 +110,15 @@ files:
108
110
  - test/objects/item_test.rb
109
111
  - test/objects/queries_test.rb
110
112
  - test/objects/template_test.rb
113
+ - test/serializer/dsl_test.rb
111
114
  - test/serializer/href_test.rb
112
115
  - test/serializer/items/attributes_test.rb
113
116
  - test/serializer/items/href_test.rb
114
117
  - test/serializer/items/links_test.rb
115
- - test/serializer/items_test.rb
116
118
  - test/serializer/links_test.rb
117
119
  - test/serializer/queries_test.rb
120
+ - test/serializer/serializer_test.rb
121
+ - test/serializer/spec_test.rb
118
122
  - test/serializer/template_test.rb
119
123
  - test/support/ext_test.rb
120
124
  - test/support/support_test.rb
@@ -148,6 +152,7 @@ specification_version: 4
148
152
  summary: Serialize objects as Collection+JSON.
149
153
  test_files:
150
154
  - test/builder/builder_test.rb
155
+ - test/extensions/open_attrs_test.rb
151
156
  - test/fixtures/models.rb
152
157
  - test/fixtures/poro.rb
153
158
  - test/fixtures/serializers/custom_item_links_serializer.rb
@@ -160,13 +165,15 @@ test_files:
160
165
  - test/objects/item_test.rb
161
166
  - test/objects/queries_test.rb
162
167
  - test/objects/template_test.rb
168
+ - test/serializer/dsl_test.rb
163
169
  - test/serializer/href_test.rb
164
170
  - test/serializer/items/attributes_test.rb
165
171
  - test/serializer/items/href_test.rb
166
172
  - test/serializer/items/links_test.rb
167
- - test/serializer/items_test.rb
168
173
  - test/serializer/links_test.rb
169
174
  - test/serializer/queries_test.rb
175
+ - test/serializer/serializer_test.rb
176
+ - test/serializer/spec_test.rb
170
177
  - test/serializer/template_test.rb
171
178
  - test/support/ext_test.rb
172
179
  - test/support/support_test.rb
@@ -1,24 +0,0 @@
1
- require "minitest_helper"
2
-
3
- module CollectionJson
4
- class Serializer
5
- class TestItems < Minitest::Test
6
- def setup
7
- @user = User.new(name: "Carles Jove", email: "hola@carlus.cat")
8
- @user_serializer = UserSerializer.new(@user)
9
- end
10
-
11
- def test_an_items_instance_is_created
12
- assert_equal Items, @user_serializer.items.class
13
- end
14
-
15
- def test_that_items_has_an_attributes_dsl
16
- assert @user_serializer.items.respond_to?(:attributes)
17
- end
18
-
19
- def test_that_items_has_a_links_dsl
20
- assert @user_serializer.items.respond_to?(:links)
21
- end
22
- end
23
- end
24
- end