aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/public_body_category_link_spec.rb28
-rw-r--r--spec/models/public_body_category_spec.rb6
-rw-r--r--spec/models/public_body_heading_spec.rb54
3 files changed, 74 insertions, 14 deletions
diff --git a/spec/models/public_body_category_link_spec.rb b/spec/models/public_body_category_link_spec.rb
index 9fce062a3..105f97864 100644
--- a/spec/models/public_body_category_link_spec.rb
+++ b/spec/models/public_body_category_link_spec.rb
@@ -9,5 +9,29 @@
require 'spec_helper'
-describe PublicBodyCategoryLink do
-end \ No newline at end of file
+describe PublicBodyHeading, 'when validating' do
+
+ it 'should set a default display order based on the next available display order' do
+ heading_with_no_categories = FactoryGirl.create(:heading_with_no_categories)
+ lonely_category = FactoryGirl.create(:lonely_category)
+ category_link = PublicBodyCategoryLink.new(:heading => heading_with_no_categories,
+ :category_link => lonely_category)
+ category_link.valid?
+ category_link.category_display_order.should == PublicBodyCategoryLink.next_display_order(heading_with_no_categories)
+ end
+
+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
+ end
+
+ it 'should return one more than the highest display order if there are public body headings' do
+ silly_heading = FactoryGirl.create(:silly_heading)
+ PublicBodyCategoryLink.next_display_order(silly_heading).should == 2
+ end
+
+end
diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb
index d892c8bda..d3c91e4f8 100644
--- a/spec/models/public_body_category_spec.rb
+++ b/spec/models/public_body_category_spec.rb
@@ -33,13 +33,13 @@ describe PublicBodyCategory do
cat_group2[0].public_body_category_links.where(
:public_body_heading_id => headings[1].id).
first.
- category_display_order.should eq 1
+ category_display_order.should eq 0
cat_group2[1].title.should eq "Aardvark"
cat_group2[1].public_body_category_links.where(
:public_body_heading_id => headings[1].id).
first.
- category_display_order.should eq 2
+ category_display_order.should eq 1
end
end
@@ -116,4 +116,4 @@ describe PublicBodyCategory do
end
end
end
-end \ No newline at end of file
+end
diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb
index ec5c3ad2c..3ca01c648 100644
--- a/spec/models/public_body_heading_spec.rb
+++ b/spec/models/public_body_heading_spec.rb
@@ -10,18 +10,54 @@
require 'spec_helper'
-describe PublicBodyHeading do
+describe PublicBodyHeading, 'when loading the data' do
+
before do
load_test_categories
end
- describe 'when loading the data' do
- it 'should use the display_order field to preserve the original data order' do
- headings = PublicBodyHeading.all
- headings[0].name.should eq 'Local and regional'
- headings[0].display_order.should eq 1
- headings[1].name.should eq 'Miscellaneous'
- headings[1].display_order.should eq 2
- end
+ it 'should use the display_order field to preserve the original data order' do
+ headings = PublicBodyHeading.all
+ headings[0].name.should eq 'Local and regional'
+ headings[0].display_order.should eq 1
+ headings[1].name.should eq 'Miscellaneous'
+ headings[1].display_order.should eq 2
+ end
+
+end
+
+describe PublicBodyHeading, 'when validating' do
+
+ it 'should require a name' do
+ heading = PublicBodyHeading.new
+ heading.should_not be_valid
+ heading.errors[:name].should == ["Name can't be blank"]
+ end
+
+ it 'should require a unique name' do
+ heading = FactoryGirl.create(:silly_heading)
+ new_heading = PublicBodyHeading.new(:name => heading.name)
+ new_heading.should_not be_valid
+ new_heading.errors[:name].should == ["Name is already taken"]
+ end
+
+ it 'should set a default display order based on the next available display order' do
+ heading = PublicBodyHeading.new
+ heading.valid?
+ heading.display_order.should == PublicBodyHeading.next_display_order
end
+
+end
+
+describe PublicBodyHeading, 'when setting a display order' do
+
+ it 'should return 0 if there are no public body headings' do
+ PublicBodyHeading.next_display_order.should == 0
+ 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
+ end
+
end