Sha256: ddbe7b57e7acf1a7ec32b1e2da9c8c708eb67bc07625854304f7f463b1d4bc7e

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents


def test_report(attributes = {}, &block)
  klass = test_report_class(&block)
  klass.new(attributes)
end

def test_report_class(&block)
  Class.new.tap do |klass|
    klass.class_eval do
      include Datagrid
    end
    if block
      klass.class_eval(&block)
    end
  end
end

class SimpleReport

  include Datagrid

  scope do
    ::Entry.includes(:group).order("entries.created_at")
  end

  filter(:group_id, :integer, :multiple => true)
  filter(:category, :enum, :select => ["first", "second"])
  filter(:disabled, :eboolean)
  filter(:confirmed, :boolean)

  filter(:name) do |value|
    self.scoped(:conditions => {:name => value})
  end

  column(:group, :order => "groups.name") do
    self.group.name
  end

  column(:name) do |user|
    user.name
  end

  column(:actions, :html => true) do |model|
    render :partial => "actions", :locals => {:model => model}
  end

  column(:pet, :html => lambda {|data| content_tag :em, data}) do
    self.pet.try(:upcase)
  end

  column(:shipping_date, :before => :group)

  column(:access_level, :html => lambda {|data| content_tag :h1, data}, :after => :actions)

  def param_name
    :report
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datagrid-1.0.2 spec/support/simple_report.rb
datagrid-1.0.1 spec/support/simple_report.rb
datagrid-1.0.0 spec/support/simple_report.rb
datagrid-0.9.3 spec/support/simple_report.rb
datagrid-0.9.2 spec/support/simple_report.rb