Sha256: 3af0d03e6453574df372b564f7be4b2f7e186ac5a3923a648bc3d45977b4db00

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

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

describe "A Dog Collection" do
  before(:each) do
    dog1 = Dog.new(:breed => :golden_retriever)
    dog2 = Dog.new(:breed => :snoop)

    @dogs = [dog1, dog2]
  end

  it "should sort by breed" do
    @dogs.sort_by(&:breed).should == @dogs
  end
end

describe "A Dog" do
  
  before(:each) { @dog = Dog.new(:breed => :golden_retriever) }
  
  it "should have an enumerable breed" do
    @dog.breed.class.should == BreedGoldenRetriever
  end

  it "should respond to enum_classes" do
    @dog.breed.should respond_to('enum_classes')
  end

  it "should be valid with a valid option" do
    @dog.should be_valid
  end

  context "with an invalid breed option" do
    before { @dog.breed = :golden_doodle }
      
    it "should not be valid with an invalid option" do
      @dog.should_not be_valid
    end

    it "should have an error for the breed" do
      @dog.valid?
      @dog.errors.should include(:breed)
    end
    
    it "should have an error message containing the right options" do
      @dog.valid?
      @dog.errors[:breed].should include("must be one of #{Breed.all.map(&:to_sym).join(', ')}")
    end
  end
  
end

class Thing < ActiveRecord::Base
  classy_enum_attr :breed, :dog_breed 
end

describe "A Thing" do
  before(:each) { @thing = Thing.new(:dog_breed => :snoop) }

  it "should have an enumerable dog breed as breed" do
    @thing.dog_breed.class.should == BreedSnoop
  end

  it "should have a base class of Breed" do
    @thing.dog_breed.should respond_to('enum_classes')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
classy_enum-0.6.1 spec/classy_enum_attributes_spec.rb
classy_enum-0.6.0 spec/classy_enum_attributes_spec.rb