0

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

这一行在我的 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 模型上)时:

it { should respond_to :activity }

我收到以下错误和跟踪:

/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)>'
4

1 回答 1

0

我添加了 paper_trail gem,但没有运行安装/迁移。真的很简单明了。但这不是我以前见过的错误,所以我会发布这个,以便其他可能遇到它的人可以在浪费很长时间之前检查明显的情况。

于 2013-10-30T09:01:35.177 回答