diff options
Diffstat (limited to 'spec')
3 files changed, 90 insertions, 18 deletions
diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb index 35454990d..4c641bd75 100644 --- a/spec/controllers/admin_public_body_categories_controller_spec.rb +++ b/spec/controllers/admin_public_body_categories_controller_spec.rb @@ -6,6 +6,7 @@ describe AdminPublicBodyCategoriesController do it 'shows the index page' do get :index + expect(response).to be_success end end @@ -14,6 +15,12 @@ describe AdminPublicBodyCategoriesController do get :new assigns[:category].should be_a(PublicBodyCategory) end + + it 'renders the new template' do + get :new + expect(response).to render_template('new') + end + end context 'when creating a public body category' do @@ -44,7 +51,6 @@ describe AdminPublicBodyCategoriesController do category.public_body_headings.should == [heading] end - it 'creates a new public body category with multiple locales' do n = PublicBodyCategory.count post :create, { @@ -69,6 +75,12 @@ describe AdminPublicBodyCategoriesController do response.should redirect_to(admin_categories_path) end + + it "renders the form if creating the record was unsuccessful" do + post :create, :public_body_category => { :title => '' } + expect(response).to render_template('new') + end + end context 'when editing a public body category' do @@ -82,14 +94,21 @@ describe AdminPublicBodyCategoriesController do render_views - it "edits a public body category" do + it "finds the requested category" do get :edit, :id => @category.id + expect(assigns[:category]).to eq(@category) + end + + it "renders the edit template" do + get :edit, :id => @category.id + expect(assigns[:category]).to render_template('edit') end it "edits a public body in another locale" do - get :edit, {:id => @category.id, :locale => :en} + get :edit, { :id => @category.id, :locale => :en } - # When editing a body, the controller returns all available translations + # When editing a body, the controller returns all available + # translations assigns[:category].find_translation_by_locale("es").title.should == 'Los category' response.should render_template('edit') end @@ -161,7 +180,9 @@ describe AdminPublicBodyCategoriesController do body = FactoryGirl.create(:public_body, :tag_string => @tag) post :update, { :id => @category.id, :public_body_category => { :category_tag => "renamed" } } - request.flash[:notice].should include('can\'t') + + msg = "There are authorities associated with this category, so the tag can't be renamed" + request.flash[:error].should == msg pbc = PublicBodyCategory.find(@category.id) pbc.category_tag.should == @tag end @@ -175,18 +196,39 @@ describe AdminPublicBodyCategoriesController do pbc = PublicBodyCategory.find(category.id) pbc.category_tag.should == "renamed" end + + it "redirects to the edit page after a successful update" do + post :update, { :id => @category.id, + :public_body_category => { :title => "Renamed" } } + + expect(response).to redirect_to(edit_admin_category_path(@category)) + end + + it "re-renders the edit form after an unsuccessful update" do + post :update, { :id => @category.id, + :public_body_category => { :title => '' } } + + expect(response).to render_template('edit') + end + end context 'when destroying a public body category' do - - it "destroys a public body category" do + it "destroys empty public body categories" do pbc = PublicBodyCategory.create(:title => "Empty Category", :category_tag => "empty", :description => "-") n = PublicBodyCategory.count post :destroy, { :id => pbc.id } response.should redirect_to(admin_categories_path) PublicBodyCategory.count.should == n - 1 end - end - + it "destroys non-empty public body categories" do + authority = FactoryGirl.create(:public_body) + pbc = PublicBodyCategory.create(:title => "In-Use Category", :category_tag => "empty", :description => "-", :authorities => [authority]) + n = PublicBodyCategory.count + post :destroy, { :id => pbc.id } + response.should redirect_to(admin_categories_path) + PublicBodyCategory.count.should == n - 1 + end + end end diff --git a/spec/controllers/admin_public_body_headings_controller_spec.rb b/spec/controllers/admin_public_body_headings_controller_spec.rb index 31517d238..afbe0fa30 100644 --- a/spec/controllers/admin_public_body_headings_controller_spec.rb +++ b/spec/controllers/admin_public_body_headings_controller_spec.rb @@ -7,6 +7,11 @@ describe AdminPublicBodyHeadingsController do get :new assigns[:heading].should be_a(PublicBodyHeading) end + + it 'renders the new template' do + get :new + expect(response).to render_template('new') + end end context 'when creating a public body heading' do @@ -45,6 +50,12 @@ describe AdminPublicBodyHeadingsController do response.should redirect_to(admin_categories_path) end + + it "renders the form if creating the record was unsuccessful" do + post :create, :public_body_heading => { :name => '' } + expect(response).to render_template('new') + end + end context 'when editing a public body heading' do @@ -54,8 +65,14 @@ describe AdminPublicBodyHeadingsController do render_views - it "edits a public body heading" do + it "finds the requested heading" do get :edit, :id => @heading.id + expect(assigns[:heading]).to eq(@heading) + end + + it "renders the edit template" do + get :edit, :id => @heading.id + expect(assigns[:heading]).to render_template('edit') end end @@ -96,6 +113,21 @@ describe AdminPublicBodyHeadingsController do heading.name.should == @name end end + + it "redirects to the edit page after a successful update" do + post :update, { :id => @heading.id, + :public_body_heading => { :name => "Renamed" } } + + expect(response).to redirect_to(edit_admin_heading_path(@heading)) + end + + it "re-renders the edit form after an unsuccessful update" do + post :update, { :id => @heading.id, + :public_body_heading => { :name => '' } } + + expect(response).to render_template('edit') + end + end context 'when destroying a public body heading' do @@ -104,16 +136,19 @@ describe AdminPublicBodyHeadingsController do @heading = FactoryGirl.create(:public_body_heading) end - it "does not destroy a public body heading that has associated categories" do + it "destroys a public body heading that has associated categories" do category = FactoryGirl.create(:public_body_category) link = FactoryGirl.create(:public_body_category_link, :public_body_category => category, :public_body_heading => @heading, :category_display_order => 0) n = PublicBodyHeading.count + n_links = PublicBodyCategoryLink.count + post :destroy, { :id => @heading.id } - response.should redirect_to(edit_admin_heading_path(@heading)) - PublicBodyHeading.count.should == n + response.should redirect_to(admin_categories_path) + PublicBodyHeading.count.should == n - 1 + PublicBodyCategoryLink.count.should == n_links - 1 end it "destroys an empty public body heading" do diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index fc7143522..840b4bb28 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -7,7 +7,6 @@ describe PublicBodyController, "when showing a body" do render_views before(:each) do - PublicBodyCategory.stub!(:load_categories) load_raw_emails_data get_fixtures_xapian_index end @@ -76,10 +75,6 @@ end describe PublicBodyController, "when listing bodies" do render_views - before(:each) do - PublicBodyCategory.stub!(:load_categories) - end - it "should be successful" do get :list response.should be_success |