Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec validate uniqueness with scope

Tags:

I have this in my Line model

validates :home_team, :uniqueness => { :scope => [:visiting_team, :event_datetime], :message => "** DOUBLE EVENT **" }   

I have this in my spec

describe Line do   it { should validate_uniqueness_of(:home_team).scoped_to(:visiting_team, :event_datetime) }   

I get this error...

Failures:

1) Line   Failure/Error:   it { should validate_uniqueness_of(:home_team).scoped_to(:visiting_team, :event_datetime) }    Did not expect errors to include "has already been taken" when home_team is set to "arbitrary_string", got error:  # ./spec/models/line_spec.rb:7:in `block (2 levels) in <top (required)>' 

Any ideas why this is failing?

like image 908
slindsey3000 Avatar asked May 07 '13 19:05

slindsey3000


1 Answers

I think you need to do this make it pass

it { should validate_uniqueness_of(:home_team).scoped_to(:visiting_team, :event_datetime).with_message("** DOUBLE EVENT **") } 

The default error message of uniqueness is “has already been taken”.

like image 129
Roy Avatar answered Nov 08 '22 16:11

Roy