From ae51a2d804263d0cf5e6da6cd94b05543c7f185f Mon Sep 17 00:00:00 2001 From: did Date: Thu, 10 Mar 2011 01:15:48 +0100 Subject: [PATCH] write specs for the ordered contents --- spec/models/content_type_spec.rb | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/models/content_type_spec.rb b/spec/models/content_type_spec.rb index 6381c2fa..496a4e32 100644 --- a/spec/models/content_type_spec.rb +++ b/spec/models/content_type_spec.rb @@ -46,4 +46,41 @@ describe ContentType do end + context '#ordered_contents' do + + before(:each) do + @content_type = Factory.build(:content_type, :order_by => 'created_at') + @content_1 = stub('content_1', :name => 'Did', :_position_in_list => 2) + @content_2 = stub('content_2', :name => 'Sacha', :_position_in_list => 1) + @content_type.stubs(:contents).returns([@content_1, @content_2]) + end + + it 'orders with the ASC direction by default' do + @content_type.asc_order?.should == true + end + + it 'has a getter for manual order' do + @content_type.order_manually?.should == false + @content_type.order_by = '_position_in_list' + @content_type.order_manually?.should == true + end + + it 'returns a list of contents ordered manually' do + @content_type.order_by = '_position_in_list' + @content_type.ordered_contents.collect(&:name).should == %w(Sacha Did) + end + + it 'returns a list of contents ordered by a column specified by order_by (ASC)' do + @content_type.order_by = 'name' + @content_type.ordered_contents.collect(&:name).should == %w(Did Sacha) + end + + it 'returns a list of contents ordered by a column specified by order_by (DESC)' do + @content_type.order_by = 'name' + @content_type.order_direction = 'desc' + @content_type.ordered_contents.collect(&:name).should == %w(Sacha Did) + end + + end + end