acfs 0.17.0 → 0.18.0

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: 879fbc544d14669fd0db86a7705c1ff10e997a56
4
- data.tar.gz: 6424e9a7fcc978e739e80a0ee009fa141ce2ad25
3
+ metadata.gz: dfb99fe53f15f18d5bb38f6d14aab35df106395b
4
+ data.tar.gz: 822c5e1fd59b02589aa946252d57302d5afd0ca5
5
5
  SHA512:
6
- metadata.gz: 697f3c7d31e1aa7081eb0e471e1065dcb2a9ec0be7e57b0f9f130cea0c40bb96dba91bbbb9faaf30eaec0aac29de99ee5b27df8b278696d7d43a9c8d1d4e2826
7
- data.tar.gz: da505f1e0fcf03d21f594d81f32527dbe0b991dea6b310a400c0d5182cd573a9f3bfabeb3fddd5438a69dee344ef0dcbd540bc8994ee61cadf92e04a3238f436
6
+ metadata.gz: 114ea5f3dc9cf97f99ee2b920810f8ea7dabe2264ea2e17d64cdfe9e26ea729339b4de31e32ce9deeb460d6c3be57c865199f32101644a5c2dba4d854eb7e9b9
7
+ data.tar.gz: c32d14d4f25013beebb3aa60fe6edcaeb6de071597b0f41cc276cae51e5bd4b363b875f3f0ccd919172a9b84a24bbae14e4b4e423be2c28476cef25e4942fe3f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.0
4
+
5
+ * Basic DELETE operations
6
+
3
7
  ## 0.17.0
4
8
 
5
9
  * Basic messaging
@@ -26,7 +26,7 @@ module Acfs
26
26
  # user2.save
27
27
  # user2.persisted? # => true
28
28
  #
29
- # @return [ Boolean ] True if resource has no changes and is not newly created, false otherwise.
29
+ # @return [TrueClass, FalseClass] True if resource has no changes and is not newly created, false otherwise.
30
30
  #
31
31
  def persisted?
32
32
  !new? && !changed?
@@ -36,7 +36,7 @@ module Acfs
36
36
  #
37
37
  # Return true if model is a new record and was not saved yet.
38
38
  #
39
- # @return [ Boolean ] True if resource is newly created, false otherwise.
39
+ # @return [TrueClass, FalseClass] True if resource is newly created, false otherwise.
40
40
  #
41
41
  def new?
42
42
  read_attribute(:id).nil?
@@ -52,7 +52,7 @@ module Acfs
52
52
  #
53
53
  # Saving a resource is a synchronous operation.
54
54
  #
55
- # @return [ Boolean ] True if save operation was successful, false otherwise.
55
+ # @return [TrueClass, FalseClass] True if save operation was successful, false otherwise.
56
56
  # @see #save! See #save! for available options.
57
57
  #
58
58
  def save(*args)
@@ -68,12 +68,12 @@ module Acfs
68
68
  #
69
69
  # Saving a resource is a synchronous operation.
70
70
  #
71
- # @param [ Hash ] opts Hash with additional options.
72
- # @option opts [ Hash ] :data Data to send to remote service. Default will be resource attributes.
71
+ # @param [Hash] opts Hash with additional options.
72
+ # @option opts [Hash] :data Data to send to remote service. Default will be resource attributes.
73
73
  #
74
- # @raise [ Acfs::InvalidResource ]
74
+ # @raise [Acfs::InvalidResource]
75
75
  # If remote services respond with 422 response. Will fill errors with data from response
76
- # @raise [ Acfs::ErroneousResponse ]
76
+ # @raise [Acfs::ErroneousResponse]
77
77
  # If remote service respond with not successful response.
78
78
  #
79
79
  # @see #save
@@ -88,6 +88,44 @@ module Acfs
88
88
  end
89
89
  end
90
90
 
