openstax_accounts 7.4.0 → 7.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,52 @@ module OpenStax
29
29
  end
30
30
  end
31
31
 
32
+ context "uuid" do
33
+ it "sets the UUID on the account" do
34
+ result = described_class.handle(request: mock_omniauth_request(uuid: "howdy_ho"))
35
+ expect(result.outputs.account.uuid).to eq "howdy_ho"
36
+ end
37
+ end
38
+
39
+ context "role" do
40
+ it "sets the role on the account" do
41
+ result = described_class.handle(request: mock_omniauth_request(self_reported_role: "instructor"))
42
+ expect(result.outputs.account.role).to eq "instructor"
43
+ end
44
+
45
+ it "deals with unknown role (e.g. if Accounts update but this repo not)" do
46
+ result = described_class.handle(request: mock_omniauth_request(self_reported_role: "howdy_ho"))
47
+ expect(result.outputs.account).to be_unknown_role
48
+ end
49
+ end
50
+
51
+ context "user exists" do
52
+ it "updates the user's data" do
53
+ existing_account = FactoryGirl.create :openstax_accounts_account
54
+ result = described_class.handle(
55
+ request: mock_omniauth_request(
56
+ uid: existing_account.openstax_uid,
57
+ first_name: "1234",
58
+ last_name: "5678",
59
+ title: "900",
60
+ nickname: "191919",
61
+ faculty_status: "confirmed_faculty",
62
+ uuid: "yoyoma",
63
+ self_reported_role: "instructor")
64
+ )
65
+
66
+ account = result.outputs.account.reload
67
+ expect(account.id).to eq existing_account.id
68
+ expect(account.first_name).to eq "1234"
69
+ expect(account.last_name).to eq "5678"
70
+ expect(account.title).to eq "900"
71
+ expect(account.username).to eq "191919"
72
+ expect(account).to be_confirmed_faculty
73
+ expect(account.uuid).to eq "yoyoma"
74
+ expect(account).to be_instructor
75
+ end
76
+ end
77
+
32
78
  end
33
79
 
34
80
  end
@@ -43,17 +43,20 @@ RSpec.configure do |config|
43
43
  end
44
44
 
45
45
 
46
- def mock_omniauth_request(uid: nil, first_name: nil, last_name: nil, title: nil, nickname: nil, faculty_status: nil)
46
+ def mock_omniauth_request(uid: nil, first_name: nil, last_name: nil, title: nil,
47
+ nickname: nil, faculty_status: nil, uuid: nil, self_reported_role: nil)
47
48
  extra_hash = {
48
49
  'raw_info' => {
49
- 'faculty_status' => faculty_status
50
+ 'faculty_status' => faculty_status,
51
+ 'uuid' => uuid,
52
+ 'self_reported_role' => self_reported_role
50
53
  }
51
54
  }
52
55
 
53
56
  OpenStruct.new(
54
57
  env: {
55
58
  'omniauth.auth' => OpenStruct.new({
56
- uid: uid || SecureRandom.hex(4),
59
+ uid: uid || SecureRandom.random_number(10000000),
57
60
  provider: "openstax",
58
61
  info: OpenStruct.new({
59
62
  nickname: nickname || "",
@@ -87,3 +90,11 @@ def with_stubbing(value)
87
90
  OpenStax::Accounts.configuration.enable_stubbing = original
88
91
  end
89
92
  end
93
+
94
+ def silence_omniauth
95
+ previous_logger = OmniAuth.config.logger
96
+ OmniAuth.config.logger = Logger.new("/dev/null")
97
+ yield
98
+ ensure
99
+ OmniAuth.config.logger = previous_logger
100
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.0
4
+ version: 7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails