Created
July 22, 2011 01:21
-
-
Save findchris/1098642 to your computer and use it in GitHub Desktop.
Weird shoulda issue
This file contains hidden or 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
| bundle exec rspec spec/models/user_spec.rb | |
| ..FF.FF | |
| Failures: | |
| 1) User validations | |
| Failure/Error: it { should validate_presence_of(:secret) } | |
| Expected errors to include "can't be blank" when secret is set to nil, got errors: ["name can't be blank (nil)"] | |
| # ./spec/models/user_spec.rb:10:in `block (3 levels) in <top (required)>' | |
| 3) User validations | |
| Failure/Error: it { should validate_uniqueness_of(:secret) } | |
| Expected errors to include "has already been taken" when secret is set to "c96e36f3cc7aac38767cef6212cdab38", got errors: ["name can't be blank (nil)"] | |
| # ./spec/models/user_spec.rb:13:in `block (3 levels) in <top (required)>' |
This file contains hidden or 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
| # app/models/user.rb | |
| class User < ActiveRecord::Base | |
| validates :name, :uniqueness => true, :presence => true | |
| validates :secret, :uniqueness => true, :presence => true | |
| before_validation :assign_secret, :on => :create | |
| private | |
| def assign_secret | |
| self.secret = SecureRandom.hex(16) | |
| end | |
| end | |
| # spec/models/user_spec.rb | |
| require 'spec_helper' | |
| describe User do | |
| context "validations" do | |
| before(:each) { User.create!(:name => 'I am the First App') } | |
| it { should validate_presence_of(:name) } | |
| it { should validate_presence_of(:secret) } | |
| it { should validate_uniqueness_of(:name) } | |
| it { should validate_uniqueness_of(:secret) } | |
| end | |
| end | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi I've the exact same problem. Did you manage to find a solution ?