restpack_service 0.0.67 → 0.0.68
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/restpack_service/command.rb +123 -123
- data/lib/restpack_service/support/matchers/create_command.rb +25 -25
- data/lib/restpack_service/support/matchers/single_create_command.rb +19 -19
- data/lib/restpack_service/support/matchers.rb +15 -0
- data/lib/restpack_service/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f9e8b4c16a16101ef2a668bcf7a3daeae92dcd
|
4
|
+
data.tar.gz: 7e381efa954dc5b2f0ca30120126bb9e5fc5e6c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74847cc12dd7ffae0943ef26c9e590924cdb86bea04d0a73127ad03f2ba0ffd9f202310fe1b0580ae661e475e28144ddc3c7f55c71fdca46663d0e07ff0a8b87
|
7
|
+
data.tar.gz: 63ab3e2370ada81a80720beaee94827a8bb3cc4cf4024b61948d985ca7375103c2862b412d36d64db416d9e752f0bf3e2342c7eeedb4c2a584ab0ca22f851358
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'modularize'
|
2
2
|
|
3
|
-
module RestPack
|
3
|
+
module RestPack::Service
|
4
4
|
class Command < Mutations::Command
|
5
5
|
attr_accessor :response
|
6
6
|
|
@@ -113,125 +113,125 @@ module RestPack
|
|
113
113
|
end
|
114
114
|
|
115
115
|
#TODO: GJ: remove this legacy class
|
116
|
-
module RestPack::Service
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
end
|
116
|
+
# module RestPack::Service
|
117
|
+
# class Command < Mutations::Command
|
118
|
+
# attr_accessor :response
|
119
|
+
|
120
|
+
# def run
|
121
|
+
# @response = Response.new
|
122
|
+
|
123
|
+
# begin
|
124
|
+
# init
|
125
|
+
# mutation = super
|
126
|
+
|
127
|
+
# if mutation.errors
|
128
|
+
# mutation.errors.message.each do |error|
|
129
|
+
# @response.add_error(error[0], error[1].gsub(error[0].capitalize, ''))
|
130
|
+
# end
|
131
|
+
|
132
|
+
# @response.status ||= :unprocessable_entity
|
133
|
+
# else
|
134
|
+
# @response.status ||= :ok
|
135
|
+
# end
|
136
|
+
|
137
|
+
# if @response.status == :ok
|
138
|
+
# @response.result = mutation.result if mutation.result
|
139
|
+
# end
|
140
|
+
# rescue Exception => e
|
141
|
+
# puts "---COMMAND EXCEPTION---"
|
142
|
+
# puts e.message #TODO: GJ: logging
|
143
|
+
# puts e.backtrace
|
144
|
+
# puts "-----------------------"
|
145
|
+
|
146
|
+
# @response.add_error(:base, 'Service Error')
|
147
|
+
# @response.status = :internal_service_error
|
148
|
+
# end
|
149
|
+
|
150
|
+
# @response
|
151
|
+
# end
|
152
|
+
|
153
|
+
# def init
|
154
|
+
# end
|
155
|
+
|
156
|
+
# def status(status)
|
157
|
+
# @response.status = status
|
158
|
+
# end
|
159
|
+
|
160
|
+
# def valid?
|
161
|
+
# !has_errors?
|
162
|
+
# end
|
163
|
+
|
164
|
+
# def service_error(message)
|
165
|
+
# field_error :base, message
|
166
|
+
# end
|
167
|
+
|
168
|
+
# def field_error(key, message)
|
169
|
+
# add_error key, key, message
|
170
|
+
# end
|
171
|
+
|
172
|
+
# def get
|
173
|
+
# identifier = service_identifiers[:resources]
|
174
|
+
# result = Serializer.resource(inputs)
|
175
|
+
|
176
|
+
# if result[identifier].empty?
|
177
|
+
# status :not_found
|
178
|
+
# else
|
179
|
+
# result
|
180
|
+
# end
|
181
|
+
# end
|
182
|
+
|
183
|
+
# def list
|
184
|
+
# serializer_klass.resource(inputs)
|
185
|
+
# end
|
186
|
+
|
187
|
+
# def create!
|
188
|
+
# identifier = service_identifiers[:resources]
|
189
|
+
# models = create_models!(inputs[identifier])
|
190
|
+
# serialize(models)
|
191
|
+
# end
|
192
|
+
|
193
|
+
# def single_create!
|
194
|
+
# identifier = service_identifiers[:resources]
|
195
|
+
# model = model_klass.create!(inputs)
|
196
|
+
# as_json(model)
|
197
|
+
# end
|
198
|
+
|
199
|
+
# def serialize(models)
|
200
|
+
# serializer_klass.serialize(models)
|
201
|
+
# end
|
202
|
+
|
203
|
+
# def as_json(model)
|
204
|
+
# serializer_klass.as_json(model)
|
205
|
+
# end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
# def create_models!(array)
|
210
|
+
# model_klass.create!(array)
|
211
|
+
# end
|
212
|
+
|
213
|
+
# def serializer_klass
|
214
|
+
# "Serializers::#{service_namespace}".constantize
|
215
|
+
# end
|
216
|
+
|
217
|
+
# def model_klass
|
218
|
+
# "Models::#{service_namespace}".constantize
|
219
|
+
# end
|
220
|
+
|
221
|
+
# def service_namespace
|
222
|
+
# identifiers = service_identifiers
|
223
|
+
# namespace = "#{identifiers[:service]}::#{identifiers[:resource].capitalize}"
|
224
|
+
# end
|
225
|
+
|
226
|
+
# def service_identifiers
|
227
|
+
# #extract identifiers from ancestor in the form of 'Commands::Core::Application::Get'
|
228
|
+
# namespaces = self.class.ancestors.first.to_s.split('::')
|
229
|
+
# resource = namespaces[2].downcase
|
230
|
+
# return {
|
231
|
+
# service: namespaces[1].to_sym,
|
232
|
+
# resource: resource.to_sym,
|
233
|
+
# resources: resource.pluralize.to_sym
|
234
|
+
# }
|
235
|
+
# end
|
236
|
+
# end
|
237
|
+
# end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
def it_acts_as_create_command
|
2
|
-
plural = type.to_s.pluralize.to_sym
|
3
|
-
namespaced_type = "#{namespace.to_s.camelize}::#{type.to_s.camelize}"
|
4
|
-
model_class = "Models::#{namespaced_type}".constantize
|
5
|
-
serializer_class = "Serializers::#{namespaced_type}".constantize
|
6
|
-
|
1
|
+
def it_acts_as_create_command
|
7
2
|
let(:response) { subject.class.run(params) }
|
3
|
+
let(:resource_plural) { subject.Serializer.plural_key }
|
4
|
+
let(:resource_singular) { subject.Serializer.singular_key }
|
8
5
|
|
9
6
|
context "with valid params" do
|
10
7
|
context "when creating a single item" do
|
11
|
-
let(:item) { build("api_#{
|
12
|
-
let(:params) { {
|
8
|
+
let(:item) { build("api_#{resource_singular}") }
|
9
|
+
let(:params) { { resource_plural => [item] } }
|
13
10
|
|
14
|
-
|
15
|
-
response.
|
16
|
-
response.result.should include(plural), "The reponse should include :#{plural} array"
|
11
|
+
it_succeeds "and returns the newly created resource" do
|
12
|
+
expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}"
|
17
13
|
|
18
|
-
response_items = response.result[
|
19
|
-
response_items.length.
|
20
|
-
response_item = response_items.first
|
14
|
+
response_items = response.result[resource_plural]
|
15
|
+
expect(response_items.length).to eq(1)
|
21
16
|
|
22
|
-
|
23
|
-
|
17
|
+
response_item = response_items.first
|
18
|
+
model = subject.Model.find(response_item[:id])
|
19
|
+
expect(response_item).to eq(subject.Serializer.as_json(model))
|
24
20
|
end
|
25
21
|
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when creating multiple items" do
|
25
|
+
let(:item1) { build("api_#{resource_singular}".to_sym) }
|
26
|
+
let(:item2) { build("api_#{resource_singular}".to_sym) }
|
27
|
+
let(:params) { { resource_plural => [item1, item2] } }
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
let(:item2) { build("api_#{type}".to_sym) }
|
30
|
-
let(:params) { { plural => [item1, item2] } }
|
29
|
+
it_succeeds "and returns the newly created resources" do
|
30
|
+
expect(response.result).to include(resource_plural), "The reponse should include an array of :#{resource_plural}"
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
response.result.should include(plural), "The reponse should include :#{plural} array"
|
32
|
+
response_items = response.result[resource_plural]
|
33
|
+
expect(response_items.length).to eq(2)
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
response_items.each do |response_item|
|
36
|
+
model = subject.Model.find(response_item[:id])
|
37
|
+
expect(response_item).to eq(subject.Serializer.as_json(model))
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
def it_acts_as_single_create_command(namespace, type)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# def it_acts_as_single_create_command(namespace, type)
|
2
|
+
# plural = type.to_s.pluralize.to_sym
|
3
|
+
# namespaced_type = "#{namespace.to_s.camelize}::#{type.to_s.camelize}"
|
4
|
+
# model_class = "Models::#{namespaced_type}".constantize
|
5
|
+
# serializer_class = "Serializers::#{namespaced_type}".constantize
|
6
6
|
|
7
|
-
|
7
|
+
# let(:response) { subject.class.run(params) }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
# context "with valid params" do
|
10
|
+
# context "when creating a single item" do
|
11
|
+
# let(:item) { build("api_#{type}".to_sym) }
|
12
|
+
# let(:params) { item }
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
14
|
+
# it "returns the newly created #{type}" do
|
15
|
+
# response.success?.should == true
|
16
|
+
# response.result[:id].should_not == nil
|
17
|
+
# model = model_class.find(response.result[:id])
|
18
|
+
# response.result.should == serializer_class.as_json(model)
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
@@ -33,3 +33,18 @@ def service_should_map(param, map)
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
def it_is(status)
|
38
|
+
it "is :#{status}" do
|
39
|
+
expect(response.success?).to eq(false)
|
40
|
+
expect(response.result).to eq({})
|
41
|
+
expect(response.status).to eq(:forbidden)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def it_succeeds(message='succeeds', &block)
|
46
|
+
it message do
|
47
|
+
expect(response.success?).to eq(true)
|
48
|
+
instance_eval(&block)
|
49
|
+
end
|
50
|
+
end
|