redbooth-ruby 0.0.5 → 0.1.0

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +0 -1
  4. data/README.md +187 -115
  5. data/lib/redbooth-ruby/client.rb +6 -39
  6. data/lib/redbooth-ruby/client_operations/perform.rb +93 -0
  7. data/lib/redbooth-ruby/file.rb +8 -0
  8. data/lib/redbooth-ruby/helpers.rb +32 -0
  9. data/lib/redbooth-ruby/operations/base.rb +3 -2
  10. data/lib/redbooth-ruby/request/collection.rb +3 -2
  11. data/lib/redbooth-ruby/request/connection.rb +66 -30
  12. data/lib/redbooth-ruby/request/helpers.rb +2 -2
  13. data/lib/redbooth-ruby/request/info.rb +1 -1
  14. data/lib/redbooth-ruby/request/validator.rb +2 -2
  15. data/lib/redbooth-ruby/session.rb +34 -11
  16. data/lib/redbooth-ruby/task_list.rb +28 -0
  17. data/lib/redbooth-ruby/version.rb +2 -2
  18. data/lib/redbooth-ruby.rb +6 -3
  19. data/spec/cassettes/RedboothRuby_File/_download/downloads_a_file.yml +354 -0
  20. data/spec/cassettes/RedboothRuby_Organization/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_organization.yml +4 -4
  21. data/spec/cassettes/RedboothRuby_Project/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_project.yml +110 -110
  22. data/spec/cassettes/RedboothRuby_Session/_refresh_access_token_/.yml +55 -0
  23. data/spec/cassettes/RedboothRuby_Session/_refresh_access_token_/call_on_token_refresh_with_the_old_and_new_token.yml +55 -0
  24. data/spec/cassettes/RedboothRuby_Session/_refresh_access_token_/refreshes_the_access_token.yml +55 -0
  25. data/spec/redbooth-ruby/base_spec.rb +5 -5
  26. data/spec/redbooth-ruby/client_operations/metadata_spec.rb +4 -4
  27. data/spec/redbooth-ruby/client_operations/perform_spec.rb +135 -0
  28. data/spec/redbooth-ruby/client_operations/search_spec.rb +4 -4
  29. data/spec/redbooth-ruby/client_spec.rb +2 -43
  30. data/spec/redbooth-ruby/comment_spec.rb +17 -18
  31. data/spec/redbooth-ruby/conversation_spec.rb +16 -16
  32. data/spec/redbooth-ruby/file_spec.rb +29 -22
  33. data/spec/redbooth-ruby/me_spec.rb +2 -2
  34. data/spec/redbooth-ruby/membership_spec.rb +18 -18
  35. data/spec/redbooth-ruby/note_spec.rb +16 -16
  36. data/spec/redbooth-ruby/organization_spec.rb +16 -16
  37. data/spec/redbooth-ruby/person_spec.rb +18 -18
  38. data/spec/redbooth-ruby/project_spec.rb +18 -18
  39. data/spec/redbooth-ruby/request/base_spec.rb +5 -5
  40. data/spec/redbooth-ruby/request/collection_spec.rb +3 -3
  41. data/spec/redbooth-ruby/request/connection_spec.rb +8 -8
  42. data/spec/redbooth-ruby/request/info_spec.rb +13 -13
  43. data/spec/redbooth-ruby/request/response_spec.rb +4 -4
  44. data/spec/redbooth-ruby/request/validator_spec.rb +7 -7
  45. data/spec/redbooth-ruby/session_spec.rb +100 -0
  46. data/spec/redbooth-ruby/subtaks_spec.rb +16 -16
  47. data/spec/redbooth-ruby/task_spec.rb +22 -22
  48. data/spec/redbooth-ruby/user_spec.rb +4 -4
  49. data/spec/redbooth_spec.rb +13 -13
  50. data/spec/spec_helper.rb +2 -3
  51. data/temp/spec/files/test_download.txt +8 -0
  52. metadata +41 -24
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://redbooth.com/oauth2/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=_your_consumer_key_&client_secret=_your_consumer_secret_&grant_type=refresh_token&refresh_token=_your_user_refresh_token_
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-store
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Date:
28
+ - Tue, 17 Feb 2015 19:04:21 GMT
29
+ Pragma:
30
+ - no-cache
31
+ Server:
32
+ - nginx
33
+ Status:
34
+ - 200 OK
35
+ Vary:
36
+ - Accept-Encoding
37
+ - Accept-Encoding
38
+ X-Rack-Cache:
39
+ - invalidate, pass
40
+ X-Request-Id:
41
+ - ae886c7b4f2c7fed8d6777b92282938d
42
+ X-Runtime:
43
+ - '0.098434'
44
+ X-Ua-Compatible:
45
+ - IE=Edge,chrome=1
46
+ Content-Length:
47
+ - '185'
48
+ Connection:
49
+ - keep-alive
50
+ body:
51
+ encoding: ASCII-8BIT
52
+ string: '{"access_token":"_your_new_user_token_","token_type":"bearer","expires_in":7200,"refresh_token":"_your_new_user_refresh_token_","scope":"all"}'
53
+ http_version:
54
+ recorded_at: Tue, 17 Feb 2015 19:04:22 GMT
55
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://redbooth.com/oauth2/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=_your_consumer_key_&client_secret=_your_consumer_secret_&grant_type=refresh_token&refresh_token=_your_user_refresh_token_
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-store
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Date:
28
+ - Tue, 17 Feb 2015 19:04:21 GMT
29
+ Pragma:
30
+ - no-cache
31
+ Server:
32
+ - nginx
33
+ Status:
34
+ - 200 OK
35
+ Vary:
36
+ - Accept-Encoding
37
+ - Accept-Encoding
38
+ X-Rack-Cache:
39
+ - invalidate, pass
40
+ X-Request-Id:
41
+ - ae886c7b4f2c7fed8d6777b92282938d
42
+ X-Runtime:
43
+ - '0.098434'
44
+ X-Ua-Compatible:
45
+ - IE=Edge,chrome=1
46
+ Content-Length:
47
+ - '185'
48
+ Connection:
49
+ - keep-alive
50
+ body:
51
+ encoding: ASCII-8BIT
52
+ string: '{"access_token":"_your_new_user_token_","token_type":"bearer","expires_in":7200,"refresh_token":"_your_new_user_refresh_token_","scope":"all"}'
53
+ http_version:
54
+ recorded_at: Tue, 17 Feb 2015 19:04:22 GMT
55
+ recorded_with: VCR 2.9.3
@@ -1,12 +1,12 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::Base do
4
- describe "#parse_timestamps" do
5
- context "given #created_time is present" do
6
- it "creates a Time object" do
4
+ describe '#parse_timestamps' do
5
+ context 'given #created_time is present' do
6
+ it 'creates a Time object' do
7
7
  base = RedboothRuby::Base.new(created_time: 1358300444)
