orcid 0.1.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -1
  3. data/CONTRIBUTING.md +213 -0
  4. data/README.md +2 -5
  5. data/app/controllers/orcid/profile_requests_controller.rb +11 -1
  6. data/app/models/orcid/profile_connection.rb +12 -2
  7. data/app/models/orcid/profile_status.rb +67 -0
  8. data/app/services/orcid/remote/profile_creation_service.rb +15 -0
  9. data/app/services/orcid/remote/profile_query_service/response_parser.rb +53 -0
  10. data/app/services/orcid/remote/profile_query_service.rb +4 -23
  11. data/app/views/orcid/profile_connections/_authenticated_connection.html.erb +5 -0
  12. data/app/views/orcid/profile_connections/_options_to_connect_orcid_profile.html.erb +20 -0
  13. data/app/views/orcid/profile_connections/_orcid_connector.html.erb +15 -18
  14. data/app/views/orcid/profile_connections/_pending_connection.html.erb +11 -0
  15. data/app/views/orcid/profile_connections/_profile_request_pending.html.erb +5 -0
  16. data/config/locales/orcid.en.yml +1 -1
  17. data/lib/orcid/configuration/provider.rb +8 -0
  18. data/lib/orcid/version.rb +1 -1
  19. data/lib/orcid.rb +4 -0
  20. data/spec/controllers/orcid/profile_requests_controller_spec.rb +21 -9
  21. data/spec/features/public_api_query_spec.rb +6 -0
  22. data/spec/fixtures/orcid-remote-profile_query_service-response_parser/multiple-responses-without-valid-response.json +258 -0
  23. data/spec/fixtures/orcid-remote-profile_query_service-response_parser/single-response-with-orcid-valid-profile.json +71 -0
  24. data/spec/lib/orcid/configuration/provider_spec.rb +3 -0
  25. data/spec/lib/orcid_spec.rb +8 -0
  26. data/spec/models/orcid/profile_connection_spec.rb +39 -17
  27. data/spec/models/orcid/profile_status_spec.rb +73 -0
  28. data/spec/routing/orcid/profile_request_routing_spec.rb +15 -0
  29. data/spec/services/orcid/remote/profile_creation_service_spec.rb +23 -3
  30. data/spec/services/orcid/remote/profile_query_service/response_parser_spec.rb +43 -0
  31. data/spec/services/orcid/remote/profile_query_service_spec.rb +7 -89
  32. data/spec/views/orcid/profile_connections/_authenticated_connection.html.erb_spec.rb +20 -0
  33. data/spec/views/orcid/profile_connections/_options_to_connect_orcid_profile.html.erb_spec.rb +26 -0
  34. data/spec/views/orcid/profile_connections/_orcid_connector.html.erb_spec.rb +65 -0
  35. data/spec/views/orcid/profile_connections/_pending_connection.html.erb_spec.rb +22 -0
  36. data/spec/views/orcid/profile_connections/_profile_request_pending.html.erb_spec.rb +24 -0
  37. metadata +29 -2
@@ -4,7 +4,7 @@ module Orcid
4
4
  describe ProfileRequestsController do
5
5
  def self.it_prompts_unauthenticated_users_for_signin(method, action)
6
6
  context 'unauthenticated user' do
7
- it "should redirect for sign in" do
7
+ it 'should redirect for sign in' do
8
8
  send(method, action, use_route: :orcid)
9
9
  expect(response).to redirect_to(main_app.new_user_session_path)
10
10
  end
@@ -15,14 +15,14 @@ module Orcid
15
15
  context 'user has existing orcid_profile' do
16
16
  it 'should redirect to home_path' do
17
17
  sign_in(user)
18
- orcid_profile = double("Orcid::Profile", orcid_profile_id: '1234-5678-0001-0002')
18
+ orcid_profile = double('Orcid::Profile', orcid_profile_id: '1234-5678-0001-0002')
19
19
  Orcid.should_receive(:profile_for).with(user).and_return(orcid_profile)
