Skip to content
Browse files

redirect user to app's page only if there is any app for this user

  • Loading branch information...
1 parent ffd87fd commit c5d5d2d845672252d23ed0470c8c0e60562db04c @nashby nashby committed Mar 30, 2012
Showing with 28 additions and 2 deletions.
  1. +2 −2 app/controllers/application_controller.rb
  2. +26 −0 spec/controllers/devise_sessions_controller_spec.rb
View
4 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 @@ 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
View
26 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
+

0 comments on commit c5d5d2d

Please sign in to comment.
Something went wrong with that request. Please try again.