Sha256: 8459b6ce9fe76d6b467fd247ad1eba4550280cd625f48d3739959eabee36a7e2

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

describe "Belongs To Enum models" do

  it "constants should be set" do
    User.const_defined?("Role").should be_true
  end
  
  it "constant has keys" do
    User::Role.should respond_to(:admin)
  end
  
  it "keys should start at 1" do
    User::Role.normal.should == 1
  end

  it "keys should respect hash values" do
    Vehicle::Make.honda.should == 10
  end
  
  it "keys can be iterated through" do
    User::Role.each do |role, role_id|
      role.should == :normal
      role_id.should == 1
      break
    end
  end
  
  it "has items_for_select" do
    User::Role.items_for_select.first[0].should == "Normal"
    User::Role.items_for_select.first[1].should == 1
  end
  
  it "has depreciated items method that maps to items_for_select" do
    User::Role.items.first[0].should == "Normal"
    User::Role.items.first[1].should == 1
  end
  
  it "can get item from id" do
    User::Role.get(1).should == :normal
  end

  it "pretty displays item" do
    User::Role.display(1).should == "Normal"
  end
  
  it "can access raw hash" do
    User::Role.raw_hash.is_a?(Hash)
    User::Role.raw_hash.keys[0].should == :normal
    User::Role.raw_hash.values[0].should == 1
  end
  

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
belongs_to_enum-0.2 spec/belongs_to_enum.rb