8
8
  expect(base.created_time.class).to eql(Time)
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::ClientOperations::Metadata, vcr: 'metadata' do
4
4
  include_context 'authentication'
@@ -10,10 +10,10 @@ describe RedboothRuby::ClientOperations::Metadata, vcr: 'metadata' do
10
10
  end
11
11
  let(:endpoint) { 'metadata/search' }
12
12
 
13
- describe ".metadata" do
13
+ describe '.metadata' do
14
14
  subject { client.metadata(search_params) }
15
15
 
16
- it "makes a new GET request using the correct API endpoint to receive notes collection" do
16
+ it 'makes a new GET request using the correct API endpoint to receive notes collection' do
17
17
  expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, search_params, { session: session }).and_call_original
18
18
  subject
19
19
  end
@@ -21,4 +21,4 @@ describe RedboothRuby::ClientOperations::Metadata, vcr: 'metadata' do
21
21
  it { expect(subject.class).to eql RedboothRuby::Request::Collection }
22
22
  it { expect(subject.all.first).to be_a RedboothRuby::Base }
23
23
  end
24
- end
24
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe RedboothRuby::ClientOperations::Perform do
4
+ let(:access_token) do
5
+ {
6
+ token: '_your_user_token_',
7
+ secret: '_your_secret_token_',
8
+ refresh_token: '_your_user_reset_token_'
9
+ }
10
+ end
11
+ let(:session) { RedboothRuby::Session.new(access_token) }
12
+ let(:performer) { RedboothRuby::ClientOperations::Perform.new(:user, :show, session) }
13
+
14
+ describe '#initialize' do
15
+ subject { performer }
16
+
17
+ it { expect(performer.resource_name).to eql :user }
18
+ it { expect(performer.action).to eql :show }
19
+ it { expect(performer.session).to eql session }
20
+ end
21
+
22
+ describe '#perform!' do
23
+ it 'is private' do
24
+ expect{ performer.perform! }.to raise_error
25
+ end
26
+ it 'raises RedboothRuby::AuthenticationError if session is invalid' do
27
+ allow(performer).to receive(:session).and_return(nil)
28
+ expect{ performer.perform! }.to raise_error(RedboothRuby::AuthenticationError)
29
+ end
30
+ it 'calls to the given resource' do
31
+ allow(RedboothRuby::User).to receive(:show).and_return(RedboothRuby::User.new)
32
+ expect(RedboothRuby::User).to receive(:show).with({ session: session })
33
+
34
+ performer.perform!
35
+ end
36
+
37
+ context 'oauth token expired' do
38
+ before do
39
+ allow(RedboothRuby::User).to receive(:show).and_raise(RedboothRuby::OauthTokenExpired)
40
+ end
41
+ it 'tries to refresh access_token' do
42
+ allow(session).to receive(:refresh_access_token!).and_return({})
43
+ expect(session).to receive(:refresh_access_token!)
44
+ expect{ performer.perform! }.to raise_error(RedboothRuby::OauthTokenExpired)
45
+ end
46
+ it 'raise error if `refresh_access_token` fails' do
47
+ allow(session).to receive(:refresh_access_token!).and_return(nil)
48
+ expect{ performer.perform! }.to raise_error(RedboothRuby::OauthTokenExpired)
49
+ end
50
+ it 'raise error if `auto_refresh_token` is disabled' do
51
+ session.auto_refresh_token = false
52
+ expect{ performer.perform! }.to raise_error(RedboothRuby::OauthTokenExpired)
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#perform_processing!' do
58
+ let(:processing) do
59
+ RedboothRuby::Processing.new(OpenStruct.new(data: { 'retry_after' => '0' }))
60
+ end
61
+ it 'delays the processing' do
62
+ allow(performer).to receive(:processing_error).and_return(processing)
63
+ allow(performer).to receive(:perform!).and_return(nil)
64
+ expect(performer).to receive(:perform!).once
65
+ performer.perform_processing!
66
+ end
67
+ it 'retries the the processing' do
68
+ allow(performer).to receive(:processing_error).and_return(processing)
69
+ expect(performer).to receive(:retry_in).with(0)
70
+ performer.perform_processing!
71
+ end
72
+ it 'use 10 seconds as default delay' do
73
+ expect(performer).to receive(:retry_in).with(10)
74
+ performer.perform_processing!
75
+ end
76
+ end
77
+
78
+ describe '#perform_oauth_token_expired!' do
79
+ let(:oauth_token_expired_error) { RedboothRuby::OauthTokenExpired.new }
80
+ before do
81
+ allow(performer).to receive(:oauth_token_expired_error).and_return(oauth_token_expired_error)
82
+ end
83
+
84
+ context 'when it\'s the first attempt and refresh access token present' do
85
+ before do
86
+ allow(performer.session).to receive(:refresh_access_token!).and_return({})
87
+ allow(performer).to receive(:tries).and_return(1)
88
+ end
89
+ it 'refreshes the session access token' do
90
+ allow(performer).to receive(:perform!)
91
+ allow(performer).to receive(:refresh_session_access_token!).and_return(true)
92
+ expect(performer).to receive(:refresh_session_access_token!).once
93
+ performer.perform_oauth_token_expired!
94
+ end
95
+ it 'retries the processing' do
96
+ expect(performer).to receive(:perform!).once
97
+ performer.perform_oauth_token_expired!
98
+ end
99
+ end
100
+
101
+ context 'raising the exception' do
102
+ it 'when the number of tries is not 1' do
103
+ allow(performer).to receive(:tries).and_return(2)
104
+ expect{ performer.perform_oauth_token_expired! }.to raise_error(oauth_token_expired_error)
105
+ end
106
+
107
+ it 'when refresh access token is nil' do
108
+ allow(performer.session).to receive(:refresh_access_token!).and_return(nil)
109
+ expect{ performer.perform_oauth_token_expired! }.to raise_error(oauth_token_expired_error)
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '#options_with_session' do
115
+ it 'is private' do
116
+ expect{ performer.options_with_session({}) }.to raise_error
117
+ end
118
+ it 'adds the session to the given options' do
119
+ expect(performer.send(:options_with_session, {})).to include(:session)
120
+ expect(performer.send(:options_with_session, {})[:session]).to eql(session)
121
+ end
122
+ end
123
+
124
+ describe '#resource' do
125
+ it 'is private' do
126
+ expect{ performer.resource('user') }.to raise_error
127
+ end
128
+ it 'gives the correct api resource class' do
129
+ expect(performer.send(:resource, 'user')).to eql(RedboothRuby::User)
130
+ end
131
+ it 'gives nil if there is no resource for the given name' do
132
+ expect(performer.send(:resource, 'icecream')).to be_nil
133
+ end
134
+ end
135
+ end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::ClientOperations::Search, vcr: 'search' do
4
4
  include_context 'authentication'