20
20
 
21
21
  send(method, action, use_route: :orcid)
22
22
 
23
23
  expect(response).to redirect_to(main_app.root_path)
24
24
  expect(flash[:notice]).to eq(
25
- I18n.t("orcid.requests.messages.previously_connected_profile", orcid_profile_id: orcid_profile.orcid_profile_id)
25
+ I18n.t('orcid.requests.messages.previously_connected_profile', orcid_profile_id: orcid_profile.orcid_profile_id)
26
26
  )
27
27
  end
28
28
  end
@@ -39,7 +39,7 @@ module Orcid
39
39
  context 'authenticated and authorized user' do
40
40
  before { sign_in(user) }
41
41
  let(:profile_request_id) { '1234' }
42
- let(:profile_request) { FactoryGirl.build_stubbed(:orcid_profile_request, user: user)}
42
+ let(:profile_request) { FactoryGirl.build_stubbed(:orcid_profile_request, user: user) }
43
43
 
44
44
  it 'should render the existing profile request' do
45
45
  Orcid::ProfileRequest.should_receive(:find_by_user).
@@ -58,7 +58,7 @@ module Orcid
58
58
 
59
59
  get :show, use_route: :orcid
60
60
 
61
- expect(flash[:notice]).to eq(I18n.t("orcid.requests.messages.existing_request_not_found"))
61
+ expect(flash[:notice]).to eq(I18n.t('orcid.requests.messages.existing_request_not_found'))
62
62
  expect(response).to redirect_to(orcid.new_profile_request_path)
63
63
  end
64
64
  end
@@ -82,7 +82,7 @@ module Orcid
82
82
  it 'should guard against duplicate requests' do
83
83
  Orcid::ProfileRequest.should_receive(:find_by_user).with(user).and_return(Orcid::ProfileRequest.new)
84
84
  get :new, use_route: :orcid
85
- expect(flash[:notice]).to eq(I18n.t("orcid.requests.messages.existing_request"))
85
+ expect(flash[:notice]).to eq(I18n.t('orcid.requests.messages.existing_request'))
86
86
  expect(response).to redirect_to(orcid.profile_request_path)
87
87
  end
88
88
  end
@@ -98,15 +98,27 @@ module Orcid
98
98
  Orcid::ProfileRequest.should_receive(:find_by_user).with(user).and_return(nil)
99
99
  Orcid.should_receive(:enqueue).with(an_instance_of(Orcid::ProfileRequest))
100
100
 
101
- post :create, profile_request: profile_request_attributes, use_route: :orcid
102
- expect(response).to be_redirect
101
+ expect do
102
+ post :create, profile_request: profile_request_attributes, use_route: :orcid
103
+ end.to change { Orcid::ProfileRequest.count }.by(1)
104
+ expect(response).to redirect_to(orcid.profile_request_path)
105
+ end
106
+
107
+ it 'should handle invalid data' do
108
+ Orcid::ProfileRequest.should_receive(:find_by_user).with(user).and_return(nil)
109
+ Orcid.should_not_receive(:enqueue)
110
+
111
+ expect do
112
+ post :create, profile_request: {}, use_route: :orcid
113
+ end.to change { Orcid::ProfileRequest.count }.by(0)
114
+ expect(response).to render_template('new')
103
115
  end
104
116
 
105
117
  it 'should guard against duplicate requests' do
106
118
  Orcid::ProfileRequest.should_receive(:find_by_user).with(user).and_return(Orcid::ProfileRequest.new)
107
119
  post :create, profile_request: profile_request_attributes, use_route: :orcid
108
120
 
109
- expect(flash[:notice]).to eq(I18n.t("orcid.requests.messages.existing_request"))
121
+ expect(flash[:notice]).to eq(I18n.t('orcid.requests.messages.existing_request'))
110
122
  expect(response).to redirect_to(orcid.profile_request_path)
111
123
  end
112
124
 
