Sha256: 58680623e4ba704e5233857c020546a0147acdad98ded4032ccb583612138ed8

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 KB

Contents

require File.dirname(__FILE__) + '/../test_helper.rb'

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

14 entries across 14 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.33 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.32 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.31 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.30 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.29 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.28 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.27 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.26 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.25 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.24 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.23 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.22 vendor/plugins/authlogic/test/session_test/scopes_test.rb
refinerycms-0.9.6.21 vendor/plugins/authlogic/test/session_test/scopes_test.rb