-
-
Save tubbo/391ffb0161f30582274c to your computer and use it in GitHub Desktop.
validate() isn't detected by shoulda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Question < ActiveRecord::Base | |
belongs_to :user | |
has_many :answers | |
#validate :text, :presence => true, :uniqueness => true | |
validates_presence_of :text | |
validates_uniqueness_of :text | |
attr_accessible :text | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fabricator(:question) do | |
text "#{Faker::Lorem.sentence(5)}?" | |
user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Question do | |
it {should belong_to :user} | |
it {should have_many :answers} | |
it {should validate_presence_of :text} | |
it {should validate_uniqueness_of :text} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) Answer | |
Failure/Error: it {should belong_to :project} | |
Expected Answer to have a belongs_to association called project (no association called project) | |
# ./spec/models/answer_spec.rb:4:in `block (2 levels) in <top (required)>' | |
2) Answer | |
Failure/Error: it {should validate_presence_of :text} | |
Expected errors to include "can't be blank" when text is set to nil, got no errors | |
# ./spec/models/answer_spec.rb:5:in `block (2 levels) in <top (required)>' | |
3) Answer | |
Failure/Error: it {should validate_presence_of :correct} | |
Expected errors to include "can't be blank" when correct is set to nil, got no errors | |
# ./spec/models/answer_spec.rb:6:in `block (2 levels) in <top (required)>' | |
Finished in 18.91 seconds | |
8 examples, 3 failures | |
Failed examples: | |
rspec ./spec/models/answer_spec.rb:4 # Answer | |
rspec ./spec/models/answer_spec.rb:5 # Answer | |
rspec ./spec/models/answer_spec.rb:6 # Answer | |
rake aborted! | |
ruby /Users/necromancer/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -S rspec ./spec/models/answer_spec.rb ./spec/models/question_spec.rb ./spec/models/user_spec.rb failed | |
Tasks: TOP => spec | |
(See full trace by running task with --trace) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment