Skip to content

Commit

Permalink
redirect user to app's page only if there is any app for this user
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Mar 30, 2012
1 parent ffd87fd commit c5d5d2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
# redirect to that app's path instead of the root path (apps#index).
def stored_location_for(resource)
location = super || root_path
(location == root_path && App.count == 1) ? app_path(App.first) : location
(location == root_path && current_user.apps.count == 1) ? app_path(current_user.apps.first) : location
end

rescue_from ActionController::RedirectBackError, :with => :redirect_to_root
Expand All @@ -24,7 +24,7 @@ def require_admin!
def redirect_to_root
redirect_to(root_path)
end

def set_time_zone
Time.zone = current_user.time_zone if user_signed_in?
end
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/devise_sessions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe Devise::SessionsController do
render_views

describe "POST /users/sign_in" do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end

let(:app) { Fabricate(:app) }
let(:user) { Fabricate(:user) }

it 'redirects to app index page if there are no apps for the user' do
post :create, { :user => { 'email' => user.email, 'password' => user.password } }
response.should redirect_to(root_path)
end

it 'redirects to app page if there is app for the user' do
Fabricate(:user_watcher, :app => app, :user => user)
post :create, { :user => { 'email' => user.email, 'password' => user.password } }
response.should redirect_to(app_path(app))
end
end
end

0 comments on commit c5d5d2d

Please sign in to comment.