@@ -28,6 +28,12 @@ describe 'public api query', requires_net_connect: true do
28
28
  Then { expect(result.size).to be > 0 }
29
29
  end
30
30
 
31
+ context 'with bogus text query' do
32
+ Given(:parameters) { { text: 'orcid@sufia.org' } }
33
+ When(:result) { runner.call(parameters) }
34
+ Then { expect(result.size).to eq 0 }
35
+ end
36
+
31
37
  context 'with a compound text query' do
32
38
  Given(:parameters) { { email: "nobody@gmail.com", text: '"Jeremy+Friesen"' } }
33
39
  When(:result) { runner.call(parameters) }
@@ -0,0 +1,258 @@
1
+ {
2
+ "message-version": "1.1",
3
+ "orcid-search-results": {
4
+ "orcid-search-result": [
5
+ {
6
+ "relevancy-score": {
7
+ "value": 0.016482107
8
+ },
9
+ "orcid-profile": {
10
+ "orcid": null,
11
+ "orcid-bio": {
12
+ "personal-details": {
13
+ "given-names": {
14
+ "value": "Reserved For Claim"
15
+ }
16
+ },
17
+ "keywords": null,
18
+ "delegation": null,
19
+ "applications": null,
20
+ "scope": null
21
+ },
22
+ "orcid-activities": {
23
+ "affiliations": null
24
+ },
25
+ "type": null,
26
+ "group-type": null,
27
+ "client-type": null
28
+ }
29
+ },
30
+ {
31
+ "relevancy-score": {
32
+ "value": 0.016482107
33
+ },
34
+ "orcid-profile": {
35
+ "orcid": null,
36
+ "orcid-bio": {
37
+ "personal-details": {
38
+ "given-names": {
39
+ "value": "Reserved For Claim"
40
+ }
41
+ },
42
+ "keywords": null,
43
+ "delegation": null,
44
+ "applications": null,
45
+ "scope": null
46
+ },
47
+ "orcid-activities": {
48
+ "affiliations": null
49
+ },
50
+ "type": null,
51
+ "group-type": null,
52
+ "client-type": null
53
+ }
54
+ },
55
+ {
56
+ "relevancy-score": {
57
+ "value": 0.016482107
58
+ },
59
+ "orcid-profile": {
60
+ "orcid": null,
61
+ "orcid-bio": {
62
+ "personal-details": {
63
+ "given-names": {
64
+ "value": "Reserved For Claim"
65
+ }
66
+ },
67
+ "keywords": null,
68
+ "delegation": null,
69
+ "applications": null,
70
+ "scope": null
71
+ },
72
+ "orcid-activities": {
73
+ "affiliations": null
74
+ },
75
+ "type": null,
76
+ "group-type": null,
77
+ "client-type": null
78
+ }
79
+ },
80
+ {
81
+ "relevancy-score": {
82
+ "value": 0.016482107
83
+ },
84
+ "orcid-profile": {
85
+ "orcid": null,
86
+ "orcid-bio": {
87
+ "personal-details": {
88
+ "given-names": {
89
+ "value": "Reserved For Claim"
90
+ }
91
+ },
92
+ "keywords": null,
93
+ "delegation": null,
94
+ "applications": null,
95
+ "scope": null
96
+ },
97
+ "orcid-activities": {
98
+ "affiliations": null
99
+ },
100
+ "type": null,
101
+ "group-type": null,
102
+ "client-type": null
103
+ }
104
+ },
105
+ {
106
+ "relevancy-score": {
107
+ "value": 0.016482107
108
+ },
109
+ "orcid-profile": {
110
+ "orcid": null,
111
+ "orcid-bio": {
112
+ "personal-details": {
113
+ "given-names": {
114
+ "value": "Reserved For Claim"
115
+ }
116
+ },
117
+ "keywords": null,
118
+ "delegation": null,
119
+ "applications": null,
120
+ "scope": null
121
+ },
122
+ "orcid-activities": {
123
+ "affiliations": null
124
+ },
125
+ "type": null,
126
+ "group-type": null,
127
+ "client-type": null
128
+ }
129
+ },
130
+ {
131
+ "relevancy-score": {
132
+ "value": 0.016482107
133
+ },
134
+ "orcid-profile": {
135
+ "orcid": null,
136
+ "orcid-bio": {
137
+ "personal-details": {
138
+ "given-names": {
139
+ "value": "Reserved For Claim"
140
+ }
141
+ },
142
+ "keywords": null,
143
+ "delegation": null,
144
+ "applications": null,
145
+ "scope": null
146
+ },
147
+ "orcid-activities": {
148
+ "affiliations": null
149
+ },
150
+ "type": null,
151
+ "group-type": null,
152
+ "client-type": null
153
+ }
154
+ },
155
+ {
156
+ "relevancy-score": {
157
+ "value": 0.016482107
158
+ },
159
+ "orcid-profile": {
160
+ "orcid": null,
161
+ "orcid-bio": {
162
+ "personal-details": {
163
+ "given-names": {
164
+ "value": "Reserved For Claim"
165
+ }
166
+ },
167
+ "keywords": null,
168
+ "delegation": null,
169
+ "applications": null,
170
+ "scope": null
171
+ },
172
+ "orcid-activities": {
173
+ "affiliations": null
174
+ },
175
+ "type": null,
176
+ "group-type": null,
177
+ "client-type": null
178
+ }
179
+ },
180
+ {
181
+ "relevancy-score": {
182
+ "value": 0.016482107
183
+ },
184
+ "orcid-profile": {
185
+ "orcid": null,
186
+ "orcid-bio": {
187
+ "personal-details": {
188
+ "given-names": {
189
+ "value": "Reserved For Claim"
190
+ }
191
+ },
192
+ "keywords": null,
193
+ "delegation": null,
194
+ "applications": null,
195
+ "scope": null
196
+ },
197
+ "orcid-activities": {
198
+ "affiliations": null
199
+ },
200
+ "type": null,
201
+ "group-type": null,
202
+ "client-type": null
203
+ }
204
+ },
205
+ {
206
+ "relevancy-score": {
207
+ "value": 0.016482107
208
+ },
209
+ "orcid-profile": {
210
+ "orcid": null,
211
+ "orcid-bio": {
212
+ "personal-details": {
213
+ "given-names": {
214
+ "value": "Reserved For Claim"
215
+ }
216
+ },
217
+ "keywords": null,
218
+ "delegation": null,
219
+ "applications": null,
220
+ "scope": null
221
+ },
222
+ "orcid-activities": {
223
+ "affiliations": null
224
+ },
225
+ "type": null,
226
+ "group-type": null,
227
+ "client-type": null
228
+ }
229
+ },
230
+ {
231
+ "relevancy-score": {
232
+ "value": 0.016482107
233
+ },
234
+ "orcid-profile": {
235
+ "orcid": null,
236
+ "orcid-bio": {
237
+ "personal-details": {
238
+ "given-names": {
239
+ "value": "Reserved For Claim"
240
+ }
241
+ },
242
+ "keywords": null,
243
+ "delegation": null,
244
+ "applications": null,
245
+ "scope": null
246
+ },
247
+ "orcid-activities": {
248
+ "affiliations": null
249
+ },
250
+ "type": null,
251
+ "group-type": null,
252
+ "client-type": null
253
+ }
254
+ }
255
+ ],
256
+ "num-found": 0
257
+ }
258
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "message-version": "1.1",
3
+ "orcid-search-results": {
4
+ "orcid-search-result": [
5
+ {
6
+ "relevancy-score": {
7
+ "value": 14.298138
8
+ },
9
+ "orcid-profile": {
10
+ "orcid": null,
11
+ "orcid-identifier": {
12
+ "value": null,
13
+ "uri": "http://orcid.org/MY-ORCID-PROFILE-ID",
14
+ "path": "MY-ORCID-PROFILE-ID",
15
+ "host": "orcid.org"
16
+ },
17
+ "orcid-bio": {
18
+ "personal-details": {
19
+ "given-names": {
20
+ "value": "Corwin"
21
+ },
22
+ "family-name": {
23
+ "value": "Amber"
24
+ }
25
+ },
26
+ "biography": {
27
+ "value": "MY-ORCID-BIOGRAPHY",
28
+ "visibility": null
29
+ },
30
+ "contact-details": {
31
+ "email": [
32
+ {
33
+ "value": "MY-ORCID-EMAIL",
34
+ "primary": true,
35
+ "current": true,
36
+ "verified": true,
37
+ "visibility": null,
38
+ "source": null
39
+ }
40
+ ],
41
+ "address": {
42
+ "country": {
43
+ "value": "US",
44
+ "visibility": null
45
+ }
46
+ }
47
+ },
48
+ "keywords": {
49
+ "keyword": [
50
+ {
51
+ "value": "Lord of Amber"
52
+ }
53
+ ],
54
+ "visibility": null
55
+ },
56
+ "delegation": null,
57
+ "applications": null,
58
+ "scope": null
59
+ },
60
+ "orcid-activities": {
61
+ "affiliations": null
62
+ },
63
+ "type": null,
64
+ "group-type": null,
65
+ "client-type": null
66
+ }
67
+ }
68
+ ],
69
+ "num-found": 1
70
+ }
71
+ }
@@ -13,6 +13,7 @@ module Orcid
13
13
  'ORCID_AUTHORIZE_URL' => '_AUTHORIZE_URL',
