refinerycms-authentication-devise 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +89 -0
- data/.travis.yml +15 -0
- data/Gemfile +50 -0
- data/Rakefile +20 -0
- data/app/controllers/refinery/authentication/devise/admin/users_controller.rb +147 -0
- data/app/controllers/refinery/authentication/devise/passwords_controller.rb +58 -0
- data/app/controllers/refinery/authentication/devise/sessions_controller.rb +39 -0
- data/app/controllers/refinery/authentication/devise/users_controller.rb +50 -0
- data/app/decorators/controllers/action_controller_base_decorator.rb +25 -0
- data/app/decorators/controllers/refinery/admin_controller_decorator.rb +20 -0
- data/app/decorators/controllers/refinery/application_controller_decorator.rb +7 -0
- data/app/mailers/refinery/authentication/devise/user_mailer.rb +26 -0
- data/app/models/refinery/authentication/devise/nil_user.rb +31 -0
- data/app/models/refinery/authentication/devise/role.rb +22 -0
- data/app/models/refinery/authentication/devise/roles_users.rb +12 -0
- data/app/models/refinery/authentication/devise/user.rb +166 -0
- data/app/models/refinery/authentication/devise/user_plugin.rb +11 -0
- data/app/views/refinery/authentication/devise/admin/users/_actions.html.erb +7 -0
- data/app/views/refinery/authentication/devise/admin/users/_form.html.erb +94 -0
- data/app/views/refinery/authentication/devise/admin/users/_records.html.erb +10 -0
- data/app/views/refinery/authentication/devise/admin/users/_user.html.erb +23 -0
- data/app/views/refinery/authentication/devise/admin/users/_users.html.erb +4 -0
- data/app/views/refinery/authentication/devise/admin/users/edit.html.erb +1 -0
- data/app/views/refinery/authentication/devise/admin/users/index.html.erb +6 -0
- data/app/views/refinery/authentication/devise/admin/users/new.html.erb +1 -0
- data/app/views/refinery/authentication/devise/passwords/edit.html.erb +26 -0
- data/app/views/refinery/authentication/devise/passwords/new.html.erb +17 -0
- data/app/views/refinery/authentication/devise/sessions/new.html.erb +27 -0
- data/app/views/refinery/authentication/devise/user_mailer/reset_notification.html.erb +12 -0
- data/app/views/refinery/authentication/devise/user_mailer/reset_notification.text.plain.erb +7 -0
- data/app/views/refinery/authentication/devise/users/new.html.erb +29 -0
- data/app/views/refinery/layouts/login.html.erb +22 -0
- data/bin/rails +5 -0
- data/bin/rake +21 -0
- data/bin/rspec +22 -0
- data/bin/spring +18 -0
- data/config/locales/bg.yml +73 -0
- data/config/locales/ca.yml +75 -0
- data/config/locales/cs.yml +77 -0
- data/config/locales/da.yml +73 -0
- data/config/locales/de.yml +73 -0
- data/config/locales/el.yml +73 -0
- data/config/locales/en.yml +77 -0
- data/config/locales/es.yml +73 -0
- data/config/locales/fi.yml +73 -0
- data/config/locales/fr.yml +73 -0
- data/config/locales/hu.yml +73 -0
- data/config/locales/it.yml +77 -0
- data/config/locales/ja.yml +73 -0
- data/config/locales/ko.yml +73 -0
- data/config/locales/lt.yml +56 -0
- data/config/locales/lv.yml +73 -0
- data/config/locales/nb.yml +73 -0
- data/config/locales/nl.yml +77 -0
- data/config/locales/pl.yml +73 -0
- data/config/locales/pt-BR.yml +69 -0
- data/config/locales/pt.yml +73 -0
- data/config/locales/rs.yml +73 -0
- data/config/locales/ru.yml +70 -0
- data/config/locales/sk.yml +73 -0
- data/config/locales/sl.yml +62 -0
- data/config/locales/sv.yml +65 -0
- data/config/locales/tr.yml +73 -0
- data/config/locales/uk.yml +71 -0
- data/config/locales/vi.yml +73 -0
- data/config/locales/zh-CN.yml +73 -0
- data/config/locales/zh-TW.yml +74 -0
- data/config/routes.rb +49 -0
- data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +43 -0
- data/db/migrate/20120301234455_add_slug_to_refinery_users.rb +7 -0
- data/db/migrate/20130805143059_add_full_name_to_refinery_users.rb +5 -0
- data/db/migrate/20150503125200_rename_tables_to_new_namespace.rb +17 -0
- data/lib/generators/refinery/authentication/devise/generator.rb +18 -0
- data/lib/generators/refinery/authentication/devise/templates/config/initializers/refinery/authentication/devise.rb.erb +8 -0
- data/lib/refinery/authentication/devise/authorisation_adapter.rb +36 -0
- data/lib/refinery/authentication/devise/authorisation_manager.rb +30 -0
- data/lib/refinery/authentication/devise/configuration.rb +22 -0
- data/lib/refinery/authentication/devise/engine.rb +43 -0
- data/lib/refinery/authentication/devise/initialiser.rb +228 -0
- data/lib/refinery/authentication/devise/system.rb +63 -0
- data/lib/refinery/authentication/devise.rb +26 -0
- data/lib/refinerycms-authentication-devise.rb +1 -0
- data/license.md +21 -0
- data/readme.md +11 -0
- data/refinerycms-authentication-devise.gemspec +22 -0
- data/spec/controllers/refinery/authentication/devise/admin/users_controller_spec.rb +90 -0
- data/spec/factories/user.rb +27 -0
- data/spec/features/refinery/authentication/devise/admin/users_spec.rb +88 -0
- data/spec/features/refinery/authentication/devise/passwords_spec.rb +71 -0
- data/spec/features/refinery/authentication/devise/sessions_spec.rb +103 -0
- data/spec/lib/refinery/authentication/devise/configuration_spec.rb +41 -0
- data/spec/models/refinery/user_spec.rb +285 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/refinery/authentication/devise/controller_macros.rb +48 -0
- data/spec/support/refinery/authentication/devise/feature_macros.rb +26 -0
- data/tasks/rspec.rake +4 -0
- metadata +225 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "sign in", :type => :feature do
|
4
|
+
let(:login_path) { refinery.new_authentication_devise_user_session_path }
|
5
|
+
let(:login_retry_path) { refinery.authentication_devise_user_session_path }
|
6
|
+
let(:admin_path) { "/#{Refinery::Core.backend_route}" }
|
7
|
+
let!(:user) {
|
8
|
+
FactoryGirl.create(:authentication_devise_refinery_user, :username => "ugisozols",
|
9
|
+
:password => "123456",
|
10
|
+
:password_confirmation => "123456")
|
11
|
+
}
|
12
|
+
|
13
|
+
before do
|
14
|
+
visit refinery.login_path
|
15
|
+
end
|
16
|
+
|
17
|
+
it "shows login form" do
|
18
|
+
expect(page).to have_content("Hello! Please sign in.")
|
19
|
+
expect(page).to have_content("I forgot my password")
|
20
|
+
expect(page).to have_selector("a[href*='/refinery/users/password/new']")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when supplied data is valid" do
|
24
|
+
it "logs in user" do
|
25
|
+
fill_in "Username or email", :with => "ugisozols"
|
26
|
+
fill_in "Password", :with => "123456"
|
27
|
+
click_button "Sign in"
|
28
|
+
expect(page).to have_content("Signed in successfully.")
|
29
|
+
expect(current_path).to match(/\A#{admin_path}/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when supplied data is not valid" do
|
34
|
+
it "shows flash error" do
|
35
|
+
fill_in "Username or email", :with => "Hmmm"
|
36
|
+
fill_in "Password", :with => "Hmmm"
|
37
|
+
click_button "Sign in"
|
38
|
+
expect(page).to have_content("Sorry, your login or password was incorrect.")
|
39
|
+
expect(current_path).to eq(login_retry_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'user sign up', :type => :feature do
|
45
|
+
before do
|
46
|
+
Refinery::Authentication::Devise::User.delete_all
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'when there are no users' do
|
50
|
+
it 'allows user creation' do
|
51
|
+
# Verify that we can access the sign up page.
|
52
|
+
visit Refinery::Core.backend_path
|
53
|
+
expect(page).to have_content("There are no users yet, so we'll set you up first")
|
54
|
+
|
55
|
+
# Fill in user details.
|
56
|
+
fill_in 'user[username]', :with => 'rspec'
|
57
|
+
fill_in 'user[email]', :with => 'rspec@example.com'
|
58
|
+
fill_in 'user[password]', :with => 'spectacular'
|
59
|
+
fill_in 'user[password_confirmation]', :with => 'spectacular'
|
60
|
+
|
61
|
+
# Sign up and verify!
|
62
|
+
expect {
|
63
|
+
click_button "Sign up"
|
64
|
+
}.to change(Refinery::Authentication::Devise::User, :count).from(0).to(1)
|
65
|
+
expect(page).to have_content("Welcome to Refinery, rspec.")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'redirects', :type => :feature do
|
71
|
+
let(:protected_path) { refinery.new_authentication_devise_admin_user_path }
|
72
|
+
let(:login_path) { refinery.login_path }
|
73
|
+
|
74
|
+
before do
|
75
|
+
FactoryGirl.create(:authentication_devise_refinery_user,
|
76
|
+
:username => "ugisozols",
|
77
|
+
:password => "123456",
|
78
|
+
:password_confirmation => "123456"
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when visiting a protected path" do
|
83
|
+
before { visit protected_path }
|
84
|
+
|
85
|
+
it "redirects to the login" do
|
86
|
+
expect(current_path).to eq(login_path)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "shows login form" do
|
90
|
+
expect(page).to have_content("Hello! Please sign in.")
|
91
|
+
expect(page).to have_content("I forgot my password")
|
92
|
+
expect(page).to have_selector("a[href*='/refinery/users/password/new']")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "redirects to the protected path on login" do
|
96
|
+
fill_in "Username or email", :with => "ugisozols"
|
97
|
+
fill_in "Password", :with => "123456"
|
98
|
+
page.click_button "Sign in"
|
99
|
+
expect(current_path).to eq(protected_path)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
module Authentication
|
5
|
+
module Devise
|
6
|
+
describe 'configuration' do
|
7
|
+
|
8
|
+
describe '.email_from_name' do
|
9
|
+
# reset any previously defined email from name
|
10
|
+
before do
|
11
|
+
Refinery::Authentication::Devise.email_from_name = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when set in configuration' do
|
15
|
+
it 'returns name set by Refinery::Authentication::Devise.config' do
|
16
|
+
allow(Refinery::Authentication::Devise).to receive(:email_from_name).and_return('support')
|
17
|
+
expect(Refinery::Authentication::Devise.email_from_name).to eq('support')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when set in locale file' do
|
22
|
+
before do
|
23
|
+
::I18n.backend.store_translations :en, :refinery => {
|
24
|
+
:authentication => {
|
25
|
+
:config => {
|
26
|
+
:email_from_name => 'supporto'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns name set in locale' do
|
33
|
+
expect(Refinery::Authentication::Devise.email_from_name).to eq('supporto')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Refinery
|
4
|
+
module Authentication
|
5
|
+
module Devise
|
6
|
+
describe User, :type => :model do
|
7
|
+
|
8
|
+
let(:user) { FactoryGirl.create(:authentication_devise_user) }
|
9
|
+
let(:refinery_user) {
|
10
|
+
FactoryGirl.create(:authentication_devise_refinery_user)
|
11
|
+
}
|
12
|
+
|
13
|
+
context "Roles" do
|
14
|
+
context "add_role" do
|
15
|
+
it "raises Exception when Role object is passed" do
|
16
|
+
expect {user.add_role(Refinery::Authentication::Devise::Role.new)}.to raise_exception
|
17
|
+
end
|
18
|
+
|
19
|
+
it "adds a Role to the User when role not yet assigned to User" do
|
20
|
+
expect(proc {
|
21
|
+
user.add_role(:new_role)
|
22
|
+
}).to change(user.roles, :count).by(1)
|
23
|
+
expect(user.roles.collect(&:title)).to include("NewRole")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not add a Role to the User when this Role is already assigned to User" do
|
27
|
+
expect(proc {
|
28
|
+
refinery_user.add_role(:refinery)
|
29
|
+
}).not_to change(refinery_user.roles, :count)
|
30
|
+
expect(refinery_user.roles.collect(&:title)).to include("Refinery")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "has_role" do
|
35
|
+
it "raises Exception when Role object is passed" do
|
36
|
+
expect{ user.has_role?(Refinery::Authentication::Devise::Role.new)}.to raise_exception
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the true if user has Role" do
|
40
|
+
expect(refinery_user.has_role?(:refinery)).to be_truthy
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false if user hasn't the Role" do
|
44
|
+
expect(refinery_user.has_role?(:refinery_fail)).to be_falsey
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "role association" do
|
49
|
+
it "have a roles attribute" do
|
50
|
+
expect(user).to respond_to(:roles)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "validations" do
|
56
|
+
# email and password validations are done by including devises validatable
|
57
|
+
# module so those validations are not tested here
|
58
|
+
let(:attributes) do
|
59
|
+
{
|
60
|
+
:username => "Refinery CMS",
|
61
|
+
:email => "refinery@cms.com",
|
62
|
+
:password => "123456",
|
63
|
+
:password_confirmation => "123456"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "requires username" do
|
68
|
+
expect(User.new(attributes.merge(:username => ""))).not_to be_valid
|
69
|
+
end
|
70
|
+
|
71
|
+
it "rejects duplicate usernames" do
|
72
|
+
User.create!(attributes)
|
73
|
+
expect(User.new(attributes.merge(:email => "another@email.com"))).not_to be_valid
|
74
|
+
end
|
75
|
+
|
76
|
+
it "rejects duplicate usernames regardless of case" do
|
77
|
+
User.create!(attributes)
|
78
|
+
expect(User.new(attributes.merge(
|
79
|
+
:username => attributes[:username].upcase,
|
80
|
+
:email => "another@email.com")
|
81
|
+
)).not_to be_valid
|
82
|
+
end
|
83
|
+
|
84
|
+
it "rejects duplicate usernames regardless of whitespace" do
|
85
|
+
User.create!(attributes)
|
86
|
+
new_user = User.new(attributes.merge(:username => " Refinery CMS "))
|
87
|
+
new_user.valid?
|
88
|
+
expect(new_user.username).to eq('refinery cms')
|
89
|
+
expect(new_user).not_to be_valid
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe ".find_for_database_authentication" do
|
94
|
+
it "finds user either by username or email" do
|
95
|
+
expect(User.find_for_database_authentication(:login => user.username)).to eq(user)
|
96
|
+
expect(User.find_for_database_authentication(:login => user.email)).to eq(user)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#can_delete?" do
|
101
|
+
let(:user_not_persisted) { FactoryGirl.build(:authentication_devise_refinery_user) }
|
102
|
+
let(:super_user) do
|
103
|
+
FactoryGirl.create(:authentication_devise_refinery_user).tap do |user|
|
104
|
+
user.add_role(:superuser)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "won't allow to delete" do
|
109
|
+
it "not persisted user record" do
|
110
|
+
expect(refinery_user.can_delete?(user_not_persisted)).to be_falsey
|
111
|
+
end
|
112
|
+
|
113
|
+
it "user with superuser role" do
|
114
|
+
expect(refinery_user.can_delete?(super_user)).to be_falsey
|
115
|
+
end
|
116
|
+
|
117
|
+
it "if user count with refinery role < 1" do
|
118
|
+
::Refinery::Authentication::Devise::Role[:refinery].users.delete([ refinery_user, super_user ])
|
119
|
+
expect(super_user.can_delete?(refinery_user)).to be_falsey
|
120
|
+
end
|
121
|
+
|
122
|
+
it "user himself" do
|
123
|
+
expect(refinery_user.can_delete?(refinery_user)).to be_falsey
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "allow to delete" do
|
128
|
+
it "if user count with refinery role = 1" do
|
129
|
+
::Refinery::Authentication::Devise::Role[:refinery].users.delete(refinery_user)
|
130
|
+
expect(super_user.can_delete?(refinery_user)).to be_truthy
|
131
|
+
end
|
132
|
+
|
133
|
+
it "if all conditions return true" do
|
134
|
+
expect(super_user.can_delete?(refinery_user)).to be_truthy
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#can_edit?" do
|
140
|
+
let(:user_not_persisted) { FactoryGirl.build(:authentication_devise_refinery_user) }
|
141
|
+
let(:super_user) do
|
142
|
+
FactoryGirl.create(:authentication_devise_refinery_user).tap do |user|
|
143
|
+
user.add_role(:superuser)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
let(:user_persisted) { FactoryGirl.create(:authentication_devise_refinery_user)}
|
147
|
+
|
148
|
+
context "won't allow to edit" do
|
149
|
+
it "non-persisted user record" do
|
150
|
+
expect(refinery_user.can_edit?(user_not_persisted)).to be_falsey
|
151
|
+
end
|
152
|
+
|
153
|
+
it "user is not a super user" do
|
154
|
+
expect(refinery_user.can_edit?(user_persisted)).to be_falsey
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "allows to edit" do
|
159
|
+
it "when I am a user super" do
|
160
|
+
expect(super_user.can_edit?(user_persisted)).to be_truthy
|
161
|
+
end
|
162
|
+
|
163
|
+
it "if all conditions return true" do
|
164
|
+
expect(super_user.can_edit?(refinery_user)).to be_truthy
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "#plugins=" do
|
170
|
+
context "when user is not persisted" do
|
171
|
+
it "does not add plugins for this user" do
|
172
|
+
new_user = FactoryGirl.build(:authentication_devise_user)
|
173
|
+
new_user.plugins = ["test"]
|
174
|
+
expect(new_user.plugins).to be_empty
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when user is persisted" do
|
179
|
+
it "only assigns plugins with names that are of string type" do
|
180
|
+
user.plugins = [1, :test, false, "refinery_one"]
|
181
|
+
expect(user.plugins.collect(&:name)).to eq(["refinery_one"])
|
182
|
+
end
|
183
|
+
|
184
|
+
it "won't raise exception if plugins position is not a number" do
|
185
|
+
Refinery::Authentication::Devise::UserPlugin.create! :name => "refinery_one", :user_id => user.id
|
186
|
+
|
187
|
+
expect { user.plugins = ["refinery_one", "refinery_two"] }.to_not raise_error
|
188
|
+
end
|
189
|
+
|
190
|
+
context "when no plugins assigned" do
|
191
|
+
it "assigns them to user" do
|
192
|
+
expect(user.plugins).to eq([])
|
193
|
+
|
194
|
+
plugin_list = ["refinery_one", "refinery_two", "refinery_three"]
|
195
|
+
user.plugins = plugin_list
|
196
|
+
expect(user.plugins.collect(&:name)).to eq(plugin_list)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "assigns them to user with unique positions" do
|
200
|
+
expect(user.plugins).to eq([])
|
201
|
+
|
202
|
+
plugin_list = ["refinery_one", "refinery_two", "refinery_three"]
|
203
|
+
user.plugins = plugin_list
|
204
|
+
expect(user.plugins.pluck(:position)).to match_array([1,2,3])
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "when plugins are already assigned" do
|
209
|
+
it "only adds new ones and deletes ones that are not used" do
|
210
|
+
user.plugins = ["refinery_one", "refinery_two", "refinery_three"]
|
211
|
+
new_plugin_list = ["refinery_one", "refinery_two", "refinery_four"]
|
212
|
+
|
213
|
+
user.plugins = new_plugin_list
|
214
|
+
user.plugins.reload
|
215
|
+
expect(user.plugins.collect(&:name)).to eq(new_plugin_list)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "#authorised_plugins" do
|
222
|
+
it "returns array of user and always allowed plugins" do
|
223
|
+
["refinery_one", "refinery_two", "refinery_three"].each_with_index do |name, index|
|
224
|
+
user.plugins.create!(:name => name, :position => index)
|
225
|
+
end
|
226
|
+
expect(user.authorised_plugins).to eq(user.plugins.collect(&:name) | ::Refinery::Plugins.always_allowed.names)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe "plugins association" do
|
231
|
+
let(:plugin_list) { ["refinery_one", "refinery_two", "refinery_three"] }
|
232
|
+
before { user.plugins = plugin_list }
|
233
|
+
|
234
|
+
it "have a plugins attribute" do
|
235
|
+
expect(user).to respond_to(:plugins)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "returns plugins in ASC order" do
|
239
|
+
expect(user.plugins[0].name).to eq(plugin_list[0])
|
240
|
+
expect(user.plugins[1].name).to eq(plugin_list[1])
|
241
|
+
expect(user.plugins[2].name).to eq(plugin_list[2])
|
242
|
+
end
|
243
|
+
|
244
|
+
it "deletes associated plugins" do
|
245
|
+
user.destroy
|
246
|
+
expect(UserPlugin.find_by_user_id(user.id)).to be_nil
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "#create_first" do
|
251
|
+
let(:first_user) do
|
252
|
+
FactoryGirl.build(:authentication_devise_user).tap do |user|
|
253
|
+
user.create_first
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
it "adds refinery role" do
|
258
|
+
expect(first_user.roles.collect(&:title)).to include("Refinery")
|
259
|
+
end
|
260
|
+
|
261
|
+
it "adds superuser role" do
|
262
|
+
expect(first_user.roles.collect(&:title)).to include("Superuser")
|
263
|
+
end
|
264
|
+
|
265
|
+
it "adds registered plugins" do
|
266
|
+
expect(first_user.plugins.collect(&:name)).to eq(
|
267
|
+
%w(refinery_authentication_devise refinery_images refinery_files refinery_pages)
|
268
|
+
)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "returns true on success" do
|
272
|
+
allow(first_user).to receive(:valid?).and_return(true)
|
273
|
+
expect(first_user.create_first).to eq(true)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "returns false on failure" do
|
277
|
+
allow(first_user).to receive(:valid?).and_return(false)
|
278
|
+
expect(first_user.create_first).to eq(false)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV["RAILS_ENV"] ||= 'test'
|
5
|
+
|
6
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
7
|
+
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'capybara/rspec'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rspec
|
13
|
+
config.filter_run :focus => true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.backtrace_exclusion_patterns = %w(
|
16
|
+
rails actionpack railties capybara activesupport rack warden rspec actionview
|
17
|
+
activerecord dragonfly benchmark
|
18
|
+
).map { |noisy| /#{noisy}/ }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Requires supporting files with custom matchers and macros, etc,
|
22
|
+
# in ./support/ and its subdirectories including factories.
|
23
|
+
([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
|
24
|
+
Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
|
25
|
+
}.flatten.sort.each do |support_file|
|
26
|
+
require support_file
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Authentication
|
3
|
+
module Devise
|
4
|
+
module ControllerMacros
|
5
|
+
def self.extended(base)
|
6
|
+
base.send :include, ::Devise::TestHelpers
|
7
|
+
end
|
8
|
+
|
9
|
+
def refinery_login_with_devise(*roles)
|
10
|
+
roles = handle_deprecated_roles!(roles).flatten
|
11
|
+
let(:logged_in_user) do
|
12
|
+
FactoryGirl.create(:authentication_devise_user).tap do |user|
|
13
|
+
roles.each do |role|
|
14
|
+
user.add_role(role)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
before do
|
19
|
+
@request.env["devise.mapping"] = ::Devise.mappings[:authentication_devise_user]
|
20
|
+
sign_in logged_in_user
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def factory_user(factory)
|
25
|
+
let(:logged_in_user) { FactoryGirl.create(factory) }
|
26
|
+
before do
|
27
|
+
@request.env["devise.mapping"] = ::Devise.mappings[:authentication_devise_user]
|
28
|
+
sign_in logged_in_user
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def handle_deprecated_roles!(*roles)
|
34
|
+
mappings = {
|
35
|
+
:user => [],
|
36
|
+
:refinery_user => [:refinery],
|
37
|
+
:refinery_superuser => [:refinery, :superuser]
|
38
|
+
}
|
39
|
+
mappings[roles.flatten.first] || roles
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.configure do |config|
|
47
|
+
config.extend Refinery::Authentication::Devise::ControllerMacros, type: :controller
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Authentication
|
3
|
+
module Devise
|
4
|
+
module FeatureMacros
|
5
|
+
|
6
|
+
def refinery_login_with_devise(factory)
|
7
|
+
let!(:logged_in_user) { FactoryGirl.create(factory) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
visit refinery.login_path
|
11
|
+
|
12
|
+
fill_in "Username or email", with: logged_in_user.username
|
13
|
+
fill_in "Password", with: "refinerycms"
|
14
|
+
|
15
|
+
click_button "Sign in"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.extend Refinery::Authentication::Devise::FeatureMacros, type: :feature
|
26
|
+
end
|
data/tasks/rspec.rake
ADDED