redbooth-ruby 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/spec/cassettes/Redbooth_Me/_initialize/.yml +48 -0
  3. data/spec/cassettes/Redbooth_Me/_show/.yml +48 -0
  4. data/spec/cassettes/Redbooth_Me/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_user.yml +48 -0
  5. data/spec/cassettes/Redbooth_Me/_update/.yml +97 -0
  6. data/spec/cassettes/Redbooth_Me/_update/integration/.yml +97 -0
  7. data/spec/cassettes/Redbooth_Organization/_create/.yml +47 -0
  8. data/spec/cassettes/Redbooth_Organization/_create/makes_a_new_POST_request_using_the_correct_API_endpoint_to_create_a_specific_organization.yml +47 -0
  9. data/spec/cassettes/Redbooth_Organization/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_organization.yml +123 -0
  10. data/spec/cassettes/Redbooth_Organization/_index/.yml +58 -0
  11. data/spec/cassettes/Redbooth_Organization/_index/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_organization.yml +58 -0
  12. data/spec/cassettes/Redbooth_Organization/_initialize/.yml +64 -0
  13. data/spec/cassettes/Redbooth_Organization/_show/.yml +64 -0
  14. data/spec/cassettes/Redbooth_Organization/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_organization.yml +64 -0
  15. data/spec/cassettes/Redbooth_Organization/_update/.yml +48 -0
  16. data/spec/cassettes/Redbooth_Organization/_update/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_organization.yml +48 -0
  17. data/spec/cassettes/Redbooth_Person/_create/integration/.yml +83 -0
  18. data/spec/cassettes/Redbooth_Person/_create/makes_a_new_POST_request_using_the_correct_API_endpoint_to_create_a_specific_person.yml +83 -0
  19. data/spec/cassettes/Redbooth_Person/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_person.yml +83 -0
  20. data/spec/cassettes/Redbooth_Person/_index/.yml +127 -0
  21. data/spec/cassettes/Redbooth_Person/_index/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_person.yml +54 -0
  22. data/spec/cassettes/Redbooth_Person/_initialize/.yml +117 -0
  23. data/spec/cassettes/Redbooth_Person/_show/.yml +117 -0
  24. data/spec/cassettes/Redbooth_Person/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_person.yml +44 -0
  25. data/spec/cassettes/Redbooth_Person/_update/.yml +163 -0
  26. data/spec/cassettes/Redbooth_Person/_update/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_person.yml +294 -0
  27. data/spec/cassettes/Redbooth_Project/_create/.yml +47 -0
  28. data/spec/cassettes/Redbooth_Project/_create/makes_a_new_POST_request_using_the_correct_API_endpoint_to_create_a_specific_project.yml +47 -0
  29. data/spec/cassettes/Redbooth_Project/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_project.yml +2296 -0
  30. data/spec/cassettes/Redbooth_Project/_index/.yml +62 -0
  31. data/spec/cassettes/Redbooth_Project/_index/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_project.yml +62 -0
  32. data/spec/cassettes/Redbooth_Project/_initialize/.yml +44 -0
  33. data/spec/cassettes/Redbooth_Project/_show/.yml +44 -0
  34. data/spec/cassettes/Redbooth_Project/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_project.yml +44 -0
  35. data/spec/cassettes/Redbooth_Project/_update/.yml +47 -0
  36. data/spec/cassettes/Redbooth_Project/_update/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_project.yml +47 -0
  37. data/spec/cassettes/Redbooth_Request_Collection/_all/.yml +59 -0
  38. data/spec/cassettes/Redbooth_Request_Collection/_count/.yml +59 -0
  39. data/spec/cassettes/Redbooth_Request_Collection/_current_page/.yml +59 -0
  40. data/spec/cassettes/Redbooth_Request_Collection/_current_page/where_endpoint_is_not_paginated/.yml +59 -0
  41. data/spec/cassettes/Redbooth_Request_Collection/_initialize/.yml +59 -0
  42. data/spec/cassettes/Redbooth_Request_Collection/_next_page/.yml +106 -0
  43. data/spec/cassettes/Redbooth_Request_Collection/_next_page/where_endpoint_is_not_paginated/.yml +59 -0
  44. data/spec/cassettes/Redbooth_Request_Collection/_next_page/where_is_the_last_page/.yml +59 -0
  45. data/spec/cassettes/Redbooth_Request_Collection/_per_page/.yml +59 -0
  46. data/spec/cassettes/Redbooth_Request_Collection/_per_page/where_endpoint_is_not_paginated/.yml +59 -0
  47. data/spec/cassettes/Redbooth_Request_Collection/_prev_page/.yml +115 -0
  48. data/spec/cassettes/Redbooth_Request_Collection/_prev_page/where_endpoint_is_not_paginated/.yml +59 -0
  49. data/spec/cassettes/Redbooth_Request_Collection/_prev_page/where_is_the_first_page/.yml +159 -0
  50. data/spec/cassettes/Redbooth_Request_Collection/_total_pages/.yml +59 -0
  51. data/spec/cassettes/Redbooth_Request_Collection/_total_pages/where_endpoint_is_not_paginated/.yml +59 -0
  52. data/spec/cassettes/Redbooth_Task/_create/.yml +47 -0
  53. data/spec/cassettes/Redbooth_Task/_create/makes_a_new_POST_request_using_the_correct_API_endpoint_to_create_a_specific_task.yml +47 -0
  54. data/spec/cassettes/Redbooth_Task/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_task.yml +84 -0
  55. data/spec/cassettes/Redbooth_Task/_index/.yml +1037 -0
  56. data/spec/cassettes/Redbooth_Task/_index/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +437 -0
  57. data/spec/cassettes/Redbooth_Task/_initialize/.yml +47 -0
  58. data/spec/cassettes/Redbooth_Task/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +47 -0
  59. data/spec/cassettes/Redbooth_Task/_show/returns_a_task_with_the_correct_assigned_id.yml +47 -0
  60. data/spec/cassettes/Redbooth_Task/_show/returns_a_task_with_the_correct_id.yml +47 -0
  61. data/spec/cassettes/Redbooth_Task/_show/returns_a_task_with_the_correct_name.yml +47 -0
  62. data/spec/cassettes/Redbooth_Task/_show/returns_a_task_with_the_correct_project_id.yml +47 -0
  63. data/spec/cassettes/Redbooth_Task/_update/.yml +47 -0
  64. data/spec/cassettes/Redbooth_Task/_update/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +47 -0
  65. data/spec/cassettes/Redbooth_User/_create/.yml +84 -0
  66. data/spec/cassettes/Redbooth_User/_create/makes_a_new_POST_request_using_the_correct_API_endpoint_to_create_a_specific_task.yml +47 -0
  67. data/spec/cassettes/Redbooth_User/_create/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +47 -0
  68. data/spec/cassettes/Redbooth_User/_create/name/.yml +47 -0
  69. data/spec/cassettes/Redbooth_User/_create/project_id/.yml +47 -0
  70. data/spec/cassettes/Redbooth_User/_create/task_list_id/.yml +47 -0
  71. data/spec/cassettes/Redbooth_User/_delete/makes_a_new_DELETE_request_using_the_correct_API_endpoint_to_delete_a_specific_task.yml +84 -0
  72. data/spec/cassettes/Redbooth_User/_index/.yml +413 -0
  73. data/spec/cassettes/Redbooth_User/_index/class/.yml +400 -0
  74. data/spec/cassettes/Redbooth_User/_index/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +400 -0
  75. data/spec/cassettes/Redbooth_User/_initialize/.yml +88 -0
  76. data/spec/cassettes/Redbooth_User/_initialize/assigned_id/.yml +47 -0
  77. data/spec/cassettes/Redbooth_User/_initialize/description/.yml +47 -0
  78. data/spec/cassettes/Redbooth_User/_initialize/due_on/.yml +47 -0
  79. data/spec/cassettes/Redbooth_User/_initialize/id/.yml +47 -0
  80. data/spec/cassettes/Redbooth_User/_initialize/initializes_all_attributes_correctly.yml +44 -0
  81. data/spec/cassettes/Redbooth_User/_initialize/name/.yml +47 -0
  82. data/spec/cassettes/Redbooth_User/_initialize/project_id/.yml +47 -0
  83. data/spec/cassettes/Redbooth_User/_show/.yml +44 -0
  84. data/spec/cassettes/Redbooth_User/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +47 -0
  85. data/spec/cassettes/Redbooth_User/_show/makes_a_new_GET_request_using_the_correct_API_endpoint_to_receive_a_specific_user.yml +88 -0
  86. data/spec/cassettes/Redbooth_User/_show/returns_a_task_with_the_correct_assigned_id.yml +47 -0
  87. data/spec/cassettes/Redbooth_User/_show/returns_a_task_with_the_correct_id.yml +47 -0
  88. data/spec/cassettes/Redbooth_User/_show/returns_a_task_with_the_correct_name.yml +47 -0
  89. data/spec/cassettes/Redbooth_User/_show/returns_a_task_with_the_correct_project_id.yml +47 -0
  90. data/spec/cassettes/Redbooth_User/_show/returns_a_user_with_the_correct_email.yml +393 -0
  91. data/spec/cassettes/Redbooth_User/_show/returns_a_user_with_the_correct_first_name.yml +393 -0
  92. data/spec/cassettes/Redbooth_User/_show/returns_a_user_with_the_correct_id.yml +393 -0
  93. data/spec/cassettes/Redbooth_User/_show/returns_a_user_with_the_correct_last_name.yml +393 -0
  94. data/spec/cassettes/Redbooth_User/_update/.yml +47 -0
  95. data/spec/cassettes/Redbooth_User/_update/id/.yml +47 -0
  96. data/spec/cassettes/Redbooth_User/_update/makes_a_new_PUT_request_using_the_correct_API_endpoint_to_receive_a_specific_task.yml +47 -0
  97. data/spec/cassettes/Redbooth_User/_update/name/.yml +47 -0
  98. data/spec/fixtures/hola.txt +1 -0
  99. data/spec/redbooth/base_spec.rb +12 -0
  100. data/spec/redbooth/client_spec.rb +69 -0
  101. data/spec/redbooth/me_spec.rb +56 -0
  102. data/spec/redbooth/organization_spec.rb +80 -0
  103. data/spec/redbooth/person_spec.rb +85 -0
  104. data/spec/redbooth/project_spec.rb +80 -0
  105. data/spec/redbooth/request/base_spec.rb +53 -0
  106. data/spec/redbooth/request/collection_spec.rb +104 -0
  107. data/spec/redbooth/request/connection_spec.rb +82 -0
  108. data/spec/redbooth/request/info_spec.rb +27 -0
  109. data/spec/redbooth/request/response_spec.rb +32 -0
  110. data/spec/redbooth/request/validator_spec.rb +45 -0
  111. data/spec/redbooth/task_spec.rb +90 -0
  112. data/spec/redbooth/user_spec.rb +32 -0
  113. data/spec/redbooth_spec.rb +69 -0
  114. data/spec/shared/authentication_context.rb +24 -0
  115. data/spec/spec_helper.rb +22 -0
  116. metadata +370 -0
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Base do
4
+ let(:consumer_key) { '_your_consumen_key_' }
5
+ let(:consumer_secret) { '_your_consumen_secret_' }
6
+ let(:info) { double(:info, session: session ) }
7
+ let(:session) { double(:session, valid?: true ) }
8
+ let(:request_base) { Redbooth::Request::Base.new(info) }
9
+ let(:connection) { double(:connection) }
10
+ let(:validator) { double(:validator) }
11
+
12
+ before :each do
13
+ allow(Redbooth::Request::Connection).to receive(:new).and_return(connection)
14
+ allow(Redbooth::Request::Validator).to receive(:new).and_return(validator)
15
+ Redbooth.config do |configuration|
16
+ configuration[:consumer_key] = consumer_key
17
+ configuration[:consumer_secret] = consumer_secret
18
+ end
19
+ end
20
+
21
+ describe "#perform" do
22
+ it 'raises AuthenticationError if request is not valid' do
23
+ allow(request_base).to receive(:valid?).and_return(false)
24
+ expect{request_base.perform}.to raise_error{ Redbooth::AuthenticationError }
25
+ end
26
+ it "performs an https request" do
27
+ allow_any_instance_of(Redbooth::Request::Base).to receive(:valid?).and_return(true)
28
+
29
+ expect(connection).to receive(:set_request_data)
30
+ expect(connection).to receive(:request)
31
+ expect(validator).to receive(:validated_response_for)
32
+
33
+ Redbooth::Request::Base.new(nil).perform
34
+ end
35
+ end
36
+
37
+ describe "#valid?" do
38
+ it 'is not valid if no info object given' do
39
+ expect(Redbooth::Request::Base.new(nil)).to_not be_valid
40
+ end
41
+ it 'is not valid if there is no session in info object' do
42
+ allow(info).to receive(:session).and_return(nil)
43
+ expect(request_base).to_not be_valid
44
+ end
45
+ it 'is not valid if session is invalid' do
46
+ allow(session).to receive(:valid?).and_return(false)
47
+ expect(request_base).to_not be_valid
48
+ end
49
+ it 'id valid othercase' do
50
+ expect(request_base).to be_valid
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,104 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Collection, vcr: 'collection' do
4
+ include_context 'authentication'
5
+ let(:collection) { client.task(:index, per_page: 2) }
6
+
7
+ describe "#initialize" do
8
+ subject { collection }
9
+
10
+ it { should be_a Redbooth::Request::Collection }
11
+ it { expect(subject.response).to be_a(Redbooth::Request::Response) }
12
+ it { expect(subject.params).to be_a(Hash) }
13
+ it { expect(subject.method).to eql(:index) }
14
+ it { expect(subject.session).to eql(client.session) }
15
+ it { expect(subject.resource).to eql(Redbooth::Task) }
16
+ end
17
+
18
+ describe '#all' do
19
+ subject { collection.all }
20
+
21
+ it { should be_a Array }
22
+ it { expect(subject.first).to be_a(Redbooth::Task) }
23
+ end
24
+
25
+ describe '#total_pages' do
26
+ subject { collection.total_pages }
27
+
28
+ it { should be_a Integer }
29
+
30
+ context 'where endpoint is not paginated' do
31
+ before { collection.response.headers.delete('PaginationTotalPages') }
32
+
33
+ it { should be_nil }
34
+ end
35
+ end
36
+
37
+ describe '#per_page' do
38
+ subject { collection.per_page }
39
+
40
+ it { should be_a Integer }
41
+
42
+ context 'where endpoint is not paginated' do
43
+ before { collection.response.headers.delete('PaginationPerPage') }
44
+
45
+ it { should be_nil }
46
+ end
47
+ end
48
+
49
+ describe '#current_page' do
50
+ subject { collection.current_page }
51
+
52
+ it { should be_a Integer }
53
+
54
+ context 'where endpoint is not paginated' do
55
+ before { collection.response.headers.delete('PaginationCurrentPage') }
56
+
57
+ it { should be_nil }
58
+ end
59
+ end
60
+
61
+ describe '#count' do
62
+ subject { collection.count }
63
+
64
+ it { should be_a Integer }
65
+ end
66
+
67
+ describe '#next_page' do
68
+ subject { collection.next_page }
69
+
70
+ it { should be_a Redbooth::Request::Collection }
71
+
72
+ context 'where endpoint is not paginated' do
73
+ before { collection.response.headers.delete('PaginationCurrentPage') }
74
+
75
+ it { should be_nil }
76
+ end
77
+
78
+ context 'where is the last page' do
79
+ before { collection.response.headers['PaginationCurrentPage'] = collection.total_pages.to_s }
80
+
81
+ it { should be_nil }
82
+ end
83
+ end
84
+
85
+ describe '#prev_page' do
86
+ before { collection.response.headers['PaginationCurrentPage'] = 4 }
87
+ subject { collection.prev_page }
88
+
89
+ it { should be_a Redbooth::Request::Collection }
90
+
91
+ context 'where endpoint is not paginated' do
92
+ before { collection.response.headers.delete('PaginationCurrentPage') }
93
+
94
+ it { should be_nil }
95
+ end
96
+
97
+ context 'where is the first page' do
98
+ before { collection.response.headers['PaginationCurrentPage'] = 1 }
99
+
100
+ it { should be_nil }
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Connection do
4
+ let(:consumer_key) { '_your_consumen_key_' }
5
+ let(:consumer_secret) { '_your_consumen_secret_' }
6
+ let(:access_token) do
7
+ {
8
+ token: '_your_user_token_',
9
+ secret: '_your_secret_token_'
10
+ }
11
+ end
12
+ let(:connection) { Redbooth::Request::Connection.new(info) }
13
+ let(:info) do
14
+ Redbooth::Request::Info.new(:get,
15
+ nil,
16
+ 'user',
17
+ {},
18
+ { session: session }
19
+ )
20
+ end
21
+ let(:client) { Redbooth::Client.new(session) }
22
+ let(:session) { Redbooth::Session.new(access_token) }
23
+ let(:redbooth_protocol) { Redbooth.configuration[:use_ssl] ? 'https' : 'http' }
24
+ let(:redbooth_url) { "#{redbooth_protocol}://#{Redbooth.configuration[:api_base]}/#{Redbooth.configuration[:api_base_path]}/#{Redbooth.configuration[:api_version]}" }
25
+
26
+ before :each do
27
+ Redbooth.config do |configuration|
28
+ configuration[:consumer_key] = consumer_key
29
+ configuration[:consumer_secret] = consumer_secret
30
+ end
31
+ end
32
+
33
+ describe '#set_request_data' do
34
+ it 'creates a request_data object' do
35
+ connection.set_request_data
36
+
37
+ expect(connection.request_data).to_not be_nil
38
+ end
39
+ end
40
+
41
+ describe '#request' do
42
+ it 'performs the actual request' do
43
+ connection.set_request_data
44
+ allow(connection).to receive(:set_request_data)
45
+
46
+ expect(connection.access_token).to receive(:send).with(*connection.request_data)
47
+
48
+ connection.request
49
+ end
50
+ end
51
+
52
+ describe '#request_data' do
53
+ it 'correctly formats the form data' do
54
+ info = double(
55
+ http_method: :post,
56
+ url: '/some/path',
57
+ data: params,
58
+ subdomain: Redbooth::DOMAIN_BASE,
59
+ session: session
60
+ )
61
+ connection = Redbooth::Request::Connection.new(info)
62
+ connection.set_request_data
63
+
64
+ expect(connection.request_data).to eq(
65
+ [
66
+ :post,
67
+ "#{redbooth_url}/some/path",
68
+ { body: { email: "abc_abc.com",
69
+ event_types: ["user.created", "user.failed", "team.created", "documents.available"] }
70
+ }
71
+ ]
72
+ )
73
+ end
74
+ end
75
+
76
+ def params
77
+ {
78
+ email: "abc_abc.com",
79
+ event_types: ["user.created","user.failed", "team.created", "documents.available"]
80
+ }
81
+ end
82
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Info do
4
+ describe "#url" do
5
+ it "constructs the url" do
6
+ info = Redbooth::Request::Info.new(:get, nil, "random", {id: 1} )
7
+
8
+ expect(info.url).to match /random/
9
+ end
10
+ end
11
+
12
+ describe "#path_with_params" do
13
+ it "does nothing when no params" do
14
+ info = Redbooth::Request::Info.new(:get, nil, "random", nil)
15
+ path = "/path/to/someplace"
16
+
17
+ expect(info.path_with_params(path, {})).to eq path
18
+ end
19
+
20
+ it "constructs the path with params" do
21
+ info = Redbooth::Request::Info.new(:get, nil, "random", nil)
22
+ path = "/path/to/someplace"
23
+
24
+ expect(info.path_with_params(path, {random: "stuff"})).to eq "#{path}?random=stuff"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Response do
4
+ let(:headers) { {} }
5
+ let(:status) { 200 }
6
+ let(:body) { '{"response":"ok"}' }
7
+ let(:response) { Redbooth::Request::Response.new(body: body,
8
+ status: status,
9
+ headers: headers) }
10
+
11
+ describe "#initialize" do
12
+ subject { response }
13
+
14
+ it { should be_a Redbooth::Request::Response }
15
+ it { expect(subject.data).to eq("response" => "ok") }
16
+ it { expect(subject.body).to eq(body) }
17
+ it { expect(subject.headers).to eq(headers) }
18
+ it { expect(subject.status).to eq(status) }
19
+
20
+ context 'with wrong json body' do
21
+ let(:body) { '<html> asdfasdf </html>' }
22
+
23
+ it { expect(subject.data).to be_empty }
24
+ end
25
+
26
+ context 'with empty body' do
27
+ let(:body) { nil }
28
+
29
+ it { expect(subject.data).to be_empty }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Request::Validator do
4
+ let(:info) { Redbooth::Request::Info.new(:get, nil, "random", OpenStruct.new(id: 1)) }
5
+ let(:validator) { Redbooth::Request::Validator.new info }
6
+ let(:headers) { {} }
7
+ let(:response) { OpenStruct.new(body: '{"response":"ok"}', status: 200, headers: headers) }
8
+
9
+ describe "#validated_response_for" do
10
+ subject { validator.validated_response_for(response) }
11
+
12
+ it { should be_a Redbooth::Request::Response }
13
+ it { expect(subject.data).to eq("response" => "ok") }
14
+
15
+ context 'where 401 status code returned' do
16
+ let(:response) { OpenStruct.new(body: '{"error":{"message":"Unauthorized"}}', status: 401, headers: headers) }
17
+
18
+ it { expect{subject}.to raise_error(Redbooth::AuthenticationError) }
19
+
20
+ context 'where token was expired' do
21
+ before { headers['WWW-Authenticate'] = %{Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token was expired"} }
22
+
23
+ it { expect{subject}.to raise_error(Redbooth::OauhtTokenExpired) }
24
+ end
25
+
26
+ context 'where token was revoked' do
27
+ before { headers['WWW-Authenticate'] = %{Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token was revoked"} }
28
+
29
+ it { expect{subject}.to raise_error(Redbooth::OauhtTokenRevoked) }
30
+ end
31
+ end
32
+
33
+ context 'where 500 status code returned' do
34
+ let(:response) { OpenStruct.new(body: '{"error":{"message":"Something went wrong"}}', status: 500, headers: headers) }
35
+
36
+ it { expect{subject}.to raise_error(Redbooth::APIError) }
37
+ end
38
+
39
+ context 'where 404 status code returned' do
40
+ let(:response) { OpenStruct.new(body: '{"error":{"message":"There is no task with the given id in the system"}}', status: 404, headers: headers) }
41
+
42
+ it { expect{subject}.to raise_error(Redbooth::NotFound) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::Task, vcr: 'tasks' do
4
+ include_context 'authentication'
5
+
6
+ let(:create_task_params) do
7
+ { project_id: 2,
8
+ name: 'new created task',
9
+ task_list_id: 3 }
10
+ end
11
+ let(:new_task) { Redbooth::Task.create(create_task_params.merge(session: session)) }
12
+ let(:task) do
13
+ Redbooth::Task.show(session: session, id: 1)
14
+ end
15
+
16
+ describe "#initialize" do
17
+ subject { task }
18
+
19
+ it { expect(subject.id).to eql 1 }
20
+ it { expect(subject.name).to eql 'Register all EarthworksYoga TLDs' }
21
+ it { expect(subject.description).to eql 'The ships hung in the sky in much the same way that bricks don\'t.' }
22
+ it { expect(subject.project_id).to eql 2 }
23
+ it { expect(subject.assigned_id).to eql 8 }
24
+ it { expect(subject.due_on).to eql '2014-11-04' }
25
+ end
26
+
27
+ describe ".show" do
28
+ it "makes a new GET request using the correct API endpoint to receive a specific task" do
29
+ expect(Redbooth).to receive(:request).with(:get, nil, "tasks/1", {}, { session: session }).and_call_original
30
+ task
31
+ end
32
+ it 'returns a task with the correct name' do
33
+ expect(task.name).to eql('Register all EarthworksYoga TLDs')
34
+ end
35
+ it 'returns a task with the correct id' do
36
+ expect(task.id).to eql(1)
37
+ end
38
+ it 'returns a task with the correct project_id' do
39
+ expect(task.project_id).to eql(2)
40
+ end
41
+ it 'returns a task with the correct assigned_id' do
42
+ expect(task.assigned_id).to eql(8)
43
+ end
44
+ end
45
+
46
+ describe ".update" do
47
+ subject { Redbooth::Task.update(session: session, id: 2, name: 'new test name') }
48
+
49
+ it "makes a new PUT request using the correct API endpoint to receive a specific task" do
50
+ expect(Redbooth).to receive(:request).with(:put, nil, "tasks/2", { name: 'new test name' }, { session: session }).and_call_original
51
+ subject
52
+ end
53
+
54
+ it { expect(subject.name).to eql 'new test name' }
55
+ it { expect(subject.id).to eql 2 }
56
+ end
57
+
58
+ describe ".create" do
59
+ subject { new_task }
60
+
61
+ it "makes a new POST request using the correct API endpoint to create a specific task" do
62
+ expect(Redbooth).to receive(:request).with(:post, nil, "tasks", create_task_params, { session: session }).and_call_original
63
+ subject
64
+ end
65
+
66
+ it { expect(subject.name).to eql 'new created task' }
67
+ it { expect(subject.project_id).to eql 2 }
68
+ it { expect(subject.task_list_id).to eql 3 }
69
+ end
70
+
71
+ describe ".delete" do
72
+ subject { Redbooth::Task.delete(session: session, id: new_task.id) }
73
+
74
+ it "makes a new DELETE request using the correct API endpoint to delete a specific task" do
75
+ expect(Redbooth).to receive(:request).with(:delete, nil, "tasks/#{new_task.id}", {}, { session: session }).and_call_original
76
+ subject
77
+ end
78
+ end
79
+
80
+ describe ".index" do
81
+ subject { Redbooth::Task.index(session: session) }
82
+
83
+ it "makes a new PUT request using the correct API endpoint to receive a specific task" do
84
+ expect(Redbooth).to receive(:request).with(:get, nil, "tasks", {}, { session: session }).and_call_original
85
+ subject
86
+ end
87
+
88
+ it { expect(subject.class).to eql Redbooth::Request::Collection }
89
+ end
90
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Redbooth::User, vcr: 'users' do
4
+ include_context 'authentication'
5
+
6
+ let(:user) do
7
+ Redbooth::User.show(session: session, id: 1)
8
+ end
9
+
10
+ describe "#initialize" do
11
+ subject { user }
12
+
13
+ it { expect(subject.email).to eql('example_frank@redbooth.com') }
14
+ it { expect(subject.id).to eql(1) }
15
+ it { expect(subject.first_name).to eql('Frank') }
16
+ it { expect(subject.last_name).to eql('Kramer') }
17
+ end
18
+
19
+ describe ".show" do
20
+ subject { Redbooth::User.show(session: session, id: 1) }
21
+
22
+ it 'makes a new GET request using the correct API endpoint to receive a specific user' do
23
+ expect(Redbooth).to receive(:request).with(:get, nil, "users/1", {}, { session: session }).and_call_original
24
+ subject
25
+ end
26
+
27
+ it { expect(subject.email).to eql('example_frank@redbooth.com') }
28
+ it { expect(subject.id).to eql(1) }
29
+ it { expect(subject.first_name).to eql('Frank') }
30
+ it { expect(subject.last_name).to eql('Kramer') }
31
+ end
32
+ end