在RSpec spec\u helper中检查挂起的迁移时,如何修复ActiveRecord::DangerousAttributeError?

在RSpec spec\u helper中检查挂起的迁移时,如何修复ActiveRecord::DangerousAttributeError?,activerecord,rspec,ruby-on-rails-4,rails-migrations,Activerecord,Rspec,Ruby On Rails 4,Rails Migrations,好的,这是一个新的。RSPec。轨道4 这一行位于my spec_helper.rb中: # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) 当我运行一个简单的测试

好的,这是一个新的。RSPec。轨道4

这一行位于my spec_helper.rb中:

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
当我运行一个简单的测试(在ActiveRecord模型上)时:

我得到以下错误和跟踪:

/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord 4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?': version is defined by Active Record (ActiveRecord::DangerousAttributeError)
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `synchronize'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:793:in `current_version'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
    from /projects/subset_of_projects/this_project_group/projectname/spec/spec_helper.rb:17:in `<top (required)>'
/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord 4.0.0/lib/active\u record/attribute\u methods.rb:59:在“实例\u方法\u已实现”中:版本由active record定义(activerecord::DangerousAttributeError)
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in`block in define_attribute_method'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active\u model/attribute\u methods.rb:279:in'each'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active\u model/attribute\u methods.rb:279:in“define\u attribute\u method”
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active\u model/attribute\u methods.rb:246:in`block in define\u attribute\u methods'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active\u model/attribute\u methods.rb:246:in'each'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active\u model/attribute\u methods.rb:246:in“define\u attribute\u methods”
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u-record/attribute\u-methods.rb:29:in`block in-define\u-attribute\u-methods'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u-record/attribute\u-methods.rb:26:in'synchronize'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u-record/attribute\u-methods.rb:26:in'define\u-attribute\u-methods'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/attribute\u methods.rb:167:in'respond\u to'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active\u-support/callbacks.rb:368:in`\u-define\u-callbacks'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active\u support/callbacks.rb:79:in'run\u callbacks'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/core.rb:216:in'init\u with'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/persistence.rb:55:在“实例化”中
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/querying.rb:45:in'block in find\u by\u sql'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in`block in each'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/result.rb:21:in'each'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/result.rb:21:in'each'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/querying.rb:45:in'map'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/querying.rb:45:in'find\u by\u sql'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/relation.rb:585:in'exec\u querys'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in'load'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/relation.rb:220:in'to\u a'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_-record/relation/delegation.rb:12:in'map'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/migration.rb:787:in'get\u all\u versions'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/migration.rb:793:in'current\u version'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/migration.rb:800:in'needs\u migration'
来自/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active\u record/migration.rb:379:in'check\u pending!'
from/projects/subset\u of\u projects/this\u project\u group/projectname/spec/spec\u helper.rb:17:in`'

我已经添加了纸质文档,但没有运行安装/迁移。简单明了。但这不是我以前见过的错误,因此我将发布这篇文章,以便其他可能遇到它的人可以在浪费很长时间之前检查明显的错误。

哦,答案是显而易见的,但我还不能回答。。。当时间到了,我会把它贴在下面,以防其他人遇到这个错误并搜索它,只需要一个显而易见的声明!
/Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord 4.0.0/lib/active_record/attribute_methods.rb:59:in `instance_method_already_implemented?': version is defined by Active Record (ActiveRecord::DangerousAttributeError)
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_method'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:279:in `define_attribute_method'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `block in define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activemodel-4.0.0/lib/active_model/attribute_methods.rb:246:in `define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:29:in `block in define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `synchronize'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:26:in `define_attribute_methods'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:167:in `respond_to?'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:368:in `__define_callbacks'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:79:in `run_callbacks'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/core.rb:216:in `init_with'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/persistence.rb:55:in `instantiate'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `block in find_by_sql'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `block in each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/result.rb:21:in `each'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `map'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/querying.rb:45:in `find_by_sql'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:12:in `map'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:787:in `get_all_versions'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:793:in `current_version'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:800:in `needs_migration?'
    from /Users/dev/.rvm/gems/ruby-2.0.0-p247@projectname/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!'
    from /projects/subset_of_projects/this_project_group/projectname/spec/spec_helper.rb:17:in `<top (required)>'