@@ -10,10 +10,10 @@ describe RedboothRuby::ClientOperations::Search, vcr: 'search' do
10
10
  end
11
11
  let(:endpoint) { 'search' }
12
12
 
13
- describe ".index" do
13
+ describe '.index' do
14
14
  subject { client.search(query: 'task') }
15
15
 
16
- it "makes a new GET request using the correct API endpoint to receive notes collection" do
16
+ it 'makes a new GET request using the correct API endpoint to receive notes collection' do
17
17
  expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, { query: 'task' }, { session: session }).and_call_original
18
18
  subject
19
19
  end
@@ -21,4 +21,4 @@ describe RedboothRuby::ClientOperations::Search, vcr: 'search' do
21
21
  it { expect(subject.class).to eql RedboothRuby::Request::Collection }
22
22
  it { expect(subject.all.first).to be_a RedboothRuby::Base }
23
23
  end
24
- end
24
+ end
@@ -1,8 +1,6 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::Client do
4
- let(:consumer_key) { '_your_consumen_key_' }
5
- let(:consumer_secret) { '_your_consumen_secret_' }
6
4
  let(:access_token) do
7
5
  {
8
6
  token: '_your_user_token_',
@@ -27,43 +25,4 @@ describe RedboothRuby::Client do
27
25
  expect{client}.to raise_error{ RedboothRuby::AuthenticationError }
28
26
  end
29
27
  end
30
-
31
- describe '#perform!' do
32
- it 'is private' do
33
- expect{client.perform!(:user, :show)}.to raise_error
34
- end
35
- it 'raises RedboothRuby::AuthenticationError if session is invalid' do
36
- allow(client).to receive(:session).and_return(nil)
37
- expect{client.perform!(:user, :show)}.to raise_error{ RedboothRuby::AuthenticationError }
38
- end
39
- it 'calls to the given resource' do
40
- allow(RedboothRuby::User).to receive(:show).and_return(RedboothRuby::User.new)
41
- expect(RedboothRuby::User).to receive(:show).with({ session: session })
42
-
43
- client.send(:perform!, :user, :show)
44
- end
45
- end
46
-
47
- describe '#options_with_session' do
48
- it 'is private' do
49
- expect{client.options_with_session({})}.to raise_error
50
- end
51
- it 'adds the session to the given options' do
52
- expect(client.send(:options_with_session,{})).to include(:session)
53
- expect(client.send(:options_with_session,{})[:session]).to eql(session)
54
- end
55
- end
56
-
57
- describe '#resource' do
58
- it 'is private' do
59
- expect{client.resource('user')}.to raise_error
60
- end
61
- it 'gives the correct api resource class' do
62
- expect(client.send(:resource, 'user')).to eql(RedboothRuby::User)
63
- end
64
- it 'gives nil if there is no resource for the given name' do
65
- expect(client.send(:resource, 'icecream')).to be_nil
66
- end
67
- end
68
-
69
- end
28
+ end
@@ -1,5 +1,4 @@
1
- # Encoding: utf-8
2
- require "spec_helper"
1
+ require 'spec_helper'
3
2
 
4
3
  describe RedboothRuby::Comment, vcr: 'comments' do
5
4
  include_context 'authentication'
@@ -16,7 +15,7 @@ describe RedboothRuby::Comment, vcr: 'comments' do
16
15
  client.comment(:show, id: 1)
17
16
  end
18
17
 
19
- describe "#initialize" do
18
+ describe '#initialize' do
20
19
  subject { comment }
21
20
 
22
21
  it { expect(subject.id).to eql 1 }
@@ -27,11 +26,11 @@ describe RedboothRuby::Comment, vcr: 'comments' do
27
26
  it { expect(subject.is_private).to eql false }
28
27
  end
29
28
 
30
- describe ".show" do
29
+ describe '.show' do
31
30
  subject { comment }
32
31
 
33
- it "makes a new GET request using the correct API endpoint to receive a specific comment" do
34
- expect(RedboothRuby).to receive(:request).with(:get, nil, "#{endpoint}/1", {}, { session: session }).and_call_original
32
+ it 'makes a new GET request using the correct API endpoint to receive a specific comment' do
33
+ expect(RedboothRuby).to receive(:request).with(:get, nil, "#{ endpoint }/1", {}, { session: session }).and_call_original
35
34
  subject
36
35
  end
37
36
 
@@ -40,11 +39,11 @@ describe RedboothRuby::Comment, vcr: 'comments' do
40
39
  it { expect(subject.project_id).to eql 2 }
41
40
  end
42
41
 
43
- describe ".update" do
42
+ describe '.update' do
44
43
  subject { client.comment(:update, id: 24, body: 'new test body') }
45
44
 
46
- it "makes a new PUT request using the correct API endpoint to receive a specific comment" do
47
- expect(RedboothRuby).to receive(:request).with(:put, nil, "#{endpoint}/24", { body: 'new test body' }, { session: session }).and_call_original
45
+ it 'makes a new PUT request using the correct API endpoint to receive a specific comment' do
46
+ expect(RedboothRuby).to receive(:request).with(:put, nil, "#{ endpoint }/24", { body: 'new test body' }, { session: session }).and_call_original
48
47
  subject
49
48
  end
50
49
 
@@ -52,10 +51,10 @@ describe RedboothRuby::Comment, vcr: 'comments' do
52
51
  it { expect(subject.id).to eql 24 }
53
52
  end
54
53
 
55
- describe ".create" do
54
+ describe '.create' do
56
55
  subject { new_record }
57
56
 
58
- it "makes a new POST request using the correct API endpoint to create a specific comment" do
57
+ it 'makes a new POST request using the correct API endpoint to create a specific comment' do
59
58
  expect(RedboothRuby).to receive(:request).with(:post, nil, endpoint, create_params, { session: session }).and_call_original
60
59
  subject
61
60
  end
@@ -65,23 +64,23 @@ describe RedboothRuby::Comment, vcr: 'comments' do
65
64
  it { expect(subject.user_id).to eql 1 }
66
65
  end
67
66
 
68
- describe ".delete" do
67
+ describe '.delete' do
69
68
  subject { client.comment(:delete, id: new_record.id) }
70
69
 
71
- it "makes a new DELETE request using the correct API endpoint to delete a specific comment" do
72
- expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{endpoint}/#{new_record.id}", {}, { session: session }).and_call_original
70
+ it 'makes a new DELETE request using the correct API endpoint to delete a specific comment' do
71
+ expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{ endpoint }/#{ new_record.id }", {}, { session: session }).and_call_original
73
72
  subject
74
73
  end
75
74
  end
76
75
 
77
- describe ".index" do
76
+ describe '.index' do
78
77
  subject { client.comment(:index, target_type: 'Task', target_id: 1) }
79
78
 
80
- it "makes a new GET request using the correct API endpoint to receive comments collection" do
81
- expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, {target_type: 'Task', target_id: 1}, { session: session }).and_call_original
79
+ it 'makes a new GET request using the correct API endpoint to receive comments collection' do
80
+ expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, { target_type: 'Task', target_id: 1 }, { session: session }).and_call_original
82
81
  subject
