spyou_rpx_now 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require 'spec/spec_helper'
2
+
3
+ class User
4
+ include RPXNow::UserIntegration
5
+
6
+ def id
7
+ 5
8
+ end
9
+ end
10
+
11
+ describe RPXNow::UserProxy do
12
+ before { @user = User.new }
13
+
14
+ it "has a proxy" do
15
+ @user.rpx.class.should == RPXNow::UserProxy
16
+ end
17
+
18
+ it "has identifiers" do
19
+ RPXNow.should_receive(:mappings).with(@user.id).and_return(['identifiers'])
20
+ @user.rpx.identifiers.should == ['identifiers']
21
+ end
22
+
23
+ it "can map" do
24
+ RPXNow.should_receive(:map).with('identifier', @user.id)
25
+ @user.rpx.map('identifier')
26
+ end
27
+
28
+ it "can unmap" do
29
+ RPXNow.should_receive(:unmap).with('identifier', @user.id)
30
+ @user.rpx.unmap('identifier')
31
+ end
32
+ end
@@ -0,0 +1,326 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe RPXNow do
4
+ def fake_response(replace={})
5
+ body = {'stat' => 'ok'}.merge(replace)
6
+ mock({:code => "200", :body => body.to_json})
7
+ end
8
+
9
+ describe :api_key= do
10
+ before do
11
+ RPXNow.api_key='XX'
12
+ end
13
+
14
+ it "is stored" do
15
+ RPXNow.api_key.should == 'XX'
16
+ end
17
+
18
+ it "stores the api key, so i do not have to supply everytime" do
19
+ RPXNow::Api.should_receive(:request).
20
+ with(anything, hash_including(:apiKey => 'XX')).
21
+ and_return fake_response
22
+ RPXNow.mappings(1)
23
+ end
24
+
25
+ it "is not overwritten when overwriting for a single request" do
26
+ RPXNow::Api.should_receive(:request).
27
+ with(anything, hash_including(:apiKey => 'YY')).
28
+ and_return fake_response
29
+ RPXNow.mappings(1, :apiKey => 'YY')
30
+ RPXNow.api_key.should == 'XX'
31
+ end
32
+ end
33
+
34
+ describe :api_version= do
35
+ it "is 2 by default" do
36
+ RPXNow.api_version.should == 2
37
+ end
38
+
39
+ it "is stored" do
40
+ RPXNow.api_version='XX'
41
+ RPXNow.api_version.should == 'XX'
42
+ end
43
+
44
+ it "used for every request" do
45
+ RPXNow.api_version='XX'
46
+ RPXNow::Api.should_receive(:request).
47
+ with('/api/vXX/mappings', anything).
48
+ and_return fake_response
49
+ RPXNow.mappings(1)
50
+ end
51
+
52
+ it "is not overwritten when overwriting for a single request" do
53
+ RPXNow.api_version='XX'
54
+ RPXNow::Api.should_receive(:request).
55
+ with('/api/vYY/mappings', anything).
56
+ and_return fake_response
57
+ RPXNow.mappings(1, :api_version => 'YY')
58
+ RPXNow.api_version.should == 'XX'
59
+ end
60
+
61
+ it "is not passed in data for request" do
62
+ RPXNow.api_version='XX'
63
+ RPXNow::Api.should_receive(:request).
64
+ with(anything, hash_not_including(:api_version => 'YY')).
65
+ and_return fake_response
66
+ RPXNow.mappings(1, :api_version => 'YY')
67
+ end
68
+ end
69
+
70
+ describe :embed_code do
71
+ it "contains the subdomain" do
72
+ RPXNow.embed_code('xxx','my_url').should =~ /xxx/
73
+ end
74
+
75
+ it "contains the url" do
76
+ RPXNow.embed_code('xxx','my_url').should =~ /token_url=my_url/
77
+ end
78
+
79
+ it "defaults to no language" do
80
+ RPXNow.embed_code('xxx', 'my_url').should_not =~ /language_preference/
81
+ end
82
+
83
+ it "has a changeable language" do
84
+ RPXNow.embed_code('xxx', 'my_url', :language => 'es').should =~ /language_preference=es/
85
+ end
86
+
87
+ it "defaults to 400px width" do
88
+ RPXNow.embed_code('xxx', 'my_url').should =~ /width:400px;/
89
+ end
90
+
91
+ it "has a changeable width" do
92
+ RPXNow.embed_code('xxx', 'my_url', :width => '300').should =~ /width:300px;/
93
+ end
94
+
95
+ it "defaults to 240px height" do
96
+ RPXNow.embed_code('xxx', 'my_url').should =~ /height:240px;/
97
+ end
98
+
99
+ it "has a changeable height" do
100
+ RPXNow.embed_code('xxx', 'my_url', :height => '500').should =~ /height:500px;/
101
+ end
102
+ end
103
+
104
+ describe :popup_code do
105
+ it "defaults to obtrusive output" do
106
+ RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/').should =~ /script src=/
107
+ end
108
+
109
+ it "does not change supplied options" do
110
+ options = {:xxx => 1}
111
+ RPXNow.popup_code('a','b','c', options)
112
+ options.should == {:xxx => 1}
113
+ end
114
+
115
+ describe 'unobstrusive' do
116
+ it "can build an unobtrusive widget" do
117
+ expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http://fake.domain.com/">sign on</a>)
118
+ actual = RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/', :unobtrusive => true)
119
+ actual.should == expected
120
+ end
121
+
122
+ it "can change api version" do
123
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :api_version => 'XX').should include("openid/vXX/signin?")
124
+ end
125
+
126
+ it "can change language" do
127
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :language => 'XX').should include("language_preference=XX")
128
+ end
129
+
130
+ it "can add flags" do
131
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :flags => 'test').should include("flags=test")
132
+ end
133
+
134
+ it "can add default_provider" do
135
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :default_provider => 'test').should include("default_provider=test")
136
+ end
137
+ end
138
+
139
+ it "allows to specify the version of the widget" do
140
+ RPXNow.popup_code('x','y','z', :api_version => 300).should =~ %r(/openid/v300/signin)
141
+ end
142
+
143
+ it "defaults to widget version 2" do
144
+ RPXNow.popup_code('x','y','z').should =~ %r(/openid/v2/signin)
145
+ end
146
+
147
+ describe 'language' do
148
+ it "defaults to no language" do
149
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.language_preference/
150
+ end
151
+
152
+ it "has a changeable language" do
153
+ RPXNow.popup_code('x','y','z', :language=>'de').should =~ /RPXNOW.language_preference = 'de'/
154
+ end
155
+ end
156
+
157
+ describe 'flags' do
158
+ it "defaults to no language" do
159
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.flags/
160
+ end
161
+
162
+ it "can have flags" do
163
+ RPXNow.popup_code('x','y','z', :flags=>'test').should =~ /RPXNOW.flags = 'test'/
164
+ end
165
+ end
166
+
167
+ describe 'default_provider' do
168
+ it "defaults to no provider" do
169
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.default_provider/
170
+ end
171
+
172
+ it "can have default_provider" do
173
+ RPXNow.popup_code('x','y','z', :default_provider=>'test').should =~ /RPXNOW.default_provider = 'test'/
174
+ end
175
+ end
176
+ end
177
+
178
+ describe :user_data do
179
+ before do
180
+ @response_body = {
181
+ "profile" => {
182
+ "verifiedEmail" => "grosser.michael@googlemail.com",
183
+ "displayName" => "Michael Grosser",
184
+ "preferredUsername" => "grosser.michael",
185
+ "identifier" => "https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM",
186
+ "email" => "grosser.michael@gmail.com"
187
+ }
188
+ }
189
+ @response = fake_response(@response_body)
190
+ @fake_user_data = {'profile'=>{}}
191
+ end
192
+
193
+ it "raises ApiError when used with an invalid token" do
194
+ lambda{
195
+ RPXNow.user_data('xxxx')
196
+ }.should raise_error(RPXNow::ApiError)
197
+ end
198
+
199
+ it "is empty when used with an unknown token" do
200
+ RPXNow.user_data('60d8c6374f4e9d290a7b55f39da7cc6435aef3d3').should == nil
201
+ end
202
+
203
+ it "parses JSON response to user data" do
204
+ expected = {
205
+ :name => 'Michael Grosser',
206
+ :email => 'grosser.michael@googlemail.com',
207
+ :identifier => 'https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM',
208
+ :username => 'grosser.michael',
209
+ }
210
+ RPXNow::Api.should_receive(:request).and_return @response
211
+ RPXNow.user_data('').should == expected
212
+ end
213
+
214
+ it "adds a :id when primaryKey was returned" do
215
+ @response_body['profile']['primaryKey'] = "2"
216
+ response = fake_response(@response_body)
217
+ RPXNow::Api.should_receive(:request).and_return response
218
+ RPXNow.user_data('')[:id].should == '2'
219
+ end
220
+
221
+ it "handles primaryKeys that are not numeric" do
222
+ @response_body['profile']['primaryKey'] = "dbalatero"
223
+ response = fake_response(@response_body)
224
+ RPXNow::Api.should_receive(:request).and_return response
225
+ RPXNow.user_data('')[:id].should == 'dbalatero'
226
+ end
227
+
228
+ it "hands JSON response to supplied block" do
229
+ RPXNow::Api.should_receive(:request).and_return @response
230
+ response = nil
231
+ RPXNow.user_data(''){|data| response = data}
232
+ response.delete('stat') # dunno why it happens, but is not important...
233
+ response.should == @response_body
234
+ end
235
+
236
+ it "returns what the supplied block returned" do
237
+ RPXNow::Api.should_receive(:request).and_return @response
238
+ RPXNow.user_data(''){|data| "x"}.should == 'x'
239
+ end
240
+
241
+ it "can send additional parameters" do
242
+ RPXNow::Api.should_receive(:request).
243
+ with(anything, hash_including(:extended => 'true')).
244
+ and_return @response
245
+ RPXNow.user_data('',:extended=>'true')
246
+ end
247
+
248
+ # these 2 tests are kind of duplicates of the api_version/key tests,
249
+ # but i want to be extra-sure user_data works
250
+ it "works with api version as option" do
251
+ RPXNow::Api.should_receive(:request).
252
+ with('/api/v123/auth_info', anything).
253
+ and_return @response
254
+ RPXNow.user_data('id', :extended=>'abc', :api_version=>123)
255
+ RPXNow.api_version.should == API_VERSION
256
+ end
257
+
258
+ it "works with apiKey as option" do
259
+ RPXNow::Api.should_receive(:request).
260
+ with('/api/v2/auth_info', hash_including(:apiKey=>'THE KEY')).
261
+ and_return @response
262
+ RPXNow.user_data('id', :extended=>'abc', :apiKey=>'THE KEY')
263
+ RPXNow.api_key.should == API_KEY
264
+ end
265
+ end
266
+
267
+ describe :set_status do
268
+ it "sets the status" do
269
+ RPXNow::Api.should_receive(:request).
270
+ with("/api/v2/set_status", :identifier=>"identifier", :status=>"Chillen...", :apiKey=>API_KEY).
271
+ and_return fake_response
272
+ RPXNow.set_status('identifier', 'Chillen...')
273
+ end
274
+ end
275
+
276
+ describe :read_user_data_from_response do
277
+ it "reads secondary names" do
278
+ RPXNow.send(:parse_user_data,{'profile'=>{'preferredUsername'=>'1'}})[:name].should == '1'
279
+ end
280
+
281
+ it "parses email when no name is found" do
282
+ RPXNow.send(:parse_user_data,{'profile'=>{'email'=>'1@xxx.com'}})[:name].should == '1'
283
+ end
284
+ end
285
+
286
+ describe :contacts do
287
+ it "finds all contacts" do
288
+ response = fake_response(JSON.parse(File.read('spec/fixtures/get_contacts_response.json')))
289
+ RPXNow::Api.should_receive(:request).
290
+ with('/api/v2/get_contacts',:identifier=>'xx', :apiKey=>API_KEY).
291
+ and_return response
292
+ RPXNow.contacts('xx').size.should == 5
293
+ end
294
+ end
295
+
296
+ describe :mappings do
297
+ it "shows all mappings" do
298
+ RPXNow::Api.should_receive(:request).
299
+ with("/api/v2/mappings", :apiKey=>API_KEY, :primaryKey=>1).
300
+ and_return fake_response("identifiers" => ["http://test.myopenid.com/"])
301
+ RPXNow.mappings(1).should == ["http://test.myopenid.com/"]
302
+ end
303
+ end
304
+
305
+ describe :map do
306
+ it "maps a identifier" do
307
+ RPXNow::Api.should_receive(:request).
308
+ with("/api/v2/map", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
309
+ and_return fake_response
310
+ RPXNow.map('http://test.myopenid.com',1)
311
+ end
312
+ end
313
+
314
+ describe :unmap do
315
+ it "unmaps a indentifier" do
316
+ RPXNow::Api.should_receive(:request).
317
+ with("/api/v2/unmap", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
318
+ and_return fake_response
319
+ RPXNow.unmap('http://test.myopenid.com', 1)
320
+ end
321
+ end
322
+
323
+ it "has a VERSION" do
324
+ RPXNow::VERSION.should =~ /^\d+\.\d+\.\d+$/
325
+ end
326
+ end
@@ -0,0 +1,18 @@
1
+ # ---- requirements
2
+ require 'rubygems'
3
+ require 'spec'
4
+
5
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
6
+
7
+ # ---- setup environment/plugin
8
+ require File.expand_path("../init", File.dirname(__FILE__))
9
+ API_KEY = '4b339169026742245b754fa338b9b0aebbd0a733'
10
+ API_VERSION = RPXNow.api_version
11
+
12
+ # ---- rspec
13
+ Spec::Runner.configure do |config|
14
+ config.before :each do
15
+ RPXNow.api_key = API_KEY
16
+ RPXNow.api_version = API_VERSION
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spyou_rpx_now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.6
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ - Nicolas Alpi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-12 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ description:
27
+ email: nicolas.alpi@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - CHANGELOG
37
+ - MIGRATION
38
+ - README.markdown
39
+ - Rakefile
40
+ - VERSION
41
+ - certs/ssl_cert.pem
42
+ - init.rb
43
+ - lib/rpx_now.rb
44
+ - lib/rpx_now/api.rb
45
+ - lib/rpx_now/contacts_collection.rb
46
+ - lib/rpx_now/user_integration.rb
47
+ - lib/rpx_now/user_proxy.rb
48
+ - rdoc/README.rdoc
49
+ - spec/fixtures/get_contacts_response.json
50
+ - spec/integration/mapping_spec.rb
51
+ - spec/rpx_now/api_spec.rb
52
+ - spec/rpx_now/contacts_collection_spec.rb
53
+ - spec/rpx_now/user_proxy_spec.rb
54
+ - spec/rpx_now_spec.rb
55
+ - spec/spec_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/grosser/rpx_now
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: rpx-now
80
+ rubygems_version: 1.3.4
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Helper to simplify RPX Now user login/creation
84
+ test_files:
85
+ - spec/rpx_now/api_spec.rb
86
+ - spec/rpx_now/user_proxy_spec.rb
87
+ - spec/rpx_now/contacts_collection_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/integration/mapping_spec.rb
90
+ - spec/rpx_now_spec.rb