Skip to content
Browse files

Merge pull request #171 from twinslash/fix-user-redirect

redirect user to app's page only if there is any app for this user
  • Loading branch information...
2 parents 8854ed1 + 3d888bd commit 3bfad3d8827642d9eb817ed643690d6c1d7b7c5a @ndbroadbent ndbroadbent committed Apr 5, 2012
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
2 config/routes.rb
@@ -36,8 +36,6 @@
resources :deploys, :only => [:index]
end
- devise_for :users
-
root :to => 'apps#index'
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 3bfad3d

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