Sha256: ec4f1250f5455a096d4e4c91a21a65d81f093d4d534dc62e4e6bb6912da55023

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

require 'test_helper'

class SlimDummy < ActiveRecord::Base
  set_table_name 'dummies'
  as_enum :gender, [:male, :female], :slim => true
end

class WithoutShortcutsTest < ActiveSupport::TestCase  
  def setup
    reload_db
  end

  test "that no shortcut methods are generated if :slim => true" do
    jane = SlimDummy.new
    jane.gender = :female
    
    # ensure that other methods still work as expected
    assert_equal 1, jane.gender_cd
    assert_equal :female, jane.gender
    
    # then check for availability  of shortcut methods
    assert !jane.respond_to?(:male!), "should not respond_to <male!>"
    assert !jane.respond_to?(:female?), "should not respond_to <female?>"
  end
  
  test "that saving and loading from a DB still works, even if :slim => true" do
    anna = SlimDummy.find_by_name 'Anna'
    
    assert_equal 1, anna.gender_cd
    assert_equal :female, anna.gender
    
    # change anna, save + reload
    anna.gender = :male
    anna.save!
    anna.reload
    
    assert_equal 0, anna.gender_cd
    assert_equal :male, anna.gender
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
lwe-simple_enum-0.3.0 test/without_shortcuts_test.rb
simple_enum-1.4.1 test/without_shortcuts_test.rb
simple_enum-1.4.0 test/without_shortcuts_test.rb
simple_enum-1.3.2 test/without_shortcuts_test.rb
simple_enum-1.3.1 test/without_shortcuts_test.rb
simple_enum-1.3.0 test/without_shortcuts_test.rb
simple_enum-1.2.0 test/without_shortcuts_test.rb
simple_enum-1.1.0 test/without_shortcuts_test.rb
simple_enum-1.0.1 test/without_shortcuts_test.rb
simple_enum-1.0.0 test/without_shortcuts_test.rb
simple_enum-0.9.0 test/without_shortcuts_test.rb
simple_enum-0.3.0 test/without_shortcuts_test.rb