This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add validation for matching direction

  • Loading branch information...
FrauBienenstich committed Sep 29, 2013
1 parent 9b5fe1f commit 07feadac15cbfe40ec4974c357c8a704a38ecd9b
Showing with 7 additions and 0 deletions.
  1. +1 −0 app/models/expected_event.rb
  2. +6 −0 spec/models/expected_event_spec.rb
@@ -1,5 +1,6 @@
class ExpectedEvent < ActiveRecord::Base
validates :title, presence: true, format: { with: /\A[a-z0-9\s]+\Z/i }
validates_inclusion_of :matching_direction, in: [true, false]
validates_uniqueness_of :title
has_many :alarms
@@ -5,8 +5,14 @@
it { should have_many :alarms }
it { should have_many :incoming_events }
it { should validate_presence_of :title }
#it { should ensure_inclusion_of(:matching_direction).in_array([true false]) }

This comment has been minimized.

Show comment
Hide comment
@carpodaster

carpodaster Sep 30, 2013

Contributor

First, [true false] is missing a comma to make it a proper array 😉

But yes, apparently it's a bug / an incapability of shoulda for boolean values: see this comment on Github which explains it.

@carpodaster

carpodaster Sep 30, 2013

Contributor

First, [true false] is missing a comma to make it a proper array 😉

But yes, apparently it's a bug / an incapability of shoulda for boolean values: see this comment on Github which explains it.

# seems to be a shoulda bug, does not work
it { should ensure_inclusion_of(:final_hour).in_range(1..24) }
it { should allow_value(true).for(:matching_direction) }
it { should allow_value(false).for(:matching_direction) }
it { should_not allow_value(nil).for(:matching_direction) }
it "has a valid factory" do
FactoryGirl.build(:expected_event).should be_valid
end

0 comments on commit 07feada

Please sign in to comment.