83
82
  end
84
83
 
85
84
  it { expect(subject.class).to eql RedboothRuby::Request::Collection }
86
85
  end
87
- end
86
+ end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::Conversation, vcr: 'conversations' do
4
4
  include_context 'authentication'
@@ -13,7 +13,7 @@ describe RedboothRuby::Conversation, vcr: 'conversations' do
13
13
  client.conversation(:show, id: 1)
14
14
  end
15
15
 
16
- describe "#initialize" do
16
+ describe '#initialize' do
17
17
  subject { conversation }
18
18
 
19
19
  it { expect(subject.id).to eql 1 }
@@ -23,11 +23,11 @@ describe RedboothRuby::Conversation, vcr: 'conversations' do
23
23
  it { expect(subject.is_private).to eql false }
24
24
  end
25
25
 
26
- describe ".show" do
26
+ describe '.show' do
27
27
  subject { conversation }
28
28
 
29
- it "makes a new GET request using the correct API endpoint to receive a specific conversation" do
30
- expect(RedboothRuby).to receive(:request).with(:get, nil, "#{endpoint}/1", {}, { session: session }).and_call_original
29
+ it 'makes a new GET request using the correct API endpoint to receive a specific conversation' do
30
+ expect(RedboothRuby).to receive(:request).with(:get, nil, "#{ endpoint }/1", {}, { session: session }).and_call_original
31
31
  subject
