Created
April 3, 2009 15:33
-
-
Save mytrile/89800 to your computer and use it in GitHub Desktop.
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
| class Account < ActiveRecord::Base | |
| belongs_to :user | |
| has_many :bills | |
| has_many :expenses | |
| validates_presence_of :name, :message => "You didn't provide account name" | |
| validates_length_of :name, :minimum => 4, | |
| :message => "Account name must be 4 characters minimum", | |
| :on => :create | |
| validates_numericality_of :balance, :message => "Only numbers allowed for balance", | |
| :if => :"balance", :on => :create | |
| end | |
| #shoulda account test | |
| require 'test_helper' | |
| class AccountTest < ActiveSupport::TestCase | |
| should_belong_to :user | |
| should_ensure_length_at_least :name, 4 | |
| should_have_many :bills, :expenses | |
| should_validate_numericality_of :balance | |
| end | |
| # errors | |
| 1) Failure: | |
| test: Account should ensure name has a length of at least 4. (AccountTest) | |
| [/Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb:50:in `assert_accepts' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb:254:in `__bind_1238772668_116192' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `call' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `test: Account should ensure name has a length of at least 4. ']: | |
| errors to include "is too short (minimum is 4 characters)" when name is set to "xxx", got errors: name Account name must be 4 characters minimum ("xxx") | |
| 2) Failure: | |
| test: Account should only allow numeric values for balance. (AccountTest) | |
| [/Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/assertions.rb:50:in `assert_accepts' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/active_record/macros.rb:334:in `__bind_1238772668_131158' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `call' | |
| /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `test: Account should only allow numeric values for balance. ']: | |
| errors to include "is not a number" when balance is set to "abcd", got errors: name You didn't provide account name (nil)name Account name must be 4 characters minimum (nil)balance Only numbers allowed for balance (0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment