Sha256: 154e8e86e0aefe7662679258499fe0dba50afeb82acf516a3c92f5b4ee41d8ec

Contents?: true

Size: 1.92 KB

Versions: 19

Compression:

Stored size: 1.92 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

19 entries across 19 versions & 4 rubygems

Version Path
authlogic-3.4.6 test/session_test/scopes_test.rb
authlogic-3.4.5 test/session_test/scopes_test.rb
authlogic-3.4.4 test/session_test/scopes_test.rb
authlogic-3.4.3 test/session_test/scopes_test.rb
authlogic-3.4.2 test/session_test/scopes_test.rb
authlogic-3.4.1 test/session_test/scopes_test.rb
authlogic-3.4.0 test/session_test/scopes_test.rb
authlogic-3.3.0 test/session_test/scopes_test.rb
authlogic-3.2.0 test/session_test/scopes_test.rb
authlogic-3.1.3 test/session_test/scopes_test.rb
authlogic-3.1.2 test/session_test/scopes_test.rb
authlogic-3.1.1 test/session_test/scopes_test.rb
nulogy-authlogic-3.1.0.1 test/session_test/scopes_test.rb
Empact-authlogic-3.1.0 test/session_test/scopes_test.rb
authlogic-3.1.0 test/session_test/scopes_test.rb
Empact-authlogic-3.0.3 test/session_test/scopes_test.rb
antlypls-authlogic-3.0.3 test/session_test/scopes_test.rb
authlogic-3.0.3 test/session_test/scopes_test.rb
authlogic-3.0.2 test/session_test/scopes_test.rb