91
+ # @api public
92
+ #
93
+ # Destroy resource by sending a DELETE request.
94
+ #
95
+ # Deleting a resource is a synchronous operation.
96
+ #
97
+ # @return [TrueClass, FalseClass]
98
+ # @see #delete!
99
+ #
100
+ def delete(opts = {})
101
+ delete! opts
102
+ true
103
+ rescue Acfs::Error
104
+ false
105
+ end
106
+
107
+ # @api public
108
+ #
109
+ # Destroy resource by sending a DELETE request.
110
+ # Will raise an error in case something goes wrong.
111
+ #
112
+ # Deleting a resource is a synchronous operation.
113
+
114
+ # @raise [Acfs::ErroneousResponse]
115
+ # If remote service respond with not successful response.
116
+ # @return [undefined]
117
+ # @see #delete
118
+ #
119
+ def delete!(opts = {})
120
+ opts[:params] ||= {}
121
+ opts[:params].merge! id: id
122
+
123
+ operation :delete, opts do |data|
124
+ update_with data
125
+ freeze
126
+ end
127
+ end
128
+
91
129
  module ClassMethods
92
130
 
93
131
  # @api public
@@ -97,12 +135,12 @@ module Acfs
97
135
  #
98
136
  # Saving a resource is a synchronous operation.
99
137
  #
100
- # @param [ Hash{ Symbol, String => Object }] data Data to send in create request.
101
- # @return [ self ] Newly resource object.
138
+ # @param [Hash{Symbol, String => Object}] data Data to send in create request.
139
+ # @return [self] Newly resource object.
102
140
  #
103
- # @raise [ Acfs::InvalidResource ]
141
+ # @raise [Acfs::InvalidResource]
104
142
  # If remote services respond with 422 response. Will fill errors with data from response
105
- # @raise [ Acfs::ErroneousResponse ]
143
+ # @raise [Acfs::ErroneousResponse]
106
144
  # If remote service respond with not successful response.
107
145
  #
108
146
  # @see Acfs::Model::Persistence#save! Available options. `:data` will be overridden with provided data hash.
@@ -122,10 +160,10 @@ module Acfs
122
160
  #
123
161
  # Saving a resource is a synchronous operation.
124
162
  #
125
- # @param [ Hash{ Symbol, String => Object }] data Data to send in create request.
126
- # @return [ self ] Newly resource object.
163
+ # @param [Hash{Symbol, String => Object}] data Data to send in create request.
164
+ # @return [self] Newly resource object.
127
165
  #
128
- # @raise [ Acfs::ErroneousResponse ]
166
+ # @raise [Acfs::ErroneousResponse]
129
167
  # If remote service respond with not successful response.
130
168
  #
131
169
  # @see Acfs::Model::Persistence#save! Available options. `:data` will be overridden with provided data hash.
data/lib/acfs/stub.rb CHANGED
@@ -60,7 +60,7 @@ module Acfs
60
60
  stub = stub_for op
61
61
  unless stub
62
62
  return false if allow_requests?
63
- raise RealRequestsNotAllowedError, "No stub found for `#{op.resource.name}` with params `#{op.params}`"
63
+ raise RealRequestsNotAllowedError, "No stub found for `#{op.resource.name}` with params `#{op.params}` and id `#{op.id}`."
64
64
  end
65
65
 
66
66
  if (data = stub[:return])
data/lib/acfs/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Acfs
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 17
4
+ MINOR = 18
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
 
@@ -29,7 +29,7 @@ describe Acfs::Messaging::Receiver do
29
29
  rcv_class.instance.should_receive(:receive).with(anything, anything, { message: 'Hello!'})
30
30
 
31
31
  Acfs::Messaging::Client.instance.publish('my.custom_receiver', { message: 'Hello!' })
32
- sleep 1 # Nothing better?
32
+ sleep 3 # Nothing better?
33
33
  end
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ describe Acfs::Messaging::Receiver do
38
38
  rcv_class.instance.should_receive(:receive).with(anything, anything, { message: 'Hello!'})
39
39
 
40
40
  Acfs::Messaging::Client.instance.publish('my.different', { message: 'Hello!' })
41
- sleep 1 # Nothing better?
41
+ sleep 3 # Nothing better?
42
42
  end
