require 'spec_helper'
require "will_paginate"
require "active_support/core_ext/hash"
require "active_support/core_ext/object"
describe Datagrid::Helper do
subject {ActionView::Base.new}
before(:each) do
subject.stub!(:params).and_return({})
subject.stub(:url_for) do |options|
options.to_param
end
end
let(:group) { Group.create!(:name => "Pop") }
let!(:entry) { Entry.create!(
:group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
) }
let(:grid) { SimpleReport.new }
describe ".datagrid_table" do
before(:each) do
subject.stub!(:datagrid_order_for).and_return(subject.content_tag(:div, "", :class => "order"))
end
it "should return data table html" do
subject.datagrid_table(grid).should equal_to_dom(<<-HTML)
HTML
end
it "should support giving assets explicitly" do
other_entry = Entry.create!(entry.attributes)
subject.datagrid_table(grid, [entry]).should equal_to_dom(<<-HTML)
HTML
end
it "should support giving assets implicitly" do
other_entry = Entry.create!(entry.attributes)
subject.datagrid_table(grid, [entry]).should equal_to_dom(<<-HTML)
HTML
end
it "should support cycle option" do
subject.datagrid_rows(grid, [entry], :cycle => ["odd", "even"]).should equal_to_dom(<<-HTML)
Pop |
Star |
HTML
end
it "should support urls" do
rp = test_report do
scope { Entry }
column(:name, :url => lambda {|model| model.name})
end
subject.datagrid_rows(rp, [entry], {}).should equal_to_dom(<<-HTML)
Star |
HTML
end
it "should support conditional urls" do
rp = test_report do
scope { Entry }
column(:name, :url => lambda {false})
end
subject.datagrid_rows(rp, [entry], {}).should equal_to_dom(<<-HTML)
Star |
HTML
end
end
describe ".datagrid_order_for" do
it "should render ordreing layout" do
class OrderedGrid
include Datagrid
scope { Entry }
column(:category)
end
report = OrderedGrid.new(:descending => true, :order => :category)
subject.datagrid_order_for(report, report.column_by_name(:category)).should equal_to_dom(<<-HTML)
HTML
end
end
end