shutl_resource 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,9 +21,8 @@ module Shutl::Resource
21
21
  end
22
22
 
23
23
  def find(args = {}, params = {})
24
- params = args if @singular_resource
25
-
26
24
  if @singular_resource
25
+ params = args
27
26
  url = singular_member_url params
28
27
  elsif !args.kind_of?(Hash)
29
28
  id = args
@@ -196,8 +195,8 @@ module Shutl::Resource
196
195
  args
197
196
  end
198
197
 
199
- def singular_member_url params={}
200
- generate_url! "/#{@resource_name}", params
198
+ def singular_member_url params
199
+ generate_url! "/#{@resource_name}", {}, params
201
200
  end
202
201
 
203
202
  def member_url *args
@@ -230,10 +229,10 @@ module Shutl::Resource
230
229
  'User-Agent' => "Shutl Resource Gem v#{Shutl::Resource::VERSION}"
231
230
  }
232
231
  end
233
-
232
+
234
233
  def header_options params
235
234
  header_opts = params[:headers] || {}
236
- header_opts.merge!(authorization: "Bearer #{params[:auth]}") if params[:auth]
235
+ header_opts.merge!(authorization: "Bearer #{params[:auth]}") if params[:auth]
237
236
  header_opts.merge!(from: current_user_email(params)) if current_user_email(params)
238
237
  header_opts
239
238
  end
@@ -250,7 +249,7 @@ module Shutl::Resource
250
249
  end
251
250
  end
252
251
 
253
- def header_name header_key
252
+ def header_name header_key
254
253
  header_key.split(%r{\_|\-}).map {|e| e.capitalize }.join("-")
255
254
  end
256
255
 
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '1.5.4'
3
+ VERSION = '1.5.5'
4
4
  end
5
5
  end
@@ -13,34 +13,54 @@ describe Shutl::Resource::Rest do
13
13
  context "with a singular resource" do
14
14
  let(:resource) { TestSingularResource.new }
15
15
 
16
- before do
17
- @request = stub_request(:get, 'http://host/test_singular_resource').
18
- to_return(:status => 200,
19
- :body => '{"test_singular_resource": { "a": "a", "b": 2 }}',
20
- :headers => headers)
16
+ let(:response) do
17
+ {
18
+ status: 200,
19
+ body: '{"test_singular_resource": { "a": "a", "b": 2 }}',
20
+ headers: headers
21
+ }
21
22
  end
22
23
 
23
- it 'queries the endpoint' do
24
- TestSingularResource.find(auth: "some auth")
25
- @request.should have_been_requested
26
- end
24
+ context 'without params' do
25
+ before do
26
+ @request = stub_request(:get, 'http://host/test_singular_resource').
27
+ with(headers: {'Authorization'=>'Bearer some auth'}).to_return(response)
28
+ end
27
29
 
28
- it 'should parse the result of the body to create an object' do
29
- resource = TestSingularResource.find(auth: "some auth")
30
+ it 'queries the endpoint' do
31
+ TestSingularResource.find(auth: "some auth")
32
+ @request.should have_been_requested
33
+ end
30
34
 
31
- resource.should_not be_nil
32
- resource.should be_kind_of TestSingularResource
33
- end
35
+ it 'should parse the result of the body to create an object' do
36
+ resource = TestSingularResource.find(auth: "some auth")
34
37
 
35
- it 'should assign the attributes based on the json returned' do
36
- resource = TestSingularResource.find(auth: "some auth")
38
+ resource.should_not be_nil
39
+ resource.should be_kind_of TestSingularResource
40
+ end
41
+
42
+ it 'should assign the attributes based on the json returned' do
43
+ resource = TestSingularResource.find(auth: "some auth")
44
+
45
+ resource.a.should == 'a'
46
+ resource.b.should == 2
47
+ end
37
48
 
38
- resource.a.should == 'a'
39
- resource.b.should == 2
49
+ it 'always responsd to id even if there is no attribute' do
50
+ resource.id.should be_nil
51
+ end
40
52
  end
41
53
 
42
- it 'always responsd to id even if there is no attribute' do
43
- resource.id.should be_nil
54
+ describe 'with params' do
55
+ before do
56
+ @request = stub_request(:get, 'http://host/test_singular_resource?param=value').
57
+ with(headers: {'Authorization'=>'Bearer some auth'}).to_return(response)
58
+ end
59
+
60
+ it 'adds the params to the url' do
61
+ TestSingularResource.find(param: 'value', auth: 'some auth')
62
+ @request.should have_been_requested
63
+ end
44
64
  end
45
65
  end
46
66
 
@@ -385,9 +405,9 @@ describe Shutl::Resource::Rest do
385
405
 
386
406
  it "should override the email with 'from' option" do
387
407
  request = stub_request(:post, 'http://host/test_rests').with(headers: headers.merge(from: 'new@example.com')).to_return(:status => 200)
388
- TestRest.create({}, from: 'new@example.com')
408
+ TestRest.create({}, from: 'new@example.com')
389
409
 
390
- request.should have_been_requested
410
+ request.should have_been_requested
391
411
  end
392
412
 
393
413
  it "should be thread-safe" do
@@ -395,14 +415,14 @@ describe Shutl::Resource::Rest do
395
415
  sleep 0.5
396
416
  Shutl::Resource::RestClassMethods.from_user = 'thread1 user'
397
417
  stub_request(:post, 'http://host/test_rests').with(headers: headers.merge(from: 'thread1 user')).to_return(:status => 200)
398
- TestRest.create
418
+ TestRest.create
399
419
  end
400
420
 
401
421
  t2 = Thread.new do
402
422
  Shutl::Resource::RestClassMethods.from_user = 'thread2 user'
403
423
  sleep 1
404
424
  stub_request(:post, 'http://host/test_rests').with(headers: headers.merge(from: 'thread2 user')).to_return(:status => 200)
405
- TestRest.create
425
+ TestRest.create
406
426
  end
407
427
 
408
428
  t1.join; t2.join
@@ -521,7 +541,7 @@ describe Shutl::Resource::Rest do
521
541
  test_resource = TestRest.new
522
542
  test_resource.update!({a: 'a', b: 'b'}, {from: 'new@example.com'})
523
543
 
524
- request.should have_been_requested
544
+ request.should have_been_requested
525
545
  end
526
546
 
527
547
  it "should be thread-safe" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-11-18 00:00:00.000000000 Z
15
+ date: 2014-01-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: shutl_auth