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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/acfs/model/persistence.rb +52 -14
- data/lib/acfs/stub.rb +1 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/messaging/receiver_spec.rb +3 -3
- data/spec/acfs/model/persistance_spec.rb +31 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfb99fe53f15f18d5bb38f6d14aab35df106395b
|
4
|
+
data.tar.gz: 822c5e1fd59b02589aa946252d57302d5afd0ca5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 114ea5f3dc9cf97f99ee2b920810f8ea7dabe2264ea2e17d64cdfe9e26ea729339b4de31e32ce9deeb460d6c3be57c865199f32101644a5c2dba4d854eb7e9b9
|
7
|
+
data.tar.gz: c32d14d4f25013beebb3aa60fe6edcaeb6de071597b0f41cc276cae51e5bd4b363b875f3f0ccd919172a9b84a24bbae14e4b4e423be2c28476cef25e4942fe3f
|
data/CHANGELOG.md
CHANGED
@@ -26,7 +26,7 @@ module Acfs
|
|
26
26
|
# user2.save
|
27
27
|
# user2.persisted? # => true
|
28
28
|
#
|
29
|
-
# @return [
|
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 [
|
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 [
|
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 [
|
72
|
-
# @option opts [
|
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 [
|
74
|
+
# @raise [Acfs::InvalidResource]
|
75
75
|
# If remote services respond with 422 response. Will fill errors with data from response
|
76
|
-
# @raise [
|
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 [
|
101
|
-
# @return [
|
138
|
+
# @param [Hash{Symbol, String => Object}] data Data to send in create request.
|
139
|
+
# @return [self] Newly resource object.
|
102
140
|
#
|
103
|
-
# @raise [
|
141
|
+
# @raise [Acfs::InvalidResource]
|
104
142
|
# If remote services respond with 422 response. Will fill errors with data from response
|
105
|
-
# @raise [
|
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 [
|
126
|
-
# @return [
|
163
|
+
# @param [Hash{Symbol, String => Object}] data Data to send in create request.
|
164
|
+
# @return [self] Newly resource object.
|
127
165
|
#
|
128
|
-
# @raise [
|
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
@@ -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
|
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
|
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
|
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,
|
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
|
-
|
10
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
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 =
|
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.
|
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-
|
11
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|