refinerycms-authentication 1.0.11 → 2.0.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.
- data/app/controllers/refinery/admin/users_controller.rb +100 -0
- data/app/controllers/refinery/passwords_controller.rb +51 -0
- data/app/controllers/refinery/sessions_controller.rb +26 -0
- data/app/controllers/refinery/users_controller.rb +42 -0
- data/app/helpers/refinery/sessions_helper.rb +4 -0
- data/app/helpers/refinery/users_helper.rb +4 -0
- data/app/mailers/refinery/user_mailer.rb +22 -0
- data/app/models/refinery/role.rb +18 -0
- data/app/models/refinery/roles_users.rb +8 -0
- data/app/models/refinery/user.rb +94 -0
- data/app/models/refinery/user_plugin.rb +8 -0
- data/app/views/refinery/admin/users/_actions.html.erb +6 -0
- data/app/views/{admin → refinery/admin}/users/_form.html.erb +15 -19
- data/app/views/{admin → refinery/admin}/users/_records.html.erb +1 -1
- data/app/views/refinery/admin/users/_user.html.erb +21 -0
- data/app/views/refinery/admin/users/_users.html.erb +4 -0
- data/app/views/refinery/admin/users/edit.html.erb +1 -0
- data/app/views/refinery/admin/users/index.html.erb +6 -0
- data/app/views/refinery/admin/users/new.html.erb +1 -0
- data/app/views/{layouts → refinery/layouts}/login.html.erb +3 -4
- data/app/views/refinery/passwords/edit.html.erb +26 -0
- data/app/views/refinery/passwords/new.html.erb +17 -0
- data/app/views/{sessions → refinery/sessions}/new.html.erb +6 -8
- data/app/views/refinery/user_mailer/reset_notification.html.erb +12 -0
- data/app/views/refinery/user_mailer/reset_notification.text.plain.erb +7 -0
- data/app/views/refinery/users/new.html.erb +29 -0
- data/config/locales/bg.yml +55 -55
- data/config/locales/cs.yml +58 -58
- data/config/locales/da.yml +55 -55
- data/config/locales/de.yml +55 -55
- data/config/locales/el.yml +55 -55
- data/config/locales/en.yml +55 -55
- data/config/locales/es.yml +55 -60
- data/config/locales/fi.yml +55 -55
- data/config/locales/fr.yml +55 -55
- data/config/locales/it.yml +51 -57
- data/config/locales/ja.yml +72 -0
- data/config/locales/ko.yml +72 -0
- data/config/locales/lt.yml +46 -46
- data/config/locales/lv.yml +55 -55
- data/config/locales/nb.yml +55 -55
- data/config/locales/nl.yml +55 -55
- data/config/locales/pl.yml +53 -59
- data/config/locales/pt-BR.yml +52 -52
- data/config/locales/rs.yml +62 -61
- data/config/locales/ru.yml +52 -52
- data/config/locales/sk.yml +55 -55
- data/config/locales/sl.yml +55 -54
- data/config/locales/sv.yml +52 -52
- data/config/locales/vi.yml +55 -55
- data/config/locales/zh-CN.yml +55 -55
- data/config/locales/zh-TW.yml +55 -55
- data/config/routes.rb +30 -24
- data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +30 -30
- data/lib/refinery/authenticated_system.rb +40 -0
- data/lib/refinery/authentication/configuration.rb +9 -0
- data/lib/refinery/authentication/engine.rb +36 -0
- data/lib/refinery/authentication.rb +29 -0
- data/lib/refinerycms-authentication.rb +1 -54
- data/refinerycms-authentication.gemspec +14 -109
- data/spec/controllers/refinery/admin/users_controller_spec.rb +73 -0
- data/spec/factories/user.rb +38 -0
- data/spec/models/refinery/user_spec.rb +220 -0
- data/spec/requests/refinery/admin/users_spec.rb +49 -0
- data/spec/requests/refinery/passwords_spec.rb +84 -0
- data/spec/requests/refinery/sessions_spec.rb +62 -0
- metadata +109 -124
- data/app/controllers/admin/users_controller.rb +0 -86
- data/app/controllers/passwords_controller.rb +0 -42
- data/app/controllers/sessions_controller.rb +0 -23
- data/app/controllers/users_controller.rb +0 -67
- data/app/helpers/sessions_helper.rb +0 -2
- data/app/helpers/users_helper.rb +0 -2
- data/app/mailers/user_mailer.rb +0 -20
- data/app/models/role.rb +0 -16
- data/app/models/roles_users.rb +0 -6
- data/app/models/user.rb +0 -65
- data/app/models/user_plugin.rb +0 -6
- data/app/views/admin/users/_actions.html.erb +0 -5
- data/app/views/admin/users/_user.html.erb +0 -19
- data/app/views/admin/users/_users.html.erb +0 -4
- data/app/views/admin/users/edit.html.erb +0 -1
- data/app/views/admin/users/index.html.erb +0 -6
- data/app/views/admin/users/new.html.erb +0 -1
- data/app/views/passwords/edit.html.erb +0 -31
- data/app/views/passwords/new.html.erb +0 -18
- data/app/views/user_mailer/reset_notification.html.erb +0 -12
- data/app/views/user_mailer/reset_notification.text.plain.erb +0 -7
- data/app/views/users/new.html.erb +0 -41
- data/config/locales/jp.yml +0 -72
- data/config/locales/lolcat.yml +0 -55
- data/db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb +0 -11
- data/db/migrate/20101206013505_change_to_devise_users_table.rb +0 -27
- data/db/migrate/20110106184757_add_remember_created_at_to_users.rb +0 -9
- data/db/migrate/20110325213325_remove_password_salt_from_users.rb +0 -13
- data/features/lost_password.feature +0 -49
- data/features/manage_users.feature +0 -88
- data/features/step_definitions/lost_password.rb +0 -8
- data/features/step_definitions/user_steps.rb +0 -41
- data/features/support/factories.rb +0 -32
- data/features/support/paths.rb +0 -24
- data/lib/authenticated_system.rb +0 -29
- data/lib/gemspec.rb +0 -38
- data/lib/generators/refinerycms_authentication_generator.rb +0 -8
- data/spec/models/user_spec.rb +0 -152
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# This is a temporary hack to get around some hackery with Devise when
|
|
2
|
+
# using the authentication macros in request specs that are defined in
|
|
3
|
+
# refinerycms-testing. If you remove this line ensure that tests pass
|
|
4
|
+
# in an extension that is testing against this Factory via the
|
|
5
|
+
# authentication macros in refinerycms-testing.
|
|
6
|
+
# 10-11-2011 - Jamie Winsor - jamie@enmasse.com
|
|
7
|
+
require Refinery.roots(:'refinery/authentication').join("app/models/refinery/role.rb")
|
|
8
|
+
|
|
9
|
+
FactoryGirl.define do
|
|
10
|
+
factory :user, :class => Refinery::User do
|
|
11
|
+
sequence(:username) { |n| "refinery#{n}" }
|
|
12
|
+
sequence(:email) { |n| "refinery#{n}@refinerycms.com" }
|
|
13
|
+
password "refinerycms"
|
|
14
|
+
password_confirmation "refinerycms"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
factory :refinery_user, :parent => :user do
|
|
18
|
+
roles { [ ::Refinery::Role[:refinery] ] }
|
|
19
|
+
|
|
20
|
+
after_create do |user|
|
|
21
|
+
::Refinery::Plugins.registered.each_with_index do |plugin, index|
|
|
22
|
+
user.plugins.create(:name => plugin.name, :position => index)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
factory :refinery_superuser, :parent => :refinery_user do
|
|
28
|
+
roles { [ ::Refinery::Role[:refinery], ::Refinery::Role[:superuser] ]}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
factory :refinery_translator, :parent => :user do
|
|
32
|
+
roles { [ ::Refinery::Role[:refinery], ::Refinery::Role[:translator] ] }
|
|
33
|
+
|
|
34
|
+
after_create do |user|
|
|
35
|
+
user.plugins.create(:name => 'refinery_pages', :position => 0)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Refinery
|
|
4
|
+
describe User do
|
|
5
|
+
|
|
6
|
+
let(:user) { FactoryGirl.create(:user) }
|
|
7
|
+
let(:refinery_user) { FactoryGirl.create(:refinery_user) }
|
|
8
|
+
|
|
9
|
+
context "Roles" do
|
|
10
|
+
context "add_role" do
|
|
11
|
+
it "raises Exception when Role object is passed" do
|
|
12
|
+
proc {user.add_role(Refinery::Role.new)}.should raise_exception
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "adds a Role to the User when role not yet assigned to User" do
|
|
16
|
+
proc {
|
|
17
|
+
user.add_role(:new_role)
|
|
18
|
+
}.should change(user.roles, :count).by(1)
|
|
19
|
+
user.roles.collect(&:title).should include("NewRole")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "does not add a Role to the User when this Role is already assigned to User" do
|
|
23
|
+
proc {
|
|
24
|
+
refinery_user.add_role(:refinery)
|
|
25
|
+
}.should_not change(refinery_user.roles, :count).by(1)
|
|
26
|
+
refinery_user.roles.collect(&:title).should include("Refinery")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "has_role" do
|
|
31
|
+
it "raises Exception when Role object is passed" do
|
|
32
|
+
proc{ user.has_role?(Refinery::Role.new)}.should raise_exception
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "returns the true if user has Role" do
|
|
36
|
+
refinery_user.has_role?(:refinery).should be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "returns false if user hasn't the Role" do
|
|
40
|
+
refinery_user.has_role?(:refinery_fail).should be_false
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "role association" do
|
|
45
|
+
it "have a roles attribute" do
|
|
46
|
+
user.should respond_to(:roles)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "validations" do
|
|
52
|
+
# email and password validations are done by including devises validatable
|
|
53
|
+
# module so those validations are not tested here
|
|
54
|
+
let(:attr) do
|
|
55
|
+
{
|
|
56
|
+
:username => "Refinery CMS",
|
|
57
|
+
:email => "refinery@cms.com",
|
|
58
|
+
:password => "123456",
|
|
59
|
+
:password_confirmation => "123456"
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "requires username" do
|
|
64
|
+
User.new(attr.merge(:username => "")).should_not be_valid
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "rejects duplicate usernames" do
|
|
68
|
+
User.create!(attr)
|
|
69
|
+
User.new(attr.merge(:email => "another@email.com")).should_not be_valid
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe ".find_for_database_authentication" do
|
|
74
|
+
it "finds user either by username or email" do
|
|
75
|
+
User.find_for_database_authentication(:login => user.username).should == user
|
|
76
|
+
User.find_for_database_authentication(:login => user.email).should == user
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#can_delete?" do
|
|
81
|
+
let(:user_not_persisted) { FactoryGirl.build(:refinery_user) }
|
|
82
|
+
let(:super_user) do
|
|
83
|
+
super_user = FactoryGirl.create(:refinery_user)
|
|
84
|
+
super_user.add_role(:superuser)
|
|
85
|
+
super_user
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "won't allow to delete" do
|
|
89
|
+
it "not persisted user record" do
|
|
90
|
+
refinery_user.can_delete?(user_not_persisted).should be_false
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "user with superuser role" do
|
|
94
|
+
refinery_user.can_delete?(super_user).should be_false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "if user count with refinery role < 1" do
|
|
98
|
+
::Refinery::Role[:refinery].users.delete([ refinery_user, super_user ])
|
|
99
|
+
super_user.can_delete?(refinery_user).should be_false
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "user himself" do
|
|
103
|
+
refinery_user.can_delete?(refinery_user).should be_false
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "allow to delete" do
|
|
108
|
+
it "if user count with refinery role = 1" do
|
|
109
|
+
::Refinery::Role[:refinery].users.delete(refinery_user)
|
|
110
|
+
super_user.can_delete?(refinery_user).should be_true
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "if all conditions return true" do
|
|
114
|
+
super_user.can_delete?(refinery_user).should be_true
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "#can_edit?" do
|
|
120
|
+
let(:user_not_persisted) { FactoryGirl.build(:refinery_user) }
|
|
121
|
+
let(:super_user) do
|
|
122
|
+
super_user = FactoryGirl.create(:refinery_user)
|
|
123
|
+
super_user.add_role(:superuser)
|
|
124
|
+
super_user
|
|
125
|
+
end
|
|
126
|
+
let(:user_persisted) { FactoryGirl.create(:refinery_user)}
|
|
127
|
+
|
|
128
|
+
context "won't allow to edit" do
|
|
129
|
+
it "non-persisted user record" do
|
|
130
|
+
refinery_user.can_edit?(user_not_persisted).should be_false
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "user is not a super user" do
|
|
134
|
+
refinery_user.can_edit?(user_persisted).should be_false
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
context "allows to edit" do
|
|
139
|
+
it "when I am a user super" do
|
|
140
|
+
super_user.can_edit?(user_persisted).should be_true
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "if all conditions return true" do
|
|
144
|
+
super_user.can_edit?(refinery_user).should be_true
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe "#plugins=" do
|
|
150
|
+
it "assigns plugins to user" do
|
|
151
|
+
plugin_list = ["refinery_one", "refinery_two", "refinery_three"]
|
|
152
|
+
user.plugins = plugin_list
|
|
153
|
+
user.plugins.collect { |p| p.name }.should == plugin_list
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe "#authorized_plugins" do
|
|
158
|
+
it "returns array of user and always allowd plugins" do
|
|
159
|
+
["refinery_one", "refinery_two", "refinery_three"].each_with_index do |name, index|
|
|
160
|
+
user.plugins.create!(:name => name, :position => index)
|
|
161
|
+
end
|
|
162
|
+
user.authorized_plugins.should == user.plugins.collect { |p| p.name } | ::Refinery::Plugins.always_allowed.names
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
describe "plugins association" do
|
|
167
|
+
let(:plugin_list) { ["refinery_one", "refinery_two", "refinery_three"] }
|
|
168
|
+
before { user.plugins = plugin_list }
|
|
169
|
+
|
|
170
|
+
it "have a plugins attribute" do
|
|
171
|
+
user.should respond_to(:plugins)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "returns plugins in ASC order" do
|
|
175
|
+
user.plugins[0].name.should == plugin_list[0]
|
|
176
|
+
user.plugins[1].name.should == plugin_list[1]
|
|
177
|
+
user.plugins[2].name.should == plugin_list[2]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "deletes associated plugins" do
|
|
181
|
+
user.destroy
|
|
182
|
+
UserPlugin.find_by_user_id(user.id).should be_nil
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe "#create_first" do
|
|
187
|
+
let(:first_user) do
|
|
188
|
+
first = FactoryGirl.build(:user)
|
|
189
|
+
first.create_first
|
|
190
|
+
first
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "adds refinery role" do
|
|
194
|
+
first_user.roles.collect(&:title).should include("Refinery")
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "adds superuser role" do
|
|
198
|
+
first_user.roles.collect(&:title).should include("Superuser")
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "adds registered plugins" do
|
|
202
|
+
first_user.plugins.collect(&:name).should eq(
|
|
203
|
+
["refinery_users", "refinery_dashboard", "refinery_images",
|
|
204
|
+
"refinery_files", "refinery_pages"]
|
|
205
|
+
)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it "returns true on success" do
|
|
209
|
+
first_user.stub(:valid?).and_return(true)
|
|
210
|
+
first_user.create_first.should == true
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "returns false on failure" do
|
|
214
|
+
first_user.stub(:valid?).and_return(false)
|
|
215
|
+
first_user.create_first.should == false
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "manage users" do
|
|
4
|
+
login_refinery_user
|
|
5
|
+
|
|
6
|
+
describe "new/create" do
|
|
7
|
+
it "allows to create user" do
|
|
8
|
+
visit refinery.admin_users_path
|
|
9
|
+
click_link "Add new user"
|
|
10
|
+
|
|
11
|
+
fill_in "Username", :with => "test"
|
|
12
|
+
fill_in "Email", :with => "test@refinerycms.com"
|
|
13
|
+
fill_in "Password", :with => "123456"
|
|
14
|
+
fill_in "Password confirmation", :with => "123456"
|
|
15
|
+
click_button "Save"
|
|
16
|
+
|
|
17
|
+
page.should have_content("test was successfully added.")
|
|
18
|
+
page.should have_content("test (test@refinerycms.com)")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "edit/update" do
|
|
23
|
+
it "allows to update user" do
|
|
24
|
+
visit refinery.admin_users_path
|
|
25
|
+
click_link "Edit this user"
|
|
26
|
+
|
|
27
|
+
fill_in "Username", :with => "cmsrefinery"
|
|
28
|
+
fill_in "Email", :with => "cms@refinerycms.com"
|
|
29
|
+
click_button "Save"
|
|
30
|
+
|
|
31
|
+
page.should have_content("cmsrefinery was successfully updated.")
|
|
32
|
+
page.should have_content("cmsrefinery (cms@refinerycms.com)")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "destroy" do
|
|
37
|
+
let!(:user) { FactoryGirl.create(:user, :username => "ugisozols") }
|
|
38
|
+
|
|
39
|
+
it "allows to destroy only regular user" do
|
|
40
|
+
visit refinery.admin_users_path
|
|
41
|
+
page.should have_selector("a[href='/refinery/users/#{user.username}']")
|
|
42
|
+
page.should have_no_selector("a[href='/refinery/users/refinerycms']")
|
|
43
|
+
|
|
44
|
+
click_link "Remove this user"
|
|
45
|
+
page.should have_content("'#{user.username}' was successfully removed.")
|
|
46
|
+
page.should have_content("refinerycms (refinerycms@refinerycms.com)")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Refinery
|
|
4
|
+
module Users
|
|
5
|
+
describe "password recovery" do
|
|
6
|
+
let!(:user) { FactoryGirl.create(:refinery_user, :email => "refinery@refinerycms.com") }
|
|
7
|
+
|
|
8
|
+
it "asks user to specify email address" do
|
|
9
|
+
visit refinery.new_refinery_user_session_path
|
|
10
|
+
click_link "I forgot my password"
|
|
11
|
+
page.should have_content("Please enter the email address for your account.")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "when existing email specified" do
|
|
15
|
+
it "shows success message" do
|
|
16
|
+
visit refinery.new_refinery_user_password_path
|
|
17
|
+
fill_in "refinery_user_email", :with => user.email
|
|
18
|
+
click_button "Reset password"
|
|
19
|
+
page.should have_content("An email has been sent to you with a link to reset your password.")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when non-existing email specified" do
|
|
24
|
+
it "shows failure message" do
|
|
25
|
+
visit refinery.new_refinery_user_password_path
|
|
26
|
+
fill_in "refinery_user_email", :with => "none@refinerycms.com"
|
|
27
|
+
click_button "Reset password"
|
|
28
|
+
page.should have_content("Sorry, 'none@refinerycms.com' isn't associated with any accounts.")
|
|
29
|
+
page.should have_content("Are you sure you typed the correct email address?")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "when good reset code" do
|
|
34
|
+
before do
|
|
35
|
+
user.reset_password_sent_at = 5.minutes.ago
|
|
36
|
+
user.reset_password_token = "refinerycms"
|
|
37
|
+
user.save
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "allows to change password" do
|
|
41
|
+
visit refinery.edit_refinery_user_password_path(:reset_password_token => user.reset_password_token)
|
|
42
|
+
page.should have_content("Pick a new password for #{user.email}")
|
|
43
|
+
|
|
44
|
+
fill_in "refinery_user_password", :with => "123456"
|
|
45
|
+
fill_in "refinery_user_password_confirmation", :with => "123456"
|
|
46
|
+
click_button "Reset password"
|
|
47
|
+
|
|
48
|
+
page.should have_content("Password reset successfully for '#{user.email}'")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when invalid reset code" do
|
|
53
|
+
before do
|
|
54
|
+
user.reset_password_sent_at = 5.minutes.ago
|
|
55
|
+
user.reset_password_token = "refinerycms"
|
|
56
|
+
user.save
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "shows error message" do
|
|
60
|
+
visit refinery.edit_refinery_user_password_path(:reset_password_token => "hmmm")
|
|
61
|
+
page.should have_content("We're sorry, but this reset code has expired or is invalid.")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "when expired reset code" do
|
|
66
|
+
before do
|
|
67
|
+
user.reset_password_sent_at = 1.day.ago
|
|
68
|
+
user.reset_password_token = "refinerycms"
|
|
69
|
+
user.save
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "shows error message" do
|
|
73
|
+
visit refinery.edit_refinery_user_password_path(:reset_password_token => "refinerycms")
|
|
74
|
+
|
|
75
|
+
fill_in "refinery_user_password", :with => "123456"
|
|
76
|
+
fill_in "refinery_user_password_confirmation", :with => "123456"
|
|
77
|
+
click_button "Reset password"
|
|
78
|
+
|
|
79
|
+
page.should have_content("Reset password token has expired, please request a new one")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Refinery
|
|
4
|
+
describe "sign in" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
FactoryGirl.create(:refinery_user, :username => "ugisozols",
|
|
7
|
+
:password => "123456",
|
|
8
|
+
:password_confirmation => "123456")
|
|
9
|
+
visit refinery.new_refinery_user_session_path
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "shows login form" do
|
|
13
|
+
page.should have_content("Hello! Please sign in.")
|
|
14
|
+
page.should have_content("I forgot my password")
|
|
15
|
+
page.should have_selector("a[href*='/refinery/users/password/new']")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when supplied data is valid" do
|
|
19
|
+
it "logs in user" do
|
|
20
|
+
fill_in "Login", :with => "ugisozols"
|
|
21
|
+
fill_in "Password", :with => "123456"
|
|
22
|
+
click_button "Sign in"
|
|
23
|
+
page.should have_content("Signed in successfully.")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when supplied data is not valid" do
|
|
28
|
+
it "shows flash error" do
|
|
29
|
+
fill_in "Login", :with => "Hmmm"
|
|
30
|
+
fill_in "Password", :with => "Hmmm"
|
|
31
|
+
click_button "Sign in"
|
|
32
|
+
page.should have_content("Sorry, your login or password was incorrect.")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe 'user sign up' do
|
|
38
|
+
before(:each) do
|
|
39
|
+
User.delete_all
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe 'when there are no users' do
|
|
43
|
+
it 'allows user creation' do
|
|
44
|
+
# Verify that we can access the sign up page.
|
|
45
|
+
visit refinery.root_path
|
|
46
|
+
page.should have_content("There are no users yet, so we'll set you up first")
|
|
47
|
+
|
|
48
|
+
# Fill in user details.
|
|
49
|
+
fill_in 'Username', :with => 'rspec'
|
|
50
|
+
fill_in 'Email', :with => 'rspec@example.com'
|
|
51
|
+
fill_in 'Password', :with => 'spectacular'
|
|
52
|
+
fill_in 'Password confirmation', :with => 'spectacular'
|
|
53
|
+
|
|
54
|
+
# Sign up and verify!
|
|
55
|
+
click_button "Sign up"
|
|
56
|
+
page.should have_content("Welcome to Refinery, rspec.")
|
|
57
|
+
page.should have_content("Latest Activity")
|
|
58
|
+
User.count.should == 1
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|