diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-24 17:44:43 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-24 17:44:43 +0100 |
commit | fd82802023fec28c0e467c0ba2820489d35ddc9c (patch) | |
tree | 93c4ebb80c547b1837d5479782d418607c89a9f0 /spec/models | |
parent | 7b7f5dfa21f669b75552e946bedc598174fd71db (diff) |
fixup! Replace existing PublicBodyCategories functionality with db models PublicBodyCategory and PublicBodyHeading
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/public_body_category/category_collection_spec.rb | 81 | ||||
-rw-r--r-- | spec/models/public_body_category_spec.rb | 72 | ||||
-rw-r--r-- | spec/models/public_body_heading_spec.rb | 6 |
3 files changed, 90 insertions, 69 deletions
diff --git a/spec/models/public_body_category/category_collection_spec.rb b/spec/models/public_body_category/category_collection_spec.rb new file mode 100644 index 000000000..1fbcbe739 --- /dev/null +++ b/spec/models/public_body_category/category_collection_spec.rb @@ -0,0 +1,81 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe PublicBodyCategory::CategoryCollection do + context "requesting data" do + + before do + data = [ "Local and regional", + [ "local_council", "Local councils", "a local council" ], + "Miscellaneous", + [ "other", "Miscellaneous", "miscellaneous" ] ] + @categories = PublicBodyCategory::CategoryCollection.new + data.each { |item| @categories << item } + end + + describe 'when asked for headings' do + + it 'should return a list of headings' do + @categories.headings().should == ['Local and regional', 'Miscellaneous'] + end + + end + + describe 'when asked for categories with headings' do + it 'should return a list of headings as plain strings, each followed by n tag specifications as + lists in the form: + ["tag_to_use_as_category", "Sub category title", "Instance description"]' do + expected_categories = ["Local and regional", ["local_council", + "Local councils", + "a local council"], + "Miscellaneous", ["other", + "Miscellaneous", + "miscellaneous"]] + @categories.with_headings().should == expected_categories + end + end + + + + describe 'when asked for tags by headings' do + it 'should return a hash of tags keyed by heading' do + @categories.by_heading().should == {'Local and regional' => ['local_council'], + 'Miscellaneous' => ['other']} + end + end + + describe 'when asked for categories with description' do + it 'should return a list of tag specifications as lists in the form: + ["tag_to_use_as_category", "Sub category title", "Instance description"]' do + expected_categories = [ + ["local_council", "Local councils", "a local council"], + ["other", "Miscellaneous", "miscellaneous"] + ] + @categories.with_description().should == expected_categories + end + end + + describe 'when asked for tags' do + it 'should return a list of tags' do + @categories.tags().should == ["local_council", "other"] + end + end + + describe 'when asked for categories by tag' do + it 'should return a hash of categories keyed by tag' do + @categories.by_tag().should == { + "local_council" => "Local councils", + "other" => "Miscellaneous" + } + end + end + + describe 'when asked for singular_by_tag' do + it 'should return a hash of category descriptions keyed by tag' do + @categories.singular_by_tag().should == { + "local_council" => "a local council", + "other" => "miscellaneous" + } + end + end + end +end diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index d3c91e4f8..b7ef63ac3 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -44,76 +44,12 @@ describe PublicBodyCategory do end context "requesting data" do - before do - load_test_categories - end - - describe 'when asked for categories with headings' do - it 'should return a list of headings as plain strings, each followed by n tag specifications as - lists in the form: - ["tag_to_use_as_category", "Sub category title", "Instance description"]' do - expected_categories = ["Local and regional", ["local_council", - "Local councils", - "a local council"], - "Miscellaneous", ["other", - "Miscellaneous", - "miscellaneous"]] - PublicBodyCategory::get().with_headings().should == expected_categories - end - end - - describe 'when asked for headings' do - it 'should return a list of headings' do - PublicBodyCategory::get().headings().should == ['Local and regional', 'Miscellaneous'] - end - it 'should call load_categories if categories are not already loaded' do - PublicBodyCategory.stub!(:count).and_return(0) - PublicBodyCategory.should_receive(:load_categories) - PublicBodyCategory::get() - end + it 'should call load_categories if categories are not already loaded' do + PublicBodyCategory.stub!(:count).and_return(0) + PublicBodyCategory.should_receive(:load_categories) + PublicBodyCategory::get() end - describe 'when asked for tags by headings' do - it 'should return a hash of tags keyed by heading' do - PublicBodyCategory::get().by_heading().should == {'Local and regional' => ['local_council'], - 'Miscellaneous' => ['other']} - end - end - - describe 'when asked for categories with description' do - it 'should return a list of tag specifications as lists in the form: - ["tag_to_use_as_category", "Sub category title", "Instance description"]' do - expected_categories = [ - ["local_council", "Local councils", "a local council"], - ["other", "Miscellaneous", "miscellaneous"] - ] - PublicBodyCategory::get().with_description().should == expected_categories - end - end - - describe 'when asked for tags' do - it 'should return a list of tags' do - PublicBodyCategory::get().tags().should == ["local_council", "other"] - end - end - - describe 'when asked for categories by tag' do - it 'should return a hash of categories keyed by tag' do - PublicBodyCategory::get().by_tag().should == { - "local_council" => "Local councils", - "other" => "Miscellaneous" - } - end - end - - describe 'when asked for singular_by_tag' do - it 'should return a hash of category descriptions keyed by tag' do - PublicBodyCategory::get().singular_by_tag().should == { - "local_council" => "a local council", - "other" => "miscellaneous" - } - end - end end end diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index dd0517072..91fd35be8 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -15,7 +15,11 @@ describe PublicBodyHeading do context 'when loading the data' do before do - load_test_categories + PublicBodyCategories.add(:en, [ + "Local and regional", + [ "local_council", "Local councils", "a local council" ], + "Miscellaneous", + [ "other", "Miscellaneous", "miscellaneous" ],]) end it 'should use the display_order field to preserve the original data order' do |