diff options
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/admin_public_body_category_controller_spec.rb | 23 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_heading_controller_spec.rb | 24 |
2 files changed, 35 insertions, 12 deletions
diff --git a/spec/controllers/admin_public_body_category_controller_spec.rb b/spec/controllers/admin_public_body_category_controller_spec.rb index 5037d7671..6c14c5d93 100644 --- a/spec/controllers/admin_public_body_category_controller_spec.rb +++ b/spec/controllers/admin_public_body_category_controller_spec.rb @@ -209,6 +209,8 @@ describe AdminPublicBodyCategoryController do :category_display_order => 1) @default_params = { :categories => [@second_category.id, @first_category.id], :heading_id => @heading } + @old_order = [@first_category, @second_category] + @new_order = [@second_category, @first_category] end def make_request(params=@default_params) @@ -219,11 +221,10 @@ describe AdminPublicBodyCategoryController do it 'should reorder categories for the heading according to their position \ in the submitted params' do - old_order = [@first_category, @second_category] - new_order = [@second_category, @first_category] - @heading.public_body_categories.should == old_order + + @heading.public_body_categories.should == @old_order make_request - @heading.public_body_categories(reload=true).should == new_order + @heading.public_body_categories(reload=true).should == @new_order end it 'should return a success status' do @@ -234,13 +235,23 @@ describe AdminPublicBodyCategoryController do context 'when handling invalid input' do + before do + @new_category = FactoryGirl.create(:public_body_category) + @params = @default_params.merge(:categories => [@second_category.id, + @first_category.id, + @new_category.id]) + end + it 'should return an "unprocessable entity" status and an error message' do - @first_category.destroy - make_request + make_request(@params) assert_response :unprocessable_entity response.body.should match("Couldn't find PublicBodyCategoryLink") end + it 'should not reorder the categories for the heading' do + make_request(@params) + @heading.public_body_categories(reload=true).should == @old_order + end end end diff --git a/spec/controllers/admin_public_body_heading_controller_spec.rb b/spec/controllers/admin_public_body_heading_controller_spec.rb index fc93a22b4..d41b09807 100644 --- a/spec/controllers/admin_public_body_heading_controller_spec.rb +++ b/spec/controllers/admin_public_body_heading_controller_spec.rb @@ -160,12 +160,24 @@ describe AdminPublicBodyHeadingController do end end - it 'should return an "unprocessable entity" status and an error message' do - @first.destroy - make_request - assert_response :unprocessable_entity - response.body.should match("Couldn't find PublicBodyHeading with id") - end + context 'when handling invalid input' do + + before do + @params = { :headings => [@second.id, @first.id, @second.id + 1]} + end + + it 'should return an "unprocessable entity" status and an error message' do + make_request(@params) + assert_response :unprocessable_entity + response.body.should match("Couldn't find PublicBodyHeading with id") + end + + it 'should not reorder headings' do + make_request(@params) + PublicBodyHeading.find(@first.id).display_order.should == 0 + PublicBodyHeading.find(@second.id).display_order.should == 1 + end + end end end |