14
14
  'ORCID_APP_ID' => '_APP_ID',
15
15
  'ORCID_APP_SECRET' => '_APP_SECRET',
16
+ 'ORCID_HOST_URL' => '_HOST_URL',
16
17
  }
17
18
  }
18
19
 
@@ -22,6 +23,7 @@ module Orcid
22
23
  its(:site_url) { should eq storage.fetch('ORCID_SITE_URL') }
23
24
  its(:token_url) { should eq storage.fetch('ORCID_TOKEN_URL') }
24
25
  its(:signin_via_json_url) { should eq storage.fetch('ORCID_REMOTE_SIGNIN_URL') }
26
+ its(:host_url) { should eq storage.fetch('ORCID_HOST_URL') }
25
27
  its(:authorize_url) { should eq storage.fetch('ORCID_AUTHORIZE_URL') }
26
28
  its(:id) { should eq storage.fetch('ORCID_APP_ID') }
27
29
  its(:secret) { should eq storage.fetch('ORCID_APP_SECRET') }
@@ -32,6 +34,7 @@ module Orcid
32
34
  And { expect(provider.site_url).to be_an_instance_of(String) }
33
35
  And { expect(provider.token_url).to be_an_instance_of(String) }
34
36
  And { expect(provider.signin_via_json_url).to be_an_instance_of(String) }
