spec/helpers_spec.rb in magic_grid-0.11.0 vs spec/helpers_spec.rb in magic_grid-0.11.1
- old
+ new
@@ -18,19 +18,31 @@
double(:connection).tap do |c|
c.stub(:quote_column_name) { |col| col.to_s }
end
end
-def fake_active_record_collection(table_name = 'some_table')
+def fake_active_record_collection(table_name = 'some_table',
+ columns = [:name, :description])
+
+ columns = columns.map { |c|
+ double.tap do |col|
+ col.stub(:name) { c }
+ end
+ }
(1..1000).to_a.tap do |c|
c.stub(:connection => fake_connection)
+ c.stub(:quoted_table_name => table_name)
c.stub(:table_name => table_name)
c.stub(:where) { c }
+ c.stub(:table) {
+ double.tap do |t|
+ t.stub(:columns) { columns }
+ end
+ }
end
end
-
describe MagicGrid::Helpers do
# Let's use the helpers the way they're meant to be used!
include MagicGrid::Helpers
@@ -250,8 +262,54 @@
}.to_not raise_error
end
end
end
end
+
+ context "sorting" do
+ let(:sortable_collection) {
+ columns = column_list.map { |c|
+ double.tap do |col|
+ col.stub(:name) { c }
+ end
+ }
+ collection = fake_active_record_collection.tap do |c|
+ c.stub(:table) {
+ double.tap do |t|
+ t.stub(:columns) { columns }
+ end
+ }
+ end
+ }
+ it "should render sortable column headers when a collection is sortable" do
+ grid = magic_grid(sortable_collection, column_list)
+ grid.should match_select("thead>tr>th.sorter>a>span.ui-icon", column_list.count)
+ end
+
+ # context "when a sort column is given" do
+ # let(:search_param) { 'foobar' }
+ # let(:controller) {
+ # make_controller.tap { |c|
+ # c.stub(:params) { {:grid_id_col => 1} }
+ # }
+ # }
+ # end
+ # context "when a sort order is given" do
+ # let(:controller) {
+ # make_controller.tap { |c|
+ # c.stub(:params) { {:grid_id_order => 1} }
+ # }
+ # }
+ # end
+ # context "when a sort order and column are given" do
+ # let(:search_param) { 'foobar' }
+ # let(:controller) {
+ # make_controller.tap { |c|
+ # c.stub(:params) { {:grid_id_q => 1} }
+ # }
+ # }
+ # end
+ end
+
end
end