<commit_before>require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "click_link" do
  it "should click links with ampertands" do
    with_html <<-HTML
      <html>
      <a href="/page">Save &amp; go back</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Save & go back"
  end

  it "should use get by default" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Link text"
  end

  it "should click get links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Link text", :method => :get
  end

  it "should click link on substring" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "ink tex", :method => :get
  end

  it "should click delete links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:delete).with("/page", {})
    click_link "Link text", :method => :delete
  end


  it "should click post links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/page", {})
    click_link "Link text", :method => :post
  end

  it "should click put links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:put).with("/page", {})
    click_link "Link text", :method => :put
  end

  it "should click links by regexp" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /link [a-z]/i
  end

  it "should click links by id" do
    with_html <<-HTML
      <html>
      <a id="link_text_link" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "link_text_link"
  end

  it "should click links by id regexp" do
    with_html <<-HTML
      <html>
      <a id="link_text_link" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /_text_/
  end

  it "should click links by title" do
    with_html <<-HTML
      <html>
      <a title="piddle" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link 'piddle'
  end

  it "should click links by title regex" do
    with_html <<-HTML
      <html>
      <a title="piddlediddle" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /iddle/
  end


  it "should click rails javascript links with authenticity tokens" do
    with_html <<-HTML
      <html>
      <a href="/posts" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var s = document.createElement('input');
        s.setAttribute('type', 'hidden');
        s.setAttribute('name', 'authenticity_token');
        s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62');
        f.appendChild(s);
        f.submit();
        return false;">Posts</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "<KEY>")
    click_link "Posts"
  end
  
  it "should click rails 2.3.4 javascript links with authenticity tokens" do
    with_html <<-HTML
      <html>
      <a href="/posts" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var s = document.createElement('input');
        s.setAttribute('type', 'hidden');
        s.setAttribute('name', 'authenticity_token');
        s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a');
        f.appendChild(s);
        f.submit();
        return false;">Posts</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "<KEY>=/$a")
    click_link "Posts"
  end

  it "should click rails javascript delete links" do
    with_html <<-HTML
      <html>
      <a href="/posts/1" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var m = document.createElement('input');<commit_msg>Whitespace<commit_after>require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "click_link" do
  it "should click links with ampertands" do
    with_html <<-HTML
      <html>
      <a href="/page">Save &amp; go back</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Save & go back"
  end

  it "should use get by default" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Link text"
  end

  it "should click get links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "Link text", :method => :get
  end

  it "should click link on substring" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "ink tex", :method => :get
  end

  it "should click delete links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:delete).with("/page", {})
    click_link "Link text", :method => :delete
  end


  it "should click post links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/page", {})
    click_link "Link text", :method => :post
  end

  it "should click put links" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:put).with("/page", {})
    click_link "Link text", :method => :put
  end

  it "should click links by regexp" do
    with_html <<-HTML
      <html>
      <a href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /link [a-z]/i
  end

  it "should click links by id" do
    with_html <<-HTML
      <html>
      <a id="link_text_link" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link "link_text_link"
  end

  it "should click links by id regexp" do
    with_html <<-HTML
      <html>
      <a id="link_text_link" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /_text_/
  end

  it "should click links by title" do
    with_html <<-HTML
      <html>
      <a title="piddle" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link 'piddle'
  end

  it "should click links by title regex" do
    with_html <<-HTML
      <html>
      <a title="piddlediddle" href="/page">Link text</a>
      </html>
    HTML
    webrat_session.should_receive(:get).with("/page", {})
    click_link /iddle/
  end


  it "should click rails javascript links with authenticity tokens" do
    with_html <<-HTML
      <html>
      <a href="/posts" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var s = document.createElement('input');
        s.setAttribute('type', 'hidden');
        s.setAttribute('name', 'authenticity_token');
        s.setAttribute('value', '<PASSWORD>cb3<PASSWORD>a60a3<PASSWORD>7e29<PASSWORD>4f74<PASSWORD>');
        f.appendChild(s);
        f.submit();
        return false;">Posts</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "<KEY>")
    click_link "Posts"
  end

  it "should click rails 2.3.4 javascript links with authenticity tokens" do
    with_html <<-HTML
      <html>
      <a href="/posts" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var s = document.createElement('input');
        s.setAttribute('type', 'hidden');
        s.setAttribute('name', 'authenticity_token');
        s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a');
        f.appendChild(s);
        f.submit();
        return false;">Posts</a>
      </html>
    HTML
    webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "<KEY>=/$a")
    click_link "Posts"
  end

  it "should click rails javascript delete links" do
    with_html <<-HTML
      <html>
      <a href="/posts/1" onclick="var f = document.createElement('form');
        f.style.display = 'none';
        this.parentNode.appendChild(f);
        f.method = 'POST';
        f.action = this.href;
        var m = document.createElement('input');
{'fraction_non_alphanumeric': 0.15571325722513626, 'fraction_numerical': 0.009873495834618945, 'mean_word_length': 2.6001480932987784, 'pattern_counts': {'":': 0, '<': 188, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738058', 'n_tokens_mistral': 3315, 'n_tokens_neox': 3214, 'n_words': 751}