jat 0.0.7 → 0.0.8
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/lib/jat/attribute.rb +4 -5
- data/lib/jat/plugins/{common/_activerecord_preloads/_activerecord_preloads.rb → base/base_activerecord_preloads/base_activerecord_preloads.rb} +3 -3
- data/lib/jat/plugins/{common/_activerecord_preloads → base/base_activerecord_preloads}/lib/preloader.rb +3 -1
- data/lib/jat/plugins/{common/_lower_camel_case/_lower_camel_case.rb → base/base_lower_camel_case/base_lower_camel_case.rb} +3 -3
- data/lib/jat/plugins/{common/_preloads/_preloads.rb → base/base_preloads/base_preloads.rb} +3 -3
- data/lib/jat/plugins/{common/_preloads → base/base_preloads}/lib/format_user_preloads.rb +1 -1
- data/lib/jat/plugins/{common/_preloads → base/base_preloads}/lib/preloads_with_path.rb +1 -1
- data/lib/jat/plugins/json_api/lib/response_piece.rb +2 -2
- data/lib/jat/plugins/json_api/plugins/json_api_activerecord/json_api_activerecord.rb +1 -1
- data/lib/jat/plugins/json_api/plugins/json_api_lower_camel_case/json_api_lower_camel_case.rb +1 -1
- data/lib/jat/plugins/json_api/plugins/json_api_preloads/json_api_preloads.rb +1 -1
- data/lib/jat/plugins/simple_api/plugins/simple_api_activerecord/simple_api_activerecord.rb +1 -1
- data/lib/jat/plugins/simple_api/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb +1 -1
- data/lib/jat/plugins/simple_api/plugins/simple_api_preloads/simple_api_preloads.rb +1 -1
- data/lib/jat/plugins/simple_api/simple_api.rb +1 -1
- data/lib/jat/plugins.rb +37 -25
- data/lib/jat.rb +8 -6
- data/test/lib/jat/attribute_test.rb +8 -0
- data/test/lib/jat/plugins/activerecord/activerecord_test.rb +27 -0
- data/test/lib/jat/plugins/{_activerecord_preloads/_activerecord_preloads_test.rb → base_activerecord_preloads/base_activerecord_preloads_test.rb} +3 -3
- data/test/lib/jat/plugins/{_activerecord_preloads → base_activerecord_preloads}/lib/preloader_test.rb +2 -2
- data/test/lib/jat/plugins/{_camel_lower/_camel_lower_test.rb → base_lower_camel_case/base_lower_camel_case_test.rb} +2 -2
- data/test/lib/jat/plugins/{_preloads/_preloads_test.rb → base_preloads/base_preloads_test.rb} +2 -2
- data/test/lib/jat/plugins/{_preloads → base_preloads}/lib/format_user_preloads_test.rb +3 -3
- data/test/lib/jat/plugins/{_preloads → base_preloads}/lib/preloads_with_path_test.rb +2 -2
- data/test/lib/jat/plugins/json_api/json_api_test.rb +1 -1
- data/test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb +20 -12
- data/test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb +25 -9
- data/test/lib/jat/plugins/json_api/lib/map_test.rb +132 -124
- data/test/lib/jat/plugins/json_api/lib/response_piece_test.rb +13 -0
- data/test/lib/jat/plugins/json_api/lib/response_test.rb +6 -0
- data/test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb +1 -1
- data/test/lib/jat/plugins/{json_api_camel_lower/json_api_camel_lower_test.rb → json_api_lower_camel_case/json_api_lower_camel_case_test.rb} +6 -0
- data/test/lib/jat/plugins/json_api_preloads/json_api_preloads_test.rb +16 -2
- data/test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb +30 -6
- data/test/lib/jat/plugins/lower_camel_case/lower_camel_case_test.rb +27 -0
- data/test/lib/jat/plugins/maps_cache/maps_cache_test.rb +27 -0
- data/test/lib/jat/plugins/preloads/preloads_test.rb +27 -0
- data/test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb +53 -43
- data/test/lib/jat/plugins/simple_api/lib/map_test.rb +90 -82
- data/test/lib/jat/plugins/simple_api/lib/response_piece_test.rb +13 -0
- data/test/lib/jat/plugins/simple_api/lib/response_test.rb +10 -2
- data/test/lib/jat/plugins/simple_api/simple_api_test.rb +36 -1
- data/test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb +1 -1
- data/test/lib/jat/plugins/{simple_api_camel_lower/simple_api_camel_lower_test.rb → simple_api_lower_camel_case/simple_api_lower_camel_case_test.rb} +7 -1
- data/test/lib/jat/plugins/simple_api_preloads/simple_api_preloads_test.rb +16 -2
- data/test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb +12 -0
- data/test/lib/jat/plugins/types/types_test.rb +5 -0
- data/test/lib/jat/plugins/validate_params/validate_params_test.rb +27 -0
- data/test/lib/jat/plugins_test.rb +88 -0
- data/test/test_helper.rb +7 -3
- metadata +40 -24
@@ -52,137 +52,145 @@ describe "Jat::Plugins::JsonApi::Map" do
|
|
52
52
|
ser
|
53
53
|
end
|
54
54
|
|
55
|
-
describe "
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
describe ".call" do
|
56
|
+
describe "with default :exposed option" do
|
57
|
+
it "returns exposed by default attributes" do
|
58
|
+
result = described_class.call(exposed: :default)
|
59
|
+
expected_result = {
|
60
|
+
a: {serializer: a, attributes: %i[a1 a2], relationships: %i[b]},
|
61
|
+
b: {serializer: b, attributes: %i[b1 b2], relationships: %i[]}
|
62
|
+
}
|
63
|
+
|
64
|
+
assert_equal expected_result, result
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns exposed by default attributes when no :exposed param provided" do
|
68
|
+
result = described_class.call({})
|
69
|
+
expected_result = {
|
70
|
+
a: {serializer: a, attributes: %i[a1 a2], relationships: %i[b]},
|
71
|
+
b: {serializer: b, attributes: %i[b1 b2], relationships: %i[]}
|
72
|
+
}
|
73
|
+
|
74
|
+
assert_equal expected_result, result
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns additionally included fields specified in :includes option" do
|
78
|
+
includes = "c,b.d"
|
79
|
+
result = described_class.call(include: includes)
|
80
|
+
expected_result = {
|
81
|
+
a: {serializer: a, attributes: %i[a1 a2], relationships: %i[b c]},
|
82
|
+
b: {serializer: b, attributes: %i[b1 b2], relationships: %i[d]},
|
83
|
+
c: {serializer: c, attributes: %i[c1 c2], relationships: %i[]},
|
84
|
+
d: {serializer: d, attributes: %i[d1 d2], relationships: %i[]}
|
85
|
+
}
|
86
|
+
|
87
|
+
assert_equal expected_result, result
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns fields specified in :fields option (only specified fields for specified type)" do
|
91
|
+
fields = {b: "b1,d"}
|
92
|
+
result = described_class.call(fields: fields)
|
93
|
+
expected_result = {
|
94
|
+
a: {serializer: a, attributes: %i[a1 a2], relationships: %i[b]},
|
95
|
+
b: {serializer: b, attributes: %i[b1], relationships: %i[d]},
|
96
|
+
d: {serializer: d, attributes: %i[d1 d2], relationships: %i[]}
|
97
|
+
}
|
98
|
+
|
99
|
+
assert_equal expected_result, result
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns fields specified in :includes and :fields options" do
|
103
|
+
includes = "c"
|
104
|
+
fields = {c: "c1"}
|
105
|
+
result = described_class.call(include: includes, fields: fields)
|
106
|
+
expected_result = {
|
107
|
+
a: {serializer: a, attributes: %i[a1 a2], relationships: %i[b c]},
|
108
|
+
b: {serializer: b, attributes: %i[b1 b2], relationships: %i[]},
|
109
|
+
c: {serializer: c, attributes: %i[c1], relationships: %i[]}
|
110
|
+
}
|
111
|
+
|
112
|
+
assert_equal expected_result, result
|
113
|
+
end
|
64
114
|
end
|
65
115
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
116
|
+
describe "with exposed: :none option" do
|
117
|
+
it "returns no attributes" do
|
118
|
+
result = described_class.call(exposed: :none)
|
119
|
+
expected_result = {
|
120
|
+
a: {serializer: a, attributes: %i[], relationships: %i[]}
|
121
|
+
}
|
122
|
+
|
123
|
+
assert_equal expected_result, result
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns additionally included fields specified in :includes option" do
|
127
|
+
includes = "b.c"
|
128
|
+
result = described_class.call(exposed: :none, include: includes)
|
129
|
+
expected_result = {
|
130
|
+
a: {serializer: a, attributes: %i[], relationships: %i[b]},
|
131
|
+
b: {serializer: b, attributes: %i[], relationships: %i[c]},
|
132
|
+
c: {serializer: c, attributes: %i[], relationships: %i[]}
|
133
|
+
}
|
134
|
+
|
135
|
+
assert_equal expected_result, result
|
136
|
+
end
|
137
|
+
|
138
|
+
it "returns fields specified in :fields option (only specified fields for specified type)" do
|
139
|
+
fields = {a: "a1,b", b: "b1,d"}
|
140
|
+
result = described_class.call(exposed: :none, fields: fields)
|
141
|
+
expected_result = {
|
142
|
+
a: {serializer: a, attributes: %i[a1], relationships: %i[b]},
|
143
|
+
b: {serializer: b, attributes: %i[b1], relationships: %i[d]},
|
144
|
+
d: {serializer: d, attributes: %i[], relationships: %i[]}
|
145
|
+
}
|
146
|
+
|
147
|
+
assert_equal expected_result, result
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns fields specified in :includes and :fields options" do
|
151
|
+
includes = "c"
|
152
|
+
fields = {c: "c1"}
|
153
|
+
result = described_class.call(exposed: :none, include: includes, fields: fields)
|
154
|
+
expected_result = {
|
155
|
+
a: {serializer: a, attributes: %i[], relationships: %i[c]},
|
156
|
+
c: {serializer: c, attributes: %i[c1], relationships: %i[]}
|
157
|
+
}
|
158
|
+
|
159
|
+
assert_equal expected_result, result
|
160
|
+
end
|
99
161
|
end
|
100
162
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
163
|
+
describe "with exposed: :all option" do
|
164
|
+
it "returns all attributes" do
|
165
|
+
result = described_class.call(exposed: :all)
|
166
|
+
expected_result = {
|
167
|
+
a: {serializer: a, attributes: %i[a1 a2 a3], relationships: %i[b c d]},
|
168
|
+
b: {serializer: b, attributes: %i[b1 b2 b3], relationships: %i[c d]},
|
169
|
+
c: {serializer: c, attributes: %i[c1 c2 c3], relationships: %i[]},
|
170
|
+
d: {serializer: d, attributes: %i[d1 d2 d3], relationships: %i[]}
|
171
|
+
}
|
172
|
+
|
173
|
+
assert_equal expected_result, result
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns only specified fields for specified fields types" do
|
177
|
+
fields = {b: "b1", c: "c2"}
|
178
|
+
result = described_class.call(exposed: :all, fields: fields)
|
179
|
+
expected_result = {
|
180
|
+
a: {serializer: a, attributes: %i[a1 a2 a3], relationships: %i[b c d]},
|
181
|
+
b: {serializer: b, attributes: %i[b1], relationships: %i[]},
|
182
|
+
c: {serializer: c, attributes: %i[c2], relationships: %i[]},
|
183
|
+
d: {serializer: d, attributes: %i[d1 d2 d3], relationships: %i[]}
|
184
|
+
}
|
185
|
+
|
186
|
+
assert_equal expected_result, result
|
187
|
+
end
|
112
188
|
end
|
113
189
|
end
|
114
190
|
|
115
|
-
describe "
|
116
|
-
it "returns
|
117
|
-
|
118
|
-
expected_result = {
|
119
|
-
a: {serializer: a, attributes: %i[], relationships: %i[]}
|
120
|
-
}
|
121
|
-
|
122
|
-
assert_equal expected_result, result
|
123
|
-
end
|
124
|
-
|
125
|
-
it "returns additionally included fields specified in :includes option" do
|
126
|
-
includes = "b.c"
|
127
|
-
result = described_class.call(exposed: :none, include: includes)
|
128
|
-
expected_result = {
|
129
|
-
a: {serializer: a, attributes: %i[], relationships: %i[b]},
|
130
|
-
b: {serializer: b, attributes: %i[], relationships: %i[c]},
|
131
|
-
c: {serializer: c, attributes: %i[], relationships: %i[]}
|
132
|
-
}
|
133
|
-
|
134
|
-
assert_equal expected_result, result
|
135
|
-
end
|
136
|
-
|
137
|
-
it "returns fields specified in :fields option (only specified fields for specified type)" do
|
138
|
-
fields = {a: "a1,b", b: "b1,d"}
|
139
|
-
result = described_class.call(exposed: :none, fields: fields)
|
140
|
-
expected_result = {
|
141
|
-
a: {serializer: a, attributes: %i[a1], relationships: %i[b]},
|
142
|
-
b: {serializer: b, attributes: %i[b1], relationships: %i[d]},
|
143
|
-
d: {serializer: d, attributes: %i[], relationships: %i[]}
|
144
|
-
}
|
145
|
-
|
146
|
-
assert_equal expected_result, result
|
147
|
-
end
|
148
|
-
|
149
|
-
it "returns fields specified in :includes and :fields options" do
|
150
|
-
includes = "c"
|
151
|
-
fields = {c: "c1"}
|
152
|
-
result = described_class.call(exposed: :none, include: includes, fields: fields)
|
153
|
-
expected_result = {
|
154
|
-
a: {serializer: a, attributes: %i[], relationships: %i[c]},
|
155
|
-
c: {serializer: c, attributes: %i[c1], relationships: %i[]}
|
156
|
-
}
|
157
|
-
|
158
|
-
assert_equal expected_result, result
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe "with exposed: :all option" do
|
163
|
-
it "returns all attributes" do
|
164
|
-
result = described_class.call(exposed: :all)
|
165
|
-
expected_result = {
|
166
|
-
a: {serializer: a, attributes: %i[a1 a2 a3], relationships: %i[b c d]},
|
167
|
-
b: {serializer: b, attributes: %i[b1 b2 b3], relationships: %i[c d]},
|
168
|
-
c: {serializer: c, attributes: %i[c1 c2 c3], relationships: %i[]},
|
169
|
-
d: {serializer: d, attributes: %i[d1 d2 d3], relationships: %i[]}
|
170
|
-
}
|
171
|
-
|
172
|
-
assert_equal expected_result, result
|
173
|
-
end
|
174
|
-
|
175
|
-
it "returns only specified fields for specified fields types" do
|
176
|
-
fields = {b: "b1", c: "c2"}
|
177
|
-
result = described_class.call(exposed: :all, fields: fields)
|
178
|
-
expected_result = {
|
179
|
-
a: {serializer: a, attributes: %i[a1 a2 a3], relationships: %i[b c d]},
|
180
|
-
b: {serializer: b, attributes: %i[b1], relationships: %i[]},
|
181
|
-
c: {serializer: c, attributes: %i[c2], relationships: %i[]},
|
182
|
-
d: {serializer: d, attributes: %i[d1 d2 d3], relationships: %i[]}
|
183
|
-
}
|
184
|
-
|
185
|
-
assert_equal expected_result, result
|
191
|
+
describe ".inspect" do
|
192
|
+
it "returns self name" do
|
193
|
+
assert_equal "#{a}::Map", described_class.inspect
|
186
194
|
end
|
187
195
|
end
|
188
196
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::JsonApi::ResponsePiece" do
|
6
|
+
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
7
|
+
|
8
|
+
describe ".inspect" do
|
9
|
+
it "returns self name" do
|
10
|
+
assert_equal "#{jat_class}::ResponsePiece", jat_class::ResponsePiece.inspect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -486,4 +486,10 @@ describe "Jat::Plugins::JsonApi::Response" do
|
|
486
486
|
assert_equal({self: "/self", related: "/foo/self"}, links)
|
487
487
|
end
|
488
488
|
end
|
489
|
+
|
490
|
+
describe ".inspect" do
|
491
|
+
it "returns self name" do
|
492
|
+
assert_equal "#{base_class}::Response", base_class::Response.inspect
|
493
|
+
end
|
494
|
+
end
|
489
495
|
end
|
@@ -19,6 +19,6 @@ describe "Jat::Plugins::JsonApiActiverecord" do
|
|
19
19
|
jat_class.plugin :json_api_activerecord
|
20
20
|
|
21
21
|
assert jat_class.plugin_used?(:json_api_preloads)
|
22
|
-
assert jat_class.plugin_used?(:
|
22
|
+
assert jat_class.plugin_used?(:base_activerecord_preloads)
|
23
23
|
end
|
24
24
|
end
|
@@ -15,6 +15,12 @@ describe "Jat::Plugins::JsonApiLowerCamelCase" do
|
|
15
15
|
jat_class.id { |object| object }
|
16
16
|
end
|
17
17
|
|
18
|
+
it "checks json_api plugin loaded before" do
|
19
|
+
jat_class = Class.new(Jat)
|
20
|
+
error = assert_raises(Jat::Error) { jat_class.plugin :json_api_lower_camel_case }
|
21
|
+
assert_match(/json_api/, error.message)
|
22
|
+
end
|
23
|
+
|
18
24
|
it "returns attributes in lowerCamelCase case" do
|
19
25
|
jat_class.attribute(:foo_bar) { 1 }
|
20
26
|
|
@@ -17,13 +17,13 @@ describe "Jat::Plugins::JsonApiPreloads" do
|
|
17
17
|
jat_class = Class.new(Jat)
|
18
18
|
jat_class.plugin :json_api
|
19
19
|
|
20
|
-
jat_class.expects(:plugin).with(:
|
20
|
+
jat_class.expects(:plugin).with(:base_preloads, foo: :bar)
|
21
21
|
|
22
22
|
@plugin.before_load(jat_class, foo: :bar)
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "InstanceMethods" do
|
26
|
-
it "
|
26
|
+
it "adds #preloads method as a delegator to #{@plugin}::Preloads" do
|
27
27
|
jat_class = Class.new(Jat)
|
28
28
|
jat_class.plugin :json_api
|
29
29
|
jat_class.plugin @plugin
|
@@ -34,4 +34,18 @@ describe "Jat::Plugins::JsonApiPreloads" do
|
|
34
34
|
assert_equal "RES", jat.preloads
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe "ClassMethods" do
|
39
|
+
it "adds .preloads method as a delegator to #{@plugin}::Preloads" do
|
40
|
+
jat_class = Class.new(Jat)
|
41
|
+
jat_class.plugin :json_api
|
42
|
+
jat_class.plugin @plugin
|
43
|
+
|
44
|
+
jat = jat_class.allocate
|
45
|
+
jat_class.expects(:new).with("CONTEXT").returns(jat)
|
46
|
+
@plugin::Preloads.expects(:call).with(jat).returns("RES")
|
47
|
+
|
48
|
+
assert_equal "RES", jat_class.preloads("CONTEXT")
|
49
|
+
end
|
50
|
+
end
|
37
51
|
end
|
@@ -13,34 +13,50 @@ describe "Jat::Plugins::JsonApiValidateParams" do
|
|
13
13
|
assert_match(/json_api/, error.message)
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:
|
16
|
+
let(:base) do
|
17
17
|
jat_class = Class.new(Jat)
|
18
18
|
jat_class.plugin :json_api
|
19
|
+
jat_class
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:serializer) do
|
23
|
+
jat_class = Class.new(base)
|
19
24
|
jat_class.plugin @plugin
|
20
25
|
|
21
26
|
jat_class.type "foo"
|
22
27
|
jat_class.attribute :foo_bar
|
23
|
-
jat_class.relationship :foo_bazz, serializer:
|
28
|
+
jat_class.relationship :foo_bazz, serializer: foo_bazz_serializer
|
29
|
+
jat_class
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:foo_bazz_serializer) do
|
33
|
+
jat_class = Class.new(base)
|
34
|
+
jat_class.type "foo_bazz"
|
35
|
+
jat_class.attribute :bazz
|
24
36
|
jat_class
|
25
37
|
end
|
26
38
|
|
27
39
|
let(:serializer_lower_camel_case) do
|
28
|
-
jat_class = Class.new(
|
29
|
-
jat_class.plugin :json_api
|
40
|
+
jat_class = Class.new(base)
|
30
41
|
jat_class.plugin :json_api_lower_camel_case
|
31
42
|
jat_class.plugin @plugin
|
32
43
|
|
33
44
|
jat_class.type "foo"
|
34
45
|
jat_class.attribute :foo_bar
|
35
|
-
jat_class.relationship :foo_bazz, serializer:
|
46
|
+
jat_class.relationship :foo_bazz, serializer: foo_bazz_serializer
|
36
47
|
jat_class
|
37
48
|
end
|
38
49
|
|
50
|
+
it "returns true when provided fields present" do
|
51
|
+
jat = serializer.new(fields: {foo: "foo_bar,foo_bazz", foo_bazz: "bazz"})
|
52
|
+
assert jat.validate
|
53
|
+
end
|
54
|
+
|
39
55
|
it "validates fields types" do
|
40
56
|
jat = serializer.new(fields: {bar: "any"})
|
41
57
|
error = assert_raises(Jat::JsonApiParamsError) { jat.validate }
|
42
58
|
|
43
|
-
expected_message = "Response does not have resources with type 'bar'. Existing types are: 'foo'"
|
59
|
+
expected_message = "Response does not have resources with type 'bar'. Existing types are: 'foo', 'foo_bazz'"
|
44
60
|
assert_equal(expected_message, error.message)
|
45
61
|
end
|
46
62
|
|
@@ -81,4 +97,12 @@ describe "Jat::Plugins::JsonApiValidateParams" do
|
|
81
97
|
expected_message = "Type 'foo' has no included 'extra' relationship. Existing relationships are: 'fooBazz'"
|
82
98
|
assert_equal(expected_message, error.message)
|
83
99
|
end
|
100
|
+
|
101
|
+
it "validates nested includes" do
|
102
|
+
jat = serializer.new(include: "foo_bazz.extra")
|
103
|
+
error = assert_raises(Jat::JsonApiParamsError) { jat.validate }
|
104
|
+
|
105
|
+
expected_message = "Type 'foo_bazz' has no included 'extra' relationship. Existing relationships are: ''"
|
106
|
+
assert_equal(expected_message, error.message)
|
107
|
+
end
|
84
108
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::LowerCamelCase" do
|
6
|
+
it "raises error if no response plugin is loaded" do
|
7
|
+
new_class = Class.new(Jat)
|
8
|
+
err = assert_raises(Jat::Error) { new_class.plugin :lower_camel_case }
|
9
|
+
assert_equal "Please load :json_api or :simple_api plugin first", err.message
|
10
|
+
end
|
11
|
+
|
12
|
+
it "loads simple_api compatible plugin" do
|
13
|
+
new_class = Class.new(Jat)
|
14
|
+
new_class.plugin :simple_api
|
15
|
+
new_class.plugin :lower_camel_case
|
16
|
+
|
17
|
+
assert new_class.plugin_used?(:simple_api_lower_camel_case)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "loads json_api compatible plugin" do
|
21
|
+
new_class = Class.new(Jat)
|
22
|
+
new_class.plugin :json_api
|
23
|
+
new_class.plugin :lower_camel_case
|
24
|
+
|
25
|
+
assert new_class.plugin_used?(:json_api_lower_camel_case)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::MapsCache" do
|
6
|
+
it "raises error if no response plugin is loaded" do
|
7
|
+
new_class = Class.new(Jat)
|
8
|
+
err = assert_raises(Jat::Error) { new_class.plugin :maps_cache }
|
9
|
+
assert_equal "Please load :json_api or :simple_api plugin first", err.message
|
10
|
+
end
|
11
|
+
|
12
|
+
it "loads simple_api compatible plugin" do
|
13
|
+
new_class = Class.new(Jat)
|
14
|
+
new_class.plugin :simple_api
|
15
|
+
new_class.plugin :maps_cache
|
16
|
+
|
17
|
+
assert new_class.plugin_used?(:simple_api_maps_cache)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "loads json_api compatible plugin" do
|
21
|
+
new_class = Class.new(Jat)
|
22
|
+
new_class.plugin :json_api
|
23
|
+
new_class.plugin :maps_cache
|
24
|
+
|
25
|
+
assert new_class.plugin_used?(:json_api_maps_cache)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::Preloads" do
|
6
|
+
it "raises error if no response plugin is loaded" do
|
7
|
+
new_class = Class.new(Jat)
|
8
|
+
err = assert_raises(Jat::Error) { new_class.plugin :preloads }
|
9
|
+
assert_equal "Please load :json_api or :simple_api plugin first", err.message
|
10
|
+
end
|
11
|
+
|
12
|
+
it "loads simple_api compatible plugin" do
|
13
|
+
new_class = Class.new(Jat)
|
14
|
+
new_class.plugin :simple_api
|
15
|
+
new_class.plugin :preloads
|
16
|
+
|
17
|
+
assert new_class.plugin_used?(:simple_api_preloads)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "loads json_api compatible plugin" do
|
21
|
+
new_class = Class.new(Jat)
|
22
|
+
new_class.plugin :json_api
|
23
|
+
new_class.plugin :preloads
|
24
|
+
|
25
|
+
assert new_class.plugin_used?(:json_api_preloads)
|
26
|
+
end
|
27
|
+
end
|
@@ -13,65 +13,75 @@ describe "Jat::Plugins::SimpleApi::FieldsParamParser" do
|
|
13
13
|
ser
|
14
14
|
end
|
15
15
|
|
16
|
+
let(:described_class) { jat_class::FieldsParamParser }
|
17
|
+
|
16
18
|
def parse(str)
|
17
19
|
jat_class::FieldsParamParser.parse(str)
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
describe ".inspect" do
|
23
|
+
it "returns self name" do
|
24
|
+
assert_equal "#{jat_class}::FieldsParamParser", described_class.inspect
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
describe ".parse" do
|
29
|
+
it "returns empty hash when nil provided" do
|
30
|
+
assert_equal({}, parse(nil))
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
it "returns empty hash when empty string provided" do
|
34
|
+
assert_equal({}, parse(""))
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
it "parses single field" do
|
38
|
+
assert_equal({id: {}}, parse("id"))
|
39
|
+
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
it "parses multiple fields" do
|
42
|
+
assert_equal({id: {}, name: {}}, parse("id, name"))
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
it "parses single resource with single field" do
|
46
|
+
assert_equal({users: {id: {}}}, parse("users(id)"))
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
it "parses fields started with open PAREN" do
|
50
|
+
assert_equal({users: {id: {}}}, parse("(users(id))"))
|
51
|
+
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
id: {},
|
52
|
-
posts: {title: {}, text: {}},
|
53
|
-
news: {title: {}, text: {}}
|
54
|
-
}
|
53
|
+
it "parses single resource with multiple fields" do
|
54
|
+
assert_equal({users: {id: {}, name: {}}}, parse("users(id,name)"))
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
it "parses multiple resources with fields" do
|
58
|
+
fields = "id,posts(title,text),news(title,text)"
|
59
|
+
resp = {
|
60
|
+
id: {},
|
61
|
+
posts: {title: {}, text: {}},
|
62
|
+
news: {title: {}, text: {}}
|
63
|
+
}
|
64
|
+
|
65
|
+
assert_equal(resp, parse(fields))
|
66
|
+
end
|
58
67
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
it "parses included resources" do
|
69
|
+
fields = "id,posts(title,text,comments(author(name),comment))"
|
70
|
+
resp = {
|
71
|
+
id: {},
|
72
|
+
posts: {
|
73
|
+
title: {},
|
74
|
+
text: {},
|
75
|
+
comments: {
|
76
|
+
author: {
|
77
|
+
name: {}
|
78
|
+
},
|
79
|
+
comment: {}
|
80
|
+
}
|
71
81
|
}
|
72
82
|
}
|
73
|
-
}
|
74
83
|
|
75
|
-
|
84
|
+
assert_equal(resp, parse(fields))
|
85
|
+
end
|
76
86
|
end
|
77
87
|
end
|