43
43
  end
44
44
  end
@@ -48,7 +48,7 @@ describe Acfs::Messaging::Receiver do
48
48
  rcv_class.instance.should_not_receive(:receive)
49
49
 
50
50
  Acfs::Messaging::Client.instance.publish('abc.cde', { message: 'Hello!' })
51
- sleep 1 # Nothing better?
51
+ sleep 3 # Nothing better?
52
52
  end
53
53
  end
54
54
  end
@@ -3,28 +3,31 @@ require 'spec_helper'
3
3
  describe Acfs::Model::Persistence do
4
4
  let(:model_class) { MyUser }
5
5
  before do
6
- @get_stub = stub_request(:get, "http://users.example.org/users/1").to_return response({ id: 1, name: "Anon", age: 12 })
6
+ @get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name: "Anon", age: 12 })
7
7
 
8
8
  @patch_stub = stub_request(:put, 'http://users.example.org/users/1')
9
- .with(
10
- body: '{"id":1,"name":"Idefix","age":12}')
11
- .to_return response({ id: 1, name: 'Idefix', age: 12 })
9
+ .with(body: '{"id":1,"name":"Idefix","age":12}')
10
+ .to_return response({ id: 1, name: 'Idefix', age: 12 })
12
11
 
13
12
  @post_stub = stub_request(:post, 'http://users.example.org/users')
14
- .with(body: '{"id":null,"name":"Idefix","age":12}')
15
- .to_return response({ id: 5, name: 'Idefix', age: 12 })
13
+ .with(body: '{"id":null,"name":"Idefix","age":12}')
14
+ .to_return response({ id: 5, name: 'Idefix', age: 12 })
16
15
 
17
16
  stub_request(:post, 'http://users.example.org/users')
18
- .with(body: '{"id":null,"name":"Anon","age":null}')
19
- .to_return response({ id: 5, name: 'Anon', age: 12 })
17
+ .with(body: '{"id":null,"name":"Anon","age":null}')
18
+ .to_return response({ id: 5, name: 'Anon', age: 12 })
20
19
 
21
20
  stub_request(:post, 'http://users.example.org/users')
22
- .with(body: '{"name":"Idefix","age":12}')
23
- .to_return response({ id: 5, name: 'Idefix', age: 12 })
21
+ .with(body: '{"name":"Idefix","age":12}')
22
+ .to_return response({ id: 5, name: 'Idefix', age: 12 })
24
23
 
25
24
  stub_request(:post, 'http://users.example.org/users')
26
- .with(body: '{"age":12}')
27
- .to_return response({ errors: { name: [ 'required' ] }}, status: 422)
25
+ .with(body: '{"age":12}')
26
+ .to_return response({ errors: { name: [ 'required' ] }}, status: 422)
27
+
28
+ @del = stub_request(:delete, 'http://users.example.org/users/1')
29
+ .with(body: '{}')
30
+ .to_return response({ id: 1, name: 'Idefix', age: 12 }, status: 200)
28
31
  end
29
32
 
30
33
  context 'new model' do
@@ -79,11 +82,26 @@ describe Acfs::Model::Persistence do
79
82
 
80
83
  context 'with changes' do
81
84
  let(:model) { model_class.find 1 }
82
- before { model; Acfs.run; model.name = "dhh" }
85
+ before { model; Acfs.run; model.name = 'dhh' }
83
86
 
84
87
  it { expect(model).to_not be_persisted }
85
88
  it { expect(model).to_not be_new }
86
89
  end
90
+
91
+ describe '#delete!' do
92
+ let(:model) { model_class.find 1 }
93
+ before { model; Acfs.run }
94
+
95
+ it 'should trigger DELETE request' do
96
+ model.delete!
97
+ expect(@del).to have_been_requested
98
+ end
99
+
100
+ it 'should be frozen after DELETE' do
101
+ model.delete!
102
+ expect(model).to be_frozen
103
+ end
104
+ end
87
105
  end
88
106
 
89
107
  describe '.create!' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-27 00:00:00.000000000 Z
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport