diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-24 12:21:47 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-24 13:29:53 +0100 |
commit | 0eeed68a2c5bfdf4d5404e5191bed4c0c11eda60 (patch) | |
tree | a5e1cdf7188a52ffb276f71c07f623cf97b4bb35 | |
parent | 03471adfe714994524a07c9d99fc38ae9bddfa5c (diff) |
fixup! Remove dependence on default public bodies.
-rw-r--r-- | spec/controllers/admin_public_body_category_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_heading_controller_spec.rb | 27 | ||||
-rw-r--r-- | spec/factories/public_body_categories.rb | 23 | ||||
-rw-r--r-- | spec/factories/public_body_category_links.rb | 12 | ||||
-rw-r--r-- | spec/factories/public_body_headings.rb | 27 | ||||
-rw-r--r-- | spec/models/public_body_category_link_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/public_body_heading_spec.rb | 6 |
7 files changed, 48 insertions, 88 deletions
diff --git a/spec/controllers/admin_public_body_category_controller_spec.rb b/spec/controllers/admin_public_body_category_controller_spec.rb index e0a31e97e..18e6eb822 100644 --- a/spec/controllers/admin_public_body_category_controller_spec.rb +++ b/spec/controllers/admin_public_body_category_controller_spec.rb @@ -33,7 +33,7 @@ describe AdminPublicBodyCategoryController do end it "saves the public body category's heading associations" do - heading = FactoryGirl.create(:popular_heading) + heading = FactoryGirl.create(:public_body_heading) post :create, { :public_body_category => { :title => 'New Category', @@ -76,9 +76,9 @@ describe AdminPublicBodyCategoryController do context 'when editing a public body category' do before do - @category = FactoryGirl.create(:useless_category) + @category = FactoryGirl.create(:public_body_category) I18n.with_locale('es') do - @category.title = 'Los useless ministries' + @category.title = 'Los category' @category.save! end end @@ -93,7 +93,7 @@ describe AdminPublicBodyCategoryController do get :edit, {:id => @category.id, :locale => :en} # When editing a body, the controller returns all available translations - assigns[:category].find_translation_by_locale("es").title.should == 'Los useless ministries' + assigns[:category].find_translation_by_locale("es").title.should == 'Los category' response.should render_template('edit') end end @@ -101,12 +101,15 @@ describe AdminPublicBodyCategoryController do context 'when updating a public body category' do before do - @heading = FactoryGirl.create(:silly_heading) - @category = @heading.public_body_categories.detect do |category| - category.title == 'Useless ministries' - end + @heading = FactoryGirl.create(:public_body_heading) + @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) + @tag = @category.category_tag I18n.with_locale('es') do - @category.title = 'Los useless ministries' + @category.title = 'Los category' @category.save! end end @@ -122,9 +125,8 @@ describe AdminPublicBodyCategoryController do end it "saves edits to a public body category's heading associations" do - @category.public_body_headings.count.should == 1 - @category.public_body_headings.first.name.should == "Silly ministries" - heading = FactoryGirl.create(:popular_heading) + @category.public_body_headings.should == [@heading] + heading = FactoryGirl.create(:public_body_heading) post :update, { :id => @category.id, :public_body_category => { :title => "Renamed" }, :headings => {"heading_#{heading.id}" => heading.id} } @@ -135,11 +137,11 @@ describe AdminPublicBodyCategoryController do it "saves edits to a public body category in another locale" do I18n.with_locale(:es) do - @category.title.should == 'Los useless ministries' + @category.title.should == 'Los category' post :update, { :id => @category.id, :public_body_category => { - :title => "Useless ministries", + :title => "Category", :translated_versions => { @category.id => {:locale => "es", :title => "Renamed"} @@ -154,16 +156,17 @@ describe AdminPublicBodyCategoryController do pbc.title.should == "Renamed" end I18n.with_locale(:en) do - pbc.title.should == "Useless ministries" + pbc.title.should == "Category" end end it "does not save edits to category_tag if the category has associated bodies" 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') pbc = PublicBodyCategory.find(@category.id) - pbc.category_tag.should == "useless_agency" + pbc.category_tag.should == @tag end diff --git a/spec/controllers/admin_public_body_heading_controller_spec.rb b/spec/controllers/admin_public_body_heading_controller_spec.rb index 58a3adbaa..22a21f2c3 100644 --- a/spec/controllers/admin_public_body_heading_controller_spec.rb +++ b/spec/controllers/admin_public_body_heading_controller_spec.rb @@ -57,7 +57,7 @@ describe AdminPublicBodyHeadingController do context 'when editing a public body heading' do before do - @heading = FactoryGirl.create(:silly_heading) + @heading = FactoryGirl.create(:public_body_heading) end render_views @@ -69,7 +69,8 @@ describe AdminPublicBodyHeadingController do context 'when updating a public body heading' do before do - @heading = FactoryGirl.create(:silly_heading) + @heading = FactoryGirl.create(:public_body_heading) + @name = @heading.name end it "saves edits to a public body heading" do @@ -82,11 +83,10 @@ describe AdminPublicBodyHeadingController do it "saves edits to a public body heading in another locale" do I18n.with_locale(:es) do - @heading.name.should == 'Silly ministries' post :update, { :id => @heading.id, :public_body_heading => { - :name => "Silly ministries", + :name => @name, :translated_versions => { @heading.id => {:locale => "es", :name => "Renamed"} @@ -101,25 +101,32 @@ describe AdminPublicBodyHeadingController do heading.name.should == "Renamed" end I18n.with_locale(:en) do - heading.name.should == "Silly ministries" + heading.name.should == @name end end end context 'when destroying a public body heading' do + before do + @heading = FactoryGirl.create(:public_body_heading) + end + it "does not destroy a public body heading that has associated categories" do - heading = FactoryGirl.create(:silly_heading) + 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 - post :destroy, { :id => heading.id } - response.should redirect_to(:controller=>'admin_public_body_heading', :action=>'edit', :id => heading.id) + post :destroy, { :id => @heading.id } + response.should redirect_to(:controller=>'admin_public_body_heading', :action=>'edit', :id => @heading.id) PublicBodyHeading.count.should == n end it "destroys an empty public body heading" do - heading = FactoryGirl.create(:heading_with_no_categories) n = PublicBodyHeading.count - post :destroy, { :id => heading.id } + post :destroy, { :id => @heading.id } response.should redirect_to(:controller=>'admin_public_body_category', :action=>'index') PublicBodyHeading.count.should == n - 1 end diff --git a/spec/factories/public_body_categories.rb b/spec/factories/public_body_categories.rb index a69bf912c..baa474c6b 100644 --- a/spec/factories/public_body_categories.rb +++ b/spec/factories/public_body_categories.rb @@ -1,23 +1,8 @@ FactoryGirl.define do - factory :public_body_categories do - - factory :useless_category do - title 'Useless ministries' - category_tag 'useless_agency' - description "a useless ministry" - end - - factory :lonely_category do - title 'Lonely agencies' - category_tag 'lonely_agency' - description "a lonely agency" - end - - factory :popular_category do - title 'Popular agencies' - category_tag 'popular_agency' - description "a popular agency" - end + factory :public_body_category do + sequence(:title) { |n| "Example Public Body Category #{n}" } + sequence(:category_tag) { |n| "example_tag_#{n}" } + sequence(:description) { |n| "Example Public body Description #{n}" } end end diff --git a/spec/factories/public_body_category_links.rb b/spec/factories/public_body_category_links.rb index 758dd0c52..0b71376be 100644 --- a/spec/factories/public_body_category_links.rb +++ b/spec/factories/public_body_category_links.rb @@ -1,13 +1,3 @@ FactoryGirl.define do - factory :public_body_category_link do - factory :useless_link do - association :public_body_category, :factory => :useless_category - end - factory :lonely_link do - association :public_body_category, :factory => :lonely_category - end - factory :popular_link do - association :public_body_category, :factory => :popular_category - end - end + factory :public_body_category_link end diff --git a/spec/factories/public_body_headings.rb b/spec/factories/public_body_headings.rb index dda40f207..ed54ddada 100644 --- a/spec/factories/public_body_headings.rb +++ b/spec/factories/public_body_headings.rb @@ -1,30 +1,5 @@ FactoryGirl.define do factory :public_body_heading do - - factory :silly_heading do - name 'Silly ministries' - display_order 0 - after_create do |heading| - FactoryGirl.create(:useless_link, :public_body_heading => heading, - :category_display_order => 0) - FactoryGirl.create(:lonely_link, :public_body_heading => heading, - :category_display_order => 1) - end - end - - factory :popular_heading do - name 'Popular agencies' - display_order 1 - after_create do |heading| - FactoryGirl.create(:popular_link, :public_body_heading => heading, - :category_display_order => 0) - end - end - - factory :heading_with_no_categories do - name 'Heading with no categories' - display_order 2 - end - + sequence(:name) { |n| "Example Public Body Heading #{n}" } end end diff --git a/spec/models/public_body_category_link_spec.rb b/spec/models/public_body_category_link_spec.rb index 7108f124b..5964a164e 100644 --- a/spec/models/public_body_category_link_spec.rb +++ b/spec/models/public_body_category_link_spec.rb @@ -17,7 +17,7 @@ describe PublicBodyHeading, 'when validating' do category_link = PublicBodyCategoryLink.new(:public_body_heading => heading, :public_body_category => category) category_link.valid? - category_link.category_display_order.should == PublicBodyCategoryLink.next_display_order(heading_with_no_categories) + category_link.category_display_order.should == PublicBodyCategoryLink.next_display_order(heading) end end @@ -25,8 +25,8 @@ end describe PublicBodyCategoryLink, 'when setting a category display order' do it 'should return 0 if there are no public body headings' do - heading_with_no_categories = FactoryGirl.create(:heading_with_no_categories) - PublicBodyCategoryLink.next_display_order(heading_with_no_categories).should == 0 + heading = FactoryGirl.create(:public_body_heading) + PublicBodyCategoryLink.next_display_order(heading).should == 0 end it 'should return one more than the highest display order if there are public body headings' do diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index 5e581e713..dd0517072 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -37,7 +37,7 @@ describe PublicBodyHeading do end it 'should require a unique name' do - heading = FactoryGirl.create(:silly_heading) + heading = FactoryGirl.create(:public_body_heading) new_heading = PublicBodyHeading.new(:name => heading.name) new_heading.should_not be_valid new_heading.errors[:name].should == ["Name is already taken"] @@ -57,8 +57,8 @@ describe PublicBodyHeading do end it 'should return one more than the highest display order if there are public body headings' do - heading = FactoryGirl.create(:popular_heading) - PublicBodyHeading.next_display_order.should == 2 + heading = FactoryGirl.create(:public_body_heading) + PublicBodyHeading.next_display_order.should == 1 end end end |