2

我已经开始了新的 rails 4 项目,并为我的资源生成了脚手架:文章。

Rails 为我的控制器生成了功能测试,如下所示:

test "should update article" do      
  patch :update, id: @article, article: { :indexx=>'TEST001' }
  assert_redirected_to article_path(assigns(:article))
end

在控制器示例方法中:

def update
  respond_to do |format|
    if @article.update(article_params)
      format.html { redirect_to @article, notice: 'Article was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @article.errors, status: :unprocessable_entity }
    end
  end
end

当我运行测试时,我会收到如下警告:

DEPRECATION WARNING: Relation#first with finder options is deprecated. Please build a scope and then call #first on it instead. (called from block in <class:ArticlesControllerTest> at /home/harry/s/b2c/test/controllers/articles_controller_test.rb:56)
DEPRECATION WARNING: Relation#first with finder options is deprecated. Please build a scope and then call #first on it instead. (called from block in <class:ArticlesControllerTest> at /home/harry/s/b2c/test/controllers/articles_controller_test.rb:50)

我在谷歌上搜索并在 stackoverflow 上搜索了一段时间,但没有任何结果可以改变我的项目以使其完美地通过测试。什么是正确的解决方案?

这是我的 Gemfile.lock:

actionmailer (4.0.0.beta1)
  actionpack (= 4.0.0.beta1)
  mail (~> 2.5.3)
actionpack (4.0.0.beta1)
  activesupport (= 4.0.0.beta1)
  builder (~> 3.1.0)
  erubis (~> 2.7.0)
  rack (~> 1.5.2)
  rack-test (~> 0.6.2)
activemodel (4.0.0.beta1)
  activesupport (= 4.0.0.beta1)
  builder (~> 3.1.0)
activerecord (4.0.0.beta1)
  activemodel (= 4.0.0.beta1)
  activerecord-deprecated_finders (~> 0.0.3)
  activesupport (= 4.0.0.beta1)
  arel (~> 4.0.0.beta1)
activerecord-deprecated_finders (0.0.3)
activesupport (4.0.0.beta1)
  i18n (~> 0.6.2)
  minitest (~> 4.2)
  multi_json (~> 1.3)
  thread_safe (~> 0.1)
  tzinfo (~> 0.3.33)
ansi (1.4.3)
arel (4.0.0)
atomic (1.1.8)
bcrypt-ruby (3.0.1)
builder (3.1.4)
carrierwave (0.8.0)
  activemodel (>= 3.2.0)
  activesupport (>= 3.2.0)
coffee-rails (4.0.0)
  coffee-script (>= 2.2.0)
  railties (>= 4.0.0.beta, < 5.0)
coffee-script (2.2.0)
  coffee-script-source
  execjs
coffee-script-source (1.6.2)
devise (1.5.4)
  bcrypt-ruby (~> 3.0)
  orm_adapter (~> 0.0.3)
  warden (~> 1.1)
erubis (2.7.0)
execjs (1.4.0)
  multi_json (~> 1.0)
factory_girl (4.2.0)
  activesupport (>= 3.0.0)
factory_girl_rails (4.2.1)
  factory_girl (~> 4.2.0)
  railties (>= 3.0.0)
hashr (0.0.22)
hike (1.2.2)
i18n (0.6.4)
jbuilder (1.0.2)
  activesupport (>= 3.0.0)
jquery-rails (2.2.1)
  railties (>= 3.0, < 5.0)
  thor (>= 0.14, < 2.0)
json (1.7.7)
mail (2.5.3)
  i18n (>= 0.4.0)
  mime-types (~> 1.16)
  treetop (~> 1.4.8)
mime-types (1.23)
minitest (4.7.3)
multi_json (1.7.2)
orm_adapter (0.0.7)
polyglot (0.3.3)
protected_attributes (1.0.1)
  activemodel (>= 4.0.0.beta, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
  rack (>= 1.0)
rails (4.0.0.beta1)
  actionmailer (= 4.0.0.beta1)
  actionpack (= 4.0.0.beta1)
  activerecord (= 4.0.0.beta1)
  activesupport (= 4.0.0.beta1)
  bundler (>= 1.3.0, < 2.0)
  railties (= 4.0.0.beta1)
  sprockets-rails (~> 2.0.0.rc3)
railties (4.0.0.beta1)
  actionpack (= 4.0.0.beta1)
  activesupport (= 4.0.0.beta1)
  rake (>= 0.8.7)
  rdoc (~> 3.4)
  thor (>= 0.17.0, < 2.0)
rake (10.0.4)
rdoc (3.12.2)
  json (~> 1.4)
rest-client (1.6.7)
  mime-types (>= 1.16)
sass (3.2.8)
sass-rails (4.0.0.rc1)
  railties (>= 4.0.0.beta, < 5.0)
  sass (>= 3.1.10)
  sprockets-rails (~> 2.0.0.rc0)
  tilt (~> 1.3)
simplecov (0.7.1)
  multi_json (~> 1.0)
  simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
sprockets (2.9.3)
  hike (~> 1.2)
  multi_json (~> 1.0)
  rack (~> 1.0)
  tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.0.rc4)
  actionpack (>= 3.0)
  activesupport (>= 3.0)
  sprockets (~> 2.8)
sqlite3 (1.3.7)
thor (0.18.1)
thread_safe (0.1.0)
  atomic
tilt (1.3.7)
tire (0.5.7)
  activemodel (>= 3.0)
  activesupport
  ansi
  hashr (~> 0.0.19)
  multi_json (~> 1.3)
  rake
  rest-client (~> 1.6)
treetop (1.4.12)
  polyglot
  polyglot (>= 0.3.1)
turbolinks (1.1.1)
  coffee-rails
tzinfo (0.3.37)
uglifier (2.0.1)
  execjs (>= 0.3.0)
  multi_json (~> 1.0, >= 1.0.2)
warden (1.2.1)
  rack (>= 1.0)
will_paginate (3.0.4)
4

0 回答 0