passaporteweb-client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,24 +4,24 @@ require 'spec_helper'
4
4
  describe PassaporteWeb::Notification do
5
5
 
6
6
  describe "constants" do
7
- it { PassaporteWeb::Notification::ATTRIBUTES.should == [:body, :target_url, :uuid, :absolute_url, :scheduled_to, :sender_data, :read_at, :notification_type, :destination] }
8
- it { PassaporteWeb::Notification::CREATABLE_ATTRIBUTES.should == [:body, :target_url, :scheduled_to, :destination] }
7
+ it { expect(PassaporteWeb::Notification::ATTRIBUTES).to eq([:body, :target_url, :uuid, :absolute_url, :scheduled_to, :sender_data, :read_at, :notification_type, :destination]) }
8
+ it { expect(PassaporteWeb::Notification::CREATABLE_ATTRIBUTES).to eq([:body, :target_url, :scheduled_to, :destination]) }
9
9
  end
10
10
 
11
11
  describe ".new" do
12
12
  it "should instanciate an empty object" do
13
13
  notification = PassaporteWeb::Notification.new
14
- notification.should_not be_persisted
15
- notification.attributes.should == {:body=>nil, :target_url=>nil, :uuid=>nil, :absolute_url=>nil, :scheduled_to=>nil, :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>nil}
16
- notification.uuid.should be_nil
17
- notification.destination.should be_nil
18
- notification.body.should be_nil
19
- notification.target_url.should be_nil
20
- notification.scheduled_to.should be_nil
21
- notification.absolute_url.should be_nil
22
- notification.sender_data.should be_nil
23
- notification.read_at.should be_nil
24
- notification.notification_type.should be_nil
14
+ expect(notification).not_to be_persisted
15
+ expect(notification.attributes).to eq({:body=>nil, :target_url=>nil, :uuid=>nil, :absolute_url=>nil, :scheduled_to=>nil, :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>nil})
16
+ expect(notification.uuid).to be_nil
17
+ expect(notification.destination).to be_nil
18
+ expect(notification.body).to be_nil
19
+ expect(notification.target_url).to be_nil
20
+ expect(notification.scheduled_to).to be_nil
21
+ expect(notification.absolute_url).to be_nil
22
+ expect(notification.sender_data).to be_nil
23
+ expect(notification.read_at).to be_nil
24
+ expect(notification.notification_type).to be_nil
25
25
  end
26
26
  it "should instanciate an object with attributes set" do
27
27
  attributes = {
@@ -31,17 +31,17 @@ describe PassaporteWeb::Notification do
31
31
  "scheduled_to" => "2012-01-01 00:00:00"
32
32
  }
33
33
  notification = PassaporteWeb::Notification.new(attributes)
