Rspec“编辑”动作路由

时间:2014-01-22 07:40:29

标签: ruby-on-rails ruby rspec

始终无法正确测试“编辑”操作的路线。我怀疑是因为'edit'动作与edit_ids相关联?即,你永远不会看/编辑,但总是/编辑/ asdfsafsadfds(ID字符串)。

在这种情况下不确定约定是什么。这是我有的RSpec:

describe "create - with valid data" do
    it "redirects to edit action" do
        post :create, request: FactoryGirl.attributes_for(:request)
        response.should redirect_to :controller => :requests, :action => :edit
    end
...
end

请注意,我还尝试了redirect_to'edit',redirect_to:edit,render_template'edit',render_template:edit,所有这些都失败了。供参考:

控制器代码:

def create
    @request = Request.new(request_params)
    if @request.save
    ...
    redirect_to edit_request_path(@request.edit_id)
    ...
    end
end

路线代码:

get 'edit/:edit_id', to: 'requests#edit', as: 'edit_request'

1 个答案:

答案 0 :(得分:0)

OH根据我的最后评论@ veritas1,你在那里得到了90%。我试图做的是对的,我写错了。它应该是

redirect_to edit_request_url(assigns[:request].edit_id)

不指定[:request.edit_id]