cul_omniauth 0.4.2 → 0.4.3
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.
- checksums.yaml +4 -4
- data/Rakefile +18 -25
- data/app/controllers/concerns/cul/omniauth/authorizing_controller.rb +2 -2
- data/config/locales/cul_omniauth.en.yml +5 -0
- data/lib/cul/omniauth/version.rb +1 -1
- data/lib/omni_auth/strategies/saml/logout_request.rb +8 -0
- data/lib/tasks/cul_omniauth_tasks.rake +33 -0
- data/spec/cul_omniauth_spec.rb +22 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/roles.yml +4 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +124 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/integration/navigation_spec.rb +4 -0
- data/spec/lib/cul/omniauth/abilities_spec.rb +166 -0
- data/spec/lib/cul/omniauth/callbacks_spec.rb +77 -0
- data/spec/lib/cul/omniauth/remote_ip_ability_spec.rb +43 -0
- data/spec/lib/cul/omniauth/users_spec.rb +46 -0
- data/spec/lib/omni_auth/strategies/saml/service_ticket_validator_spec.rb +53 -0
- data/spec/lib/omni_auth/strategies/wind/service_ticket_validator_spec.rb +36 -0
- data/spec/spec_helper.rb +60 -0
- metadata +96 -3
|
File without changes
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cul::Omniauth::Abilities do
|
|
4
|
+
let(:request) {
|
|
5
|
+
DummyRequest.new
|
|
6
|
+
}
|
|
7
|
+
let(:role_config) {
|
|
8
|
+
Hash.new
|
|
9
|
+
}
|
|
10
|
+
let(:rig_class) {
|
|
11
|
+
c = Class.new
|
|
12
|
+
c.class_eval do
|
|
13
|
+
include Cul::Omniauth::RemoteIpAbility
|
|
14
|
+
end
|
|
15
|
+
c
|
|
16
|
+
}
|
|
17
|
+
let(:current_user) { User.new }
|
|
18
|
+
let(:proxy) { Cul::Omniauth::AbilityProxy.new }
|
|
19
|
+
let(:rig) {
|
|
20
|
+
rig = rig_class.new
|
|
21
|
+
allow(rig).to receive(:request) { request }
|
|
22
|
+
allow(rig).to receive(:current_user) { current_user }
|
|
23
|
+
allow(rig).to receive(:session) { Hash.new }
|
|
24
|
+
rig
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
subject do
|
|
28
|
+
rig.current_ability
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when no valid session, role or id" do
|
|
32
|
+
before do
|
|
33
|
+
Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
|
|
34
|
+
rig.instance_variable_set :@current_ability, nil
|
|
35
|
+
end
|
|
36
|
+
after do
|
|
37
|
+
Ability.instance_variable_set :@role_proxy_config, nil
|
|
38
|
+
end
|
|
39
|
+
let(:rules) do
|
|
40
|
+
YAML.load(fixture('test/role_config/and.yml').read)['_all_environments']
|
|
41
|
+
end
|
|
42
|
+
it do
|
|
43
|
+
expect(subject.can? :download, proxy).not_to be
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "when user has a valid role" do
|
|
48
|
+
before do
|
|
49
|
+
Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
|
|
50
|
+
rig.instance_variable_set :@current_ability, nil
|
|
51
|
+
end
|
|
52
|
+
after do
|
|
53
|
+
Ability.instance_variable_set :@role_proxy_config, nil
|
|
54
|
+
end
|
|
55
|
+
let(:rules) do
|
|
56
|
+
YAML.load(fixture('test/role_config/and.yml').read)['_all_environments']
|
|
57
|
+
end
|
|
58
|
+
context "in a session" do
|
|
59
|
+
before do
|
|
60
|
+
allow(rig).to receive(:session) { {'devise.roles' => [:'downloaders']} }
|
|
61
|
+
end
|
|
62
|
+
it do
|
|
63
|
+
expect(subject.can? :download, proxy).to be
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
context "in a user" do
|
|
67
|
+
it do
|
|
68
|
+
#allow(current_user).to receive(:role?).and_return(false)
|
|
69
|
+
allow(current_user).to receive(:role?).with(:*).and_return(true)
|
|
70
|
+
allow(current_user).to receive(:role?).with(:downloaders).and_return(true)
|
|
71
|
+
expect(subject.can? :download, proxy).to be
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "when combining with and" do
|
|
77
|
+
let(:rules) do
|
|
78
|
+
YAML.load(fixture('test/role_config/and.yml').read)['_all_environments']
|
|
79
|
+
end
|
|
80
|
+
before do
|
|
81
|
+
Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
|
|
82
|
+
rig.instance_variable_set :@current_ability, nil
|
|
83
|
+
end
|
|
84
|
+
after do
|
|
85
|
+
Ability.instance_variable_set :@role_proxy_config, nil
|
|
86
|
+
end
|
|
87
|
+
context "when the IP is on the approved list and login is right" do
|
|
88
|
+
before do
|
|
89
|
+
allow(current_user).to receive(:uid).and_return('test_user')
|
|
90
|
+
request.remote_ip = '255.255.255.255'
|
|
91
|
+
end
|
|
92
|
+
it do
|
|
93
|
+
expect(subject.can? :download, proxy).to be
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
context "when the IP is not on the approved list" do
|
|
97
|
+
before do
|
|
98
|
+
allow(current_user).to receive(:uid).and_return('test_user')
|
|
99
|
+
request.remote_ip = '255.255.255.1'
|
|
100
|
+
end
|
|
101
|
+
it do
|
|
102
|
+
expect(subject.can? :download, proxy).not_to be
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
context "when login is wrong" do
|
|
106
|
+
before do
|
|
107
|
+
allow(current_user).to receive(:uid).and_return('wrong_user')
|
|
108
|
+
request.remote_ip = '255.255.255.255'
|
|
109
|
+
end
|
|
110
|
+
it do
|
|
111
|
+
expect(subject.can? :download, proxy).not_to be
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
context "when combining with or" do
|
|
116
|
+
let(:rules) do
|
|
117
|
+
YAML.load(fixture('test/role_config/or.yml').read)['_all_environments']
|
|
118
|
+
end
|
|
119
|
+
before do
|
|
120
|
+
Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
|
|
121
|
+
rig.instance_variable_set :@current_ability, nil
|
|
122
|
+
end
|
|
123
|
+
after do
|
|
124
|
+
Ability.instance_variable_set :@role_proxy_config, nil
|
|
125
|
+
end
|
|
126
|
+
subject do
|
|
127
|
+
rig.current_ability
|
|
128
|
+
end
|
|
129
|
+
context "when the IP is on the approved list and login is right" do
|
|
130
|
+
before do
|
|
131
|
+
allow(current_user).to receive(:uid).and_return('test_user')
|
|
132
|
+
request.remote_ip = '255.255.255.255'
|
|
133
|
+
end
|
|
134
|
+
it do
|
|
135
|
+
expect(subject.can? :download, proxy).to be
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
context "when neither IP or login is approved" do
|
|
139
|
+
before do
|
|
140
|
+
allow(current_user).to receive(:uid).and_return('wrong_user')
|
|
141
|
+
request.remote_ip = '255.255.255.1'
|
|
142
|
+
end
|
|
143
|
+
it do
|
|
144
|
+
expect(subject.can? :download, proxy).not_to be
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
context "when the IP is not on the approved list" do
|
|
148
|
+
before do
|
|
149
|
+
allow(current_user).to receive(:uid).and_return('test_user')
|
|
150
|
+
request.remote_ip = '255.255.255.1'
|
|
151
|
+
end
|
|
152
|
+
it do
|
|
153
|
+
expect(subject.can? :download, proxy).to be
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
context "when login is wrong" do
|
|
157
|
+
before do
|
|
158
|
+
allow(current_user).to receive(:uid).and_return('wrong_user')
|
|
159
|
+
request.remote_ip = '255.255.255.255'
|
|
160
|
+
end
|
|
161
|
+
it do
|
|
162
|
+
expect(subject.can? :download, proxy).to be
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cul::Omniauth::Callbacks do
|
|
4
|
+
let(:oa_response) do
|
|
5
|
+
{}
|
|
6
|
+
end
|
|
7
|
+
let(:request) {
|
|
8
|
+
DummyRequest.new
|
|
9
|
+
}
|
|
10
|
+
let(:role_config) {
|
|
11
|
+
Hash.new
|
|
12
|
+
}
|
|
13
|
+
let(:rig_class) {
|
|
14
|
+
c = Class.new
|
|
15
|
+
c.class_eval do
|
|
16
|
+
attr_accessor :request, :flash, :session
|
|
17
|
+
include Cul::Omniauth::Callbacks
|
|
18
|
+
end
|
|
19
|
+
c
|
|
20
|
+
}
|
|
21
|
+
let(:current_user) { User.new }
|
|
22
|
+
let(:rig) {
|
|
23
|
+
rig = rig_class.new
|
|
24
|
+
rig
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
it do
|
|
28
|
+
is_expected.to be_a Module
|
|
29
|
+
end
|
|
30
|
+
context "is included" do
|
|
31
|
+
subject { rig }
|
|
32
|
+
before do
|
|
33
|
+
rig.instance_variable_set :@current_user, current_user
|
|
34
|
+
rig.request = request
|
|
35
|
+
rig.session = {}
|
|
36
|
+
oa_response['uid'] = 'foo'
|
|
37
|
+
oa_response['extra'] = {}
|
|
38
|
+
request.env = {'omniauth.auth' => oa_response}
|
|
39
|
+
rig.flash = {}
|
|
40
|
+
end
|
|
41
|
+
['SAML', 'CAS', 'WIND'].each do |method|
|
|
42
|
+
context "logging in with #{method}" do
|
|
43
|
+
before do
|
|
44
|
+
allow(oa_response).to receive(:provider).and_return(method)
|
|
45
|
+
end
|
|
46
|
+
it do
|
|
47
|
+
is_expected.to receive(:redirect_to)
|
|
48
|
+
is_expected.to receive(:root_url)
|
|
49
|
+
expect(User).not_to receive("find_for_#{method.downcase}".to_sym)
|
|
50
|
+
subject.send method.downcase.to_sym
|
|
51
|
+
expect(rig.flash[:notice]).to be
|
|
52
|
+
end
|
|
53
|
+
context "user is persisted" do
|
|
54
|
+
before do
|
|
55
|
+
current_user.persisted = true
|
|
56
|
+
end
|
|
57
|
+
it do
|
|
58
|
+
is_expected.to receive(:sign_in_and_redirect)
|
|
59
|
+
subject.send method.downcase.to_sym
|
|
60
|
+
expect(rig.flash[:notice]).to be
|
|
61
|
+
end
|
|
62
|
+
context "no current_user" do
|
|
63
|
+
before do
|
|
64
|
+
rig.instance_variable_set :@current_user, nil
|
|
65
|
+
end
|
|
66
|
+
it do
|
|
67
|
+
is_expected.to receive(:sign_in_and_redirect)
|
|
68
|
+
expect(User).to receive("find_for_#{method.downcase}".to_sym).and_return(current_user)
|
|
69
|
+
subject.send method.downcase.to_sym
|
|
70
|
+
expect(rig.flash[:notice]).to be
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cul::Omniauth::RemoteIpAbility do
|
|
4
|
+
let(:request) {
|
|
5
|
+
DummyRequest.new
|
|
6
|
+
}
|
|
7
|
+
let(:role_config) {
|
|
8
|
+
Hash.new
|
|
9
|
+
}
|
|
10
|
+
let(:rig_class) {
|
|
11
|
+
c = Class.new
|
|
12
|
+
c.class_eval do
|
|
13
|
+
include Cul::Omniauth::RemoteIpAbility
|
|
14
|
+
end
|
|
15
|
+
c
|
|
16
|
+
}
|
|
17
|
+
let(:current_user) { User.new }
|
|
18
|
+
let(:rig) {
|
|
19
|
+
rig = rig_class.new
|
|
20
|
+
allow(rig).to receive(:request) { request }
|
|
21
|
+
allow(rig).to receive(:current_user) { current_user }
|
|
22
|
+
allow(rig).to receive(:session) { Hash.new }
|
|
23
|
+
rig
|
|
24
|
+
}
|
|
25
|
+
before do
|
|
26
|
+
Ability.instance_variable_set :@role_proxy_config, Hash.new
|
|
27
|
+
rig.instance_variable_set :@current_ability, nil
|
|
28
|
+
end
|
|
29
|
+
after do
|
|
30
|
+
Ability.instance_variable_set :@role_proxy_config, nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it do
|
|
34
|
+
is_expected.to be_a Module
|
|
35
|
+
end
|
|
36
|
+
context "is included" do
|
|
37
|
+
subject { request }
|
|
38
|
+
it do
|
|
39
|
+
is_expected.to receive(:remote_ip)
|
|
40
|
+
rig.current_ability
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Cul::Omniauth::Users do
|
|
4
|
+
|
|
5
|
+
it do
|
|
6
|
+
is_expected.to be_a Module
|
|
7
|
+
end
|
|
8
|
+
context "is included" do
|
|
9
|
+
let(:token){ {'uid'=> uid, 'provider'=> provider} }
|
|
10
|
+
let(:uid) { 'foo' }
|
|
11
|
+
let(:provider) { 'lol' }
|
|
12
|
+
subject { User }
|
|
13
|
+
context "token has no uid" do
|
|
14
|
+
before do
|
|
15
|
+
token['uid'] = nil
|
|
16
|
+
end
|
|
17
|
+
it do
|
|
18
|
+
expect(subject.find_for_provider(token, provider)).not_to be
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
context "existing user" do
|
|
22
|
+
let(:users) { [double(User)]}
|
|
23
|
+
it do
|
|
24
|
+
is_expected.to receive(:where).with(uid: uid, provider: provider).and_return(users)
|
|
25
|
+
is_expected.not_to receive(:"create!")
|
|
26
|
+
subject.find_for_provider(token, provider)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
context "new user" do
|
|
30
|
+
let(:users) { []}
|
|
31
|
+
it do
|
|
32
|
+
is_expected.to receive(:where).with(uid: uid, provider: provider).and_return(users)
|
|
33
|
+
is_expected.to receive(:"create!").with(uid: uid, provider: provider).and_return(double(User))
|
|
34
|
+
subject.find_for_provider(token, provider)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
["cas", "saml", "wind"].each do |method|
|
|
38
|
+
context "find with #{method} provider" do
|
|
39
|
+
it do
|
|
40
|
+
is_expected.to receive(:find_for_provider).with(token,method)
|
|
41
|
+
subject.send :"find_for_#{method}", token
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OmniAuth::Strategies::SAML::ServiceTicketValidator do
|
|
4
|
+
it "should be a class" do
|
|
5
|
+
expect(OmniAuth::Strategies::SAML::ServiceTicketValidator).to be_a Class
|
|
6
|
+
end
|
|
7
|
+
describe "success parsing" do
|
|
8
|
+
let(:strategy) do
|
|
9
|
+
mock = double('strategy')
|
|
10
|
+
allow(mock).to receive(:service_validate_url) {'/validate'}
|
|
11
|
+
|
|
12
|
+
mock
|
|
13
|
+
end
|
|
14
|
+
let(:options) do
|
|
15
|
+
{}
|
|
16
|
+
end
|
|
17
|
+
let(:return_to_url) do
|
|
18
|
+
'http://test.server/test'
|
|
19
|
+
end
|
|
20
|
+
let(:ticket) do
|
|
21
|
+
SecureRandom.hex(16)
|
|
22
|
+
end
|
|
23
|
+
subject do
|
|
24
|
+
OmniAuth::Strategies::SAML::ServiceTicketValidator.new(strategy, options, return_to_url, ticket)
|
|
25
|
+
end
|
|
26
|
+
it "should generate the ticket envelope" do
|
|
27
|
+
pattern = "<samlp:AssertionArtifact>#{ticket}</samlp:AssertionArtifact>"
|
|
28
|
+
SAML_NS = {
|
|
29
|
+
samla: "urn:oasis:names:tc:SAML:1.0:assertion",
|
|
30
|
+
samlp: "urn:oasis:names:tc:SAML:1.0:protocol",
|
|
31
|
+
}
|
|
32
|
+
actual = Nokogiri::XML(subject.get_service_request_body).xpath('//samlp:AssertionArtifact', SAML_NS).text
|
|
33
|
+
expect(actual).to eql(ticket)
|
|
34
|
+
end
|
|
35
|
+
context "on a successful authentication" do
|
|
36
|
+
before do
|
|
37
|
+
allow(subject).to receive(:get_service_response_body) {
|
|
38
|
+
fixture('test/saml/success_affils.xml') {|io| io.read }
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
it "should find the user id" do
|
|
42
|
+
user_info = subject.call.user_info
|
|
43
|
+
puts user_info.inspect
|
|
44
|
+
expect(user_info['user']).to eql('de3')
|
|
45
|
+
end
|
|
46
|
+
it "should find the affils" do
|
|
47
|
+
user_info = subject.call.user_info
|
|
48
|
+
puts user_info.inspect
|
|
49
|
+
expect(user_info['affiliations'].size).to eql(6)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OmniAuth::Strategies::WIND::ServiceTicketValidator do
|
|
4
|
+
it "should be a class" do
|
|
5
|
+
expect(OmniAuth::Strategies::WIND::ServiceTicketValidator).to be_a Class
|
|
6
|
+
end
|
|
7
|
+
describe "success parsing" do
|
|
8
|
+
let(:strategy) do
|
|
9
|
+
mock = double('strategy')
|
|
10
|
+
allow(mock).to receive(:service_validate_url) {'/validate'}
|
|
11
|
+
|
|
12
|
+
mock
|
|
13
|
+
end
|
|
14
|
+
let(:options) do
|
|
15
|
+
{}
|
|
16
|
+
end
|
|
17
|
+
let(:return_to_url) do
|
|
18
|
+
'http://test.server/test'
|
|
19
|
+
end
|
|
20
|
+
let(:ticket) do
|
|
21
|
+
mock = double('ticket')
|
|
22
|
+
mock
|
|
23
|
+
end
|
|
24
|
+
subject do
|
|
25
|
+
OmniAuth::Strategies::WIND::ServiceTicketValidator.new(strategy, options, return_to_url, ticket)
|
|
26
|
+
end
|
|
27
|
+
it do
|
|
28
|
+
allow(subject).to receive(:get_service_response_body) {
|
|
29
|
+
fixture('test/wind/success_affils.xml') {|io| io.read }
|
|
30
|
+
}
|
|
31
|
+
user_info = subject.call.user_info
|
|
32
|
+
puts user_info.inspect
|
|
33
|
+
expect(user_info[:affiliations].size).to eql(2)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV["RAILS_ENV"] ||= "test"
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
|
|
5
|
+
if ENV['COVERAGE']
|
|
6
|
+
require 'simplecov'
|
|
7
|
+
SimpleCov.command_name "spec"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require File.expand_path("../../spec/dummy/config/environment.rb", __FILE__)
|
|
11
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../spec/dummy/db/migrate", __FILE__)]
|
|
12
|
+
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
|
13
|
+
|
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
15
|
+
|
|
16
|
+
# Load support files
|
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
18
|
+
|
|
19
|
+
$:.unshift File.join('..','spec','lib')
|
|
20
|
+
$:.unshift File.join('..','app','models','concerns')
|
|
21
|
+
|
|
22
|
+
require 'cancan'
|
|
23
|
+
require 'cul/omniauth/users'
|
|
24
|
+
require 'cul/omniauth/abilities'
|
|
25
|
+
|
|
26
|
+
# Load fixtures from the engine
|
|
27
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
|
28
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fixture(filename, mode="r")
|
|
32
|
+
path = File.join(File.dirname(__FILE__),'..','fixtures',filename)
|
|
33
|
+
if block_given?
|
|
34
|
+
open(path, mode) {|io| yield io}
|
|
35
|
+
else
|
|
36
|
+
open(path, mode)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def symbolize_hash_keys(hash)
|
|
41
|
+
hash.symbolize_keys!
|
|
42
|
+
hash.values.select{|v| v.is_a? Hash}.each{|h| symbolize_hash_keys(h)}
|
|
43
|
+
hash
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class DummyRequest
|
|
47
|
+
attr_accessor :remote_ip
|
|
48
|
+
attr_accessor :env
|
|
49
|
+
end
|
|
50
|
+
class Ability
|
|
51
|
+
include CanCan::Ability
|
|
52
|
+
include Cul::Omniauth::Abilities
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class User
|
|
56
|
+
attr_accessor :uid, :persisted
|
|
57
|
+
def self.devise(*args); end
|
|
58
|
+
def persisted?; persisted; end
|
|
59
|
+
include Cul::Omniauth::Users
|
|
60
|
+
end
|