37
+ And { expect(provider.host_url).to be_an_instance_of(String) }
35
38
  And { expect(provider.authorize_url).to be_an_instance_of(String) }
36
39
  And { expect { provider.id }.to raise_error Orcid::ConfigurationError }
37
40
  And { expect { provider.secret }.to raise_error Orcid::ConfigurationError }
@@ -85,6 +85,14 @@ describe Orcid do
85
85
  end
86
86
  end
87
87
 
88
+ context '.url_for_orcid_id' do
89
+ it 'should render a valid uri' do
90
+ profile_id = '123-456'
91
+ uri = URI.parse(Orcid.url_for_orcid_id(profile_id))
92
+ expect(uri.path).to eq('/123-456')
93
+ end
94
+ end
95
+
88
96
  =begin
89
97
  context '#authenticated_orcid' do
90
98
  it 'should be authenticated' do
@@ -1,16 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # :nodoc:
3
4
  module Orcid
4
5
  describe ProfileConnection do
5
- let(:email) { 'test@hello.com'}
6
+ let(:email) { 'test@hello.com' }
7
+ let(:dois) { '123' }
6
8
  let(:user) { FactoryGirl.build_stubbed(:user) }
7
- let(:profile_query_service) { double("Profile Lookup Service") }
9
+ let(:profile_query_service) { double('Profile Lookup Service') }
8
10
 
