diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-19 09:22:35 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-22 12:42:08 +0100 |
commit | ffb60e1a6cbd35c8cae4902bb28d7ba4f32ed740 (patch) | |
tree | aec571c88d7001b83745f10ece089f12ee1f8e13 /spec/controllers | |
parent | 897177e0660a3d567fcb4c4d203c1f7da8b5b0a4 (diff) |
Add actions for reordering public body headings and categories.
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/admin_public_body_category_controller_spec.rb | 51 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_heading_controller_spec.rb | 39 |
2 files changed, 89 insertions, 1 deletions
diff --git a/spec/controllers/admin_public_body_category_controller_spec.rb b/spec/controllers/admin_public_body_category_controller_spec.rb index 4f921bb9b..47ae38176 100644 --- a/spec/controllers/admin_public_body_category_controller_spec.rb +++ b/spec/controllers/admin_public_body_category_controller_spec.rb @@ -171,4 +171,55 @@ describe AdminPublicBodyCategoryController do PublicBodyCategory.count.should == n - 1 end end + + context 'when reordering public body categories' do + + render_views + + before do + @silly_heading = FactoryGirl.create(:silly_heading) + @useless_category = @silly_heading.public_body_categories.detect do |category| + category.title == 'Useless ministries' + end + @lonely_category = @silly_heading.public_body_categories.detect do |category| + category.title == 'Lonely agencies' + end + @default_params = { :categories => [@lonely_category.id, @useless_category.id], + :heading_id => @silly_heading } + end + + def make_request(params=@default_params) + post :reorder, params + end + + context 'when handling valid input' do + + it 'should reorder categories for the heading according to their position \ + in the submitted params' do + old_order = [@useless_category, @lonely_category] + new_order = [@lonely_category, @useless_category] + @silly_heading.public_body_categories.should == old_order + make_request + @silly_heading.public_body_categories(reload=true).should == new_order + end + + it 'should return a success status' do + make_request + response.should be_success + end + end + + context 'when handling invalid input' do + + it 'should return an "unprocessable entity" status and an error message' do + @lonely_category.destroy + make_request + assert_response :unprocessable_entity + response.body.should match("Couldn't find PublicBodyCategoryLink") + end + + 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 2a8214703..58a3adbaa 100644 --- a/spec/controllers/admin_public_body_heading_controller_spec.rb +++ b/spec/controllers/admin_public_body_heading_controller_spec.rb @@ -117,11 +117,48 @@ describe AdminPublicBodyHeadingController do end it "destroys an empty public body heading" do - heading = PublicBodyHeading.create(:name => "Empty Heading") + heading = FactoryGirl.create(:heading_with_no_categories) n = PublicBodyHeading.count post :destroy, { :id => heading.id } response.should redirect_to(:controller=>'admin_public_body_category', :action=>'index') PublicBodyHeading.count.should == n - 1 end end + + context 'when reordering public body headings' do + + render_views + + before do + @silly_heading = FactoryGirl.create(:silly_heading) + @popular_heading = FactoryGirl.create(:popular_heading) + @default_params = { :headings => [@popular_heading.id, @silly_heading.id] } + end + + def make_request(params=@default_params) + post :reorder, params + end + + context 'when handling valid input' do + + it 'should reorder headings according to their position in the submitted params' do + make_request + PublicBodyHeading.find(@popular_heading.id).display_order.should == 0 + PublicBodyHeading.find(@silly_heading.id).display_order.should == 1 + end + + it 'should return a "success" status' do + make_request + response.should be_success + end + end + + it 'should return an "unprocessable entity" status and an error message' do + @popular_heading.destroy + make_request + assert_response :unprocessable_entity + response.body.should match("Couldn't find PublicBodyHeading with id") + end + + end end |