govuk_content_models 6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +22 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +5 -0
- data/Rakefile +46 -0
- data/app/models/action.rb +60 -0
- data/app/models/answer_edition.rb +13 -0
- data/app/models/artefact.rb +341 -0
- data/app/models/artefact_action.rb +27 -0
- data/app/models/artefact_external_link.rb +15 -0
- data/app/models/business_support/business_size.rb +14 -0
- data/app/models/business_support/business_type.rb +14 -0
- data/app/models/business_support/location.rb +14 -0
- data/app/models/business_support/purpose.rb +14 -0
- data/app/models/business_support/sector.rb +14 -0
- data/app/models/business_support/stage.rb +14 -0
- data/app/models/business_support/support_type.rb +14 -0
- data/app/models/business_support_edition.rb +69 -0
- data/app/models/campaign_edition.rb +72 -0
- data/app/models/completed_transaction_edition.rb +14 -0
- data/app/models/curated_list.rb +32 -0
- data/app/models/edition.rb +286 -0
- data/app/models/expectant.rb +21 -0
- data/app/models/expectation.rb +12 -0
- data/app/models/guide_edition.rb +19 -0
- data/app/models/help_page_edition.rb +13 -0
- data/app/models/licence_edition.rb +35 -0
- data/app/models/local_authority.rb +58 -0
- data/app/models/local_interaction.rb +20 -0
- data/app/models/local_service.rb +49 -0
- data/app/models/local_transaction_edition.rb +49 -0
- data/app/models/overview_dashboard.rb +25 -0
- data/app/models/part.rb +28 -0
- data/app/models/parted.rb +32 -0
- data/app/models/place_edition.rb +20 -0
- data/app/models/programme_edition.rb +26 -0
- data/app/models/simple_smart_answer_edition.rb +66 -0
- data/app/models/simple_smart_answer_edition/node.rb +40 -0
- data/app/models/simple_smart_answer_edition/node/option.rb +31 -0
- data/app/models/tag.rb +88 -0
- data/app/models/transaction_edition.rb +28 -0
- data/app/models/travel_advice_edition.rb +177 -0
- data/app/models/user.rb +54 -0
- data/app/models/video_edition.rb +24 -0
- data/app/models/workflow.rb +217 -0
- data/app/models/workflow_actor.rb +141 -0
- data/app/traits/attachable.rb +60 -0
- data/app/traits/govspeak_smart_quotes_fixer.rb +19 -0
- data/app/traits/taggable.rb +113 -0
- data/app/validators/safe_html.rb +33 -0
- data/app/validators/slug_validator.rb +53 -0
- data/config/mongoid.yml +5 -0
- data/govuk_content_models.gemspec +42 -0
- data/jenkins.sh +7 -0
- data/lib/fact_check_address.rb +36 -0
- data/lib/govuk_content_models.rb +12 -0
- data/lib/govuk_content_models/require_all.rb +14 -0
- data/lib/govuk_content_models/test_helpers/factories.rb +213 -0
- data/lib/govuk_content_models/test_helpers/local_services.rb +24 -0
- data/lib/govuk_content_models/version.rb +4 -0
- data/test/fixtures/contactotron_api_response.json +1 -0
- data/test/fixtures/uploads/image.jpg +0 -0
- data/test/models/artefact_action_test.rb +123 -0
- data/test/models/artefact_external_link_test.rb +32 -0
- data/test/models/artefact_tag_test.rb +52 -0
- data/test/models/artefact_test.rb +583 -0
- data/test/models/business_support/business_size_test.rb +25 -0
- data/test/models/business_support/business_type_test.rb +25 -0
- data/test/models/business_support/location_test.rb +25 -0
- data/test/models/business_support/purpose_test.rb +29 -0
- data/test/models/business_support/sector_test.rb +25 -0
- data/test/models/business_support/stage_test.rb +25 -0
- data/test/models/business_support/support_type_test.rb +25 -0
- data/test/models/business_support_edition_test.rb +186 -0
- data/test/models/campaign_edition_test.rb +90 -0
- data/test/models/curated_list_test.rb +32 -0
- data/test/models/edition_test.rb +826 -0
- data/test/models/fact_check_address_test.rb +36 -0
- data/test/models/help_page_edition_test.rb +38 -0
- data/test/models/licence_edition_test.rb +104 -0
- data/test/models/local_authority_test.rb +113 -0
- data/test/models/local_service_test.rb +199 -0
- data/test/models/local_transaction_edition_test.rb +78 -0
- data/test/models/overview_dashboard_test.rb +47 -0
- data/test/models/simple_smart_answer_edition_test.rb +169 -0
- data/test/models/simple_smart_answer_node_test.rb +134 -0
- data/test/models/simple_smart_answer_option_test.rb +90 -0
- data/test/models/tag_test.rb +92 -0
- data/test/models/time_zone_test.rb +48 -0
- data/test/models/transaction_edition_test.rb +20 -0
- data/test/models/travel_advice_edition_test.rb +480 -0
- data/test/models/user_test.rb +114 -0
- data/test/models/video_edition_test.rb +64 -0
- data/test/models/workflow_actor_test.rb +61 -0
- data/test/models/workflow_test.rb +307 -0
- data/test/test_helper.rb +47 -0
- data/test/traits/attachable_test.rb +143 -0
- data/test/traits/taggable_test.rb +114 -0
- data/test/validators/safe_html_validator_test.rb +86 -0
- data/test/validators/slug_validator_test.rb +42 -0
- metadata +511 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "fact_check_address"
|
3
|
+
|
4
|
+
class FactCheckAddressTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
setup do
|
7
|
+
dummy_plek = mock do
|
8
|
+
stubs(:find).with("publisher").returns("publisher.wibble.alphagov.co.uk")
|
9
|
+
end
|
10
|
+
Plek.stubs(:current).returns(dummy_plek)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "can tell if an address is valid" do
|
14
|
+
service = FactCheckAddress.new
|
15
|
+
address = service.for_edition(Edition.new)
|
16
|
+
assert service.valid_address?(address), "Address should be valid but isn't"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "can tell if an address is invalid" do
|
20
|
+
service = FactCheckAddress.new
|
21
|
+
address = "factcheck+notwibble-abde@alphagov.co.uk"
|
22
|
+
refute service.valid_address?(address), "Address should be invalid but isn't"
|
23
|
+
end
|
24
|
+
|
25
|
+
test "can extract edition ID from an address" do
|
26
|
+
service = FactCheckAddress.new
|
27
|
+
address = "factcheck+wibble-abde@alphagov.co.uk"
|
28
|
+
assert_equal "abde", service.edition_id_from_address(address)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "can generate an address from an edition" do
|
32
|
+
service = FactCheckAddress.new
|
33
|
+
e = Edition.new
|
34
|
+
assert_match /#{e.id}/, service.for_edition(e)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class HelpPageEditionTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@artefact = FactoryGirl.create(:artefact, :kind => 'help_page', :slug => "help/foo")
|
6
|
+
end
|
7
|
+
|
8
|
+
should "have correct extra fields" do
|
9
|
+
h = FactoryGirl.build(:help_page_edition, :panopticon_id => @artefact.id)
|
10
|
+
h.body = "I'm a help page."
|
11
|
+
h.safely.save!
|
12
|
+
|
13
|
+
h = HelpPageEdition.first
|
14
|
+
assert_equal "I'm a help page.", h.body
|
15
|
+
end
|
16
|
+
|
17
|
+
should "give a friendly (legacy supporting) description of its format" do
|
18
|
+
help_page = HelpPageEdition.new
|
19
|
+
assert_equal "HelpPage", help_page.format
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return the body as whole_body" do
|
23
|
+
h = FactoryGirl.build(:help_page_edition,
|
24
|
+
:panopticon_id => @artefact.id,
|
25
|
+
:body => "Something")
|
26
|
+
assert_equal h.body, h.whole_body
|
27
|
+
end
|
28
|
+
|
29
|
+
should "clone extra fields when cloning edition" do
|
30
|
+
help_page = FactoryGirl.create(:help_page_edition,
|
31
|
+
:panopticon_id => @artefact.id,
|
32
|
+
:state => "published",
|
33
|
+
:body => "I'm very helpful")
|
34
|
+
|
35
|
+
new_help_page = help_page.build_clone
|
36
|
+
assert_equal help_page.body, new_help_page.body
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class LicenceEditionTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
@artefact = FactoryGirl.create(:artefact)
|
6
|
+
end
|
7
|
+
|
8
|
+
should "have correct extra fields" do
|
9
|
+
l = FactoryGirl.build(:licence_edition, panopticon_id: @artefact.id)
|
10
|
+
l.licence_identifier = "AB1234"
|
11
|
+
l.licence_short_description = "Short description of licence"
|
12
|
+
l.licence_overview = "Markdown overview of licence..."
|
13
|
+
l.will_continue_on = "The HMRC website"
|
14
|
+
l.continuation_link = "http://www.hmrc.gov.uk"
|
15
|
+
l.safely.save!
|
16
|
+
|
17
|
+
l = LicenceEdition.first
|
18
|
+
assert_equal "AB1234", l.licence_identifier
|
19
|
+
assert_equal "Short description of licence", l.licence_short_description
|
20
|
+
assert_equal "Markdown overview of licence...", l.licence_overview
|
21
|
+
assert_equal "The HMRC website", l.will_continue_on
|
22
|
+
assert_equal "http://www.hmrc.gov.uk", l.continuation_link
|
23
|
+
end
|
24
|
+
|
25
|
+
context "validations" do
|
26
|
+
setup do
|
27
|
+
@l = FactoryGirl.build(:licence_edition, panopticon_id: @artefact.id)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "require a licence identifier" do
|
31
|
+
@l.licence_identifier = ''
|
32
|
+
assert_equal false, @l.valid?, "expected licence edition not to be valid"
|
33
|
+
end
|
34
|
+
|
35
|
+
context "licence identifier uniqueness" do
|
36
|
+
should "require a unique licence identifier" do
|
37
|
+
artefact2 = FactoryGirl.create(:artefact)
|
38
|
+
FactoryGirl.create(:licence_edition, :licence_identifier => "wibble", panopticon_id: artefact2.id)
|
39
|
+
@l.licence_identifier = "wibble"
|
40
|
+
assert ! @l.valid?, "expected licence edition not to be valid"
|
41
|
+
end
|
42
|
+
|
43
|
+
should "not consider archived editions when evaluating uniqueness" do
|
44
|
+
artefact2 = FactoryGirl.create(:artefact)
|
45
|
+
FactoryGirl.create(:licence_edition, :licence_identifier => "wibble", panopticon_id: artefact2.id, :state => "archived")
|
46
|
+
@l.licence_identifier = "wibble"
|
47
|
+
assert @l.valid?, "expected licence edition to be valid"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "not require a unique licence identifier for different versions of the same licence edition" do
|
52
|
+
@l.state = 'published'
|
53
|
+
@l.licence_identifier = 'wibble'
|
54
|
+
@l.save!
|
55
|
+
|
56
|
+
new_version = @l.build_clone
|
57
|
+
assert_equal 'wibble', new_version.licence_identifier
|
58
|
+
assert new_version.valid?, "Expected clone to be valid"
|
59
|
+
end
|
60
|
+
|
61
|
+
should "not validate the continuation link when blank" do
|
62
|
+
@l.continuation_link = ""
|
63
|
+
assert @l.valid?, "continuation link validation should not be triggered when the field is blank"
|
64
|
+
end
|
65
|
+
should "fail validation when the continuation link has an invalid url" do
|
66
|
+
@l.continuation_link = "not&a+valid_url"
|
67
|
+
assert !@l.valid?, "continuation link validation should fail with a invalid url"
|
68
|
+
end
|
69
|
+
should "pass validation with a valid continuation link url" do
|
70
|
+
@l.continuation_link = "http://www.hmrc.gov.uk"
|
71
|
+
assert @l.valid?, "continuation_link validation should pass with a valid url"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
should "clone extra fields when cloning edition" do
|
76
|
+
licence = FactoryGirl.create(:licence_edition,
|
77
|
+
:panopticon_id => @artefact.id,
|
78
|
+
:state => "published",
|
79
|
+
:licence_identifier => "1234",
|
80
|
+
:licence_short_description => "Short description of licence",
|
81
|
+
:licence_overview => "Overview to be cloned",
|
82
|
+
:will_continue_on => "Continuation text to be cloned",
|
83
|
+
:continuation_link => "http://www.gov.uk")
|
84
|
+
new_licence = licence.build_clone
|
85
|
+
|
86
|
+
assert_equal licence.licence_identifier, new_licence.licence_identifier
|
87
|
+
assert_equal licence.licence_short_description, new_licence.licence_short_description
|
88
|
+
assert_equal licence.licence_overview, new_licence.licence_overview
|
89
|
+
assert_equal licence.will_continue_on, new_licence.will_continue_on
|
90
|
+
assert_equal licence.continuation_link, new_licence.continuation_link
|
91
|
+
end
|
92
|
+
|
93
|
+
context "indexable_content" do
|
94
|
+
should "include the licence_overview, removing markup" do
|
95
|
+
licence = FactoryGirl.create(:licence_edition, licence_overview: "## Overview")
|
96
|
+
assert_equal "Overview", licence.indexable_content
|
97
|
+
end
|
98
|
+
|
99
|
+
should "include the licence_short_description" do
|
100
|
+
licence = FactoryGirl.create(:licence_edition, licence_short_description: "Short desc")
|
101
|
+
assert_equal "Short desc", licence.indexable_content
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe LocalAuthority do
|
4
|
+
before :each do
|
5
|
+
LocalAuthority.delete_all
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should create an authority with correct field types" do
|
9
|
+
# Although it may seem overboard, this test is helpful to confirm
|
10
|
+
# the correct field types are being used on the model
|
11
|
+
LocalAuthority.create!(
|
12
|
+
name: "Example",
|
13
|
+
snac: "AA00",
|
14
|
+
local_directgov_id: 1,
|
15
|
+
tier: "county",
|
16
|
+
contact_address: ["Line one", "line two", "line three"],
|
17
|
+
contact_url: "http://example.gov/contact",
|
18
|
+
contact_phone: "0000000000",
|
19
|
+
contact_email: "contact@example.gov")
|
20
|
+
authority = LocalAuthority.first
|
21
|
+
assert_equal "Example", authority.name
|
22
|
+
assert_equal "AA00", authority.snac
|
23
|
+
assert_equal 1, authority.local_directgov_id
|
24
|
+
assert_equal "county", authority.tier
|
25
|
+
assert_equal ["Line one", "line two", "line three"], authority.contact_address
|
26
|
+
assert_equal "http://example.gov/contact", authority.contact_url
|
27
|
+
assert_equal "0000000000", authority.contact_phone
|
28
|
+
assert_equal "contact@example.gov", authority.contact_email
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "validating local_interactions" do
|
32
|
+
before :each do
|
33
|
+
@authority = FactoryGirl.create(:local_authority)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should require a lgsl_code and lgil_code" do
|
37
|
+
li = @authority.local_interactions.build
|
38
|
+
refute li.valid?
|
39
|
+
assert_equal ["can't be blank"], li.errors[:lgsl_code]
|
40
|
+
assert_equal ["can't be blank"], li.errors[:lgil_code]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not allow duplicate lgsl/lgil pairs" do
|
44
|
+
li1 = @authority.local_interactions.create!(:lgsl_code => 42, :lgil_code => 8, :url => "http://www.example.com/one")
|
45
|
+
li2 = @authority.local_interactions.build(:lgsl_code => 42, :lgil_code => 8, :url => "http://www.example.com/two")
|
46
|
+
|
47
|
+
refute li2.valid?
|
48
|
+
assert_equal ["is already taken"], li2.errors[:lgil_code]
|
49
|
+
|
50
|
+
li2.lgil_code = 3
|
51
|
+
assert li2.valid?
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should only validate uniqueness within the authority" do
|
55
|
+
authority2 = FactoryGirl.create(:local_authority)
|
56
|
+
li1 = @authority.local_interactions.create!(:lgsl_code => 42, :lgil_code => 8, :url => "http://www.example.com/one")
|
57
|
+
li2 = authority2.local_interactions.build(:lgsl_code => 42, :lgil_code => 8, :url => "http://www.example.com/two")
|
58
|
+
|
59
|
+
assert li2.valid?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "preferred_interaction_for" do
|
64
|
+
before :each do
|
65
|
+
@authority = FactoryGirl.create(:local_authority)
|
66
|
+
@lgsl_code = "142"
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "with no LIGL specified" do
|
70
|
+
it "should return the lowest LGIL that's not 8" do
|
71
|
+
@interaction1 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
72
|
+
:lgil_code => 12)
|
73
|
+
@interaction2 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
74
|
+
:lgil_code => LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION)
|
75
|
+
@interaction3 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
76
|
+
:lgil_code => 9)
|
77
|
+
|
78
|
+
assert_equal @interaction3, @authority.preferred_interaction_for(@lgsl_code)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return LGIL 8 if there are no others" do
|
82
|
+
@interaction2 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
83
|
+
:lgil_code => LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION)
|
84
|
+
|
85
|
+
assert_equal @interaction2, @authority.preferred_interaction_for(@lgsl_code)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "with an LGIL specified" do
|
90
|
+
it "should return the interaction for the specified LGIL" do
|
91
|
+
@interaction1 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
92
|
+
:lgil_code => 12)
|
93
|
+
@interaction2 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
94
|
+
:lgil_code => LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION)
|
95
|
+
@interaction3 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
96
|
+
:lgil_code => 9)
|
97
|
+
|
98
|
+
assert_equal @interaction2, @authority.preferred_interaction_for(@lgsl_code, 8)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return nil if there is no interaction with the specified LGIL" do
|
102
|
+
@interaction1 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
103
|
+
:lgil_code => 12)
|
104
|
+
@interaction2 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
105
|
+
:lgil_code => LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION)
|
106
|
+
@interaction3 = FactoryGirl.create(:local_interaction, :local_authority => @authority, :lgsl_code => @lgsl_code,
|
107
|
+
:lgil_code => 9)
|
108
|
+
|
109
|
+
assert_equal nil, @authority.preferred_interaction_for(@lgsl_code, 3)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "govuk_content_models/test_helpers/local_services"
|
3
|
+
|
4
|
+
class LocalServiceTest < ActiveSupport::TestCase
|
5
|
+
include LocalServicesHelper
|
6
|
+
|
7
|
+
def create_service_for_tiers(*tiers)
|
8
|
+
@service = LocalService.create!(
|
9
|
+
lgsl_code: @lgsl_code,
|
10
|
+
providing_tier: tiers.map(&:to_s)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
LocalAuthority.delete_all
|
16
|
+
@lgsl_code = 123
|
17
|
+
@snac_code = "AA00"
|
18
|
+
@county_council = FactoryGirl.create(
|
19
|
+
:local_authority,
|
20
|
+
tier: "county",
|
21
|
+
snac: "AA00"
|
22
|
+
)
|
23
|
+
FactoryGirl.create(
|
24
|
+
:local_interaction,
|
25
|
+
local_authority: @county_council,
|
26
|
+
lgsl_code: @lgsl_code,
|
27
|
+
url: "http://some.county.council.gov/do-123.html"
|
28
|
+
)
|
29
|
+
@district_council = FactoryGirl.create(
|
30
|
+
:local_authority,
|
31
|
+
tier: "district",
|
32
|
+
snac: "AA"
|
33
|
+
)
|
34
|
+
FactoryGirl.create(
|
35
|
+
:local_interaction,
|
36
|
+
local_authority: @district_council,
|
37
|
+
lgsl_code: @lgsl_code,
|
38
|
+
url: "http://some.district.council.gov/do-123.html"
|
39
|
+
)
|
40
|
+
@unitary_authority = FactoryGirl.create(
|
41
|
+
:local_authority,
|
42
|
+
tier: "unitary",
|
43
|
+
snac: "BB00"
|
44
|
+
)
|
45
|
+
FactoryGirl.create(
|
46
|
+
:local_interaction,
|
47
|
+
local_authority: @unitary_authority,
|
48
|
+
lgsl_code: @lgsl_code,
|
49
|
+
url: "http://some.unitary.council.gov/do-123.html"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
test "should return county URL for county/UA service in county" do
|
54
|
+
service = create_service_for_tiers(:county, :unitary)
|
55
|
+
councils = [@county_council.snac, @district_council.snac]
|
56
|
+
assert_equal "http://some.county.council.gov/do-123.html",
|
57
|
+
service.preferred_interaction(councils).url
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should return UA URL for county/UA service in UA" do
|
61
|
+
service = create_service_for_tiers(:county, :unitary)
|
62
|
+
councils = [@unitary_authority.snac]
|
63
|
+
assert_equal "http://some.unitary.council.gov/do-123.html",
|
64
|
+
service.preferred_interaction(councils).url
|
65
|
+
end
|
66
|
+
|
67
|
+
test "should return nil for county/UA service in district" do
|
68
|
+
service = create_service_for_tiers(:county, :unitary)
|
69
|
+
councils = [@district_council.snac]
|
70
|
+
assert_nil service.preferred_interaction(councils)
|
71
|
+
end
|
72
|
+
|
73
|
+
test "should allow overriding returned LGIL" do
|
74
|
+
FactoryGirl.create(:local_interaction,
|
75
|
+
local_authority: @county_council,
|
76
|
+
lgsl_code: @lgsl_code,
|
77
|
+
lgil_code: 12,
|
78
|
+
url: "http://some.county.council.gov/do-456.html"
|
79
|
+
)
|
80
|
+
service = create_service_for_tiers(:county, :unitary)
|
81
|
+
councils = [@county_council.snac, @district_council.snac]
|
82
|
+
assert_equal "http://some.county.council.gov/do-456.html",
|
83
|
+
service.preferred_interaction(councils, 12).url
|
84
|
+
end
|
85
|
+
|
86
|
+
test "should not list a county (in a UA) as providing a service it does not provide" do
|
87
|
+
service = create_service_for_tiers(:county, :unitary)
|
88
|
+
other_service = service.lgsl_code.to_i + 1
|
89
|
+
FactoryGirl.create(
|
90
|
+
:local_interaction,
|
91
|
+
local_authority: @county_council,
|
92
|
+
lgsl_code: other_service
|
93
|
+
)
|
94
|
+
authority = FactoryGirl.create(
|
95
|
+
:local_authority,
|
96
|
+
tier: "county",
|
97
|
+
snac: "CC00"
|
98
|
+
)
|
99
|
+
FactoryGirl.create(
|
100
|
+
:local_interaction,
|
101
|
+
local_authority: authority,
|
102
|
+
lgsl_code: other_service
|
103
|
+
)
|
104
|
+
|
105
|
+
refute_includes service.provided_by.map(&:snac), "CC00"
|
106
|
+
end
|
107
|
+
|
108
|
+
test "should not list a UA as providing a service it does not provide" do
|
109
|
+
service = create_service_for_tiers(:county, :unitary)
|
110
|
+
other_service = service.lgsl_code.to_i + 1
|
111
|
+
FactoryGirl.create(
|
112
|
+
:local_interaction,
|
113
|
+
local_authority: @county_council,
|
114
|
+
lgsl_code: other_service
|
115
|
+
)
|
116
|
+
authority = FactoryGirl.create(
|
117
|
+
:local_authority,
|
118
|
+
tier: "unitary",
|
119
|
+
snac: "CC01"
|
120
|
+
)
|
121
|
+
FactoryGirl.create(
|
122
|
+
:local_interaction,
|
123
|
+
local_authority: authority,
|
124
|
+
lgsl_code: other_service
|
125
|
+
)
|
126
|
+
|
127
|
+
refute_includes service.provided_by.map(&:snac), "CC01"
|
128
|
+
end
|
129
|
+
|
130
|
+
test "should list a county (in a UA) that provides a service" do
|
131
|
+
service = create_service_for_tiers(:county, :unitary)
|
132
|
+
assert_includes service.provided_by.map(&:snac), @county_council.snac
|
133
|
+
end
|
134
|
+
|
135
|
+
test "should list a UA that provides a service" do
|
136
|
+
service = create_service_for_tiers(:county, :unitary)
|
137
|
+
assert_includes service.provided_by.map(&:snac), @unitary_authority.snac
|
138
|
+
end
|
139
|
+
|
140
|
+
test "should return district URL for district/UA service in county/district" do
|
141
|
+
service = create_service_for_tiers(:district, :unitary)
|
142
|
+
councils = [@county_council.snac, @district_council.snac]
|
143
|
+
assert_equal "http://some.district.council.gov/do-123.html",
|
144
|
+
service.preferred_interaction(councils).url
|
145
|
+
end
|
146
|
+
|
147
|
+
test "should return UA URL for district/UA service in UA" do
|
148
|
+
service = create_service_for_tiers(:district, :unitary)
|
149
|
+
councils = [@unitary_authority.snac]
|
150
|
+
assert_match "http://some.unitary.council.gov/do-123.html",
|
151
|
+
service.preferred_interaction(councils).url
|
152
|
+
end
|
153
|
+
|
154
|
+
test "should return nil for district/UA service in county" do
|
155
|
+
service = create_service_for_tiers(:district, :unitary)
|
156
|
+
councils = [@county_council.snac]
|
157
|
+
assert_nil service.preferred_interaction(councils)
|
158
|
+
end
|
159
|
+
|
160
|
+
test "should list only districts and UAs as providers" do
|
161
|
+
service = create_service_for_tiers(:district, :unitary)
|
162
|
+
providers = service.provided_by
|
163
|
+
assert_equal 2, providers.length
|
164
|
+
assert_includes providers.map(&:snac), @district_council.snac
|
165
|
+
assert_includes providers.map(&:snac), @unitary_authority.snac
|
166
|
+
end
|
167
|
+
|
168
|
+
test "should return district URL for both-tier service in county/district" do
|
169
|
+
service = create_service_for_tiers("district", "unitary", "county")
|
170
|
+
councils = [@county_council.snac, @district_council.snac]
|
171
|
+
url = service.preferred_interaction(councils).url
|
172
|
+
assert_equal "http://some.district.council.gov/do-123.html", url
|
173
|
+
end
|
174
|
+
|
175
|
+
test "should return UA URL for both-tier service in UA" do
|
176
|
+
service = create_service_for_tiers("district", "unitary", "county")
|
177
|
+
councils = [@unitary_authority.snac]
|
178
|
+
url = service.preferred_interaction(councils).url
|
179
|
+
assert_equal "http://some.unitary.council.gov/do-123.html", url
|
180
|
+
end
|
181
|
+
|
182
|
+
# This shouldn't really ever happen and suggests that the data
|
183
|
+
# is incorrect somehow, but we might as well fall back to county council
|
184
|
+
test "should return county URL for both-tier service in county" do
|
185
|
+
service = create_service_for_tiers("district", "unitary", "county")
|
186
|
+
councils = [@county_council.snac]
|
187
|
+
url = service.preferred_interaction(councils).url
|
188
|
+
assert_equal "http://some.county.council.gov/do-123.html", url
|
189
|
+
end
|
190
|
+
|
191
|
+
test "should list all authorities providing a both-tier service" do
|
192
|
+
service = create_service_for_tiers("district", "unitary", "county")
|
193
|
+
make_authority("county", snac: "CC00", lgsl: 124)
|
194
|
+
providers = service.provided_by
|
195
|
+
assert_includes providers.map(&:snac), @district_council.snac
|
196
|
+
assert_includes providers.map(&:snac), @unitary_authority.snac
|
197
|
+
assert_includes providers.map(&:snac), @county_council.snac
|
198
|
+
end
|
199
|
+
end
|