@@ -23,6 +23,9 @@ class OmniauthableIntegrationTest < Devise::IntegrationTest
23
23
"extra" => { "user_hash" => FACEBOOK_INFO }
24
24
}
25
25
OmniAuth . config . add_camelization 'facebook' , 'FaceBook'
26
+ if OmniAuth . config . respond_to? ( :request_validation_phase )
27
+ OmniAuth . config . request_validation_phase = -> ( env ) { }
28
+ end
26
29
end
27
30
28
31
teardown do
@@ -45,17 +48,17 @@ def stub_action!(name)
45
48
test "omniauth sign in should not run model validations" do
46
49
stub_action! ( :sign_in_facebook ) do
47
50
create_user
48
- visit "/users/sign_in "
49
- click_link "Sign in with FaceBook"
51
+ post "/users/auth/facebook "
52
+ follow_redirect!
50
53
assert warden . authenticated? ( :user )
51
54
52
55
refute User . validations_performed
53
56
end
54
57
end
55
58
56
59
test "can access omniauth.auth in the env hash" do
57
- visit "/users/sign_in "
58
- click_link "Sign in with FaceBook"
60
+ post "/users/auth/facebook "
61
+ follow_redirect!
59
62
60
63
json = ActiveSupport ::JSON . decode ( response . body )
61
64
@@ -68,8 +71,8 @@ def stub_action!(name)
68
71
69
72
test "cleans up session on sign up" do
70
73
assert_no_difference "User.count" do
71
- visit "/users/sign_in "
72
- click_link "Sign in with FaceBook"
74
+ post "/users/auth/facebook "
75
+ follow_redirect!
73
76
end
74
77
75
78
assert session [ "devise.facebook_data" ]
@@ -89,8 +92,8 @@ def stub_action!(name)
89
92
90
93
test "cleans up session on cancel" do
91
94
assert_no_difference "User.count" do
92
- visit "/users/sign_in "
93
- click_link "Sign in with FaceBook"
95
+ post "/users/auth/facebook "
96
+ follow_redirect!
94
97
end
95
98
96
99
assert session [ "devise.facebook_data" ]
@@ -100,8 +103,8 @@ def stub_action!(name)
100
103
101
104
test "cleans up session on sign in" do
102
105
assert_no_difference "User.count" do
103
- visit "/users/sign_in "
104
- click_link "Sign in with FaceBook"
106
+ post "/users/auth/facebook "
107
+ follow_redirect!
105
108
end
106
109
107
110
assert session [ "devise.facebook_data" ]
@@ -110,23 +113,28 @@ def stub_action!(name)
110
113
end
111
114
112
115
test "sign in and send remember token if configured" do
113
- visit "/users/sign_in "
114
- click_link "Sign in with FaceBook"
116
+ post "/users/auth/facebook "
117
+ follow_redirect!
115
118
assert_nil warden . cookies [ "remember_user_token" ]
116
119
117
120
stub_action! ( :sign_in_facebook ) do
118
121
create_user
119
- visit "/users/sign_in "
120
- click_link "Sign in with FaceBook"
122
+ post "/users/auth/facebook "
123
+ follow_redirect!
121
124
assert warden . authenticated? ( :user )
122
125
assert warden . cookies [ "remember_user_token" ]
123
126
end
124
127
end
125
128
129
+ test "generates a link to authenticate with provider" do
130
+ visit "/users/sign_in"
131
+ assert_select "a[href=?][data-method='post']" , "/users/auth/facebook" , text : "Sign in with FaceBook"
132
+ end
133
+
126
134
test "generates a proper link when SCRIPT_NAME is set" do
127
135
header 'SCRIPT_NAME' , '/q'
128
136
visit "/users/sign_in"
129
- assert_select "a" , href : "/q/users/auth/facebook"
137
+ assert_select "a[href=?][data-method='post'] " , "/q/users/auth/facebook" , text : "Sign in with FaceBook "
130
138
end
131
139
132
140
test "handles callback error parameter according to the specification" do
@@ -139,10 +147,10 @@ def stub_action!(name)
139
147
test "handles other exceptions from OmniAuth" do
140
148
OmniAuth . config . mock_auth [ :facebook ] = :invalid_credentials
141
149
142
- visit "/users/sign_in"
143
- click_link "Sign in with FaceBook"
150
+ post "/users/auth/facebook"
151
+ follow_redirect!
152
+ follow_redirect!
144
153
145
- assert_current_url "/users/sign_in"
146
154
assert_contain 'Could not authenticate you from FaceBook because "Invalid credentials".'
147
155
end
148
156
end
0 commit comments