diff options
author | lizconlan <liz@mysociety.org> | 2014-11-14 13:08:19 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-11-19 13:41:31 +0000 |
commit | 0ceaec8e0f0ff2ec49b74d49805f3f7b4cd8e953 (patch) | |
tree | 65bb51abd0ceeacc7bc5671d64878ba476f8edb1 | |
parent | e09f967869bc53751a98bfe2cd88d81feca1423f (diff) |
Fix view bug preventing PublicBodyCategories being deleted in the admin interface
-rw-r--r-- | app/views/admin_public_body_categories/edit.html.erb | 34 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_categories_controller_spec.rb | 14 |
2 files changed, 27 insertions, 21 deletions
diff --git a/app/views/admin_public_body_categories/edit.html.erb b/app/views/admin_public_body_categories/edit.html.erb index 95988d688..0664a0515 100644 --- a/app/views/admin_public_body_categories/edit.html.erb +++ b/app/views/admin_public_body_categories/edit.html.erb @@ -1,14 +1,15 @@ -<h1><%=@title%></h1> +<h1><%= @title %></h1> <div class="row"> - <div class="span8"> - <div id="public_body_category_form"> - <%= form_for @category, :url => admin_category_path(@category), :html => { :class => "form form-horizontal" } do |f| %> - <%= render :partial => 'form', :locals => {:f => f} %> - <div class="form-actions"> - <%= f.submit 'Save', :accesskey => 's', :class => "btn btn-success" %></p> - </div> - <% end %> + <div class="span8"> + <div id="public_body_category_form"> + <%= form_for @category, :url => admin_category_path(@category), :html => { :class => "form form-horizontal" } do |f| %> + <%= render :partial => 'form', :locals => { :f => f } %> + + <div class="form-actions"> + <%= f.submit 'Save', :accesskey => 's', :class => "btn btn-success" %> + </div> + <% end %> </div> </div> @@ -18,13 +19,12 @@ </div> </div> -<% if @tagged_public_bodies.empty? %> - <div class="row"> - <div class="span8"> - <%= form_tag(admin_category_path(@category), :method => 'delete', :class => "form form-inline") do %> - <%= hidden_field_tag(:public_body_id, { :value => @category.id } ) %> - <%= submit_tag "Destroy #{@category.title}", :title => @category.title, :class => "btn btn-danger" %> (this is permanent!) +<div class="row"> + <div class="span8"> + <%= form_for @category, :url => admin_category_path(@category), :method => 'delete', :class => "form form-inline" do |f| %> + <%= f.submit "Destroy #{ @category.title }", + :title => @category.title, + :class => "btn btn-danger" %> (this is permanent!) <% end %> - </div> </div> -<% end %> +</div> diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb index 35454990d..e58677a5d 100644 --- a/spec/controllers/admin_public_body_categories_controller_spec.rb +++ b/spec/controllers/admin_public_body_categories_controller_spec.rb @@ -178,15 +178,21 @@ describe AdminPublicBodyCategoriesController do 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 |