Commit 3bfad3d8827642d9eb817ed643690d6c1d7b7c5a
Exists in
master
and in
1 other branch
Merge pull request #171 from twinslash/fix-user-redirect
redirect user to app's page only if there is any app for this user
Showing
3 changed files
with
28 additions
and
4 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base |
8 | 8 | # redirect to that app's path instead of the root path (apps#index). |
9 | 9 | def stored_location_for(resource) |
10 | 10 | location = super || root_path |
11 | - (location == root_path && App.count == 1) ? app_path(App.first) : location | |
11 | + (location == root_path && current_user.apps.count == 1) ? app_path(current_user.apps.first) : location | |
12 | 12 | end |
13 | 13 | |
14 | 14 | rescue_from ActionController::RedirectBackError, :with => :redirect_to_root |
... | ... | @@ -24,7 +24,7 @@ protected |
24 | 24 | def redirect_to_root |
25 | 25 | redirect_to(root_path) |
26 | 26 | end |
27 | - | |
27 | + | |
28 | 28 | def set_time_zone |
29 | 29 | Time.zone = current_user.time_zone if user_signed_in? |
30 | 30 | end | ... | ... |
config/routes.rb
... | ... | @@ -0,0 +1,26 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe Devise::SessionsController do | |
4 | + render_views | |
5 | + | |
6 | + describe "POST /users/sign_in" do | |
7 | + before do | |
8 | + @request.env["devise.mapping"] = Devise.mappings[:user] | |
9 | + end | |
10 | + | |
11 | + let(:app) { Fabricate(:app) } | |
12 | + let(:user) { Fabricate(:user) } | |
13 | + | |
14 | + it 'redirects to app index page if there are no apps for the user' do | |
15 | + post :create, { :user => { 'email' => user.email, 'password' => user.password } } | |
16 | + response.should redirect_to(root_path) | |
17 | + end | |
18 | + | |
19 | + it 'redirects to app page if there is app for the user' do | |
20 | + Fabricate(:user_watcher, :app => app, :user => user) | |
21 | + post :create, { :user => { 'email' => user.email, 'password' => user.password } } | |
22 | + response.should redirect_to(app_path(app)) | |
23 | + end | |
24 | + end | |
25 | +end | |
26 | + | ... | ... |