Skip to content

Instantly share code, notes, and snippets.

@diabolo
Created May 24, 2010 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diabolo/411689 to your computer and use it in GitHub Desktop.
Save diabolo/411689 to your computer and use it in GitHub Desktop.
require 'spec_helper'
module PriceBandSpecHelper
def valid_attributes
{
:start_margin => 10,
:end_margin => 30
}
end
end
describe PriceBand do
include PriceBandSpecHelper
before { @price_band = PriceBand.new }
subject { @price_band }
it { should respond_to :start_margin }
it { should respond_to :end_margin }
describe 'start_margin' do
it "should be mandatory" do
@price_band.attributes = valid_attributes.except(:start_margin)
@price_band.should have_at_least(1).error_on(:start_margin)
end
it "should be an integer" do
@price_band.attributes = valid_attributes.with(:start_margin => 10.1)
@price_band.start_margin.should == 10
@price_band.start_margin.should_not == 10.1
end
it "should be < 100" do
@price_band.attributes = valid_attributes.with(:start_margin => 100)
@price_band.should have(1).error_on(:start_margin)
end
it "should be > -100" do
@price_band.attributes = valid_attributes.with(:start_margin => -100)
@price_band.should have(1).error_on(:start_margin)
end
end
describe 'end_margin' do
it "should be mandatory" do
@price_band.attributes = valid_attributes.except(:end_margin)
@price_band.should have_at_least(1).error_on(:end_margin)
end
it "should be an integer" do
@price_band.attributes = valid_attributes.with(:end_margin => 10.1)
@price_band.end_margin.should == 10
@price_band.end_margin.should_not == 10.1
end
it "should be < 100" do
@price_band.attributes = valid_attributes.with(:end_margin => 100)
@price_band.should have(1).error_on(:end_margin)
end
it "should be > -100" do
@price_band.attributes = valid_attributes.with(:end_margin => -100)
@price_band.should have(1).error_on(:end_margin)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment