Sha256: 36c066ad9c51d257c6d8d80dfb020efe3175f4d2fcb0c7f0e99414cb0e5cfe77

Contents?: true

Size: 708 Bytes

Versions: 5

Compression:

Stored size: 708 Bytes

Contents

require 'test_helper'

class ArrayConversionsTest < ActiveSupport::TestCase  
  def setup
    reload_db :genders => true
  end
  
  test "that conversion of Gender.find(:all).map {...} to enumeration values as symbols works the same as [:male,:female]" do
    class DummyArrayTest1 < ActiveRecord::Base
      set_table_name 'dummies'
      as_enum :gender, Gender.find(:all).map { |g| [g.name.to_sym, g.id] }
    end
    with_enum = DummyArrayTest1
    
    assert_equal 0, with_enum.male
    assert_equal 1, with_enum.female
    assert_equal 1, with_enum.genders(:female)
    
    jane = with_enum.new :gender => :female
    assert_equal :female, jane.gender
    assert_equal 1, jane.gender_cd    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_enum-1.4.1 test/array_conversions_test.rb
simple_enum-1.4.0 test/array_conversions_test.rb
simple_enum-1.3.2 test/array_conversions_test.rb
simple_enum-1.3.1 test/array_conversions_test.rb
simple_enum-1.3.0 test/array_conversions_test.rb