32
32
  end
33
33
 
@@ -36,11 +36,11 @@ describe RedboothRuby::Conversation, vcr: 'conversations' do
36
36
  it { expect(subject.project_id).to eql 2 }
37
37
  end
38
38
 
39
- describe ".update" do
39
+ describe '.update' do
40
40
  subject { client.conversation(:update, id: 2, name: 'new test name') }
41
41
 
42
- it "makes a new PUT request using the correct API endpoint to receive a specific conversation" do
43
- expect(RedboothRuby).to receive(:request).with(:put, nil, "#{endpoint}/2", { name: 'new test name' }, { session: session }).and_call_original
42
+ it 'makes a new PUT request using the correct API endpoint to receive a specific conversation' do
43
+ expect(RedboothRuby).to receive(:request).with(:put, nil, "#{ endpoint }/2", { name: 'new test name' }, { session: session }).and_call_original
44
44
  subject
45
45
  end
46
46
 
@@ -48,10 +48,10 @@ describe RedboothRuby::Conversation, vcr: 'conversations' do
48
48
  it { expect(subject.id).to eql 2 }
49
49
  end
50
50
 
51
- describe ".create" do
51
+ describe '.create' do
52
52
  subject { new_record }
53
53
 
54
- it "makes a new POST request using the correct API endpoint to create a specific conversation" do
54
+ it 'makes a new POST request using the correct API endpoint to create a specific conversation' do
55
55
  expect(RedboothRuby).to receive(:request).with(:post, nil, endpoint, create_params, { session: session }).and_call_original
