spec/table_spec.rb in tableficate-0.1.3 vs spec/table_spec.rb in tableficate-0.2.0

- old
+ new

@@ -1,10 +1,13 @@ require 'spec_helper' describe Tableficate::Table do before(:each) do - @table = Tableficate::Table.new(nil, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}}) + template = mock('Template') + template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([])) + template.lookup_context.stub!(:exists?).and_return(true) + @table = Tableficate::Table.new(template, NobelPrizeWinner.limit(1), {}, {current_sort: {column: :first_name, dir: 'asc'}}) end it 'should have the current sort if provided' do @table.current_sort.should == {column: :first_name, dir: 'asc'} end @@ -63,32 +66,54 @@ table.column(:first_name, show_sort: false) table.show_sort?.should be false end - it 'should add an InputFilter' do - @table.input_filter(:first_name, label: 'First') - @table.input_filter(:last_name, label: 'Last') + it 'should add an Input filter' do + @table.filter(:first_name, label: 'First') + @table.filter(:last_name, label: 'Last') @table.filters.first.name.should == :first_name - @table.filters.first.is_a?(Tableficate::InputFilter).should be true + @table.filters.first.is_a?(Tableficate::Filter::Input).should be true @table.filters.last.name.should == :last_name end - it 'should add an InputRangeFilter' do - @table.input_range_filter(:first_name, label: 'First') - @table.input_range_filter(:last_name, label: 'Last') + it 'should raise an error if Input is passed an unknown type' do + lambda {@table.filter(:first_name, as: :foo)}.should raise_error(Tableficate::Filter::UnknownInputType) + end + it 'should add the Input for known types and pass through the type based on :as' do + @table.filter(:first_name, as: :search) + + @table.filters.first.is_a?(Tableficate::Filter::Input).should be true + @table.filters.first.options[:type].should == 'search' + end + + it 'should add a InputRange filter' do + @table.filter_range(:first_name, label: 'First') + @table.filter_range(:last_name, label: 'Last') + @table.filters.first.name.should == :first_name - @table.filters.first.is_a?(Tableficate::InputRangeFilter).should be true + @table.filters.first.is_a?(Tableficate::Filter::InputRange).should be true @table.filters.last.name.should == :last_name end - it 'should add an SelectFilter' do - @table.select_filter(:first_name, {}, label: 'First') - @table.select_filter(:last_name, {}, label: 'Last') + it 'should raise an error if InputRange is passed an unknown type' do + lambda {@table.filter_range(:first_name, as: :foo)}.should raise_error(Tableficate::Filter::UnknownInputType) + end + it 'should add the InputRange for known types and pass through the type based on :as' do + @table.filter_range(:first_name, as: :search) + + @table.filters.first.is_a?(Tableficate::Filter::InputRange).should be true + @table.filters.first.options[:type].should == 'search' + end + + it 'should add a Select filter' do + @table.filter(:first_name, collection: {}, label: 'First') + @table.filter(:last_name, collection: {}, label: 'Last') + @table.filters.first.name.should == :first_name - @table.filters.first.is_a?(Tableficate::SelectFilter).should be true + @table.filters.first.is_a?(Tableficate::Filter::Select).should be true @table.filters.last.name.should == :last_name end end