Sha256: 6d762cd90a8b0256ef1f100c6558823ebc8d4a524fc43b5b6d204aa673c87116

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

require 'test_helper'

module SessionTest
  class ScopesTest < ActiveSupport::TestCase
    def test_scope_method
      assert_nil Authlogic::Session::Base.scope
      
      thread1 = Thread.new do
        scope = {:id => :scope1}
        Authlogic::Session::Base.send(:scope=, scope)
        assert_equal scope, Authlogic::Session::Base.scope
      end
      thread1.join
      
      assert_nil Authlogic::Session::Base.scope
      
      thread2 = Thread.new do
        scope = {:id => :scope2}
        Authlogic::Session::Base.send(:scope=, scope)
        assert_equal scope, Authlogic::Session::Base.scope
      end
      thread2.join

      assert_nil Authlogic::Session::Base.scope
    end
  
    def test_with_scope_method
      assert_raise(ArgumentError) { UserSession.with_scope }
      
      UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
        assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, UserSession.scope)
      end
      
      assert_nil UserSession.scope
    end
  
    def test_initialize
      UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
        session = UserSession.new
        assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, session.scope)
        session.id = :another_id
        assert_equal "another_id_some_id_test", session.send(:build_key, "test")
      end
    end
    
    def test_search_for_record_with_scopes
      binary_logic = companies(:binary_logic)
      ben = users(:ben)
      zack = users(:zack)
      
      session = UserSession.new
      assert_equal zack, session.send(:search_for_record, "find_by_login", zack.login)
      
      session.scope = {:find_options => {:conditions => ["company_id = ?", binary_logic.id]}}
      assert_nil session.send(:search_for_record, "find_by_login", zack.login)
      
      assert_equal ben, session.send(:search_for_record, "find_by_login", ben.login)
    end
  end
end

Version data entries

8 entries across 8 versions & 6 rubygems

Version Path
authlogic-3.0.1 test/session_test/scopes_test.rb
authlogic-3.0.0 test/session_test/scopes_test.rb
authlogic-rails3-2.2 test/session_test/scopes_test.rb
kb-authlogic-2.1.7 test/session_test/scopes_test.rb
railsware-authlogic-2.1.6.1 test/session_test/scopes_test.rb
cotweet-authlogic-2.1.6 test/session_test/scopes_test.rb
jdl-authlogic-2.1.6.2 test/session_test/scopes_test.rb
jdl-authlogic-2.1.6.1 test/session_test/scopes_test.rb