我的控制器只有两个操作 - :create
和:delete
。因此定义了创建动作:
def create
# some code...
if @thing.save
redirect_to :back, :notice => "Successfully created."
else
redirect_to :back, :notice => "Successfully deleted."
end
end
我使用...
链接到该操作<%= link_to "Become a friend", things_path(...), :method => :post %>
...在视图中。
当我在浏览器中与应用程序进行交互时,此工作正常。但是,我希望使用Webrat的帮助方法 - click_link "Become a friend"
使用RSpec集成测试来测试此功能 - 我认为这是正确的。但是我得到了这个错误
Failure/Error: click_link "I like Person-1's taste"
AbstractController::ActionNotFound:
The action 'index' could not be found for ThingsController
我可以在Things控制器中创建一个空的索引操作,但这会违反KISS Principle。
我该如何解决/修复此问题?对于这样的案例,有没有最佳实践?
答案 0 :(得分:0)
问题是:method =&gt; :post使rails创建一个表单,然后在单击该链接时提交该表单。这仅适用于启用了javascript的webrat不支持开箱即用。看看https://github.com/brynary/webrat/wiki并尝试使用selenium运行测试。由于selenium实际上使用的是真正的浏览器,因此您的规格应该会运行。