restpack_service 0.0.60 → 0.0.61
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.rb +1 -0
- data/lib/restpack_service/command.rb +14 -4
- data/lib/restpack_service/commands/single_create.rb +13 -0
- data/lib/restpack_service/support/matchers.rb +1 -0
- data/lib/restpack_service/support/matchers/single_create_command.rb +22 -0
- data/lib/restpack_service/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a95b9d5052a646a8f6e3e865ff7bcf6806c600d8
|
4
|
+
data.tar.gz: 8e0a7bf646a1bb1fb776e2b148b917c21c864c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0664e5d6596aa1bf088d7e1de976355fda3a641e9e14c1f36692cefda05e717489c542602967568bdcaa9d416fc376b2d2200bf080176c0665ec3381ef2b994
|
7
|
+
data.tar.gz: 47e3e1b81388698b28e185b90c97b54e0188d8f4cfa290e3af11e0344d75eb6400331e8758ee15f1c2889389958529913d2acbb877367b264eec4b3fa70fc56f
|
data/lib/restpack_service.rb
CHANGED
@@ -11,6 +11,7 @@ require "restpack_service/command"
|
|
11
11
|
|
12
12
|
require "restpack_service/commands/get"
|
13
13
|
require "restpack_service/commands/create"
|
14
|
+
require "restpack_service/commands/single_create"
|
14
15
|
require "restpack_service/commands/list"
|
15
16
|
|
16
17
|
require "restpack_service/loader"
|
@@ -54,10 +54,6 @@ module RestPack::Service
|
|
54
54
|
add_error key, key, message
|
55
55
|
end
|
56
56
|
|
57
|
-
def serialize(models)
|
58
|
-
serializer_klass.serialize(models)
|
59
|
-
end
|
60
|
-
|
61
57
|
def get
|
62
58
|
identifier = service_identifiers[:resources]
|
63
59
|
result = serializer_klass.resource(inputs)
|
@@ -79,6 +75,20 @@ module RestPack::Service
|
|
79
75
|
serialize(models)
|
80
76
|
end
|
81
77
|
|
78
|
+
def single_create!
|
79
|
+
identifier = service_identifiers[:resources]
|
80
|
+
model = model_klass.create!(inputs)
|
81
|
+
as_json(model)
|
82
|
+
end
|
83
|
+
|
84
|
+
def serialize(models)
|
85
|
+
serializer_klass.serialize(models)
|
86
|
+
end
|
87
|
+
|
88
|
+
def as_json(model)
|
89
|
+
serializer_klass.as_json(model)
|
90
|
+
end
|
91
|
+
|
82
92
|
private
|
83
93
|
|
84
94
|
def create_models!(array)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#NOTE: GJ: create commands will accept a single resource
|
2
|
+
# until jsonapi.org a validation solution for compound documents
|
3
|
+
# https://github.com/json-api/json-api/issues/7
|
4
|
+
|
5
|
+
module RestPack::Service
|
6
|
+
module Commands
|
7
|
+
class SingleCreate < RestPack::Service::Command
|
8
|
+
def execute
|
9
|
+
single_create!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +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
|
6
|
+
|
7
|
+
let(:response) { subject.class.run(params) }
|
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 }
|
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
|
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.
|
4
|
+
version: 0.0.61
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
@@ -226,11 +226,13 @@ files:
|
|
226
226
|
- lib/restpack_service/commands/create.rb
|
227
227
|
- lib/restpack_service/commands/get.rb
|
228
228
|
- lib/restpack_service/commands/list.rb
|
229
|
+
- lib/restpack_service/commands/single_create.rb
|
229
230
|
- lib/restpack_service/configuration.rb
|
230
231
|
- lib/restpack_service/loader.rb
|
231
232
|
- lib/restpack_service/response.rb
|
232
233
|
- lib/restpack_service/support/matchers.rb
|
233
234
|
- lib/restpack_service/support/matchers/create_command.rb
|
235
|
+
- lib/restpack_service/support/matchers/single_create_command.rb
|
234
236
|
- lib/restpack_service/support/spec_helper.rb
|
235
237
|
- lib/restpack_service/version.rb
|
236
238
|
- restpack_service.gemspec
|