Ruby on rails 3 Rails3RSpec2存在以下问题:locale和RESTfull路径
我的rspec文件中的Ruby on rails 3 Rails3RSpec2存在以下问题:locale和RESTfull路径,ruby-on-rails-3,rspec2,Ruby On Rails 3,Rspec2,我的rspec文件中的编辑用户路径(user)有问题: it "should forward to the requested page after signin" do user = Factory(:user) visit edit_user_path(user) fill_in :email, :with => user.email fill_in :password, :with => user.password click_button r
编辑用户路径(user)
有问题:
it "should forward to the requested page after signin" do
user = Factory(:user)
visit edit_user_path(user)
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
response.should render_template('users/edit')
end
我得到这个错误:
Failure/Error: visit edit_user_path(user)
ActionController::RoutingError:
No route matches {:action=>"edit", :controller=>"users", :locale=>#<User id: 1, name: "Max Mustermann", email: "mel@example.com", encrypted_password: "1b0befc5caf12c2abf53d99sdfsd5ba15ebe28362eae21b2fb3...", salt: "331ca07444f5dcee76605bsdfasd95c833b7d5135b36a253723...", created_at: "2011-02-03 18:54:34", updated_at: "2011-02-03 18:54:34">}
当您使用区域设置时,的
url\u可能无法推断正确的参数?试着这样做:
visit edit_user_path(:id=>user.id)
好的,我在测试中找到了解决这个问题的方法(参见)
我将此代码放在spec_helper.rb中
class ActionView::TestCase
class TestController
def default_url_options
{:locale => 'en'}
end
end
end
在spec\u helper.rb
中包含这一点对我很有用:
config.before do
default_url_options[:locale] = I18n.default_locale
end
我试着把它放到config/environments/test.rb
中,为我工作:
config.before do
default_url_options[:locale] = I18n.default_locale
end
config.action\u controller.default\u url\u options={locale:I18n.locale}
您能发布routes.rb
文件的相关部分吗?这里的问题完全相同。但我不想改变我的密码。有没有办法在测试中解决这个问题?对我来说也很有效,但是当路由是新的用户路径时我该怎么办?因为它不接受任何参数