9
- subject {
10
- Orcid::ProfileConnection.new(email: email, user: user).tap { |pc|
11
+ subject do
12
+ Orcid::ProfileConnection.new(email: email, user: user).tap do |pc|
11
13
  pc.profile_query_service = profile_query_service
12
- }
13
- }
14
+ end
15
+ end
14
16
 
15
17
  its(:email) { should eq email }
16
18
  its(:to_model) { should eq subject }
@@ -22,11 +24,20 @@ module Orcid
22
24
  subject { Orcid::ProfileConnection.new.available_query_attribute_names }
23
25
  it { should include(:email) }
24
26
  it { should include(:text) }
27
+ it { should include(:digital_object_ids) }
25
28
  end
26
29
 
27
30
  context '#query_attributes' do
28
- subject { Orcid::ProfileConnection.new(email: email, user: user)}
29
- its(:query_attributes) { should eq(email: email, text: nil) }
31
+ subject do
32
+ Orcid::ProfileConnection.new(
33
+ email: email, user: user, digital_object_ids: dois
34
+ )
35
+ end
36
+ its(:query_attributes) do
37
+ should eq(
38
+ 'email' => email, 'text' => nil, 'digital-object-ids' => dois
39
+ )
40
+ end
30
41
  end
31
42
 
32
43
  context '#query_requested?' do
@@ -35,27 +46,30 @@ module Orcid
35
46
  its(:query_requested?) { should eq false }
36
47
  end
37
48
  context 'with attribute set' do
38
- subject { Orcid::ProfileConnection.new(email: email, user: user)}
49
+ subject { Orcid::ProfileConnection.new(email: email, user: user) }
39
50
  its(:query_requested?) { should eq true }
40
51
  end
41
52
  end
42
53
 
43
54
  context '#save' do
44
55
  let(:orcid_profile_id) { '1234-5678' }
45
- let(:persister) { double("Persister") }
56
+ let(:persister) { double('Persister') }
46
57
 
47
58
  it 'should call the persister when valid' do
48
59
  subject.orcid_profile_id = orcid_profile_id
49
- persister.should_receive(:call).with(user, orcid_profile_id).and_return(:persisted)
60
+ persister.should_receive(:call).
61
+ with(user, orcid_profile_id).
62
+ and_return(:persisted)
63
+
50
64
  expect(subject.save(persister: persister)).to eq(:persisted)
51
65
  end
52
66
 
53
67
  it 'should NOT call the persister and add errors when not valid' do
54
68
  subject.user = nil
55
69
  subject.orcid_profile_id = nil
56
- expect {
57
- subject.save(persister: persister)
58
- }.to change { subject.errors.count }.by(2)
70
+
71
+ expect { subject.save(persister: persister) }.
72
+ to change { subject.errors.count }.by(2)
59
73
  end
60
74
  end
61
75
 
@@ -64,8 +78,14 @@ module Orcid
64
78
 
65
79
  it 'should yield the query response' do
66
80
  subject.email = email
67
- profile_query_service.should_receive(:call).with(subject.query_attributes).and_return(:query_response)
68
- expect {|b| subject.with_orcid_profile_candidates(&b) }.to yield_with_args(:query_response)
81
+
82
+ profile_query_service.
83
+ should_receive(:call).
84
+ with(subject.query_attributes).
85
+ and_return(:query_response)
86
+
87
+ expect { |b| subject.with_orcid_profile_candidates(&b) }.
88
+ to yield_with_args(:query_response)
69
89
  end
70
90
  end
