Sha256: 760dad6863fb522b7758dfdb775eaf5511ff24d204d45b251d892e43883bebac

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

require 'spec_helper'

describe Datagrid::Ordering do


  let!(:first) { Entry.create!(:name => "aa")}
  let!(:second) { Entry.create!(:name => "bb")}
  let!(:third) { Entry.create!(:name => "cc")}


  it "should support order" do
    test_report(:order => "name") do
      scope do
        Entry
      end
      column :name
    end.assets.should discover(first, second, third).with_exact_order

  end

  it "should support desc order" do
    test_report(:order => "name", :descending => true) do
      scope do
        Entry
      end
      column :name
    end.assets.should discover(third, second, first).with_exact_order


  end


  it "should raise error if ordered by not existing column" do
    lambda {
      test_report(:order => :hello)
    }.should raise_error(Datagrid::OrderUnsupported)
  end

  it "should raise error if ordered by column without order" do
    lambda do
      test_report(:order => :category) do
        filter(:category, :default, :order => false) do |value|
          self
        end
      end
    end.should raise_error(Datagrid::OrderUnsupported)
  end

  it "should override default order" do

    test_report(:order => :id) do
      scope { Entry.order("id desc")}
      column(:id) do
        self.order("id asc")
      end
    end.assets.should discover(first, second, third).with_exact_order
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datagrid-0.6.4 spec/datagrid/ordering_spec.rb
datagrid-0.6.3 spec/datagrid/ordering_spec.rb
datagrid-0.6.2 spec/datagrid/ordering_spec.rb
datagrid-0.6.0 spec/datagrid/ordering_spec.rb
datagrid-0.5.4 spec/datagrid/ordering_spec.rb
datagrid-0.5.3 spec/datagrid/ordering_spec.rb
datagrid-0.5.2 spec/datagrid/ordering_spec.rb
datagrid-0.5.1 spec/datagrid/ordering_spec.rb
datagrid-0.5.0 spec/datagrid/ordering_spec.rb
datagrid-0.4.1 spec/datagrid/ordering_spec.rb
datagrid-0.4.0 spec/datagrid/ordering_spec.rb
datagrid-0.3.6 spec/datagrid/ordering_spec.rb
datagrid-0.3.5 spec/datagrid/ordering_spec.rb