6

コメント ビューに、次のようなコメントに返信するためのリンクがあります。

<%= link_to t('.reply', :default => t("helpers.links.reply")), new_story_comment_path(comment.story, parent_id: comment)%>

テストの一部は次のようになります。

  it "replies to a comment" do
    comment = FactoryGirl.create :comment, story_id: story.id, user_id: user.id
    visit story_path story
    save_and_open_page
    click_link "reply"
    current_path.should eq(new_story_comment_path story.id, parent_id: comment.id)
    ...
  end

次のエラーが表示されます。

  1) Comments replies to a comment
     Failure/Error: current_path.should eq(new_story_comment_path story.id, parent_id: comment.id)

       expected: "/stories/1/comments/new?parent_id=1"
            got: "/stories/1/comments/new"

       (compared using ==)
     # ./spec/requests/comments_spec.rb:23:in `block (2 levels) in <top (required)>'

save_and_open_page でページを確認しましたが、リンクは正しいです:

file:///stories/1/comments/new?parent_id=1

また、test.log ファイルを確認したところ、次の行が表示されます。

Started GET "/stories/1/comments/new?parent_id=1" for 127.0.0.1 at 2012-09-02 21:05:57

正しいはずなのに、毎回このエラーが発生するのはなぜですか?

4

1 に答える 1

7

current_path にはパスのみが含まれ、URL パラメーターは含まれません。URL 全体を取得するには、おそらく current_url を使用する必要があります。

于 2012-09-02T16:42:37.993 に答える