require File.expand_path('../../test_helper', __FILE__)

#let's use the existing functional test so we don't have to re-setup everything
#+ we are sure that existing tests pass each time we run this file only
require Rails.root.join('test/functional/account_controller_test')

class AccountControllerTest
  fixtures :users, :roles

  context "GET /login CAS button" do
    should "show up only if there's a plugin setting for CAS URL" do
      Setting["plugin_redmine_omniauth_cas"]["cas_server"] = ""
      get :login
      assert_select '#cas-login', 0
      Setting["plugin_redmine_omniauth_cas"]["cas_server"] = "blah"
      get :login
      assert_select '#cas-login'
    end
  end

  context "GET login_with_omniauth" do
    should "redirect to /my/page after successful login" do
      request.env["omniauth.auth"] = {"uid"=>"admin"}
      get :login_with_omniauth, :provider => "cas"
      assert_redirected_to '/my/page'
    end

    should "redirect to /login after failed login" do
      request.env["omniauth.auth"] = {"uid"=>"non-existent"}
      get :login_with_omniauth, :provider => "cas"
      assert_redirected_to '/login'
    end
  end
end

require File.expand_path('../../test_helper', __FILE__)

#let's use the existing functional test so we don't have to re-setup everything
#+ we are sure that existing tests pass each time we run this file only
require Rails.root.join('test/functional/account_controller_test')

class AccountControllerTest
  context "GET /login CAS button" do
    should "show up only if there's a plugin setting for CAS URL" do
      Setting["plugin_redmine_omniauth_cas"]["cas_server"] = ""
      get :login
      assert_select '#cas-login', 0
      Setting["plugin_redmine_omniauth_cas"]["cas_server"] = "blah"
      get :login
      assert_select '#cas-login'
    end
  end
end

--- 
+++ 
@@ -5,6 +5,8 @@
 require Rails.root.join('test/functional/account_controller_test')
 
 class AccountControllerTest
+  fixtures :users, :roles
+
   context "GET /login CAS button" do
     should "show up only if there's a plugin setting for CAS URL" do
       Setting["plugin_redmine_omniauth_cas"]["cas_server"] = ""
@@ -15,4 +17,18 @@
       assert_select '#cas-login'
     end
   end
+
+  context "GET login_with_omniauth" do
+    should "redirect to /my/page after successful login" do
+      request.env["omniauth.auth"] = {"uid"=>"admin"}
+      get :login_with_omniauth, :provider => "cas"
+      assert_redirected_to '/my/page'
+    end
+
+    should "redirect to /login after failed login" do
+      request.env["omniauth.auth"] = {"uid"=>"non-existent"}
+      get :login_with_omniauth, :provider => "cas"
+      assert_redirected_to '/login'
+    end
+  end
 end
Add some tests for omniauth login
