Skip to content

Commit

Permalink
Add validation for bus.id
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Douglas Smith committed Mar 3, 2012
1 parent ccc62fb commit 84c221c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hrt_bus/bus.rb
Expand Up @@ -11,7 +11,7 @@ class Bus
validates_numericality_of :lat, greater_than: 0
validates_numericality_of :lon, less_than: 0

validates :time, :lat, :lon, :route_id, :presence => true
validates :id, :time, :lat, :lon, :route_id, :presence => true

def initialize(attributes={})
self.attributes = attributes
Expand Down
1 change: 1 addition & 0 deletions spec/factories/bus.rb
Expand Up @@ -2,6 +2,7 @@

FactoryGirl.define do
factory :bus, :class => HrtBus::Bus do
id { SecureRandom.random_number(1e9.to_i) }
time { Time.now }
lat { 36.8642501 }
lon { -76.2818951 }
Expand Down
7 changes: 7 additions & 0 deletions spec/models/bus_validations_spec.rb
Expand Up @@ -6,6 +6,13 @@

let(:bus) { Factory.build(:bus) }

it "should validate_presence_of :id" do
bus.should be_valid
bus.id = nil
bus.should_not be_valid
bus.errors.messages[:id].first.should match(/can't be blank/)
end

it "should validate_presence_of :time" do
bus.should be_valid
bus.time = nil
Expand Down

0 comments on commit 84c221c

Please sign in to comment.