test/failure_app_test.rb in devise-1.2.rc vs test/failure_app_test.rb in devise-1.2.rc2

- old
+ new

@@ -11,11 +11,11 @@ 'REQUEST_URI' => 'http://test.host/', 'HTTP_HOST' => 'test.host', 'REQUEST_METHOD' => 'GET', 'warden.options' => { :scope => :user }, 'rack.session' => {}, - 'action_dispatch.request.formats' => Array(env_params.delete('formats') || :html), + 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML), 'rack.input' => "", 'warden' => OpenStruct.new(:message => nil) }.merge!(env_params) @response = Devise::FailureApp.call(env).to_a @@ -67,10 +67,17 @@ swap Devise, :navigational_formats => [:xml] do call_failure('formats' => :xml) assert_equal 302, @response.first end end + + test 'redirects the correct format if it is a non-html format request' do + swap Devise, :navigational_formats => [:js] do + call_failure('formats' => :js) + assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"] + end + end end context 'For HTTP request' do test 'return 401 status' do call_failure('formats' => :xml) @@ -118,11 +125,11 @@ test 'dont return 401 with non navigational formats' do swap Devise, :http_authenticatable_on_xhr => false do call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_equal 302, @response.first - assert_equal 'http://test.host/users/sign_in', @response.second["Location"] + assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"] end end end context 'when http_authenticatable_on_xhr is true' do @@ -142,17 +149,39 @@ end end end context 'With recall' do - test 'calls the original controller' do + test 'calls the original controller if invalid email or password' do env = { "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" }, "devise.mapping" => Devise.mappings[:user], "warden" => stub_everything } call_failure(env) assert @response.third.body.include?('<h2>Sign in</h2>') assert @response.third.body.include?('Invalid email or password.') + end + + test 'calls the original controller if not confirmed email' do + env = { + "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed }, + "devise.mapping" => Devise.mappings[:user], + "warden" => stub_everything + } + call_failure(env) + assert @response.third.body.include?('<h2>Sign in</h2>') + assert @response.third.body.include?('You have to confirm your account before continuing.') + end + + test 'calls the original controller if inactive account' do + env = { + "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive }, + "devise.mapping" => Devise.mappings[:user], + "warden" => stub_everything + } + call_failure(env) + assert @response.third.body.include?('<h2>Sign in</h2>') + assert @response.third.body.include?('Your account was not activated yet.') end end end