Sha256: 815e4dee5663f5fff4a6e37a17c17982c850a609dcea91078f1b10ca42b119a8
Contents?: true
Size: 1.65 KB
Versions: 1
Compression:
Stored size: 1.65 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 blue :rgb => 0x00F 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 context "finders" do it "find_all_by_id" do Color.find_all_by_id([1, 2, 3, 4]).should == Color.all Color.find_all_by_id([1, 3]).should == [:red, :blue] Color.find_all_by_id([]).should == [] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ar-enums-0.3.4 | spec/enum_spec.rb |