Sha256: edeb554ba5aad8c03e70831e239141a3a60707d8e2b1e1de10ef36ffc3b9889f

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

require "spec_helper"

describe Datagrid::ColumnNamesAttribute do

  let(:column_names_filter_options) do
    {}
  end

  let(:report) do
    options = column_names_filter_options
    test_report do
      scope { Entry }
      column_names_filter(options)
      column(:id)
      column(:name, :mandatory => true)
      column(:category)
    end
  end
  subject { report }


  let!(:entry) do
    Entry.create!(:name => 'hello', :category => 'greeting')
  end

  it "should work" do
    subject.column_names = [:id]
    subject.mandatory_columns.map(&:name).should == [:name]
    subject.optional_columns.map(&:name).should == [:id, :category]
    subject.data.should == [["Id", "Name"], [entry.id, "hello"]]
    columns_filter = subject.filter_by_name(:column_names)
    columns_filter.should_not be_nil
    columns_filter.select(subject).should == [["Id", :id], ["Category", :category]]
  end

  it "should show only mandatory columns by default" do
    subject.row_for(entry).should == [ "hello" ]
    subject.column_names = ["name", "category"]
    subject.row_for(entry).should == ["hello", "greeting"]
  end


  context "when default option is passed to column_names_filter" do
    let(:column_names_filter_options) do
      { :default => [:id] }
    end
    its(:data) { should == [["Id", "Name"], [entry.id, 'hello']] }

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
datagrid-1.1.2 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.1.1 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.1.0 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.5 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.4 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.3 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.2 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.1 spec/datagrid/column_names_attribute_spec.rb
datagrid-1.0.0 spec/datagrid/column_names_attribute_spec.rb