passaporteweb-client 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,163 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe PassaporteWeb::ServiceAccount do
5
+
6
+ describe ".new" do
7
+ it "should instanciate an empty object" do
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}
10
+ end
11
+ it "should instanciate an object with attributes set" do
12
+ attributes = {
13
+ "plan_slug"=>"free",
14
+ "expiration"=>"2011-12-31",
15
+ "identity"=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df",
16
+ "roles"=>"admin,user",
17
+ "member_uuid"=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df",
18
+ "role"=>"owner",
19
+ "include_expired_accounts"=>"true",
20
+ "name"=>"Conta Pessoa",
21
+ "members_data" => nil,
22
+ "url" => nil,
23
+ "service_data" => nil,
24
+ "account_data" => nil,
25
+ "add_member_url" => nil
26
+ }
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"
37
+ end
38
+ end
39
+
40
+ describe ".find_all", :vcr => true do
41
+ let(:mock_response) { mock('response', body: [].to_json, code: 200, headers: {link: "<http://sandbox.app.passaporteweb.com.br/organizations/api/accounts/?page=3&limit=3>; rel=next, <http://sandbox.app.passaporteweb.com.br/organizations/api/accounts/?page=1&limit=3>; rel=prev"}) }
42
+ it "should find all accounts related to the authenticated application and return them as an array of Account instances" do
43
+ accounts_and_meta = PassaporteWeb::ServiceAccount.find_all
44
+
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]
51
+
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
58
+ end
59
+ it "should return information about all possible pages" do
60
+ accounts_and_meta = PassaporteWeb::ServiceAccount.find_all(3, 3)
61
+
62
+ service_accounts = accounts_and_meta.service_accounts
63
+ service_accounts.should be_instance_of(Array)
64
+ service_accounts.size.should == 3
65
+
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
72
+ end
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)
75
+ PassaporteWeb::ServiceAccount.find_all
76
+ end
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)
79
+ PassaporteWeb::ServiceAccount.find_all(4, 100)
80
+ end
81
+ it "should raise an error if the page does not exist" do
82
+ expect {
83
+ PassaporteWeb::ServiceAccount.find_all(4_000_000)
84
+ }.to raise_error(RestClient::ResourceNotFound, '404 Resource Not Found')
85
+ end
86
+ end
87
+
88
+ describe ".find", :vcr => true do
89
+ context "on success" do
90
+ it "should return an instance of Account with all the details" do
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 == [
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
+ {"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/"
104
+ end
105
+ end
106
+ context "on failure" do
107
+ it "should raise an error if no Account exist with that uuid" do
108
+ expect {
109
+ PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312062")
110
+ }.to raise_error(RestClient::ResourceNotFound, '404 Resource Not Found')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "#uuid", :vcr => true do
116
+ let(:service_account) { PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065") }
117
+ it "should return the uuid of the ServiceAccount" do
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'
121
+ end
122
+ it "should return nil if the ServiceAccount has no uuid yet" do
123
+ service_account = PassaporteWeb::ServiceAccount.new
124
+ service_account.account_data.should be_nil
125
+ service_account.uuid.should be_nil
126
+ end
127
+ end
128
+
129
+ describe "#save", :vcr => true do
130
+ let(:service_account) { PassaporteWeb::ServiceAccount.find("859d3542-84d6-4909-b1bd-4f43c1312065") }
131
+ context "on success" do
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'
135
+
136
+ service_account.plan_slug = 'basic'
137
+ service_account.expiration = '2014-05-01'
138
+
139
+ service_account.should be_persisted
140
+ service_account.save.should be_true
141
+ service_account.should be_persisted
142
+
143
+ service_account.plan_slug.should == 'basic'
144
+ service_account.expiration.should == '2014-05-01 00:00:00'
145
+
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'
149
+ end
150
+ end
151
+ context "on failure" do
152
+ it "should return false and set the errors hash" do
153
+ service_account.plan_slug = nil # required
154
+ service_account.expiration = nil
155
+ service_account.should be_persisted
156
+ service_account.save.should be_false
157
+ service_account.should be_persisted
158
+ service_account.errors.should == {"field_errors"=>{"plan_slug"=>["Este campo é obrigatório."]}}
159
+ end
160
+ end
161
+ end
162
+
163
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe PassaporteWeb do
5
+
6
+ it 'should have a version number' do
7
+ PassaporteWeb::VERSION.should_not be_nil
8
+ end
9
+
10
+ describe 'configuration' do
11
+ it 'should be done via block initialization' do
12
+ PassaporteWeb.configure do |c|
13
+ c.url = 'http://some/where'
14
+ c.user_agent = 'My App v1.0'
15
+ c.application_token = 'some-app-token'
16
+ c.application_secret = 'some-app-secret'
17
+ c.user_token = nil
18
+ end
19
+ PassaporteWeb.configuration.url.should == 'http://some/where'
20
+ PassaporteWeb.configuration.user_agent.should == 'My App v1.0'
21
+ PassaporteWeb.configuration.application_token.should == 'some-app-token'
22
+ PassaporteWeb.configuration.application_secret.should == 'some-app-secret'
23
+ PassaporteWeb.configuration.user_token.should be_nil
24
+ end
25
+ it 'should use a singleton object for the configuration values' do
26
+ config1 = PassaporteWeb.configuration
27
+ config2 = PassaporteWeb.configuration
28
+ config1.should === config2
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start
8
+
9
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
10
+ require 'passaporte_web'
11
+
12
+ require 'vcr'
13
+ require 'pry'
14
+
15
+ VCR.configure do |c|
16
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
17
+ c.hook_into :webmock
18
+ c.ignore_localhost = true
19
+ c.default_cassette_options = { :record => :once }
20
+ c.configure_rspec_metadata!
21
+ end
22
+
23
+ RSpec.configure do |c|
24
+ c.mock_with :rspec
25
+
26
+ # so we can use :vcr rather than :vcr => true;
27
+ # in RSpec 3 this will no longer be necessary.
28
+ c.treat_symbols_as_metadata_keys_with_true_values = true
29
+
30
+ c.before(:vcr => true) do
31
+ PassaporteWeb.configure do |c|
32
+ c.url = 'http://sandbox.app.passaporteweb.com.br' # TODO trocar para https
33
+ c.application_token = '8ab29iwKFI'
34
+ c.application_secret = 'VnWYenOqYsHtcFowrdJlwdJNALq5Go9v'
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,302 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passaporteweb-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Tassinari de Oliveira
9
+ - Rodrigo Martins
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.7
31
+ - !ruby/object:Gem::Dependency
32
+ name: multi_json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.7.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.7.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.3.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 10.0.4
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 10.0.4
79
+ - !ruby/object:Gem::Dependency
80
+ name: rdoc
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 4.0.1
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 4.0.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 2.13.0
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.13.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 2.4.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 2.4.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: webmock
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: 1.9.3
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 1.9.3
143
+ - !ruby/object:Gem::Dependency
144
+ name: pry
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ version: 0.9.12
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ~>
157
+ - !ruby/object:Gem::Version
158
+ version: 0.9.12
159
+ - !ruby/object:Gem::Dependency
160
+ name: pry-nav
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 0.2.3
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: 0.2.3
175
+ - !ruby/object:Gem::Dependency
176
+ name: awesome_print
177
+ requirement: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ~>
181
+ - !ruby/object:Gem::Version
182
+ version: 1.1.0
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ~>
189
+ - !ruby/object:Gem::Version
190
+ version: 1.1.0
191
+ - !ruby/object:Gem::Dependency
192
+ name: simplecov
193
+ requirement: !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ~>
197
+ - !ruby/object:Gem::Version
198
+ version: 0.7.1
199
+ type: :development
200
+ prerelease: false
201
+ version_requirements: !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ~>
205
+ - !ruby/object:Gem::Version
206
+ version: 0.7.1
207
+ - !ruby/object:Gem::Dependency
208
+ name: coveralls
209
+ requirement: !ruby/object:Gem::Requirement
210
+ none: false
211
+ requirements:
212
+ - - ~>
213
+ - !ruby/object:Gem::Version
214
+ version: 0.6.3
215
+ type: :development
216
+ prerelease: false
217
+ version_requirements: !ruby/object:Gem::Requirement
218
+ none: false
219
+ requirements:
220
+ - - ~>
221
+ - !ruby/object:Gem::Version
222
+ version: 0.6.3
223
+ description: A Ruby client for the PassaporteWeb REST API
224
+ email:
225
+ - rodrigo@pittlandia.net
226
+ - rodrigo.tassinari@myfreecomm.com.br
227
+ - rodrigo.martins@myfreecomm.com.br
228
+ - rodrigo@rrmartins.com
229
+ executables: []
230
+ extensions: []
231
+ extra_rdoc_files: []
232
+ files:
233
+ - .coveralls.yml
234
+ - .gitignore
235
+ - .rspec
236
+ - .travis.yml
237
+ - Gemfile
238
+ - Gemfile.lock
239
+ - LICENSE
240
+ - README.rdoc
241
+ - Rakefile
242
+ - lib/passaporte_web.rb
243
+ - lib/passaporte_web/attributable.rb
244
+ - lib/passaporte_web/configuration.rb
245
+ - lib/passaporte_web/helpers.rb
246
+ - lib/passaporte_web/http.rb
247
+ - lib/passaporte_web/identity.rb
248
+ - lib/passaporte_web/identity_service_account.rb
249
+ - lib/passaporte_web/service_account.rb
250
+ - lib/passaporte_web/service_account_member.rb
251
+ - lib/passaporte_web/version.rb
252
+ - passaporteweb-client.gemspec
253
+ - spec/passaporte_web/configuration_spec.rb
254
+ - spec/passaporte_web/helpers_spec.rb
255
+ - spec/passaporte_web/http_spec.rb
256
+ - spec/passaporte_web/identity_service_account_spec.rb
257
+ - spec/passaporte_web/identity_spec.rb
258
+ - spec/passaporte_web/service_account_member_spec.rb
259
+ - spec/passaporte_web/service_account_spec.rb
260
+ - spec/passaporte_web_spec.rb
261
+ - spec/spec_helper.rb
262
+ homepage: https://github.com/myfreecomm/passaporteweb-client-ruby
263
+ licenses:
264
+ - Apache-v2
265
+ post_install_message:
266
+ rdoc_options: []
267
+ require_paths:
268
+ - lib
269
+ required_ruby_version: !ruby/object:Gem::Requirement
270
+ none: false
271
+ requirements:
272
+ - - ! '>='
273
+ - !ruby/object:Gem::Version
274
+ version: '0'
275
+ segments:
276
+ - 0
277
+ hash: 3548297114629816547
278
+ required_rubygems_version: !ruby/object:Gem::Requirement
279
+ none: false
280
+ requirements:
281
+ - - ! '>='
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ segments:
285
+ - 0
286
+ hash: 3548297114629816547
287
+ requirements: []
288
+ rubyforge_project:
289
+ rubygems_version: 1.8.25
290
+ signing_key:
291
+ specification_version: 3
292
+ summary: ! 'A Ruby client for the PassaporteWeb REST API: https://app.passaporteweb.com.br/static/docs/'
293
+ test_files:
294
+ - spec/passaporte_web/configuration_spec.rb
295
+ - spec/passaporte_web/helpers_spec.rb
296
+ - spec/passaporte_web/http_spec.rb
297
+ - spec/passaporte_web/identity_service_account_spec.rb
298
+ - spec/passaporte_web/identity_spec.rb
299
+ - spec/passaporte_web/service_account_member_spec.rb
300
+ - spec/passaporte_web/service_account_spec.rb
301
+ - spec/passaporte_web_spec.rb
302
+ - spec/spec_helper.rb