diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6e7532c..bf8ec0d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 @@ -24,7 +24,7 @@ protected def redirect_to_root redirect_to(root_path) end - + def set_time_zone Time.zone = current_user.time_zone if user_signed_in? end diff --git a/spec/controllers/devise_sessions_controller_spec.rb b/spec/controllers/devise_sessions_controller_spec.rb new file mode 100644 index 0000000..e392225 --- /dev/null +++ b/spec/controllers/devise_sessions_controller_spec.rb @@ -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 + -- libgit2 0.21.2