rails 4.1 bundle exec rake test failed,现在显示错误

时间:2014-12-29 10:07:01

标签: ruby-on-rails model ruby-on-rails-4.1

嗨我在rails中有点新,我在模型中做了一些代码,之后我尝试了代码

bundle exec rake test

测试文件然后控制台就像这样爆炸了

rake aborted!
ArgumentError: Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/core_ext/hash/keys.rb:71:in `block in assert_valid_keys'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/core_ext/hash/keys.rb:69:in `each_key'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/core_ext/hash/keys.rb:69:in `assert_valid_keys'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/association.rb:81:in `validate_options'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/association.rb:61:in `initialize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/collection_association.rb:18:in `initialize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/association.rb:46:in `new'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/association.rb:46:in `create_builder'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations/builder/association.rb:35:in `build'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/associations.rb:1215:in `has_many'
/home/simplybel/projects/gamification/app/models/user.rb:5:in `<class:User>'
/home/simplybel/projects/gamification/app/models/user.rb:1:in `<top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:348:in `require_or_load'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:480:in `load_missing_constant'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:180:in `const_missing'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/inflector/methods.rb:238:in `const_get'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/inflector/methods.rb:238:in `block in constantize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/inflector/methods.rb:236:in `each'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/inflector/methods.rb:236:in `inject'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/inflector/methods.rb:236:in `constantize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:552:in `get'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:583:in `constantize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:302:in `get'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:80:in `to'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:75:in `modules'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:92:in `routes'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:159:in `default_used_route'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:69:in `initialize'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:336:in `new'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:336:in `add_mapping'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:224:in `block in devise_for'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `each'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `devise_for'
/home/simplybel/projects/gamification/config/routes.rb:12:in `block in <top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
/home/simplybel/projects/gamification/config/routes.rb:1:in `<top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `each'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `call'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `execute'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `instance_exec'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `run'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:54:in `run_initializers'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:300:in `initialize!'
/home/simplybel/projects/gamification/config/environment.rb:5:in `<top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/projects/gamification/test/test_helper.rb:2:in `<top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/projects/gamification/test/helpers/home_helper_test.rb:1:in `<top (required)>'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
Tasks: TOP => test:run => test:units

这些是我模特的代码

class User < ActiveRecord::Base
has_many :statuses
has_many :user_friendships
has_many :friends, through: :user_friendships,
                    conditions: { user_friendships: { state: 'accepted' }}
has_many :pending_user_friendships, class_name: 'UserFriendship',
                                    foreign_key: :user_id,
                                    conditions: { state: 'pending' }
has_many :pending_friends, through: :pending_user_friendships, source: :friend
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable
validates :first_name, presence: true
validates :last_name, presence: true
validates :profile_name, presence: true,
                     uniqueness: true,
                     format: { 
                        with: /\A[a-zA-Z0-9_-]+\z/,
                        message: 'Must be formatted correctly.'
                     }
def full_name
"#{first_name} #{last_name}"
end
def to_param
profile_name
end
def gravatar_url
stripped_email = email.strip
downcase_email = stripped_email.downcase
hash = Digest::MD5.hexdigest(downcase_email)
"http://gravatar.com/avatar/#{hash}"
end
end

我刚刚修改了模型并根据条件进行了调整,在我添加了以下条件之后它似乎失败了:条件任何帮助都会为此做,感谢,也谢谢!

1 个答案:

答案 0 :(得分:1)

在协会上以这种方式规定条件已被弃用(我相信4.0),后来被删除了。

目前的做法是

has_many :friends, through: :user_friendships,
                scope: -> { where(user_friendships: { state: 'accepted' })}

其他以前的选项也是如此,例如orderselect