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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37483a3306e5e7af106108216bc274c1f6fd3b3c
4
- data.tar.gz: a624b7decb9c3703c62761589f8e0ca7fca62228
3
+ metadata.gz: a95b9d5052a646a8f6e3e865ff7bcf6806c600d8
4
+ data.tar.gz: 8e0a7bf646a1bb1fb776e2b148b917c21c864c4a
5
5
  SHA512:
6
- metadata.gz: 4eb3c2f4beb7fb34b9936680db7b80393c453cdfea18524531d81f8667b2e2c1dd9755586f58c189b6d689140704fd61418a0a855b973990e2081c488e7289ac
7
- data.tar.gz: edd75858ee1ac55a10f7602101625d3ddadcf88bd805b82ef7045f37a4f6c40f243e501191c0736a6bd398f34ef3658c07720ed4edce002f9dfd9b1a3bd51e83
6
+ metadata.gz: b0664e5d6596aa1bf088d7e1de976355fda3a641e9e14c1f36692cefda05e717489c542602967568bdcaa9d416fc376b2d2200bf080176c0665ec3381ef2b994
7
+ data.tar.gz: 47e3e1b81388698b28e185b90c97b54e0188d8f4cfa290e3af11e0344d75eb6400331e8758ee15f1c2889389958529913d2acbb877367b264eec4b3fa70fc56f
@@ -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
@@ -1,4 +1,5 @@
1
1
  require_relative 'matchers/create_command'
2
+ require_relative 'matchers/single_create_command'
2
3
 
3
4
  def is_required(*params)
4
5
  params.each do |param|
@@ -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
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.60"
3
+ VERSION = "0.0.61"
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.60
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