我试图确保我的 Rails 模型中的布尔值不能设置为零。这是我的模型:
class Response < ActiveRecord::Base
attr_accessible :attending
# validations
validates :attending, :allow_nil => false
end
当我尝试运行我的规范时,我得到以下异常:
/Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activemodel-3.2.7/lib/active_model/validations/validates.rb:86:in `validates': You need to supply at least one validation (ArgumentError)
from /Users/helixed/Dropbox/Development/current/rsvp/app/models/response.rb:5:in `<class:Response>'
from /Users/helixed/Dropbox/Development/current/rsvp/app/models/response.rb:1:in `<top (required)>'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:359:in `require_or_load'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:190:in `each'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:190:in `const_missing'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/inflector/methods.rb:230:in `block in constantize'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/inflector/methods.rb:229:in `each'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/inflector/methods.rb:229:in `constantize'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/metal/params_wrapper.rb:133:in `inherited'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.7/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
from /Users/helixed/Dropbox/Development/current/rsvp/app/controllers/responses_controller.rb:1:in `<top (required)>'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:251:in `require'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:359:in `require_or_load'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:313:in `depend_on'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.7/lib/active_support/dependencies.rb:225:in `require_dependency'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/engine.rb:438:in `each'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/engine.rb:438:in `block in eager_load!'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/engine.rb:436:in `each'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/engine.rb:436:in `eager_load!'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/initializable.rb:30:in `run'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/initializable.rb:54:in `each'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/application.rb:136:in `initialize!'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.7/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/helixed/Dropbox/Development/current/rsvp/config/environment.rb:5:in `<top (required)>'
from /Users/helixed/Dropbox/Development/current/rsvp/spec/spec_helper.rb:3:in `require'
from /Users/helixed/Dropbox/Development/current/rsvp/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/helixed/Dropbox/Development/current/rsvp/spec/controllers/responses_controller_spec.rb:1:in `require'
from /Users/helixed/Dropbox/Development/current/rsvp/spec/controllers/responses_controller_spec.rb:1:in `<top (required)>'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/helixed/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'