34
- notification.should_not be_persisted
35
- notification.uuid.should be_nil
36
- notification.attributes.should == {:body=>"Feliz ano novo!", :target_url=>"https://app.passaporteweb.com.br", :uuid=>nil, :absolute_url=>nil, :scheduled_to=>"2012-01-01 00:00:00", :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df"}
37
- notification.destination.should == "ac3540c7-5453-424d-bdfd-8ef2d9ff78df"
38
- notification.body.should == "Feliz ano novo!"
39
- notification.target_url.should == "https://app.passaporteweb.com.br"
40
- notification.scheduled_to.should == "2012-01-01 00:00:00"
41
- notification.absolute_url.should be_nil
42
- notification.sender_data.should be_nil
43
- notification.read_at.should be_nil
44
- notification.notification_type.should be_nil
34
+ expect(notification).not_to be_persisted
35
+ expect(notification.uuid).to be_nil
36
+ expect(notification.attributes).to eq({:body=>"Feliz ano novo!", :target_url=>"https://app.passaporteweb.com.br", :uuid=>nil, :absolute_url=>nil, :scheduled_to=>"2012-01-01 00:00:00", :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df"})
37
+ expect(notification.destination).to eq("ac3540c7-5453-424d-bdfd-8ef2d9ff78df")
38
+ expect(notification.body).to eq("Feliz ano novo!")
39
+ expect(notification.target_url).to eq("https://app.passaporteweb.com.br")
40
+ expect(notification.scheduled_to).to eq("2012-01-01 00:00:00")
41
+ expect(notification.absolute_url).to be_nil
42
+ expect(notification.sender_data).to be_nil
43
+ expect(notification.read_at).to be_nil
44
+ expect(notification.notification_type).to be_nil
45
45
  end
46
46
  end
47
47
 
@@ -54,42 +54,42 @@ describe PassaporteWeb::Notification do
54
54
  data = PassaporteWeb::Notification.find_all
55
55
 
56
56
  notifications = data.notifications
57
- notifications.size.should == 2
57
+ expect(notifications.size).to eq(2)
58
58
  expect(notifications.map { |n| n.instance_of?(described_class) }.uniq).to be_truthy
59
59
  n1, n2 = notifications
60
- n1.body.should == '"oioioi"' # TODO why? was it created like this?
61
- n2.body.should == '"oioioisss"'
62
- n1.uuid.should == "2ca046be-0178-418d-80ac-3a334c264009"
63
- n2.uuid.should == "11f40530-2de0-471d-b1f7-ff39ea21363f"
60
+ expect(n1.body).to eq('"oioioi"') # TODO why? was it created like this?
61
+ expect(n2.body).to eq('"oioioisss"')
62
+ expect(n1.uuid).to eq("2ca046be-0178-418d-80ac-3a334c264009")
63
+ expect(n2.uuid).to eq("11f40530-2de0-471d-b1f7-ff39ea21363f")
64
64
 
65
65
  meta = data.meta
66
- meta.limit.should == 20
67
- meta.next_page.should == nil
68
- meta.prev_page.should == nil
69
- meta.first_page.should == 1
70
- meta.last_page.should == 1
66
+ expect(meta.limit).to eq(20)
67
+ expect(meta.next_page).to eq(nil)
68
+ expect(meta.prev_page).to eq(nil)
69
+ expect(meta.first_page).to eq(1)
70
+ expect(meta.last_page).to eq(1)
71
71
  end
72
72
  it "should return notifications for the authenticated user according to params, along with pagination information" do
73
73
  data = PassaporteWeb::Notification.find_all(2, 1, nil, true, "newest-first")
74
74
 
75
75
  notifications = data.notifications
76
- notifications.size.should == 1
76
+ expect(notifications.size).to eq(1)
77
77
  expect(notifications.map { |n| n.instance_of?(described_class) }.uniq). to be_truthy
78
78
  n1 = notifications.first
79
- n1.body.should == '"oioioi"' # TODO why? was it created like this?
80
- n1.uuid.should == "2ca046be-0178-418d-80ac-3a334c264009"
79
+ expect(n1.body).to eq('"oioioi"') # TODO why? was it created like this?
80
+ expect(n1.uuid).to eq("2ca046be-0178-418d-80ac-3a334c264009")
81
81
 
82
82
  meta = data.meta
83
- meta.limit.should == 1
84
- meta.next_page.should == nil
85
- meta.prev_page.should == 1
86
- meta.first_page.should == 1
87
- meta.last_page.should == 2
83
+ expect(meta.limit).to eq(1)
84
+ expect(meta.next_page).to eq(nil)
85
+ expect(meta.prev_page).to eq(1)
86
+ expect(meta.first_page).to eq(1)
87
+ expect(meta.last_page).to eq(2)
88
88
  end
89
89
  end
90
90
  context "on failure" do
91
91
  it "400 Bad Request" do
92
- PassaporteWeb::Notification.find_all(1, 20, nil, true, 'lalala').should == {"ordering"=>["Faça uma escolha válida. lalala não está disponível."]}
92
+ expect(PassaporteWeb::Notification.find_all(1, 20, nil, true, 'lalala')).to eq({"ordering"=>["Faça uma escolha válida. lalala não está disponível."]})
93
93
  end
94
94
  it "404 Not Found" do
95
95
  expect {
@@ -105,15 +105,15 @@ describe PassaporteWeb::Notification do
105
105
  end
106
106
  context "on success" do
107
107
  it "should return count of notifications for the authenticated user" do
108
- PassaporteWeb::Notification.count.should == 2
108
+ expect(PassaporteWeb::Notification.count).to eq(2)
109
109
  end
110
110
  it "should return count of notifications for the authenticated user, according to params" do
111
- PassaporteWeb::Notification.count(true, '2013-04-02').should == 2
111
+ expect(PassaporteWeb::Notification.count(true, '2013-04-02')).to eq(2)
112
112
  end
113
113
  end
114
114
  context "on failure" do
115
115
  it "it should return an error message if an invalid parameter is sent" do
116
- PassaporteWeb::Notification.count(false, "lalala").should == {"since"=>["Informe uma data/hora válida."]}
116
+ expect(PassaporteWeb::Notification.count(false, "lalala")).to eq({"since"=>["Informe uma data/hora válida."]})
117
117
  end
118
118
  end
119
119
  end
@@ -124,32 +124,32 @@ describe PassaporteWeb::Notification do
124
124
  context "on success" do
125
125
  it "should create the Notification on PassaporteWeb, authenticated as the user" do
126
126
  PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
127
- notification.should_not be_persisted
127
+ expect(notification).not_to be_persisted
128
128
  expect(notification.save).to be_truthy # by default authenticates as the user
129
- notification.should be_persisted
130
- notification.uuid.should_not be_nil
131
- notification.absolute_url.should_not be_nil
132
- notification.destination.should be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
133
- notification.scheduled_to.should == '2013-04-19 00:00:00' # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
134
- notification.body.should == 'feliz aniversário!'
135
- notification.target_url.should == 'http://pittlandia.net/' # PW added the trailing slash, WTF?
136
- notification.sender_data.should == {"name" => "Rodrigo Martins", "uuid" => "385f5f3c-8d33-4b95-9e0d-e87962985244"}
137
- notification.read_at.should be_nil
138
- notification.notification_type.should be_nil
129
+ expect(notification).to be_persisted
130
+ expect(notification.uuid).not_to be_nil
131
+ expect(notification.absolute_url).not_to be_nil
132
+ expect(notification.destination).to be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
133
+ expect(notification.scheduled_to).to eq('2013-04-19 00:00:00') # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
134
+ expect(notification.body).to eq('feliz aniversário!')
135
+ expect(notification.target_url).to eq('http://pittlandia.net/') # PW added the trailing slash, WTF?
136
+ expect(notification.sender_data).to eq({"name" => "Rodrigo Martins", "uuid" => "385f5f3c-8d33-4b95-9e0d-e87962985244"})
137
+ expect(notification.read_at).to be_nil
138
+ expect(notification.notification_type).to be_nil
139
139
  end
140
140
  it "should create the Notification on PassaporteWeb, authenticated as the application" do
141
- notification.should_not be_persisted
141
+ expect(notification).not_to be_persisted
142
142
  expect(notification.save('application')).to be_truthy
143
- notification.should be_persisted
144
- notification.uuid.should_not be_nil
145
- notification.absolute_url.should_not be_nil
146
- notification.destination.should be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
147
- notification.scheduled_to.should == '2013-04-19 00:00:00' # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
148
- notification.body.should == 'feliz aniversário!'
149
- notification.target_url.should == 'http://pittlandia.net/' # PW added the trailing slash, WTF?
150
- notification.sender_data.should == {"name" => "Identity Client", "slug" => "identity_client"}
151
- notification.read_at.should be_nil
152
- notification.notification_type.should be_nil
143
+ expect(notification).to be_persisted
144
+ expect(notification.uuid).not_to be_nil
145
+ expect(notification.absolute_url).not_to be_nil
146
+ expect(notification.destination).to be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
147
+ expect(notification.scheduled_to).to eq('2013-04-19 00:00:00') # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
148
+ expect(notification.body).to eq('feliz aniversário!')
149
+ expect(notification.target_url).to eq('http://pittlandia.net/') # PW added the trailing slash, WTF?
150
+ expect(notification.sender_data).to eq({"name" => "Identity Client", "slug" => "identity_client"})
151
+ expect(notification.read_at).to be_nil
152
+ expect(notification.notification_type).to be_nil
153
153
  end
154
154
  end
155
155
  context "on failure" do
@@ -161,19 +161,19 @@ describe PassaporteWeb::Notification do
161
161
  it "should return false and set the errors with the reason for the failure, authenticated as the user" do
162
162
  PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
163
163
  notification.target_url = 'lalalala'
164
- notification.should_not be_persisted
164
+ expect(notification).not_to be_persisted
165
165
  expect(notification.save('user')).to be_falsy
166
- notification.should_not be_persisted
167
- notification.uuid.should be_nil
168
- notification.errors.should == {"field_errors"=>{"target_url"=>["Informe uma URL válida."]}}
166
+ expect(notification).not_to be_persisted
167
+ expect(notification.uuid).to be_nil
168
+ expect(notification.errors).to eq({"field_errors"=>{"target_url"=>["Informe uma URL válida."]}})
169
169
  end
170
170
  it "should return false and set the errors with the reason for the failure, authenticated as the application" do
171
171
  notification.destination = nil # required field
172
- notification.should_not be_persisted
172
+ expect(notification).not_to be_persisted
173
173
  expect(notification.save('application')).to be_falsy
174
- notification.should_not be_persisted
175
- notification.uuid.should be_nil
176
- notification.errors.should == {"field_errors"=>{"destination"=>["Este campo é obrigatório."]}}
174
+ expect(notification).not_to be_persisted
175
+ expect(notification.uuid).to be_nil
176
+ expect(notification.errors).to eq({"field_errors"=>{"destination"=>["Este campo é obrigatório."]}})
177
177
  end
178
178
  end
179
179
  end
@@ -186,17 +186,17 @@ describe PassaporteWeb::Notification do
186
186
  end
187
187
  context "on success" do
188
188
  it "should mark the Notification as read" do
189
- notification.read_at.should be_nil
189
+ expect(notification.read_at).to be_nil
190
190
  expect(notification.read!).to be_truthy
191
- notification.read_at.should_not be_nil
191
+ expect(notification.read_at).not_to be_nil
192
192
  end
193
193
  end
194
194
  context "on failure" do
195
195
  it "should return false if the notification is already read" do
196
196
  read_notification = described_class.find_all(1,20,nil,true).notifications.detect { |n| !n.read_at.nil? }
197
- read_notification.read_at.should_not be_nil
197
+ expect(read_notification.read_at).not_to be_nil
198
198
  expect(read_notification.read!).to be_falsy
199
- read_notification.errors.should == {message: 'notification already read'}
199
+ expect(read_notification.errors).to eq({message: 'notification already read'})
200
200
  end
201
201
  end
202
202
  end
@@ -205,19 +205,19 @@ describe PassaporteWeb::Notification do
205
205
  let(:notification) { described_class.new(body: 'novinha', destination: 'a5868d14-6529-477a-9c6b-a09dd42a7cd2', scheduled_to: '2013-04-06') } # 2.days.from_now
206
206
  it "should return false if the record is not persisted" do
207
207
  expect(notification.destroy).to be_falsy
208
- notification.errors.should == {message: 'notification not persisted yet'}
208
+ expect(notification.errors).to eq({message: 'notification not persisted yet'})
209
209
  end
210
210
  it "should destroy the notification on PassaporteWeb if the notification has not been read and is scheduled", vcr: true do
211
211
  expect(notification.save('application')).to be_truthy
212
- notification.read_at.should be_nil
213
- notification.scheduled_to.should == "2013-04-06 00:00:00"
212
+ expect(notification.read_at).to be_nil
213
+ expect(notification.scheduled_to).to eq("2013-04-06 00:00:00")
214
214
  expect(notification.destroy).to be_truthy
215
215
  end
216
216
  it "should not exclude non-scheduled notification", vcr: true do
217
217
  notification.scheduled_to = nil
218
218
  expect(notification.save('application')).to be_truthy
219
219
  expect(notification.destroy).to be_falsy
220
- notification.errors.should == "Only scheduled notifications can be deleted via API"
220
+ expect(notification.errors).to eq("Only scheduled notifications can be deleted via API")
221
221
  end
222
222
  end
223
223
 
@@ -11,30 +11,30 @@ describe PassaporteWeb::ServiceAccountMember do
11
11
  describe ".new" do
12
12
  it "should instanciate a minumum object" do
13
13
  member = described_class.new(mock_service_account, mock_identity)
14
- member.service_account.should == mock_service_account
15
- member.identity.should == mock_identity
16
- member.roles.should == ['user']
17
- member.membership_details_url.should be_nil
18
- member.errors.should be_empty
19
- member.should_not be_persisted
20
- member.should_not be_destroyed
14
+ expect(member.service_account).to eq(mock_service_account)
15
+ expect(member.identity).to eq(mock_identity)
16
+ expect(member.roles).to eq(['user'])
17
+ expect(member.membership_details_url).to be_nil
18
+ expect(member.errors).to be_empty
19
+ expect(member).not_to be_persisted
20
+ expect(member).not_to be_destroyed
21
21
  end
22
22
  it "should instanciate an object with attributes set" do
23
23
  member = described_class.new(mock_service_account, mock_identity, ['admin', 'user'])
24
- member.roles.should == ['admin', 'user']
24
+ expect(member.roles).to eq(['admin', 'user'])
25
25
  end
26
26
  end
27
27
 
28
28
  describe ".find", vcr: true do
29
29
  it "should return an instance of ServiceAccountMember with all attributes set" do
30
30
  member = described_class.find(service_account, identity)
31
- member.service_account.should == service_account
32
- member.identity.should == identity
33
- member.roles.should == ['admin','user']
34
- member.membership_details_url.should == "/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/"
35
- member.errors.should be_empty
36
- member.should be_persisted
37
- member.should_not be_destroyed
31
+ expect(member.service_account).to eq(service_account)
32
+ expect(member.identity).to eq(identity)
33
+ expect(member.roles).to eq(['admin','user'])
34
+ expect(member.membership_details_url).to eq("/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/")
35
+ expect(member.errors).to be_empty
36
+ expect(member).to be_persisted
37
+ expect(member).not_to be_destroyed
38
38
  end
39
39
  it "should raise an 404 error if the membership does not exist" do
40
40
  expect {
@@ -47,20 +47,20 @@ describe PassaporteWeb::ServiceAccountMember do
47
47
  it "should destroy the membership, removing the association between service_account and identity" do
48
48
  member = described_class.find(service_account, identity)
49
49
  expect(member.destroy).to be_truthy
50
- member.should_not be_persisted
51
- member.should be_destroyed
52
- member.errors.should be_empty
50
+ expect(member).not_to be_persisted
51
+ expect(member).to be_destroyed
52
+ expect(member.errors).to be_empty
53
53
  expect {
54
54
  described_class.find(service_account, identity)
55
55
  }.to raise_error(RestClient::ResourceNotFound, '404 Resource Not Found')
56
56
  end
57
57
  it "should return false if the role is owner" do
58
58
  member = described_class.find(service_account, identity)
59
- member.roles.should include('owner')
59
+ expect(member.roles).to include('owner')
60
60
  expect(member.destroy).to be_falsy
61
- member.should be_persisted
62
- member.should_not be_destroyed
63
- member.errors.should == "Service owner cannot be removed from members list"
61
+ expect(member).to be_persisted
62
+ expect(member).not_to be_destroyed
63
+ expect(member.errors).to eq("Service owner cannot be removed from members list")
64
64
 
65
65
  expect {
66
66
  described_class.find(service_account, identity)
@@ -74,31 +74,31 @@ describe PassaporteWeb::ServiceAccountMember do
74
74
  context "on success" do
75
75
  it "should create the membership between the service_account and the identity" do
76
76
  expect(member.save).to be_truthy
77
- member.service_account.should == service_account
78
- member.identity.should == identity
79
- member.roles.should == ['admin','user']
80
- member.membership_details_url.should == "/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/"
81
- member.errors.should be_empty
82
- member.should be_persisted
83
- member.should_not be_destroyed
77
+ expect(member.service_account).to eq(service_account)
78
+ expect(member.identity).to eq(identity)
79
+ expect(member.roles).to eq(['admin','user'])
80
+ expect(member.membership_details_url).to eq("/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/")
81
+ expect(member.errors).to be_empty
82
+ expect(member).to be_persisted
83
+ expect(member).not_to be_destroyed
84
84
 
85
85
  member = described_class.find(service_account, identity)
86
- member.service_account.should == service_account
87
- member.identity.should == identity
88
- member.roles.should == ['admin','user']
89
- member.membership_details_url.should == "/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/"
90
- member.errors.should be_empty
91
- member.should be_persisted
92
- member.should_not be_destroyed
86
+ expect(member.service_account).to eq(service_account)
87
+ expect(member.identity).to eq(identity)
88
+ expect(member.roles).to eq(['admin','user'])
89
+ expect(member.membership_details_url).to eq("/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/")
90
+ expect(member.errors).to be_empty
91
+ expect(member).to be_persisted
92
+ expect(member).not_to be_destroyed
93
93
  end
94
94
  end
95
95
  context "on failure" do
96
96
  it "should not create the membership and set the errors on the object" do
97
97
  member.roles = ['owner'] # can't create membership for the owner
98
98
  expect(member.save).to be_falsy
99
- member.errors.should == "Adding a member as owner is not allowed"
100
- member.should_not be_persisted
101
- member.should_not be_destroyed
99
+ expect(member.errors).to eq("Adding a member as owner is not allowed")
100
+ expect(member).not_to be_persisted
101
+ expect(member).not_to be_destroyed
102
102
 
103
103
  expect {
104
104
  described_class.find(service_account, identity)
@@ -106,9 +106,9 @@ describe PassaporteWeb::ServiceAccountMember do
106
106
  end
107
107
  it "should return false if the membership already exists" do
108
108
  expect(member.save).to be_falsy
109
- member.errors.should == "Identity with uuid=5e32f927-c4ab-404e-a91c-b2abc05afb56 is already in members list of service identity_client at account 859d3542-84d6-4909-b1bd-4f43c1312065"
110
- member.should_not be_persisted
111
- member.should_not be_destroyed
109
+ expect(member.errors).to eq("Identity with uuid=5e32f927-c4ab-404e-a91c-b2abc05afb56 is already in members list of service identity_client at account 859d3542-84d6-4909-b1bd-4f43c1312065")
110
+ expect(member).not_to be_persisted
111
+ expect(member).not_to be_destroyed
112
112
 
113
113
  expect {
114
114
  described_class.find(service_account, identity)
@@ -120,27 +120,27 @@ describe PassaporteWeb::ServiceAccountMember do
120
120
  let(:member) { described_class.find(service_account, identity) }
121
121
  context "on success" do
122
122
  it "should update the member roles" do
123
- member.roles.should == ['admin', 'user']
123
+ expect(member.roles).to eq(['admin', 'user'])
124
124
  member.roles = ['user']
125
125
  expect(member.save).to be_truthy
126
- member.errors.should be_empty
127
- member.roles.should == ['user']
126
+ expect(member.errors).to be_empty
127
+ expect(member.roles).to eq(['user'])
128
128
 
129
129
  member = described_class.find(service_account, identity)
130
- member.roles.should == ['user']
130
+ expect(member.roles).to eq(['user'])
131
131
  end
132
132
  end
133
133
  context "on failure" do
134
134
  it "should return false and set the errors" do
135
135
  pending "está deixando setar como owner e não deixa setar sem nenhum role, como fazer?"
136
- member.roles.should == ['admin', 'user']
136
+ expect(member.roles).to eq(['admin', 'user'])
137
137
  member.roles = ['owner']
138
138
  expect(member.save).to be_falsy
139
- member.errors.should_not be_empty
140
- member.roles.should == ['owner']
139
+ expect(member.errors).not_to be_empty
140
+ expect(member.roles).to eq(['owner'])
141
141
 
142
142
  member = described_class.find(service_account, identity)
143
- member.roles.should == ['admin', 'user']
143
+ expect(member.roles).to eq(['admin', 'user'])
144
144
  end
145
145
  end
146
146
  end
@@ -6,7 +6,7 @@ describe PassaporteWeb::ServiceAccount do
6
6
  describe ".new" do
7
7
  it "should instanciate an empty object" do
8
8
  service_account = PassaporteWeb::ServiceAccount.new
9
- service_account.attributes.should == {:plan_slug=>nil, :expiration=>nil, :identity=>nil, :roles=>nil, :member_uuid=>nil, :role=>nil, :include_expired_accounts=>nil, :name=>nil, :members_data=>nil, :url=>nil, :service_data=>nil, :account_data=>nil, :add_member_url=>nil}
9
+ expect(service_account.attributes).to eq({:plan_slug=>nil, :expiration=>nil, :identity=>nil, :roles=>nil, :member_uuid=>nil, :role=>nil, :include_expired_accounts=>nil, :name=>nil, :members_data=>nil, :url=>nil, :service_data=>nil, :account_data=>nil, :add_member_url=>nil})
10
10
  end
11
11
  it "should instanciate an object with attributes set" do
12
12
  attributes = {
@@ -25,15 +25,15 @@ describe PassaporteWeb::ServiceAccount do
25
25
  "add_member_url" => nil
26
26
  }
27
27
  service_account = PassaporteWeb::ServiceAccount.new(attributes)
28
- service_account.attributes.should == { :plan_slug=>"free", :expiration=>"2011-12-31", :identity=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df", :roles=>"admin,user", :member_uuid=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df", :role=>"owner", :include_expired_accounts=>"true", :name=>"Conta Pessoa", :members_data=>nil, :url=>nil, :service_data=>nil, :account_data=>nil, :add_member_url=>nil }
29
- service_account.plan_slug.should == "free"
30
- service_account.expiration.should == "2011-12-31"
31
- service_account.identity.should == "ac3540c7-5453-424d-bdfd-8ef2d9ff78df"
32
- service_account.roles.should == "admin,user"
33
- service_account.member_uuid.should == "ac3540c7-5453-424d-bdfd-8ef2d9ff78df"
34
- service_account.role.should == "owner"
35
- service_account.include_expired_accounts.should == "true"
36
- service_account.name.should == "Conta Pessoa"
28
+ expect(service_account.attributes).to eq({ :plan_slug=>"free", :expiration=>"2011-12-31", :identity=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df", :roles=>"admin,user", :member_uuid=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df", :role=>"owner", :include_expired_accounts=>"true", :name=>"Conta Pessoa", :members_data=>nil, :url=>nil, :service_data=>nil, :account_data=>nil, :add_member_url=>nil })
29
+ expect(service_account.plan_slug).to eq("free")
30
+ expect(service_account.expiration).to eq("2011-12-31")
31
+ expect(service_account.identity).to eq("ac3540c7-5453-424d-bdfd-8ef2d9ff78df")
32
+ expect(service_account.roles).to eq("admin,user")
33
+ expect(service_account.member_uuid).to eq("ac3540c7-5453-424d-bdfd-8ef2d9ff78df")
34
+ expect(service_account.role).to eq("owner")
35
+ expect(service_account.include_expired_accounts).to eq("true")
36
+ expect(service_account.name).to eq("Conta Pessoa")
37
37
  end
38
38
  end
39
39
 
@@ -43,39 +43,39 @@ describe PassaporteWeb::ServiceAccount do
43
43
  accounts_and_meta = PassaporteWeb::ServiceAccount.find_all
44
44
 
45
45
  service_accounts = accounts_and_meta.service_accounts
46
- service_accounts.should be_instance_of(Array)
47
- service_accounts.size.should == 15
48
- service_accounts.map { |a| a.instance_of?(PassaporteWeb::ServiceAccount) }.uniq.should == [true]
49
- service_accounts.map(&:plan_slug).uniq.sort.should == ['free', 'passaporteweb-client-ruby']
50
- service_accounts.map(&:persisted?).uniq.sort.should == [true]
46
+ expect(service_accounts).to be_instance_of(Array)
47
+ expect(service_accounts.size).to eq(15)
48
+ expect(service_accounts.map { |a| a.instance_of?(PassaporteWeb::ServiceAccount) }.uniq).to eq([true])
49
+ expect(service_accounts.map(&:plan_slug).uniq.sort).to eq(['free', 'passaporteweb-client-ruby'])
50
+ expect(service_accounts.map(&:persisted?).uniq.sort).to eq([true])
51
51
 
52
52
  meta = accounts_and_meta.meta
53
- meta.limit.should == 20
54
- meta.next_page.should == nil
55
- meta.prev_page.should == nil
56
- meta.first_page.should == 1
57
- meta.last_page.should == 1
53
+ expect(meta.limit).to eq(20)
54
+ expect(meta.next_page).to eq(nil)
55
+ expect(meta.prev_page).to eq(nil)
56
+ expect(meta.first_page).to eq(1)
57
+ expect(meta.last_page).to eq(1)
58
58
  end
59
59
  it "should return information about all possible pages" do
60
60
  accounts_and_meta = PassaporteWeb::ServiceAccount.find_all(3, 3)
61
61
 
62
62
  service_accounts = accounts_and_meta.service_accounts
63
- service_accounts.should be_instance_of(Array)
64
- service_accounts.size.should == 3
63
+ expect(service_accounts).to be_instance_of(Array)
64
+ expect(service_accounts.size).to eq(3)
65
65
 
66
66
  meta = accounts_and_meta.meta
67
- meta.limit.should == 3
68
- meta.next_page.should == 4
69
- meta.prev_page.should == 2
70
- meta.first_page.should == 1
71
- meta.last_page.should == 5
67
+ expect(meta.limit).to eq(3)
68
+ expect(meta.next_page).to eq(4)
69
+ expect(meta.prev_page).to eq(2)
70
+ expect(meta.first_page).to eq(1)
71
+ expect(meta.last_page).to eq(5)
72
72
  end
73
73
  it "should ask for page 1 and 20 accounts per page by default" do
74
- PassaporteWeb::Http.should_receive(:get).with("/organizations/api/accounts/?page=1&limit=20").and_return(mock_response)
74
+ expect(PassaporteWeb::Http).to receive(:get).with("/organizations/api/accounts/?page=1&limit=20").and_return(mock_response)
75
75
  PassaporteWeb::ServiceAccount.find_all
76
76
  end
77
77
  it "should ask for page and accounts per page as supplied" do
78
- PassaporteWeb::Http.should_receive(:get).with("/organizations/api/accounts/?page=4&limit=100").and_return(mock_response)
78
+ expect(PassaporteWeb::Http).to receive(:get).with("/organizations/api/accounts/?page=4&limit=100").and_return(mock_response)
79
79
  PassaporteWeb::ServiceAccount.find_all(4, 100)
80
80
  end
81
81
  it "should raise an error if the page does not exist" do
@@ -89,18 +89,18 @@ describe PassaporteWeb::ServiceAccount do
89
89
  context "on success" do
90
90
  it "should return an instance of Account with all the details" do
91
91
  service_account = PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065")
92
- service_account.should be_instance_of(PassaporteWeb::ServiceAccount)
93
- service_account.plan_slug.should == "free"
94
- service_account.should be_persisted
95
- service_account.account_data.should == {"name" => "Investimentos", "uuid" => "859d3542-84d6-4909-b1bd-4f43c1312065"}
96
- service_account.service_data.should == {"name" => "Identity Client", "slug" => "identity_client"}
97
- service_account.members_data.should == [
92
+ expect(service_account).to be_instance_of(PassaporteWeb::ServiceAccount)
93
+ expect(service_account.plan_slug).to eq("free")
94
+ expect(service_account).to be_persisted
95
+ expect(service_account.account_data).to eq({"name" => "Investimentos", "uuid" => "859d3542-84d6-4909-b1bd-4f43c1312065"})
96
+ expect(service_account.service_data).to eq({"name" => "Identity Client", "slug" => "identity_client"})
97
+ expect(service_account.members_data).to eq([
98
98
  {"membership_details_url"=>"/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/20a8bbe1-3b4a-4e46-a69a-a7c524bd2ab8/", "identity"=>"20a8bbe1-3b4a-4e46-a69a-a7c524bd2ab8", "roles"=>["owner"]},
99
99
  {"membership_details_url"=>"/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/5e32f927-c4ab-404e-a91c-b2abc05afb56/", "identity"=>"5e32f927-c4ab-404e-a91c-b2abc05afb56", "roles"=>["user"]}
100
- ]
101
- service_account.expiration.should be_nil
102
- service_account.url.should == "/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/"
103
- service_account.add_member_url.should == "/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/"
100
+ ])
101
+ expect(service_account.expiration).to be_nil
102
+ expect(service_account.url).to eq("/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/")
103
+ expect(service_account.add_member_url).to eq("/organizations/api/accounts/859d3542-84d6-4909-b1bd-4f43c1312065/members/")
104
104
  end
105
105
  end
106
106
  context "on failure" do
@@ -116,13 +116,13 @@ describe PassaporteWeb::ServiceAccount do
116
116
  let(:service_account) { PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065") }
117
117
  it "should return the uuid of the ServiceAccount" do
118
118
  service_account = PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065")
119
- service_account.account_data.should == {"name" => "Investimentos", "uuid" => "859d3542-84d6-4909-b1bd-4f43c1312065"}
120
- service_account.uuid.should == '859d3542-84d6-4909-b1bd-4f43c1312065'
119
+ expect(service_account.account_data).to eq({"name" => "Investimentos", "uuid" => "859d3542-84d6-4909-b1bd-4f43c1312065"})
120
+ expect(service_account.uuid).to eq('859d3542-84d6-4909-b1bd-4f43c1312065')
121
121
  end
122
122
  it "should return nil if the ServiceAccount has no uuid yet" do
123
123
  service_account = PassaporteWeb::ServiceAccount.new
124
- service_account.account_data.should be_nil
125
- service_account.uuid.should be_nil
124
+ expect(service_account.account_data).to be_nil
125
+ expect(service_account.uuid).to be_nil
126
126
  end
127
127
  end
128
128
 
@@ -130,32 +130,32 @@ describe PassaporteWeb::ServiceAccount do
130
130
  let(:service_account) { PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065") }
131
131
  context "on success" do
132
132
  it "should update the ServiceAccount attributes on the server" do
133
- service_account.plan_slug.should == 'free'
134
- service_account.expiration.should == '2014-04-01 00:00:00'
133
+ expect(service_account.plan_slug).to eq('free')
134
+ expect(service_account.expiration).to eq('2014-04-01 00:00:00')
135
135
 
136
136
  service_account.plan_slug = 'basic'
137
137
  service_account.expiration = '2014-05-01'
138
138
 
139
- service_account.should be_persisted
139
+ expect(service_account).to be_persisted
140
140
  expect(service_account.save).to be_truthy
141
- service_account.should be_persisted
141
+ expect(service_account).to be_persisted
142
142
 
143
- service_account.plan_slug.should == 'basic'
144
- service_account.expiration.should == '2014-05-01 00:00:00'
143
+ expect(service_account.plan_slug).to eq('basic')
144
+ expect(service_account.expiration).to eq('2014-05-01 00:00:00')
145
145
 
146
146
  service_account = PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065")
147
- service_account.plan_slug.should == 'basic'
148
- service_account.expiration.should == '2014-05-01 00:00:00'
147
+ expect(service_account.plan_slug).to eq('basic')
148
+ expect(service_account.expiration).to eq('2014-05-01 00:00:00')
149
149
  end
150
150
  end
151
151
  context "on failure" do
152
152
  it "should return false and set the errors hash" do
153
153
  service_account.plan_slug = nil # required
154
154
  service_account.expiration = nil
155
- service_account.should be_persisted
155
+ expect(service_account).to be_persisted
156
156
  expect(service_account.save).to be_falsy
157
- service_account.should be_persisted
158
- service_account.errors.should == {"field_errors"=>{"plan_slug"=>["Este campo é obrigatório."]}}
157
+ expect(service_account).to be_persisted
158
+ expect(service_account.errors).to eq({"field_errors"=>{"plan_slug"=>["Este campo é obrigatório."]}})
159
159
  end
160
160
  end
161
161
  end