ddy_remote_resource 0.4.10 → 0.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Guardfile +45 -0
- data/lib/remote_resource/querying/finder_methods.rb +7 -10
- data/lib/remote_resource/querying/persistence_methods.rb +7 -8
- data/lib/remote_resource/request.rb +2 -3
- data/lib/remote_resource/version.rb +1 -1
- data/remote_resource.gemspec +3 -0
- data/spec/lib/remote_resource/querying/finder_methods_spec.rb +24 -0
- data/spec/lib/remote_resource/querying/persistence_methods_spec.rb +68 -0
- data/spec/lib/remote_resource/version_spec.rb +1 -1
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae92e08ce0a95cfc8253c09f3106087caf9ba636
|
4
|
+
data.tar.gz: 0e675db4069759cb3bf185c616821c78f55b1cad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b829236979e4f246503864b810da68b9939e84e2fdab2c288131a20bbde39fed70660b1a708d9390818e4d408579cf94db7508300c5cc1a3d1dc777cc84aeff
|
7
|
+
data.tar.gz: d8ed2d8f09246377321acb6a2a0cd1a889e2090a2504509346d209f52cb6f541b3f7e30e890cbc72e06d778c36bd10c1071c74abf2adf909e48fb737b1f14796
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/Guardfile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: 'bundle exec rspec', notification: true do
|
28
|
+
require 'guard/rspec/dsl'
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Notification (See: https://github.com/Codaisseur/terminal-notifier-guard)
|
44
|
+
notification :terminal_notifier, app_name: 'RemoteResource', activate: 'com.googlecode.iTerm2' if `uname` =~ /Darwin/
|
45
|
+
end
|
@@ -6,26 +6,23 @@ module RemoteResource
|
|
6
6
|
module ClassMethods
|
7
7
|
|
8
8
|
def find(id, connection_options = {})
|
9
|
-
connection_options.merge
|
10
|
-
response
|
11
|
-
build_resource_from_response response
|
9
|
+
response = RemoteResource::Request.new(self, :get, { id: id }, connection_options.merge(no_attributes: true)).perform
|
10
|
+
build_resource_from_response(response)
|
12
11
|
end
|
13
12
|
|
14
13
|
def find_by(params, connection_options = {})
|
15
14
|
response = RemoteResource::Request.new(self, :get, params, connection_options).perform
|
16
|
-
build_resource_from_response
|
15
|
+
build_resource_from_response(response)
|
17
16
|
end
|
18
17
|
|
19
18
|
def all(connection_options = {})
|
20
|
-
connection_options.merge
|
21
|
-
response
|
22
|
-
build_collection_from_response response
|
19
|
+
response = RemoteResource::Request.new(self, :get, {}, connection_options.merge(collection: true)).perform
|
20
|
+
build_collection_from_response(response)
|
23
21
|
end
|
24
22
|
|
25
23
|
def where(params, connection_options = {})
|
26
|
-
connection_options.merge
|
27
|
-
response
|
28
|
-
build_collection_from_response response
|
24
|
+
response = RemoteResource::Request.new(self, :get, params, connection_options.merge(collection: true)).perform
|
25
|
+
build_collection_from_response(response)
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
@@ -6,9 +6,9 @@ module RemoteResource
|
|
6
6
|
module ClassMethods
|
7
7
|
|
8
8
|
def create(attributes = {}, connection_options = {})
|
9
|
-
resource = new
|
9
|
+
resource = new(attributes)
|
10
10
|
response = RemoteResource::Request.new(self, :post, attributes, connection_options).perform
|
11
|
-
resource.handle_response
|
11
|
+
resource.handle_response(response)
|
12
12
|
end
|
13
13
|
|
14
14
|
def destroy(id, connection_options = {})
|
@@ -19,24 +19,23 @@ module RemoteResource
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def update_attributes(attributes = {}, connection_options = {})
|
22
|
-
rebuild_resource
|
23
|
-
attributes.reverse_merge
|
24
|
-
create_or_update attributes, connection_options
|
22
|
+
rebuild_resource(attributes)
|
23
|
+
create_or_update(attributes.reverse_merge(id: id), connection_options)
|
25
24
|
success? ? self : false
|
26
25
|
end
|
27
26
|
|
28
27
|
def save(connection_options = {})
|
29
|
-
create_or_update
|
28
|
+
create_or_update(self.attributes, connection_options)
|
30
29
|
success? ? self : false
|
31
30
|
end
|
32
31
|
|
33
32
|
def create_or_update(attributes = {}, connection_options = {})
|
34
|
-
if attributes.has_key?
|
33
|
+
if attributes.has_key?(:id)
|
35
34
|
response = RemoteResource::Request.new(self, :patch, attributes, connection_options).perform
|
36
35
|
else
|
37
36
|
response = RemoteResource::Request.new(self, :post, attributes, connection_options).perform
|
38
37
|
end
|
39
|
-
handle_response
|
38
|
+
handle_response(response)
|
40
39
|
end
|
41
40
|
|
42
41
|
def destroy(connection_options = {})
|
@@ -17,12 +17,11 @@ module RemoteResource
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def connection_options
|
20
|
-
@connection_options.reverse_merge
|
21
|
-
@connection_options.reverse_merge! resource.connection_options.to_hash
|
20
|
+
@connection_options.reverse_merge(threaded_connection_options).reverse_merge(resource.connection_options.to_hash)
|
22
21
|
end
|
23
22
|
|
24
23
|
def original_connection_options
|
25
|
-
@original_connection_options.reverse_merge
|
24
|
+
@original_connection_options.reverse_merge(threaded_connection_options)
|
26
25
|
end
|
27
26
|
|
28
27
|
def perform
|
data/remote_resource.gemspec
CHANGED
@@ -23,6 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
24
24
|
spec.add_development_dependency 'pry', '~> 0.10'
|
25
25
|
spec.add_development_dependency 'webmock', '~> 1.24'
|
26
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
28
|
+
spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6.1'
|
26
29
|
|
27
30
|
spec.add_runtime_dependency 'activesupport', '~> 4.1'
|
28
31
|
spec.add_runtime_dependency 'activemodel', '~> 4.1'
|
@@ -36,6 +36,12 @@ describe RemoteResource::Querying::FinderMethods do
|
|
36
36
|
dummy_class.find('12')
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'does NOT change the given connection_options' do
|
40
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
41
|
+
|
42
|
+
expect { dummy_class.find('12', connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
43
|
+
end
|
44
|
+
|
39
45
|
context 'with extra params' do
|
40
46
|
it 'performs a RemoteResource::Request with params' do
|
41
47
|
stub_request(:get, 'https://foobar.com/finder_methods_dummy/12.json?skip_associations=true').to_return(status: 200, body: {}.to_json)
|
@@ -67,6 +73,12 @@ describe RemoteResource::Querying::FinderMethods do
|
|
67
73
|
expect(dummy_class).to receive(:build_resource_from_response).with response
|
68
74
|
dummy_class.find_by params
|
69
75
|
end
|
76
|
+
|
77
|
+
it 'does NOT change the given connection_options' do
|
78
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
79
|
+
|
80
|
+
expect { dummy_class.find_by(params, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
81
|
+
end
|
70
82
|
end
|
71
83
|
|
72
84
|
describe '.all' do
|
@@ -87,6 +99,12 @@ describe RemoteResource::Querying::FinderMethods do
|
|
87
99
|
expect(dummy_class).to receive(:build_collection_from_response).with response
|
88
100
|
dummy_class.all
|
89
101
|
end
|
102
|
+
|
103
|
+
it 'does NOT change the given connection_options' do
|
104
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
105
|
+
|
106
|
+
expect { dummy_class.all(connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
107
|
+
end
|
90
108
|
end
|
91
109
|
|
92
110
|
describe '.where' do
|
@@ -110,6 +128,12 @@ describe RemoteResource::Querying::FinderMethods do
|
|
110
128
|
expect(dummy_class).to receive(:build_collection_from_response).with response
|
111
129
|
dummy_class.where params
|
112
130
|
end
|
131
|
+
|
132
|
+
it 'does NOT change the given connection_options' do
|
133
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
134
|
+
|
135
|
+
expect { dummy_class.where(params, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
136
|
+
end
|
113
137
|
end
|
114
138
|
|
115
139
|
end
|
@@ -44,6 +44,16 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
44
44
|
expect_any_instance_of(dummy_class).to receive(:handle_response).with response
|
45
45
|
dummy_class.create attributes
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'does NOT change the given attributes' do
|
49
|
+
expect { dummy_class.create(attributes) }.not_to change { attributes }.from({ name: 'Mies' })
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'does NOT change the given connection_options' do
|
53
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
54
|
+
|
55
|
+
expect { dummy_class.create(attributes, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
56
|
+
end
|
47
57
|
end
|
48
58
|
|
49
59
|
describe '.destroy' do
|
@@ -70,6 +80,12 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
70
80
|
dummy_class.destroy('15')
|
71
81
|
end
|
72
82
|
|
83
|
+
it 'does NOT change the given connection_options' do
|
84
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
85
|
+
|
86
|
+
expect { dummy_class.destroy('15', connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
87
|
+
end
|
88
|
+
|
73
89
|
context 'request' do
|
74
90
|
let(:response) { { status: 200, body: '' } }
|
75
91
|
before { allow_any_instance_of(RemoteResource::Request).to receive(:perform).and_call_original }
|
@@ -112,6 +128,16 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
112
128
|
expect(dummy).to receive(:create_or_update).with(attributes, {})
|
113
129
|
dummy.update_attributes attributes
|
114
130
|
end
|
131
|
+
|
132
|
+
it 'does NOT change the given attributes' do
|
133
|
+
expect { dummy.update_attributes(attributes) }.not_to change { attributes }.from({ id: 14, name: 'Noot' })
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'does NOT change the given connection_options' do
|
137
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
138
|
+
|
139
|
+
expect { dummy.update_attributes(attributes, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
140
|
+
end
|
115
141
|
end
|
116
142
|
|
117
143
|
context 'when the id is NOT given in the attributes' do
|
@@ -119,6 +145,16 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
119
145
|
expect(dummy).to receive(:create_or_update).with(attributes.merge(id: dummy.id), {})
|
120
146
|
dummy.update_attributes attributes
|
121
147
|
end
|
148
|
+
|
149
|
+
it 'does NOT change the given attributes' do
|
150
|
+
expect { dummy.update_attributes(attributes) }.not_to change { attributes }.from({ name: 'Noot' })
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'does NOT change the given connection_options' do
|
154
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
155
|
+
|
156
|
+
expect { dummy.update_attributes(attributes, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
157
|
+
end
|
122
158
|
end
|
123
159
|
|
124
160
|
context 'when the save was successful' do
|
@@ -151,6 +187,12 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
151
187
|
dummy.save
|
152
188
|
end
|
153
189
|
|
190
|
+
it 'does NOT change the given connection_options' do
|
191
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
192
|
+
|
193
|
+
expect { dummy.save(connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
194
|
+
end
|
195
|
+
|
154
196
|
context 'when the save was successful' do
|
155
197
|
it 'returns the resource' do
|
156
198
|
allow(dummy).to receive(:success?) { true }
|
@@ -191,6 +233,16 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
191
233
|
expect(dummy).to receive(:handle_response).with response
|
192
234
|
dummy.create_or_update attributes
|
193
235
|
end
|
236
|
+
|
237
|
+
it 'does NOT change the given attributes' do
|
238
|
+
expect { dummy.create_or_update(attributes) }.not_to change { attributes }.from({ id: 10, name: 'Kees' })
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'does NOT change the given connection_options' do
|
242
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
243
|
+
|
244
|
+
expect { dummy.create_or_update(attributes, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
245
|
+
end
|
194
246
|
end
|
195
247
|
|
196
248
|
context 'when the attributes do NOT contain an id' do
|
@@ -208,6 +260,16 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
208
260
|
expect(dummy).to receive(:handle_response).with response
|
209
261
|
dummy.create_or_update attributes
|
210
262
|
end
|
263
|
+
|
264
|
+
it 'does NOT change the given attributes' do
|
265
|
+
expect { dummy.create_or_update(attributes) }.not_to change { attributes }.from({ name: 'Mies' })
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'does NOT change the given connection_options' do
|
269
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
270
|
+
|
271
|
+
expect { dummy.create_or_update(attributes, connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
272
|
+
end
|
211
273
|
end
|
212
274
|
end
|
213
275
|
|
@@ -233,6 +295,12 @@ describe RemoteResource::Querying::PersistenceMethods do
|
|
233
295
|
dummy.destroy
|
234
296
|
end
|
235
297
|
|
298
|
+
it 'does NOT change the given connection_options' do
|
299
|
+
connection_options = { headers: { 'Foo' => 'Bar' } }
|
300
|
+
|
301
|
+
expect { dummy.destroy(connection_options) }.not_to change { connection_options }.from({ headers: { 'Foo' => 'Bar' } })
|
302
|
+
end
|
303
|
+
|
236
304
|
context 'request' do
|
237
305
|
let(:response) { { status: 200, body: '' } }
|
238
306
|
before { allow_any_instance_of(RemoteResource::Request).to receive(:perform).and_call_original }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddy_remote_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan van der Pas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,48 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.24'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.14'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.14'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: terminal-notifier-guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.6.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.6.1
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: activesupport
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,6 +238,7 @@ files:
|
|
196
238
|
- ".ruby-version"
|
197
239
|
- ".travis.yml"
|
198
240
|
- Gemfile
|
241
|
+
- Guardfile
|
199
242
|
- LICENSE.txt
|
200
243
|
- README.md
|
201
244
|
- Rakefile
|
@@ -252,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
295
|
version: '0'
|
253
296
|
requirements: []
|
254
297
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.
|
298
|
+
rubygems_version: 2.5.1
|
256
299
|
signing_key:
|
257
300
|
specification_version: 4
|
258
301
|
summary: RemoteResource, a gem to use resources with REST services.
|