require File.expand_path(File.dirname(__FILE__) + "/spec_helper") describe "clicks_link" do before do @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end it "should use get by default" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:get_via_redirect).with("/page", {}) @session.clicks_link "Link text" end it "should click get links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:get_via_redirect).with("/page", {}) @session.clicks_get_link "Link text" end it "should click delete links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:delete_via_redirect).with("/page", {}) @session.clicks_delete_link "Link text" end it "should click post links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:post_via_redirect).with("/page", {}) @session.clicks_post_link "Link text" end it "should click put links" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:put_via_redirect).with("/page", {}) @session.clicks_put_link "Link text" end it "should click rails javascript links with authenticity tokens" do @response.stubs(:body).returns(<<-EOS) Posts EOS @session.expects(:post_via_redirect).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") @session.clicks_link "Posts" end it "should click rails javascript delete links" do @response.stubs(:body).returns(<<-EOS) Delete EOS @session.expects(:delete_via_redirect).with("/posts/1", {}) @session.clicks_link "Delete" end it "should click rails javascript post links" do @response.stubs(:body).returns(<<-EOS) Posts EOS @session.expects(:post_via_redirect).with("/posts", {}) @session.clicks_link "Posts" end it "should click rails javascript put links" do @response.stubs(:body).returns(<<-EOS) Put EOS @session.expects(:put_via_redirect).with("/posts", {}) @session.clicks_link "Put" end it "should assert valid response" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:assert_response).with(:success) @session.clicks_link "Link text" end it "should not be case sensitive" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:get_via_redirect).with("/page", {}) @session.clicks_link "LINK TEXT" end it "should match link substrings" do @response.stubs(:body).returns(<<-EOS) This is some cool link text, isn't it? EOS @session.expects(:get_via_redirect).with("/page", {}) @session.clicks_link "Link text" end it "should work with elements in the link" do @response.stubs(:body).returns(<<-EOS) Link text EOS @session.expects(:get_via_redirect).with("/page", {}) @session.clicks_link "Link text" end it "should match the first matching link" do @response.stubs(:body).returns(<<-EOS) Link text Link text EOS @session.expects(:get_via_redirect).with("/page1", {}) @session.clicks_link "Link text" end it "should choose the shortest link text match" do @response.stubs(:body).returns(<<-EOS) Linkerama Link EOS @session.expects(:get_via_redirect).with("/page2", {}) @session.clicks_link "Link" end it "should click link within a selector" do @response.stubs(:body).returns(<<-EOS) Link
EOS @session.expects(:get_via_redirect).with("/page2", {}) @session.clicks_link_within "#container", "Link" end it "should not make request when link is local anchor" do @response.stubs(:body).returns(<<-EOS) Jump to Section 1 EOS # Don't know why @session.expects(:get_via_redirect).never doesn't work here @session.expects(:send).with('get_via_redirect', '#section-1', {}).never @session.clicks_link "Jump to Section 1" end it "should follow relative links" do @session.current_page.stubs(:url).returns("/page") @response.stubs(:body).returns(<<-EOS) Jump to sub page EOS @session.expects(:get_via_redirect).with("/page/sub", {}) @session.clicks_link "Jump to sub page" end it "should follow fully qualified local links" do @response.stubs(:body).returns(<<-EOS) Jump to sub page EOS @session.expects(:get_via_redirect).with("/page/sub", {}) @session.clicks_link "Jump to sub page" end it "should follow fully qualified secure local links" do @response.stubs(:body).returns(<<-EOS) Jump to sub page EOS @session.expects(:https!).with(true) @session.expects(:get_via_redirect).with("/page/sub", {}) @session.clicks_link "Jump to sub page" end it "should follow query parameters" do @session.current_page.stubs(:url).returns("/page") @response.stubs(:body).returns(<<-EOS) Jump to foo bar EOS @session.expects(:get_via_redirect).with("/page?foo=bar", {}) @session.clicks_link "Jump to foo bar" end end