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)
Group
Name
Pop Star
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 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)
ASC DESC
HTML end end end