Sha256: 6112a08efa4accad7a9c5edf765970e900ecb60e81a0cf8900dae746cc50678e

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe User do
  context "test :in" do
    before {
      User.attribute_enums :gender, :in => [:female, :male]
    }
    it { User.male.new.gender.should == "male" }
    it { User.female.new.gender.should == "female" }
    it { User.get_gender_values.should == [["Girl", "female"], ["Boy", "male"]] }
    it { User.gender_values.should == {"female"=>"Girl", "male"=>"Boy"} }
    
    let(:user) { User.create(:gender => :male) }
    it { user.gender_text.should == "Boy" }
    it { user.male?.should be_true }
    it { user.female?.should be_false }
    
    #:in default == nil
    it { User.create.gender.should be_nil }
  end
  
  context "test :in and :default" do
    before {
      User.attribute_enums :gender, :in => [:female, :male], :default => :female
    }
    let(:user) { User.create() }
    it { user.gender.should_not be_nil }
    it { user.gender.should == "female" }
  end
  

  context "test :booleans" do
    before {
      User.attribute_enums :enable, :booleans => true
    }
    it { User.enable.new.enable.should == true }
    it { User.not_enable.new.enable.should == false }
    it { User.get_enable_values.should == [["Yes", true], ["No", false]] }
    it { User.enable_values.should == {true=>"Yes", false=>"No"} }
    
    let(:user) { User.create(:enable => true) }
    it { user.enable.should be_true }
    it { user.enable_text.should == "Yes" }
    
    #:booleans default == true
    it { User.create.enable.should be_true }
  end
  
  context "test :booleans and :default => false" do
    before {
      User.attribute_enums :enable, :booleans => true, :default => false
    }    
    let(:user) { User.create() }
    it { user.enable.should be_false }
    it { user.enable.should_not be_nil }
  end
  
  context "test :booleans and :default => true" do
    before {
      User.attribute_enums :enable, :booleans => true, :default => true
    }    
    let(:user) { User.create() }
    it { user.enable.should be_true }
    it { user.enable.should_not be_nil }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attribute_enums-0.1.8 spec/models/active_record/user_spec.rb
attribute_enums-0.1.7 spec/models/active_record/user_spec.rb
attribute_enums-0.1.6 spec/models/active_record/user_spec.rb