Sha256: 39e0cd4963e0e1fdd05f14f3691848a9b2a6da6d1c19ecc0a48399b446ed7b94

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Enum" do
  it "should provide :to_sym method returning name as symbols" do
    ActiveRecord::Enum.new(:name => :green).to_sym.should == :green
  end
  
  it "should store extra columns as a hash without the :enum_class that is passed from other classes" do
    ActiveRecord::Enum.new(:name => :green, :factor => 1.5, :enum_class => Class.new).extra_columns.should == { :factor => 1.5 }
  end

  context "External enums" do
    before do
      define_model_class 'Color', 'ActiveRecord::Enum' do
        enumeration do
          red :rgb => 0xF00
          green :rgb => 0x0F0
        end
      end    

      define_model_class 'State', 'ActiveRecord::Enum' do
        enumeration do
          on :id => 80
          off :id => 90
        end
      end    
    end
    
    it "should provide :all method to access the enums" do
      Color.all[0].should be_enum_with(:name => 'red', :rgb => 0xF00)
      Color.all[1].should be_enum_with(:name => 'green', :rgb => 0x0F0)
      State.all[0].should be_enum_with(:name => 'on', :id => 80)
      State.all[1].should be_enum_with(:name => 'off', :id => 90)
    end
    
    it "should provide [] method to access the enums" do
      Color[:red].should be_enum_with(:name => 'red')
      Color['green'].should be_enum_with(:name => 'green')
      Color[2].should be_enum_with(:name => 'green')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ar-enums-0.3.3 spec/enum_spec.rb
ar-enums-0.3.2 spec/enum_spec.rb
ar-enums-0.3.1 spec/enum_spec.rb
ar-enums-0.3.0 spec/enum_spec.rb