71
91
 
@@ -73,7 +93,9 @@ module Orcid
73
93
  it 'should not yield' do
74
94
  subject.email = nil
75
95
  profile_query_service.stub(:call).and_return(:query_response)
76
- expect {|b| subject.with_orcid_profile_candidates(&b) }.to_not yield_control
96
+
97
+ expect { |b| subject.with_orcid_profile_candidates(&b) }.
98
+ to_not yield_control
77
99
  end
78
100
  end
79
101
 
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+ require 'orcid/profile_status'
3
+
4
+ module Orcid
5
+ describe ProfileStatus do
6
+ Given(:user) { nil }
7
+ Given(:profile_finder) { double('ProfileFinder') }
8
+ Given(:request_finder) { double('RequestFinder') }
9
+ Given(:callback) { StubCallback.new }
10
+ Given(:callback_config) do
11
+ callback.configure(
12
+ :unknown,
13
+ :authenticated_connection,
14
+ :pending_connection,
15
+ :profile_request_pending
16
+ )
17
+ end
18
+ Given(:subject) do
19
+ described_class.new(user, profile_finder: profile_finder, request_finder: request_finder, &callback_config)
20
+ end
21
+
22
+ context '.for' do
23
+ Given(:user) { nil }
24
+ When(:response) { described_class.for(user, &callback_config) }
25
+ Then { expect(response).to eq :unknown }
26
+ And { expect(callback.invoked).to eq [:unknown] }
27
+ end
28
+
29
+ context '#status' do
30
+ context 'user is nil' do
31
+ Given(:user) { nil }
32
+ When(:status) { subject.status }
33
+ Then { expect(status).to eq :unknown }
34
+ end
35
+
36
+ context 'user is not nil' do
37
+ Given(:user) { double('User') }
38
+ Given(:profile_finder) { double('ProfileFinder', call: nil) }
39
+ Given(:request_finder) { double('RequestFinder', call: nil) }
40
+ context 'and has a profile' do
41
+ Given(:profile_finder) { double('ProfileFinder', call: profile) }
42
+ context 'that they have remotely authenticated' do
43
+ Given(:profile) { double('Profile', verified_authentication?: true) }
44
+ When(:status) { subject.status }
45
+ Then { expect(status).to eq :authenticated_connection }
46
+ And { expect(callback.invoked).to eq [:authenticated_connection, profile] }
47
+ end
48
+ context 'that they have not remotely authenticated' do
49
+ Given(:profile) { double('Profile', verified_authentication?: false) }
50
+ When(:status) { subject.status }
51
+ Then { expect(status).to eq :pending_connection }
52
+ And { expect(callback.invoked).to eq [:pending_connection, profile] }
53
+ end
54
+ end
55
+
56
+ context 'and does not have a profile' do
57
+ context 'but has submitted a request' do
58
+ Given(:request) { double('ProfileRequest') }
59
+ Given(:request_finder) { double('RequestFinder', call: request) }
60
+ When(:status) { subject.status }
61
+ Then { expect(status).to eq :profile_request_pending }
62
+ And { expect(callback.invoked).to eq [:profile_request_pending, request] }
63
+ end
64
+ context 'user does not have a request' do
65
+ When(:status) { subject.status }
66
+ Then { expect(status).to eq :unknown }
67
+ And { expect(callback.invoked).to eq [:unknown] }
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Routes for Orcid::ProfileRequest' do
4
+ routes { Orcid::Engine.routes }
5
+ let(:persisted_profile) { Orcid::ProfileRequest.new(id: 2) }
6
+ it 'generates a conventional URL' do
7
+ expect(profile_request_path).
8
+ to(eq('/orcid/profile_request'))
9
+ end
10
+
11
+ it 'treats the input profile_request as the :format parameter' do
12
+ expect(profile_request_path(persisted_profile)).
13
+ to(eq("/orcid/profile_request.#{persisted_profile.to_param}"))
14
+ end
15
+ end