Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Add validation for matching direction
Browse files Browse the repository at this point in the history
  • Loading branch information
FrauBienenstich committed Sep 29, 2013
1 parent 9b5fe1f commit 07feada
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/expected_event.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
Expand Down
6 changes: 6 additions & 0 deletions spec/models/expected_event_spec.rb
Expand Up @@ -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.

Copy link
@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
Expand Down

0 comments on commit 07feada

Please sign in to comment.