Rails 3.1 的 Rspec 给出弃用警告 ActiveRecord::Associations::AssociationCollection 已弃用?

发布于 2024-12-06 09:36:32 字数 1295 浏览 1 评论 0原文

我升级到了 Rails 3.1,现在我的测试出现了一些问题,而之前这些测试都运行得很好。

我在测试之前收到以下警告:

弃用警告:ActiveRecord::Associations::AssociationCollection 已弃用!请改用 ActiveRecord::Associations::CollectionProxy。 (从 /home/user/rails_projects/project/config/environment.rb:5 调用)

如何使用 CollectionProxy 而不是 AssociationCollection?

这是我的 Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'jquery-rails'
gem "therubyracer", "~> 0.9.4"

gem 'carrierwave', '0.5.6'
gem 'haml', '~>3.1.2'
gem 'mysql2', '0.3.7'
gem 'rmagick', '2.13.1'
gem 'sitemap_generator', '2.0.1'
gem 'whenever', '0.6.8', :require => false
gem 'will_paginate', '3.0.pre2'

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate-models', '1.0.4'
  gem 'faker', '0.9.5', :require => false
  gem 'ruby-debug19', '0.11.6'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.3'
  gem 'factory_girl_rails', '1.0'
  gem 'spork', '~> 0.9.0.rc'
end

这是我的环境。rb:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Project::Application.initialize!

谢谢!

I upgraded to rails 3.1 and I have some problems with my tests now that worked perfectly before.

I get the following warning before the tests:

DEPRECATION WARNING: ActiveRecord::Associations::AssociationCollection is deprecated! Use ActiveRecord::Associations::CollectionProxy instead. (called from at /home/user/rails_projects/project/config/environment.rb:5)

How can I use CollectionProxy instead of AssociationCollection?

Here is my Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'jquery-rails'
gem "therubyracer", "~> 0.9.4"

gem 'carrierwave', '0.5.6'
gem 'haml', '~>3.1.2'
gem 'mysql2', '0.3.7'
gem 'rmagick', '2.13.1'
gem 'sitemap_generator', '2.0.1'
gem 'whenever', '0.6.8', :require => false
gem 'will_paginate', '3.0.pre2'

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate-models', '1.0.4'
  gem 'faker', '0.9.5', :require => false
  gem 'ruby-debug19', '0.11.6'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.3'
  gem 'factory_girl_rails', '1.0'
  gem 'spork', '~> 0.9.0.rc'
end

This is my environment.rb:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Project::Application.initialize!

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捶死心动 2024-12-13 09:36:32

我遇到了同样的问题,并通过升级到最新版本的 will_paginate 修复了它。因此,将: gem 'will_paginate', '3.0.pre2' 更改

为: gem "will_paginate", "~> 3.0.2"

保存 Gemfile,然后进行捆绑安装。

I had the same problem and fixed it by upgrading to the latest version of will_paginate. So, change this: gem 'will_paginate', '3.0.pre2'

to this: gem "will_paginate", "~> 3.0.2"

Save your Gemfile then do bundle install.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文