56
56
  subject
57
57
  end
@@ -61,23 +61,23 @@ describe RedboothRuby::Conversation, vcr: 'conversations' do
61
61
  it { expect(subject.user_id).to eql 1 }
62
62
  end
63
63
 
64
- describe ".delete" do
64
+ describe '.delete' do
65
65
  subject { client.conversation(:delete, id: new_record.id) }
66
66
 
67
- it "makes a new DELETE request using the correct API endpoint to delete a specific conversation" do
68
- expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{endpoint}/#{new_record.id}", {}, { session: session }).and_call_original
67
+ it 'makes a new DELETE request using the correct API endpoint to delete a specific conversation' do
68
+ expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{ endpoint }/#{ new_record.id }", {}, { session: session }).and_call_original
69
69
  subject
70
70
  end
71
71
  end
72
72
 
73
- describe ".index" do
73
+ describe '.index' do
74
74
  subject { client.conversation(:index) }
75
75
 
76
- it "makes a new GET request using the correct API endpoint to receive conversations collection" do
76
+ it 'makes a new GET request using the correct API endpoint to receive conversations collection' do
77
77
  expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, {}, { session: session }).and_call_original
78
78
  subject
79
79
  end
80
80
 
81
81
  it { expect(subject.class).to eql RedboothRuby::Request::Collection }
