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,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::BusinessSizeTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@charity = BusinessSupport::BusinessSize.create(name: "Under 10", slug: "under-10")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validate presence of name" do
|
9
|
+
refute BusinessSupport::BusinessSize.new(slug: "under-10").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_type = BusinessSupport::BusinessSize.new(name: "Under 10", slug: "under-10")
|
14
|
+
refute another_type.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validate presence of slug" do
|
18
|
+
refute BusinessSupport::BusinessSize.new(name: "Under 10").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_type = BusinessSupport::BusinessSize.new(name: "Under 10", slug: "under-10")
|
23
|
+
refute another_type.valid?, "should validate uniqueness of slug."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::BusinessTypeTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@charity = BusinessSupport::BusinessType.create(name: "Charity", slug: "charity")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validate presence of name" do
|
9
|
+
refute BusinessSupport::BusinessType.new(slug: "charity").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_type = BusinessSupport::BusinessType.new(name: "Charity", slug: "charity")
|
14
|
+
refute another_type.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validate presence of slug" do
|
18
|
+
refute BusinessSupport::BusinessType.new(name: "Charity").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_type = BusinessSupport::BusinessType.new(name: "Charity", slug: "charity")
|
23
|
+
refute another_type.valid?, "should validate uniqueness of slug."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::LocationTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@region = BusinessSupport::Location.create(name: "Ecclefechan", slug: "ecclefechan")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validates presence of name" do
|
9
|
+
refute BusinessSupport::Location.new(slug: "ecclefechan").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_scheme = BusinessSupport::Location.new(name: "Ecclefechan", slug: "ecclefechan")
|
14
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validate presence of slug" do
|
18
|
+
refute BusinessSupport::Location.new(name: "Ecclefechan").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_scheme = BusinessSupport::Location.new(name: "Ecclefechan", slug: "ecclefechan")
|
23
|
+
refute another_scheme.valid?, "should validate uniqueness of slug"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::PurposeTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@purpose = BusinessSupport::Purpose.create(name: "Setting up your business",
|
6
|
+
slug: "setting-up-your-business")
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should validates presence of name" do
|
10
|
+
refute BusinessSupport::Purpose.new(slug: "setting-up-your-business").valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should validate uniqueness of name" do
|
14
|
+
another_purpose = BusinessSupport::Purpose.new(name: "Setting up your business",
|
15
|
+
slug: "setting-up-your-business")
|
16
|
+
refute another_purpose.valid?, "should validate uniqueness of name."
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should validates presence of slug" do
|
20
|
+
refute BusinessSupport::Purpose.new(name: "Setting up your business").valid?
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should validate uniqueness of slug" do
|
24
|
+
another_scheme = BusinessSupport::Purpose.new(name: "Setting up your business",
|
25
|
+
slug: "setting-up-your-business")
|
26
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::SectorTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@sector = BusinessSupport::Sector.create(name: "Manufacturing", slug: "manufacturing")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validates presence of name" do
|
9
|
+
refute BusinessSupport::Sector.new(slug: "manufacturing").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_scheme = BusinessSupport::Sector.new(name: "Manufacturing", slug: "manufacturing")
|
14
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validates presence of slug" do
|
18
|
+
refute BusinessSupport::Sector.new(name: "Manufacturing").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_scheme = BusinessSupport::Sector.new(name: "Manufacturing", slug: "manufacturing")
|
23
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::StageTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@stage = BusinessSupport::Stage.create(name: "Finance", slug: "finance")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validates presence of name" do
|
9
|
+
refute BusinessSupport::Stage.new(slug: "finance").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_scheme = BusinessSupport::Stage.new(name: "Finance", slug: "finance")
|
14
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validates presence of slug" do
|
18
|
+
refute BusinessSupport::Stage.new(name: "Finance").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_scheme = BusinessSupport::Stage.new(name: "Finance", slug: "finance")
|
23
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BusinessSupport::SupportTypeTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@type = BusinessSupport::SupportType.create(name: "Loan", slug: "loan")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should validates presence of name" do
|
9
|
+
refute BusinessSupport::SupportType.new(slug: "short-term-loan").valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should validate uniqueness of name" do
|
13
|
+
another_scheme = BusinessSupport::SupportType.new(name: "Loan", slug: "short-term-loan")
|
14
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should validates presence of slug" do
|
18
|
+
refute BusinessSupport::SupportType.new(name: "Loan").valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should validate uniqueness of slug" do
|
22
|
+
another_scheme = BusinessSupport::SupportType.new(name: "Loan", slug: "loan")
|
23
|
+
refute another_scheme.valid?, "should validate uniqueness of name."
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative "../test_helper"
|
3
|
+
|
4
|
+
class BusinessSupportEditionTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@artefact = FactoryGirl.create(:artefact)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "have custom fields" do
|
10
|
+
support = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
|
11
|
+
support.short_description = "The short description"
|
12
|
+
support.body = "The body"
|
13
|
+
support.eligibility = "The eligibility"
|
14
|
+
support.evaluation = "The evaluation"
|
15
|
+
support.additional_information = "The additional information"
|
16
|
+
support.min_value = 1000
|
17
|
+
support.max_value = 3000
|
18
|
+
support.max_employees = 2000
|
19
|
+
support.organiser = "The business support people"
|
20
|
+
support.continuation_link = "http://www.gov.uk"
|
21
|
+
support.will_continue_on = "The GOVUK website"
|
22
|
+
support.contact_details = "123 The Street, Townsville, UK. 07324 123456"
|
23
|
+
support.business_support_identifier = "123-4-5"
|
24
|
+
|
25
|
+
support.priority = 2
|
26
|
+
support.business_sizes << "up-to-249"
|
27
|
+
support.business_types << "charity"
|
28
|
+
support.locations = ["scotland", "england"]
|
29
|
+
support.purposes << "making-the-most-of-the-internet"
|
30
|
+
support.sectors = ["education", "manufacturing"]
|
31
|
+
support.stages << "start-up"
|
32
|
+
support.support_types = ["grant", "loan"]
|
33
|
+
support.start_date = Date.parse("1 Jan 2000")
|
34
|
+
support.end_date = Date.parse("1 Jan 2020")
|
35
|
+
|
36
|
+
support.safely.save!
|
37
|
+
|
38
|
+
support = BusinessSupportEdition.first
|
39
|
+
assert_equal "The short description", support.short_description
|
40
|
+
assert_equal "The body", support.body
|
41
|
+
assert_equal "The eligibility", support.eligibility
|
42
|
+
assert_equal "The evaluation", support.evaluation
|
43
|
+
assert_equal "The additional information", support.additional_information
|
44
|
+
assert_equal 1000, support.min_value
|
45
|
+
assert_equal 3000, support.max_value
|
46
|
+
assert_equal 2000, support.max_employees
|
47
|
+
assert_equal "The business support people", support.organiser
|
48
|
+
assert_equal "http://www.gov.uk", support.continuation_link
|
49
|
+
assert_equal "The GOVUK website", support.will_continue_on
|
50
|
+
assert_equal "123 The Street, Townsville, UK. 07324 123456", support.contact_details
|
51
|
+
assert_equal "123-4-5", support.business_support_identifier
|
52
|
+
|
53
|
+
assert_equal 2, support.priority
|
54
|
+
assert_equal ["up-to-249"], support.business_sizes
|
55
|
+
assert_equal ["charity"], support.business_types
|
56
|
+
assert_equal ["scotland", "england"], support.locations
|
57
|
+
assert_equal ["making-the-most-of-the-internet"], support.purposes
|
58
|
+
assert_equal ["education", "manufacturing"], support.sectors
|
59
|
+
assert_equal ["start-up"], support.stages
|
60
|
+
assert_equal ["grant", "loan"], support.support_types
|
61
|
+
assert_equal Date.parse("1 Jan 2000"), support.start_date
|
62
|
+
assert_equal Date.parse("1 Jan 2020"), support.end_date
|
63
|
+
end
|
64
|
+
|
65
|
+
should "not allow max_value to be less than min_value" do
|
66
|
+
support = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
|
67
|
+
support.min_value = 100
|
68
|
+
support.max_value = 50
|
69
|
+
|
70
|
+
refute support.valid?
|
71
|
+
end
|
72
|
+
|
73
|
+
should "require a business_support_identifier" do
|
74
|
+
support = FactoryGirl.build(:business_support_edition, :business_support_identifier => '')
|
75
|
+
assert ! support.valid?, "expected business support edition not to be valid"
|
76
|
+
end
|
77
|
+
|
78
|
+
context "business support identifier uniqueness" do
|
79
|
+
setup do
|
80
|
+
@support = FactoryGirl.build(:business_support_edition, panopticon_id: @artefact.id)
|
81
|
+
@another_artefact = FactoryGirl.create(:artefact)
|
82
|
+
end
|
83
|
+
should "have a unique business support identifier" do
|
84
|
+
another_support = FactoryGirl.create(:business_support_edition, panopticon_id: @another_artefact.id,
|
85
|
+
:business_support_identifier => "this-should-be-unique")
|
86
|
+
@support.business_support_identifier = "this-should-be-unique"
|
87
|
+
assert !@support.valid?, "business_support_identifier should be unique"
|
88
|
+
@support.business_support_identifier = "this-is-different"
|
89
|
+
assert @support.valid?, "business_support_identifier should be unique"
|
90
|
+
end
|
91
|
+
|
92
|
+
should "not consider archived editions when evaluating uniqueness" do
|
93
|
+
another_support = FactoryGirl.create(:business_support_edition, panopticon_id: @another_artefact.id,
|
94
|
+
:business_support_identifier => "this-should-be-unique", :state => "archived")
|
95
|
+
@support.business_support_identifier = "this-should-be-unique"
|
96
|
+
assert @support.valid?, "business_support should be valid"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "numeric field validations" do
|
101
|
+
# https://github.com/mongoid/mongoid/issues/1735 Really Mongoid‽
|
102
|
+
[
|
103
|
+
:min_value,
|
104
|
+
:max_value,
|
105
|
+
:max_employees,
|
106
|
+
].each do |field|
|
107
|
+
should "require an integer #{field}" do
|
108
|
+
@support = FactoryGirl.build(:business_support_edition)
|
109
|
+
[
|
110
|
+
'sadfsadf',
|
111
|
+
'100,000',
|
112
|
+
1.23,
|
113
|
+
].each do |value|
|
114
|
+
@support.send("#{field}=", value)
|
115
|
+
refute @support.valid?
|
116
|
+
assert_equal 1, @support.errors[field].count
|
117
|
+
end
|
118
|
+
|
119
|
+
@support.send("#{field}=", "100")
|
120
|
+
@support.save!
|
121
|
+
s = BusinessSupportEdition.find(@support.id)
|
122
|
+
assert_equal 100, s.send(field)
|
123
|
+
|
124
|
+
@support.send("#{field}=", "")
|
125
|
+
@support.save!
|
126
|
+
s = BusinessSupportEdition.find(@support.id)
|
127
|
+
assert_equal nil, s.send(field)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "continuation_link validation" do
|
133
|
+
|
134
|
+
setup do
|
135
|
+
@bs = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
|
136
|
+
end
|
137
|
+
|
138
|
+
should "not validate the continuation link when blank" do
|
139
|
+
@bs.continuation_link = ""
|
140
|
+
assert @bs.valid?, "continuation link validation should not be triggered when the field is blank"
|
141
|
+
end
|
142
|
+
should "fail validation when the continuation link has an invalid url" do
|
143
|
+
@bs.continuation_link = "not&a+valid_url"
|
144
|
+
assert !@bs.valid?, "continuation link validation should fail with a invalid url"
|
145
|
+
end
|
146
|
+
should "pass validation with a valid continuation link url" do
|
147
|
+
@bs.continuation_link = "http://www.hmrc.gov.uk"
|
148
|
+
assert @bs.valid?, "continuation_link validation should pass with a valid url"
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
should "clone extra fields when cloning edition" do
|
154
|
+
support = FactoryGirl.create(:business_support_edition,
|
155
|
+
:panopticon_id => @artefact.id,
|
156
|
+
:state => "published",
|
157
|
+
:business_support_identifier => "1234",
|
158
|
+
:short_description => "Short description of support format",
|
159
|
+
:body => "Body to be cloned",
|
160
|
+
:min_value => 1,
|
161
|
+
:max_value => 2,
|
162
|
+
:max_employees => 3,
|
163
|
+
:organiser => "Organiser to be cloned",
|
164
|
+
:eligibility => "Eligibility to be cloned",
|
165
|
+
:evaluation => "Evaluation to be cloned",
|
166
|
+
:additional_information => "Additional info to be cloned",
|
167
|
+
:will_continue_on => "Continuation text to be cloned",
|
168
|
+
:continuation_link => "http://www.gov.uk",
|
169
|
+
:contact_details => "Contact details to be cloned")
|
170
|
+
new_support = support.build_clone
|
171
|
+
|
172
|
+
assert_equal support.business_support_identifier, new_support.business_support_identifier
|
173
|
+
assert_equal support.short_description, new_support.short_description
|
174
|
+
assert_equal support.body, new_support.body
|
175
|
+
assert_equal support.min_value, new_support.min_value
|
176
|
+
assert_equal support.max_value, new_support.max_value
|
177
|
+
assert_equal support.max_employees, new_support.max_employees
|
178
|
+
assert_equal support.organiser, new_support.organiser
|
179
|
+
assert_equal support.eligibility, new_support.eligibility
|
180
|
+
assert_equal support.evaluation, new_support.evaluation
|
181
|
+
assert_equal support.additional_information, new_support.additional_information
|
182
|
+
assert_equal support.will_continue_on, new_support.will_continue_on
|
183
|
+
assert_equal support.continuation_link, new_support.continuation_link
|
184
|
+
assert_equal support.contact_details, new_support.contact_details
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CampaignEditionTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@artefact = FactoryGirl.create(:artefact, :kind => 'campaign', :slug => "start-all-the-campaigns")
|
6
|
+
end
|
7
|
+
|
8
|
+
should "have correct extra fields" do
|
9
|
+
c = FactoryGirl.build(:campaign_edition, :panopticon_id => @artefact.id)
|
10
|
+
c.body = "Start all the campaigns!"
|
11
|
+
c.large_image_id = "large-image-id-from-the-asset-manager"
|
12
|
+
c.medium_image_id = "medium-image-id-from-the-asset-manager"
|
13
|
+
c.small_image_id = "small-image-id-from-the-asset-manager"
|
14
|
+
c.organisation_formatted_name = "Driver & Vehicle\nLicensing\nAgency"
|
15
|
+
c.organisation_url = "/government/organisations/driver-and-vehicle-licensing-agency"
|
16
|
+
c.organisation_brand_colour = "department-for-transport"
|
17
|
+
c.organisation_crest = "single-identity"
|
18
|
+
c.safely.save!
|
19
|
+
|
20
|
+
c = CampaignEdition.first
|
21
|
+
assert_equal "Start all the campaigns!", c.body
|
22
|
+
assert_equal "large-image-id-from-the-asset-manager", c.large_image_id
|
23
|
+
assert_equal "medium-image-id-from-the-asset-manager", c.medium_image_id
|
24
|
+
assert_equal "small-image-id-from-the-asset-manager", c.small_image_id
|
25
|
+
assert_equal "Driver & Vehicle\nLicensing\nAgency", c.organisation_formatted_name
|
26
|
+
assert_equal "/government/organisations/driver-and-vehicle-licensing-agency", c.organisation_url
|
27
|
+
assert_equal "department-for-transport", c.organisation_brand_colour
|
28
|
+
assert_equal "single-identity", c.organisation_crest
|
29
|
+
end
|
30
|
+
|
31
|
+
should "give a friendly (legacy supporting) description of its format" do
|
32
|
+
campaign = CampaignEdition.new
|
33
|
+
assert_equal "Campaign", campaign.format
|
34
|
+
end
|
35
|
+
|
36
|
+
should "return the body as whole_body" do
|
37
|
+
campaign = FactoryGirl.build(:campaign_edition,
|
38
|
+
:panopticon_id => @artefact.id,
|
39
|
+
:body => "Something")
|
40
|
+
assert_equal campaign.body, campaign.whole_body
|
41
|
+
end
|
42
|
+
|
43
|
+
should "clone extra fields when cloning edition" do
|
44
|
+
campaign = FactoryGirl.create(:campaign_edition,
|
45
|
+
:panopticon_id => @artefact.id,
|
46
|
+
:state => "published",
|
47
|
+
:body => "I'm very campaignful",
|
48
|
+
:large_image_id => "large-image",
|
49
|
+
:medium_image_id => "medium-image",
|
50
|
+
:small_image_id => "small-image",
|
51
|
+
:organisation_formatted_name => "Driver & Vehicle\nLicensing\nAgency",
|
52
|
+
:organisation_url => "/government/organisations/driver-and-vehicle-licensing-agency",
|
53
|
+
:organisation_brand_colour => "department-for-transport",
|
54
|
+
:organisation_crest => "single-identity" )
|
55
|
+
|
56
|
+
new_campaign = campaign.build_clone
|
57
|
+
assert_equal campaign.body, new_campaign.body
|
58
|
+
assert_equal campaign.large_image_id, new_campaign.large_image_id
|
59
|
+
assert_equal campaign.medium_image_id, new_campaign.medium_image_id
|
60
|
+
assert_equal campaign.small_image_id, new_campaign.small_image_id
|
61
|
+
assert_equal campaign.organisation_formatted_name, new_campaign.organisation_formatted_name
|
62
|
+
assert_equal campaign.organisation_url, new_campaign.organisation_url
|
63
|
+
assert_equal campaign.organisation_brand_colour, new_campaign.organisation_brand_colour
|
64
|
+
assert_equal campaign.organisation_crest, new_campaign.organisation_crest
|
65
|
+
end
|
66
|
+
|
67
|
+
should "be not valid with an organisation brand colour from outside the list" do
|
68
|
+
campaign = FactoryGirl.build(:campaign_edition, :panopticon_id => @artefact.id)
|
69
|
+
campaign.organisation_brand_colour = "something-else"
|
70
|
+
|
71
|
+
refute campaign.valid?
|
72
|
+
assert campaign.errors.has_key?(:organisation_brand_colour)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "be not valid with an organisation crest from outside the list" do
|
76
|
+
campaign = FactoryGirl.build(:campaign_edition, :panopticon_id => @artefact.id)
|
77
|
+
campaign.organisation_crest = "something-else"
|
78
|
+
|
79
|
+
refute campaign.valid?
|
80
|
+
assert campaign.errors.has_key?(:organisation_crest)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "be valid with a blank organisation crest and brand colour" do
|
84
|
+
campaign = FactoryGirl.build(:campaign_edition, :panopticon_id => @artefact.id)
|
85
|
+
campaign.organisation_crest = ''
|
86
|
+
campaign.organisation_brand_colour = ''
|
87
|
+
|
88
|
+
assert campaign.valid?
|
89
|
+
end
|
90
|
+
end
|