Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

don't change state when visit is cleared out

  • Loading branch information...
commit 931e161dc80c4f9282a6081f5ad59e0b41ac2406 1 parent 61b4d94
@phillipoertel phillipoertel authored
Showing with 11 additions and 4 deletions.
  1. +1 −1  app/models/flat.rb
  2. +10 −3 spec/models/flat_spec.rb
View
2  app/models/flat.rb
@@ -90,7 +90,7 @@ def available_until_must_be_after_available_on
# if behaviour on state changes gets more complex, add a state machine.
def change_state!
- if visit_at_changed?
+ if visit_at_changed? && visit_at.present?
self.state = "visit_scheduled"
end
end
View
13 spec/models/flat_spec.rb
@@ -50,17 +50,24 @@
assert_not_equal [], flat.errors[:base]
end
- describe "State changes" do
- it "should change status to 'visit scheduled' when a visit date was entered" do
+ describe "State changes" do
+ it "the status changes to 'visit scheduled' when a visit date is entered" do
flat = Factory.create(:flat, :visit_at => nil)
flat.visit_at = Time.now + 1.week
flat.save!
flat.state.should == 'visit_scheduled'
end
- it "should not change status when visit date wasn't changed" do
+ it "the status doesn't change when visit date isn't changed" do
flat = Factory.create(:flat, :visit_at => nil)
flat.save!
flat.state.should == "new"
end
+ it "the status doesn't change when visit date isn't changed to nil" do
+ flat = Factory.create(:flat, :visit_at => Time.now + 1.day)
+ flat.visit_at = nil
+ flat.state = "contacted"
+ flat.save!
+ flat.state.should == "contacted"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.