Sha256: d79fa08097a31aef4e89fa8010a523d966b6f4d3ab5b71fed1e19c3c7fda4004

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

#---------------------------------------------------------
# Requirements
#---------------------------------------------------------

# all generic stuff required by test helper
require "test/test_helper"



#---------------------------------------------------------
# Tests
#---------------------------------------------------------

class ActsAsCurrentSimpleTest < ActiveSupport::TestCase

  #---------------------------------------------
  # setup and teardown delegations
  #---------------------------------------------
  
  def setup
    setup_db
  end
  def teardown
    teardown_db
  end



  #---------------------------------------------
  # test composition
  #---------------------------------------------
  
  def test_composition_of_class
    assert User.respond_to?(:current)
    assert User.respond_to?(:current=)
    
    assert User.respond_to?(:acts_as_current_symbol,  true)
  end

  
  def test_composition_of_instance
    seed_users
    @one = User.first
    
    assert @one.respond_to?(:current?)
    assert @one.respond_to?(:current!)
  end
  
  
  
  #---------------------------------------------
  # test symbol method
  #---------------------------------------------
  
  def test_symbol_method
    assert_equal :user, User.send(:acts_as_current_symbol)              # this notation bypasses privacy
  end
  
  
  
  #---------------------------------------------
  # test current methods
  #---------------------------------------------
  
  def test_current_methods
    seed_users
    @one = User.first
    @two = User.last
    
    # starts as nil
    assert User.current.nil?
    
    # set current to one explicitly (instances agree)
    User.current = @one
    assert_equal User.current, @one
    assert @one.current?
    assert !@two.current?
    
    # set current to two by conversion (instances agree)
    @two.current!
    assert_equal User.current, @two
    assert !@one.current?
    assert @two.current?
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_current-1.0.0 test/acts_as_current/simple_test.rb
acts_as_current-0.1.0 test/acts_as_current/simple_test.rb