82
82
  end
83
- end
83
+ end
@@ -1,5 +1,4 @@
1
- # Encoding: utf-8
2
- require "spec_helper"
1
+ require 'spec_helper'
3
2
 
4
3
  describe RedboothRuby::File, vcr: 'files' do
5
4
  include_context 'authentication'
@@ -7,7 +6,7 @@ describe RedboothRuby::File, vcr: 'files' do
7
6
  let(:create_params) do
8
7
  { project_id: 2,
9
8
  backend: 'redbooth',
10
- asset: File.open("#{File.dirname(__FILE__)}/../fixtures/hola.txt") }
9
+ asset: File.open("#{ File.dirname(__FILE__) }/../fixtures/hola.txt") }
11
10
  end
12
11
  let(:new_record) { client.file(:create, create_params) }
13
12
  let(:endpoint) { 'files' }
@@ -15,34 +14,34 @@ describe RedboothRuby::File, vcr: 'files' do
15
14
  client.file(:show, id: 1)
16
15
  end
17
16
 
18
- describe "#initialize" do
17
+ describe '#initialize' do
19
18
  subject { file }
20
19
 
21
20
  it { expect(subject.id).to eql 1 }
22
- it { expect(subject.name).to eql "Reports" }
21
+ it { expect(subject.name).to eql 'Reports' }
23
22
  it { expect(subject.project_id).to eql 2 }
24
23
  it { expect(subject.parent_id).to eql nil }
25
24
  it { expect(subject.pinned).to eql false }
26
25
  end
27
26
 
28
- describe ".show" do
27
+ describe '.show' do
29
28
  subject { file }
30
29
 
31
- it "makes a new GET request using the correct API endpoint to receive a specific file" do
32
- expect(RedboothRuby).to receive(:request).with(:get, nil, "#{endpoint}/1", {}, { session: session }).and_call_original
30
+ it 'makes a new GET request using the correct API endpoint to receive a specific file' do
31
+ expect(RedboothRuby).to receive(:request).with(:get, nil, "#{ endpoint }/1", {}, { session: session }).and_call_original
33
32
  subject
34
33
  end
35
34
 
36
35
  it { expect(subject.id).to eql 1 }
