2
2
3
3
module Refinery
4
4
describe "sign in" do
5
+ let ( :login_path ) { refinery . new_refinery_user_session_path }
6
+ let ( :login_retry_path ) { refinery . refinery_user_session_path }
7
+ let ( :admin_path ) { refinery . admin_root_path }
8
+
5
9
before ( :each ) do
6
10
FactoryGirl . create ( :refinery_user , :username => "ugisozols" ,
7
11
:password => "123456" ,
8
12
:password_confirmation => "123456" )
9
- visit refinery . new_refinery_user_session_path
13
+ visit login_path
10
14
end
11
15
12
16
it "shows login form" do
@@ -21,6 +25,7 @@ module Refinery
21
25
fill_in "Password" , :with => "123456"
22
26
click_button "Sign in"
23
27
page . should have_content ( "Signed in successfully." )
28
+ current_path . should == admin_path
24
29
end
25
30
end
26
31
@@ -30,6 +35,7 @@ module Refinery
30
35
fill_in "Password" , :with => "Hmmm"
31
36
click_button "Sign in"
32
37
page . should have_content ( "Sorry, your login or password was incorrect." )
38
+ current_path . should == login_retry_path
33
39
end
34
40
end
35
41
end
@@ -59,4 +65,39 @@ module Refinery
59
65
end
60
66
end
61
67
end
68
+
69
+ describe 'redirects' do
70
+ let ( :protected_path ) { refinery . new_admin_user_path }
71
+ let ( :login_path ) { refinery . new_refinery_user_session_path }
72
+
73
+ before ( :each ) do
74
+ FactoryGirl . create ( :refinery_user ,
75
+ :username => "ugisozols" ,
76
+ :password => "123456" ,
77
+ :password_confirmation => "123456"
78
+ )
79
+ end
80
+
81
+ context "when visiting a protected path" do
82
+ before ( :each ) { visit protected_path }
83
+
84
+ it "redirects to the login" do
85
+ current_path . should == login_path
86
+ end
87
+
88
+ it "shows login form" do
89
+ page . should have_content ( "Hello! Please sign in." )
90
+ page . should have_content ( "I forgot my password" )
91
+ page . should have_selector ( "a[href*='/refinery/users/password/new']" )
92
+ end
93
+
94
+ it "redirects to the protected path on login" do
95
+ fill_in "Login" , :with => "ugisozols"
96
+ fill_in "Password" , :with => "123456"
97
+ page . click_button "Sign in"
98
+ current_path . should == protected_path
99
+ end
100
+ end
101
+
102
+ end
62
103
end
0 commit comments