<commit_before>require "spec_helper"

describe TableCloth::Presenters::Sortable do
  let(:dummy_table) { FactoryGirl.build(:dummy_table, name: {sortable: true} ) }
  let(:dummy_model) { FactoryGirl.build(:dummy_model) }
  let(:objects) { FactoryGirl.build_list(:dummy_model, 3) }
  let(:view_context) { ActionView::Base.new }
  subject { TableCloth::Presenters::Sortable.new(objects, dummy_table, view_context) }
  let(:params) { {sort_by: "", direction: "asc"} }
  let(:column) { subject.columns.first }

  before do
    dummy_table.presenter(described_class)
    subject.stub params: params
    column.options[:sortable] = true
  end

  it "inherits from default" do
    expect(described_class).to be < TableCloth::Presenters::Default
  end

  context ".render_sortable" do
    before do
      column.stub human_name: "Header"
    end

    it "renders an a tag" do
      element = to_element(subject.render_sortable(column), "a")
      expect(element.node_name).to eq("a")
    end

    it "renders an a tag with href direction keys" do
      params[:direction] = "desc"
      element = to_element(subject.render_sortable(column), "a")
      query_string = element[:href]

      expect(query_string).to include "direction=asc"
    end

    it "renders an a tag with href sort by keys" do
      params[:sort_by] = "desc"
      element = to_element(subject.render_sortable(column), "a")
      query_string = element[:href]

      expect(query_string).to include "sort_by=#{column.name}"
    end
  end

  context "thead" do
    it "includes a css class for a sortable column" do
      header = to_element(subject.render_header, "thead")
      expect(header.at_css("th.sortable-column")).to be_present
    end
  end
end<commit_msg>Pending spec for sortable headers.<commit_after>require "spec_helper"

describe TableCloth::Presenters::Sortable do
  let(:dummy_table) { FactoryGirl.build(:dummy_table, name: {sortable: true} ) }
  let(:dummy_model) { FactoryGirl.build(:dummy_model) }
  let(:objects) { FactoryGirl.build_list(:dummy_model, 3) }
  let(:view_context) { ActionView::Base.new }
  subject { TableCloth::Presenters::Sortable.new(objects, dummy_table, view_context) }
  let(:params) { {sort_by: "", direction: "asc"} }
  let(:column) { subject.columns.first }

  before do
    dummy_table.presenter(described_class)
    subject.stub params: params
    column.options[:sortable] = true
  end

  it "inherits from default" do
    expect(described_class).to be < TableCloth::Presenters::Default
  end

  context ".render_sortable" do
    before do
      column.stub human_name: "Header"
    end

    it "renders an a tag" do
      element = to_element(subject.render_sortable(column), "a")
      expect(element.node_name).to eq("a")
    end

    it "renders an a tag with href direction keys" do
      params[:direction] = "desc"
      element = to_element(subject.render_sortable(column), "a")
      query_string = element[:href]

      expect(query_string).to include "direction=asc"
    end

    it "renders an a tag with href sort by keys" do
      params[:sort_by] = "desc"
      element = to_element(subject.render_sortable(column), "a")
      query_string = element[:href]

      expect(query_string).to include "sort_by=#{column.name}"
    end
  end

  context "thead" do
    pending "includes a css class for a sortable column" do
      header = to_element(subject.render_header, "thead")
      expect(header.at_css("th.sortable-column")).to be_present
    end
  end
end
{'fraction_non_alphanumeric': 0.11918437679494544, 'fraction_numerical': 0.0005743825387708214, 'mean_word_length': 3.850974930362117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2631835', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1100, 'n_words': 265}