Sha256: 7bb84b1cc5c87a5a8eff4e1faa821213d1776517fdaaa976e5a475eb2e9faf50

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 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 know which member the enum is" do
    @dog.breed.is?(:golden_retriever).should be_true
  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

1 entries across 1 versions & 1 rubygems

Version Path
classy_enum-0.7.0 spec/classy_enum_attributes_spec.rb