Rails 3.1 的 Rspec 给出弃用警告 ActiveRecord::Associations::AssociationCollection 已弃用?
我升级到了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并通过升级到最新版本的 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.