37
- it { expect(subject.name).to eql "Reports" }
36
+ it { expect(subject.name).to eql 'Reports' }
38
37
  it { expect(subject.project_id).to eql 2 }
39
38
  end
40
39
 
41
- describe ".update" do
40
+ describe '.update' do
42
41
  subject { client.file(:update, id: 2, name: 'new_name.txt') }
43
42
 
44
- it "makes a new PUT request using the correct API endpoint to receive a specific file" do
45
- expect(RedboothRuby).to receive(:request).with(:put, nil, "#{endpoint}/2", { name: 'new_name.txt' }, { session: session }).and_call_original
43
+ it 'makes a new PUT request using the correct API endpoint to receive a specific file' do
44
+ expect(RedboothRuby).to receive(:request).with(:put, nil, "#{ endpoint }/2", { name: 'new_name.txt' }, { session: session }).and_call_original
46
45
  subject
47
46
  end
48
47
 
@@ -50,13 +49,13 @@ describe RedboothRuby::File, vcr: 'files' do
50
49
  it { expect(subject.id).to eql 2 }
51
50
  end
52
51
 
53
- describe ".create" do
52
+ describe '.create' do
54
53
  subject { new_record }
55
54
  let(:asset_params) {
56
- { asset_attrs: { name: "hola.txt", local_path: "#{File.dirname(__FILE__)}/../fixtures/hola.txt"} }
55
+ { asset_attrs: { name: 'hola.txt', local_path: "#{ File.dirname(__FILE__) }/../fixtures/hola.txt"} }
57
56
  }
58
57
 
59
- it "makes a new POST request using the correct API endpoint to create a specific file" do
58
+ it 'makes a new POST request using the correct API endpoint to create a specific file' do
60
59
  expect(RedboothRuby).to receive(:request).with(:post, nil, endpoint, create_params.merge(asset_params) , { session: session }).and_call_original
61
60
  subject
62
61
  end
@@ -67,23 +66,31 @@ describe RedboothRuby::File, vcr: 'files' do
67
66
  it { expect(subject.user_id).to eql 1 }
68
67
  end
69
68
 
70
- describe ".delete" do
69
+ describe '.delete' do
71
70
  subject { client.file(:delete, id: new_record.id) }
72
71
 
73
- it "makes a new DELETE request using the correct API endpoint to delete a specific comment" do
74
- expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{endpoint}/#{new_record.id}", {}, { session: session }).and_call_original
72
+ it 'makes a new DELETE request using the correct API endpoint to delete a specific comment' do
73
+ expect(RedboothRuby).to receive(:request).with(:delete, nil, "#{ endpoint }/#{ new_record.id }", {}, { session: session }).and_call_original
75
74
  subject
76
75
  end
77
76
  end
78
77
 
79
- describe ".index" do
78
+ describe '.index' do
80
79
  subject { client.file(:index, project_id: 1) }
81
80
 
82
- it "makes a new GET request using the correct API endpoint to receive comments collection" do
83
- expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, {project_id: 1}, { session: session }).and_call_original
81
+ it 'makes a new GET request using the correct API endpoint to receive comments collection' do
82
+ expect(RedboothRuby).to receive(:request).with(:get, nil, endpoint, { project_id: 1 }, { session: session }).and_call_original
84
83
  subject
85
84
  end
86
85
 
87
86
  it { expect(subject.class).to eql RedboothRuby::Request::Collection }
88
87
  end
89
- end
88
+
89
+ describe '.download' do
90
+ subject { new_record.download }
91
+
92
+ it 'downloads a file' do
93
+ open("#{ File.dirname(__FILE__) }/../../temp/spec/files/test_download.txt", 'w') { |f| f.puts subject }
94
+ end
95
+ end
96
+ end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe RedboothRuby::Me, vcr: 'me' do
4
4
  include_context 'authentication'
@@ -53,4 +53,4 @@ describe RedboothRuby::Me, vcr: 'me' do
53
53
  subject
54
54
  end
55
55
  end
56
- end
56
+ end