Permalink
Browse files

Adds @bus.early? @bus.ontime? @bus.late?

  • Loading branch information...
1 parent 371eb37 commit 5a8042140d11d109b15bb471d85342ae01d8ff47 Brian Douglas Smith committed Mar 10, 2012
Showing with 88 additions and 0 deletions.
  1. +1 −0 CHANGELOG.md
  2. +12 −0 lib/hrt_bus/bus.rb
  3. +75 −0 spec/models/bus/bus_methods_spec.rb
View
@@ -28,3 +28,4 @@
> 0.0.7
* Added adherence attribute to Bus
+* @bus.early? @bus.ontime? @bus.late?
View
@@ -39,6 +39,18 @@ def read_attribute_for_validation(key)
send(key)
end
+ def early?
+ self.adherence < 0
+ end
+
+ def ontime?
+ self.adherence == 0
+ end
+
+ def late?
+ self.adherence > 0
+ end
+
def static_map
map = GoogleStaticMap.new(:width => 960, :height => 640)
map.markers << MapMarker.new(:color => "blue",
@@ -46,4 +46,79 @@
end
+ describe "early?" do
+
+ context "the bus is early" do
+ it "should return true" do
+ bus = Factory.build(:bus, :adherence => -2)
+ bus.early?.should be_true
+ end
+ end
+
+ context "the bus is on time" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => 0)
+ bus.early?.should be_false
+ end
+ end
+
+ context "the bus is late" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => 4)
+ bus.early?.should be_false
+ end
+ end
+
+ end
+
+ describe "ontime?" do
+
+ context "the bus is early" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => -2)
+ bus.ontime?.should be_false
+ end
+ end
+
+ context "the bus is on time" do
+ it "should return true" do
+ bus = Factory.build(:bus, :adherence => 0)
+ bus.ontime?.should be_true
+ end
+ end
+
+ context "the bus is late" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => 4)
+ bus.ontime?.should be_false
+ end
+ end
+
+ end
+
+ describe "late?" do
+
+ context "the bus is early" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => -2)
+ bus.late?.should be_false
+ end
+ end
+
+ context "the bus is on time" do
+ it "should return true" do
+ bus = Factory.build(:bus, :adherence => 0)
+ bus.late?.should be_false
+ end
+ end
+
+ context "the bus is late" do
+ it "should return false" do
+ bus = Factory.build(:bus, :adherence => 4)
+ bus.late?.should be_true
+ end
+ end
+
+ end
+
end

0 comments on commit 5a80421

Please sign in to comment.