Skip to content

Commit 5d2123b

Browse files
committed
Bug fix for bounty #521: Redirect to settings page rather than home page after
linking twitter/github/linkedin account Added test case Added omniauth mock credentials to development.rb for testing through browser
1 parent 435e77d commit 5d2123b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

app/controllers/sessions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def create
2727
current_user.apply_oauth(oauth)
2828
current_user.save!
2929
flash[:notice] = "#{oauth[:provider].humanize} account linked"
30-
redirect_to(destination_url)
30+
redirect_to(edit_user_url(current_user))
3131
else
3232
@user = User.find_with_oauth(oauth)
3333
if @user && !@user.new_record?

config/environments/development.rb

+24
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,28 @@
3636
BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
3737
#Rails.logger = Logger.new(STDOUT)
3838
#Rails.logger.level = Logger::DEBUG
39+
40+
# Mock account credentials
41+
OmniAuth.config.test_mode = true
42+
OmniAuth.config.mock_auth[:linkedin] = OmniAuth::AuthHash.new({
43+
:provider => 'linkedin',
44+
:uid => 'linkedin12345',
45+
:info => {:nickname => 'linkedinuser'},
46+
:credentials => {
47+
:token => 'linkedin1',
48+
:secret => 'secret'}})
49+
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
50+
:provider => 'twitter',
51+
:uid => 'twitter123545',
52+
:info => {:nickname => 'twitteruser'},
53+
:credentials => {
54+
:token => 'twitter1',
55+
:secret => 'secret'}})
56+
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new({
57+
:provider => 'github',
58+
:uid => 'github123545',
59+
:info => {:nickname => 'githubuser'},
60+
:credentials => {
61+
:token => 'github1',
62+
:secret => 'secret'}})
3963
end

spec/controllers/sessions_controller_spec.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@
106106
expect(response).to redirect_to(new_user_url)
107107
end
108108

109-
it 'redirects back to profile page if user is already signed in' do
109+
it 'redirects back to settings page if user is already signed in' do
110110
sign_in(user = Fabricate(:user, username: 'darth'))
111111
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:github] = github_response
112112
get :create
113113
expect(flash[:notice]).to include('linked')
114-
expect(response).to redirect_to(badge_url(username: 'darth'))
114+
expect(response).to redirect_to(edit_user_url(controller.send :current_user))
115115
end
116116
end
117117

@@ -202,6 +202,15 @@
202202
get :create
203203
expect(flash[:error]).to include('already associated with a different member')
204204
end
205+
206+
it 'successful linking of an account should redirect to settings page' do
207+
user = Fabricate(:user, twitter: 'mdeiters', twitter_id: '6271932')
208+
sign_in(user)
209+
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter] = twitter_response
210+
get :create
211+
expect(flash[:notice]).to include('linked')
212+
expect(response).to redirect_to(edit_user_url(controller.send :current_user))
213+
end
205214
end
206215

207216
end

0 commit comments

Comments
 (0)