Sha256: 4dd49b2058f6488a14798390f328e46563a4f985ba015fe88d80d4622c12a55c

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'

describe Datagrid::Filters::EnumFilter do

  it "should support select option" do
    test_report do
      scope {Entry}
      filter(:group_id, :enum, :select =>  [1,2] )
    end.class.filter_by_name(:group_id).select.should == [1,2]
  end

  it "should support select option as proc" do
    test_report do
      scope {Entry}
      filter(:group_id, :enum, :select => proc { [1,2] })
    end.class.filter_by_name(:group_id).select.should == [1,2]
  end

  it "should support select option as proc with instace input" do
    klass = test_report do
              scope {Entry}
              filter(:group_id, :enum, :select => proc { |obj| obj.object_id })
            end.class
    instance = klass.new
    klass.filter_by_name(:group_id).select(instance).should == instance.object_id
  end
  
  it "should initialize select option only on instanciation" do
    class ReportWithLazySelect
      include Datagrid
      scope {Entry}
      filter(:group_id, :enum, :select => proc { raise 'hello' })
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datagrid-0.9.0 spec/datagrid/filters/enum_filter_spec.rb