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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31d15c963dd38c98efe2bed43bd29a860b75dadd
4
- data.tar.gz: 0b5e96fb57785ec34af5abffa34a629b6e4928ad
3
+ metadata.gz: e0f9e8b4c16a16101ef2a668bcf7a3daeae92dcd
4
+ data.tar.gz: 7e381efa954dc5b2f0ca30120126bb9e5fc5e6c3
5
5
  SHA512:
6
- metadata.gz: fe43fad9ec714e4966a649e78a5e830ea693ecea2f5417e0a810cf630dfecde7193587ff8fc1601153b3af4bc8a3f995aa2f47af2c80804c1fcd3f911c8cce83
7
- data.tar.gz: 2bbadd095f455abb26756a1c61bb53aa113373f066e186558154d013edb39b970b4ecc4569325744c202d6f2b11727bb21e52ed73f6b165d841315938d76e5ce
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
- 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
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(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
-
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_#{type}".to_sym) }
12
- let(:params) { { plural => [item] } }
8
+ let(:item) { build("api_#{resource_singular}") }
9
+ let(:params) { { resource_plural => [item] } }
13
10
 
14
- it "returns the newly created #{type}" do
15
- response.success?.should == true
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[plural]
19
- response_items.length.should == 1
20
- response_item = response_items.first
14
+ response_items = response.result[resource_plural]
15
+ expect(response_items.length).to eq(1)
21
16
 
22
- model = model_class.find(response_item[:id])
23
- response_item.should == serializer_class.as_json(model)
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
- context "when creating multiple items" do
28
- let(:item1) { build("api_#{type}".to_sym) }
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
- it "returns the newly created #{type}s" do
33
- response.success?.should == true
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
- response_items = response.result[plural]
37
- response_items.length.should == 2
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
- 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
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
- let(:response) { subject.class.run(params) }
7
+ # let(:response) { subject.class.run(params) }
8
8
 
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 }
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
- 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
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
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.67"
3
+ VERSION = "0.0.68"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.67
4
+ version: 0.0.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce