diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-24 12:22:26 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-24 13:29:57 +0100 |
commit | 50b494ae5e2f99cae0a1b7ecaaef98271d4831f3 (patch) | |
tree | ba071ca829d1926dcf05cc03fa8aa480c442f885 /spec/controllers | |
parent | 0eeed68a2c5bfdf4d5404e5191bed4c0c11eda60 (diff) |
fixup! 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 | 32 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_heading_controller_spec.rb | 12 |
2 files changed, 24 insertions, 20 deletions
diff --git a/spec/controllers/admin_public_body_category_controller_spec.rb b/spec/controllers/admin_public_body_category_controller_spec.rb index 18e6eb822..5037d7671 100644 --- a/spec/controllers/admin_public_body_category_controller_spec.rb +++ b/spec/controllers/admin_public_body_category_controller_spec.rb @@ -196,15 +196,19 @@ describe AdminPublicBodyCategoryController 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 } + @heading = FactoryGirl.create(:public_body_heading) + @first_category = FactoryGirl.create(:public_body_category) + @first_link = FactoryGirl.create(:public_body_category_link, + :public_body_category => @first_category, + :public_body_heading => @heading, + :category_display_order => 0) + @second_category = FactoryGirl.create(:public_body_category) + @second_link = FactoryGirl.create(:public_body_category_link, + :public_body_category => @second_category, + :public_body_heading => @heading, + :category_display_order => 1) + @default_params = { :categories => [@second_category.id, @first_category.id], + :heading_id => @heading } end def make_request(params=@default_params) @@ -215,11 +219,11 @@ describe AdminPublicBodyCategoryController 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 + old_order = [@first_category, @second_category] + new_order = [@second_category, @first_category] + @heading.public_body_categories.should == old_order make_request - @silly_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 @@ -231,7 +235,7 @@ describe AdminPublicBodyCategoryController do context 'when handling invalid input' do it 'should return an "unprocessable entity" status and an error message' do - @lonely_category.destroy + @first_category.destroy make_request assert_response :unprocessable_entity response.body.should match("Couldn't find PublicBodyCategoryLink") diff --git a/spec/controllers/admin_public_body_heading_controller_spec.rb b/spec/controllers/admin_public_body_heading_controller_spec.rb index 22a21f2c3..fc93a22b4 100644 --- a/spec/controllers/admin_public_body_heading_controller_spec.rb +++ b/spec/controllers/admin_public_body_heading_controller_spec.rb @@ -137,9 +137,9 @@ describe AdminPublicBodyHeadingController 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] } + @first = FactoryGirl.create(:public_body_heading, :display_order => 0) + @second = FactoryGirl.create(:public_body_heading, :display_order => 1) + @default_params = { :headings => [@second.id, @first.id] } end def make_request(params=@default_params) @@ -150,8 +150,8 @@ describe AdminPublicBodyHeadingController 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 + PublicBodyHeading.find(@second.id).display_order.should == 0 + PublicBodyHeading.find(@first.id).display_order.should == 1 end it 'should return a "success" status' do @@ -161,7 +161,7 @@ describe AdminPublicBodyHeadingController do end it 'should return an "unprocessable entity" status and an error message' do - @popular_heading.destroy + @first.destroy make_request assert_response :unprocessable_entity response.body.should match("Couldn't find PublicBodyHeading with id") |