govuk_content_models 34.0.0 → 35.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/app/models/artefact.rb +15 -13
  4. data/app/models/business_support/business_size.rb +1 -1
  5. data/app/models/business_support/business_type.rb +1 -1
  6. data/app/models/business_support/location.rb +1 -1
  7. data/app/models/business_support/purpose.rb +1 -1
  8. data/app/models/business_support/sector.rb +1 -1
  9. data/app/models/business_support/stage.rb +1 -1
  10. data/app/models/business_support/support_type.rb +1 -1
  11. data/app/models/business_support_edition.rb +1 -4
  12. data/app/models/curated_list.rb +1 -1
  13. data/app/models/edition.rb +14 -15
  14. data/app/models/licence_edition.rb +5 -2
  15. data/app/models/local_authority.rb +1 -1
  16. data/app/models/overview_dashboard.rb +1 -1
  17. data/app/models/part.rb +2 -2
  18. data/app/models/parted.rb +1 -1
  19. data/app/models/rendered_manual.rb +1 -1
  20. data/app/models/simple_smart_answer_edition/node/option.rb +1 -1
  21. data/app/models/simple_smart_answer_edition/node.rb +1 -1
  22. data/app/models/simple_smart_answer_edition.rb +2 -2
  23. data/app/models/tag.rb +4 -6
  24. data/app/models/travel_advice_edition.rb +18 -17
  25. data/app/models/user.rb +8 -10
  26. data/app/models/workflow.rb +4 -4
  27. data/app/traits/taggable.rb +1 -2
  28. data/config/mongoid.yml +8 -5
  29. data/govuk_content_models.gemspec +12 -10
  30. data/jenkins.sh +3 -0
  31. data/lib/govuk_content_models/action_processors/assign_processor.rb +1 -1
  32. data/lib/govuk_content_models/action_processors/new_version_processor.rb +2 -0
  33. data/lib/govuk_content_models/presentation_toggles.rb +48 -3
  34. data/lib/govuk_content_models/require_all.rb +3 -2
  35. data/lib/govuk_content_models/test_helpers/factories.rb +8 -3
  36. data/lib/govuk_content_models/version.rb +1 -1
  37. data/test/models/artefact_test.rb +9 -9
  38. data/test/models/business_support_edition_test.rb +19 -22
  39. data/test/models/campaign_edition_test.rb +12 -11
  40. data/test/models/completed_transaction_edition_test.rb +79 -0
  41. data/test/models/downtime_test.rb +1 -1
  42. data/test/models/edition_test.rb +23 -9
  43. data/test/models/help_page_edition_test.rb +17 -12
  44. data/test/models/licence_edition_test.rb +9 -8
  45. data/test/models/local_transaction_edition_test.rb +11 -7
  46. data/test/models/parted_test.rb +8 -0
  47. data/test/models/prerendered_entity_tests.rb +4 -4
  48. data/test/models/tag_test.rb +1 -8
  49. data/test/models/travel_advice_edition_test.rb +3 -1
  50. data/test/models/user_test.rb +1 -1
  51. data/test/models/video_edition_test.rb +1 -1
  52. data/test/models/workflow_test.rb +26 -26
  53. data/test/test_helper.rb +4 -1
  54. metadata +66 -24
@@ -3,7 +3,7 @@ module GovukContentModels
3
3
  class AssignProcessor < BaseProcessor
4
4
 
5
5
  def process
6
- edition.set(:assigned_to_id, action_attributes[:recipient_id])
6
+ edition.set(assigned_to_id: action_attributes[:recipient_id])
7
7
  edition.reload
8
8
  end
9
9
 
@@ -13,6 +13,8 @@ module GovukContentModels
13
13
  else
14
14
  edition.build_clone
15
15
  end
16
+
17
+ @edition.save(validate: false) if record_action?
16
18
  end
17
19
 
18
20
  def record_action?
@@ -4,6 +4,8 @@ module PresentationToggles
4
4
  included do
5
5
  field :presentation_toggles, type: Hash, default: default_presentation_toggles
6
6
  validates_presence_of :organ_donor_registration_url, if: :promote_organ_donor_registration?
7
+ validates :promotion_choice_url, presence: true, if: :promotes_something?
8
+ validates :promotion_choice, inclusion: { in: %w(none organ_donor register_to_vote) }
7
9
  end
8
10
 
9
11
  def promote_organ_donor_registration=(value)
@@ -19,20 +21,63 @@ module PresentationToggles
19
21
  def organ_donor_registration_url=(value)
20
22
  organ_donor_registration_key['organ_donor_registration_url'] = value
21
23
  end
22
-
24
+
23
25
  def organ_donor_registration_url
24
26
  organ_donor_registration_key['organ_donor_registration_url']
25
27
  end
26
28
 
27
29
  def organ_donor_registration_key
28
- presentation_toggles['organ_donor_registration']
30
+ presentation_toggles['organ_donor_registration'] ||= self.class.default_presentation_toggles['organ_donor_registration']
31
+ end
32
+
33
+ def promotion_choice=(value)
34
+ promotion_choice_key["choice"] = value
35
+ end
36
+
37
+ def promotion_choice_url=(value)
38
+ promotion_choice_key['url'] = value
39
+ end
40
+
41
+ def promotion_choice
42
+ has_legacy_promote = promote_organ_donor_registration
43
+ choice = promotion_choice_key["choice"]
44
+ if choice.empty?
45
+ if has_legacy_promote
46
+ "organ_donor"
47
+ else
48
+ "none"
49
+ end
50
+ else
51
+ choice
52
+ end
53
+ end
54
+
55
+ def promotes_something?
56
+ promotion_choice != 'none'
57
+ end
58
+
59
+ def promotion_choice_url
60
+ url = promotion_choice_key["url"]
61
+ url.empty? ? organ_donor_registration_url : url
62
+ end
63
+
64
+ def promotion_choice_key
65
+ presentation_toggles['promotion_choice'] ||= self.class.default_presentation_toggles['promotion_choice']
29
66
  end
30
67
 
31
68
  module ClassMethods
32
69
  def default_presentation_toggles
33
70
  {
34
71
  'organ_donor_registration' =>
35
- { 'promote_organ_donor_registration' => false, 'organ_donor_registration_url' => '' }
72
+ {
73
+ 'promote_organ_donor_registration' => false,
74
+ 'organ_donor_registration_url' => ''
75
+ },
76
+ 'promotion_choice' =>
77
+ {
78
+ 'choice' => '',
79
+ 'url' => ''
80
+ }
36
81
  }
37
82
  end
38
83
  end
@@ -10,5 +10,6 @@ root_path = "#{File.dirname(__FILE__)}/../.."
10
10
  end
11
11
 
12
12
  # Require validators first, then other files in app
13
- Dir.glob("#{root_path}/app/validators/*.rb").each {|f| require f }
14
- Dir.glob("#{root_path}/app/**/*.rb").each {|f| require f }
13
+ Dir.glob("#{root_path}/app/validators/*.rb").each { |f| require f }
14
+ Dir.glob("#{root_path}/app/traits/*.rb").each { |f| require f }
15
+ Dir.glob("#{root_path}/app/**/*.rb").each { |f| require f }
@@ -64,7 +64,7 @@ FactoryGirl.define do
64
64
 
65
65
  trait :non_publisher do
66
66
  kind 'smart-answer'
67
- owning_app 'smart-answers'
67
+ owning_app 'smartanswers'
68
68
  end
69
69
 
70
70
  trait :draft do
@@ -97,12 +97,17 @@ FactoryGirl.define do
97
97
  a = create(:artefact)
98
98
  a.id
99
99
  }
100
+ transient do
101
+ version_number nil
102
+ end
100
103
 
101
104
  sequence(:slug) { |n| "slug-#{n}" }
102
105
  sequence(:title) { |n| "A key answer to your question #{n}" }
103
106
 
104
- after :build do |ed|
105
- if previous = ed.series.order(version_number: "desc").first
107
+ after :build do |ed, evaluator|
108
+ if !evaluator.version_number.nil?
109
+ ed.version_number = evaluator.version_number
110
+ elsif (previous = ed.series.order(version_number: "desc").first)
106
111
  ed.version_number = previous.version_number + 1
107
112
  end
108
113
  end
@@ -1,4 +1,4 @@
1
1
  module GovukContentModels
2
2
  # Changing this causes Jenkins to tag and release the gem into the wild
3
- VERSION = "34.0.0"
3
+ VERSION = "35.0.0"
4
4
  end
@@ -124,7 +124,7 @@ class ArtefactTest < ActiveSupport::TestCase
124
124
  should "not validate need ids that were migrated from the singular need_id field" do
125
125
  artefact = FactoryGirl.create(:artefact)
126
126
  # simulate what happened during migration
127
- artefact.set(:need_ids, ['As an employer
127
+ artefact.set(need_ids: ['As an employer
128
128
  I need to know which type of DBS check an employee needs
129
129
  so that I can apply for the correct one'])
130
130
 
@@ -146,25 +146,25 @@ class ArtefactTest < ActiveSupport::TestCase
146
146
  end
147
147
 
148
148
  should "append to existing need_ids when need_id is assigned" do
149
- @artefact.set(:need_ids, ["100044"])
150
- @artefact.set(:need_id, "100044")
149
+ @artefact.set(need_ids: ["100044"])
150
+ @artefact.set(need_id: "100044")
151
151
 
152
152
  @artefact.need_id = "100045"
153
153
 
154
154
  assert_equal "100045", @artefact.need_id
155
- assert_equal ["100044", "100045"], @artefact.need_ids
155
+ assert_equal %w(100044 100045), @artefact.need_ids
156
156
  end
157
157
 
158
158
  # this should only matter till the time we have both fields
159
159
  # need_id and need_ids. can delete this test once we unset need_id.
160
160
  should "keep need_ids unchanged when need_id is removed" do
161
- @artefact.set(:need_ids, ["100044", "100045"])
162
- @artefact.set(:need_id, "100044")
161
+ @artefact.set(need_ids: %w(100044 100045))
162
+ @artefact.set(need_id: "100044")
163
163
 
164
164
  @artefact.need_id = nil
165
165
 
166
166
  assert_equal nil, @artefact.need_id
167
- assert_equal ["100044", "100045"], @artefact.need_ids
167
+ assert_equal %w(100044 100045), @artefact.need_ids
168
168
  end
169
169
  end
170
170
  end
@@ -350,7 +350,7 @@ class ArtefactTest < ActiveSupport::TestCase
350
350
  artefact = FactoryGirl.create(:draft_artefact)
351
351
  edition = FactoryGirl.create(:answer_edition, panopticon_id: artefact.id)
352
352
  old_updated_at = 2.days.ago.to_time
353
- edition.set(:updated_at, old_updated_at)
353
+ edition.set(updated_at: old_updated_at)
354
354
 
355
355
  artefact.language = "cy"
356
356
  artefact.save!
@@ -465,7 +465,7 @@ class ArtefactTest < ActiveSupport::TestCase
465
465
  artefact.update_attributes_as(user1, state: "archived")
466
466
  artefact.save!
467
467
 
468
- editions.each &:reload
468
+ editions.each(&:reload)
469
469
  editions.each do |edition|
470
470
  assert_equal "archived", edition.state
471
471
  end
@@ -10,35 +10,32 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
10
10
  support = FactoryGirl.create(
11
11
  :business_support_edition,
12
12
  panopticon_id: @artefact.id,
13
+ short_description: "The short description",
14
+ body: "The body",
15
+ eligibility: "The eligibility",
16
+ evaluation: "The evaluation",
17
+ additional_information: "The additional information",
18
+ min_value: 1000,
19
+ max_value: 3000,
20
+ max_employees: 2000,
21
+ organiser: "The business support people",
22
+ continuation_link: "http://www.gov.uk",
23
+ will_continue_on: "The GOVUK website",
24
+ contact_details: "123 The Street, Townsville, UK. 07324 123456",
25
+ priority: 2,
26
+ area_gss_codes: %w(G123 G345 G45 G9),
27
+ locations: %w(scotland england),
28
+ sectors: %w(education manufacturing),
29
+ support_types: %w(grant loan),
30
+ start_date: Date.parse("1 Jan 2000"),
31
+ end_date: Date.parse("1 Jan 2020"),
13
32
  )
14
- support.short_description = "The short description"
15
- support.body = "The body"
16
- support.eligibility = "The eligibility"
17
- support.evaluation = "The evaluation"
18
- support.additional_information = "The additional information"
19
- support.min_value = 1000
20
- support.max_value = 3000
21
- support.max_employees = 2000
22
- support.organiser = "The business support people"
23
- support.continuation_link = "http://www.gov.uk"
24
- support.will_continue_on = "The GOVUK website"
25
- support.contact_details = "123 The Street, Townsville, UK. 07324 123456"
26
33
 
27
- support.priority = 2
28
- support.area_gss_codes = ["G123","G345","G45","G9"]
29
34
  support.business_sizes << "up-to-249"
30
35
  support.business_types << "charity"
31
- support.locations = ["scotland", "england"]
32
36
  support.purposes << "making-the-most-of-the-internet"
33
- support.sectors = ["education", "manufacturing"]
34
37
  support.stages << "start-up"
35
- support.support_types = ["grant", "loan"]
36
- support.start_date = Date.parse("1 Jan 2000")
37
- support.end_date = Date.parse("1 Jan 2020")
38
38
 
39
- support.safely.save!
40
-
41
- support = BusinessSupportEdition.first
42
39
  assert_equal "The short description", support.short_description
43
40
  assert_equal "The body", support.body
44
41
  assert_equal "The eligibility", support.eligibility
@@ -6,18 +6,19 @@ class CampaignEditionTest < ActiveSupport::TestCase
6
6
  end
7
7
 
8
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!
9
+ c = FactoryGirl.create(
10
+ :campaign_edition,
11
+ panopticon_id: @artefact.id,
12
+ body: "Start all the campaigns!",
13
+ large_image_id: "large-image-id-from-the-asset-manager",
14
+ medium_image_id: "medium-image-id-from-the-asset-manager",
15
+ small_image_id: "small-image-id-from-the-asset-manager",
16
+ organisation_formatted_name: "Driver & Vehicle\nLicensing\nAgency",
17
+ organisation_url: "/government/organisations/driver-and-vehicle-licensing-agency",
18
+ organisation_brand_colour: "department-for-transport",
19
+ organisation_crest: "single-identity",
20
+ )
19
21
 
20
- c = CampaignEdition.first
21
22
  assert_equal "Start all the campaigns!", c.body
22
23
  assert_equal "large-image-id-from-the-asset-manager", c.large_image_id
23
24
  assert_equal "medium-image-id-from-the-asset-manager", c.medium_image_id
@@ -33,4 +33,83 @@ class CompletedTransactionEditionTest < ActiveSupport::TestCase
33
33
  assert completed_transaction_edition.invalid?
34
34
  assert_includes completed_transaction_edition.errors[:organ_donor_registration_url], "can't be blank"
35
35
  end
36
+
37
+ test "invalid if promotion_choice_url is not specified when a promotion choice is made" do
38
+ completed_transaction_edition = FactoryGirl.build(:completed_transaction_edition,
39
+ promotion_choice: 'organ_donor', promotion_choice_url: "")
40
+
41
+ assert completed_transaction_edition.invalid?
42
+ assert_includes completed_transaction_edition.errors[:promotion_choice_url], "can't be blank"
43
+ end
44
+
45
+ test "invalid if promotion_choice is not one of the allowed ones" do
46
+ completed_transaction_edition = FactoryGirl.build(:completed_transaction_edition, promotion_choice: 'cheese')
47
+
48
+ assert completed_transaction_edition.invalid?
49
+ assert_includes completed_transaction_edition.errors[:promotion_choice], "is not included in the list"
50
+ end
51
+
52
+ test "stores promotion choice and URL" do
53
+ completed_transaction_edition = FactoryGirl.build(:completed_transaction_edition)
54
+
55
+ completed_transaction_edition.promotion_choice = "none"
56
+ completed_transaction_edition.save!
57
+
58
+ assert_equal "none", completed_transaction_edition.reload.promotion_choice
59
+
60
+ completed_transaction_edition.promotion_choice = "organ_donor"
61
+ completed_transaction_edition.promotion_choice_url = "https://www.organdonation.nhs.uk/registration/"
62
+ completed_transaction_edition.save!
63
+
64
+ assert_equal "organ_donor", completed_transaction_edition.reload.promotion_choice
65
+ assert_equal "https://www.organdonation.nhs.uk/registration/", completed_transaction_edition.promotion_choice_url
66
+
67
+ completed_transaction_edition.promotion_choice = "register_to_vote"
68
+ completed_transaction_edition.promotion_choice_url = "https://www.gov.uk/register-to-vote"
69
+ completed_transaction_edition.save!
70
+
71
+ assert_equal "register_to_vote", completed_transaction_edition.reload.promotion_choice
72
+ assert_equal "https://www.gov.uk/register-to-vote", completed_transaction_edition.promotion_choice_url
73
+ end
74
+
75
+ test "stores promotion choice and URL on legacy documents" do
76
+ completed_transaction_edition = FactoryGirl.build(:completed_transaction_edition,
77
+ presentation_toggles: {
78
+ 'organ_donor_registration' => {
79
+ 'promote_organ_donor_registration' => false,
80
+ 'organ_donor_registration_url' => ''
81
+ },
82
+ }
83
+ )
84
+
85
+ completed_transaction_edition.promotion_choice = "none"
86
+ completed_transaction_edition.save!
87
+
88
+ assert_equal "none", completed_transaction_edition.reload.promotion_choice
89
+
90
+ completed_transaction_edition.promotion_choice = "organ_donor"
91
+ completed_transaction_edition.promotion_choice_url = "https://www.organdonation.nhs.uk/registration/"
92
+ completed_transaction_edition.save!
93
+
94
+ assert_equal "organ_donor", completed_transaction_edition.reload.promotion_choice
95
+ assert_equal "https://www.organdonation.nhs.uk/registration/", completed_transaction_edition.promotion_choice_url
96
+
97
+ completed_transaction_edition.promotion_choice = "register_to_vote"
98
+ completed_transaction_edition.promotion_choice_url = "https://www.gov.uk/register-to-vote"
99
+ completed_transaction_edition.save!
100
+
101
+ assert_equal "register_to_vote", completed_transaction_edition.reload.promotion_choice
102
+ assert_equal "https://www.gov.uk/register-to-vote", completed_transaction_edition.promotion_choice_url
103
+ end
104
+
105
+ test "passes through legacy organ donor info" do
106
+ completed_transaction_edition = FactoryGirl.build(:completed_transaction_edition,
107
+ promote_organ_donor_registration: true)
108
+
109
+ completed_transaction_edition.organ_donor_registration_url = "https://www.organdonation.nhs.uk/registration/"
110
+ completed_transaction_edition.save!
111
+
112
+ assert_equal "organ_donor", completed_transaction_edition.reload.promotion_choice
113
+ assert_equal "https://www.organdonation.nhs.uk/registration/", completed_transaction_edition.promotion_choice_url
114
+ end
36
115
  end
@@ -84,7 +84,7 @@ class DowntimeTest < ActiveSupport::TestCase
84
84
  Timecop.freeze(Time.zone.now + 10) do
85
85
  downtime = FactoryGirl.build(:downtime)
86
86
 
87
- downtime.end_time = Time.zone.now
87
+ downtime.end_time = Time.zone.now - 1.minute
88
88
  refute downtime.publicise?
89
89
  end
90
90
  end
@@ -24,8 +24,8 @@ class EditionTest < ActiveSupport::TestCase
24
24
 
25
25
  def template_published_answer(version_number = 1)
26
26
  answer = template_answer(version_number)
27
- answer.publish
28
- answer.save
27
+ answer.publish!
28
+ answer.save!
29
29
  answer
30
30
  end
31
31
 
@@ -85,6 +85,16 @@ class EditionTest < ActiveSupport::TestCase
85
85
  assert_equal [g1], g3.previous_siblings.to_a
86
86
  end
87
87
 
88
+ test "subsequent and previous siblings are in order" do
89
+ g4 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 4)
90
+ g2 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 2)
91
+ g1 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 1)
92
+ g3 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 3)
93
+
94
+ assert_equal [g2, g3, g4], g1.subsequent_siblings.to_a
95
+ assert_equal [g1, g2, g3], g4.previous_siblings.to_a
96
+ end
97
+
88
98
  test "A programme should have default parts" do
89
99
  programme = FactoryGirl.create(:programme_edition, panopticon_id: @artefact.id)
90
100
  assert_equal programme.parts.count, ProgrammeEdition::DEFAULT_PARTS.length
@@ -103,7 +113,7 @@ class EditionTest < ActiveSupport::TestCase
103
113
  edition.body += "some update"
104
114
 
105
115
  refute edition.valid?
106
- assert_include edition.errors.full_messages, %q<Body ["Don't include hover text in links. Delete the text in quotation marks eg \\"This appears when you hover over the link.\\""]>
116
+ assert_includes edition.errors.full_messages, %q<Body ["Don't include hover text in links. Delete the text in quotation marks eg \\"This appears when you hover over the link.\\""]>
107
117
  end
108
118
 
109
119
  should "allow archiving an edition with invalid links" do
@@ -723,6 +733,8 @@ class EditionTest < ActiveSupport::TestCase
723
733
 
724
734
  second_edition = edition.build_clone
725
735
  second_edition.state = "ready"
736
+ second_edition.save!
737
+
726
738
  publish(user, second_edition, "Second publication")
727
739
 
728
740
  # simulate link validation errors in published edition
@@ -732,6 +744,8 @@ class EditionTest < ActiveSupport::TestCase
732
744
  # fix link validation error in cloned edition by appending a '/' to the relative url
733
745
  third_edition.parts.first.body = "[register your vehicle](/registering-an-imported-vehicle)"
734
746
  third_edition.state = "ready"
747
+ third_edition.save!
748
+
735
749
  publish(user, third_edition, "Third publication")
736
750
 
737
751
  edition.reload
@@ -854,7 +868,7 @@ class EditionTest < ActiveSupport::TestCase
854
868
  test "user should not be able to review an edition they requested review for" do
855
869
  user = User.create(name: "Mary")
856
870
 
857
- edition = ProgrammeEdition.new(title: "Childcare", slug: "childcare", panopticon_id: @artefact.id)
871
+ edition = ProgrammeEdition.create(title: "Childcare", slug: "childcare", panopticon_id: @artefact.id)
858
872
  assert edition.can_request_review?
859
873
  request_review(user, edition)
860
874
  refute request_amendments(user, edition)
@@ -1044,8 +1058,8 @@ class EditionTest < ActiveSupport::TestCase
1044
1058
  ed2 = FactoryGirl.build(:edition, :panopticon_id => @artefact.id)
1045
1059
  ed2.version_number = ed1.version_number
1046
1060
 
1047
- assert_raises Mongo::OperationFailure do
1048
- ed2.safely.save! :validate => false
1061
+ assert_raises Mongo::Error::OperationFailure do
1062
+ ed2.save! validate: false
1049
1063
  end
1050
1064
  end
1051
1065
  end
@@ -1195,7 +1209,7 @@ class EditionTest < ActiveSupport::TestCase
1195
1209
  state: 'published')
1196
1210
  edition2 = edition1.build_clone
1197
1211
 
1198
- assert_equal edition1.updated_at, edition2.public_updated_at
1212
+ assert_in_delta edition1.updated_at, edition2.public_updated_at, 1.second
1199
1213
  end
1200
1214
 
1201
1215
  should 'return the timestamp of the first published edition when there are no major updates' do
@@ -1209,8 +1223,8 @@ class EditionTest < ActiveSupport::TestCase
1209
1223
  end
1210
1224
  edition1.update_attributes!(state: 'archived', major_change: false)
1211
1225
 
1212
- assert_equal edition1.updated_at, edition2.public_updated_at
1213
- assert_not_equal edition2.updated_at, edition2.public_updated_at
1226
+ assert_in_delta edition1.updated_at, edition2.public_updated_at, 1.second
1227
+ assert_not_in_delta edition2.updated_at, edition2.public_updated_at, 1.second
1214
1228
  end
1215
1229
 
1216
1230
  should 'return nil if there are no major updates and no published editions' do
@@ -2,15 +2,16 @@ require "test_helper"
2
2
 
3
3
  class HelpPageEditionTest < ActiveSupport::TestCase
4
4
  setup do
5
- @artefact = FactoryGirl.create(:artefact, :kind => 'help_page', :slug => "help/foo")
5
+ @artefact = FactoryGirl.create(:artefact, kind: 'help_page', slug: "help/foo")
6
6
  end
7
7
 
8
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!
9
+ h = FactoryGirl.create(
10
+ :help_page_edition,
11
+ panopticon_id: @artefact.id,
12
+ body: "I'm a help page.",
13
+ )
12
14
 
13
- h = HelpPageEdition.first
14
15
  assert_equal "I'm a help page.", h.body
15
16
  end
16
17
 
@@ -20,17 +21,21 @@ class HelpPageEditionTest < ActiveSupport::TestCase
20
21
  end
21
22
 
22
23
  should "return the body as whole_body" do
23
- h = FactoryGirl.build(:help_page_edition,
24
- :panopticon_id => @artefact.id,
25
- :body => "Something")
24
+ h = FactoryGirl.build(
25
+ :help_page_edition,
26
+ panopticon_id: @artefact.id,
27
+ body: "Something",
28
+ )
26
29
  assert_equal h.body, h.whole_body
27
30
  end
28
31
 
29
32
  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")
33
+ help_page = FactoryGirl.create(
34
+ :help_page_edition,
35
+ panopticon_id: @artefact.id,
36
+ state: "published",
37
+ body: "I'm very helpful",
38
+ )
34
39
 
35
40
  new_help_page = help_page.build_clone
36
41
  assert_equal help_page.body, new_help_page.body
@@ -6,15 +6,16 @@ class LicenceEditionTest < ActiveSupport::TestCase
6
6
  end
7
7
 
8
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!
9
+ l = FactoryGirl.create(
10
+ :licence_edition,
11
+ panopticon_id: @artefact.id,
12
+ licence_identifier: "AB1234",
13
+ licence_short_description: "Short description of licence",
14
+ licence_overview: "Markdown overview of licence...",
15
+ will_continue_on: "The HMRC website",
16
+ continuation_link: "http://www.hmrc.gov.uk"
17
+ )
16
18
 
17
- l = LicenceEdition.first
18
19
  assert_equal "AB1234", l.licence_identifier
19
20
  assert_equal "Short description of licence", l.licence_short_description
20
21
  assert_equal "Markdown overview of licence...", l.licence_overview
@@ -3,35 +3,39 @@ require "govuk_content_models/test_helpers/local_services"
3
3
 
4
4
  class LocalTransactionEditionTest < ActiveSupport::TestCase
5
5
  include LocalServicesHelper
6
+ BINS = 1
7
+ HOUSING_BENEFIT = 2
8
+ NONEXISTENT = 999
9
+
6
10
  def setup
7
11
  @artefact = FactoryGirl.create(:artefact)
8
12
  end
9
13
 
10
14
  test "should report that an authority provides a service" do
11
15
  bins_transaction = LocalTransactionEdition.new(
12
- lgsl_code: "bins",
16
+ lgsl_code: BINS,
13
17
  title: "Transaction",
14
18
  slug: "slug",
15
19
  panopticon_id: @artefact.id
16
20
  )
17
- county_council = make_authority_providing("bins")
21
+ county_council = make_authority_providing(BINS)
18
22
  assert bins_transaction.service_provided_by?(county_council.snac)
19
23
  end
20
24
 
21
25
  test "should report that an authority does not provide a service" do
22
26
  bins_transaction = LocalTransactionEdition.new(
23
- lgsl_code: "bins",
27
+ lgsl_code: BINS,
24
28
  title: "Transaction",
25
29
  slug: "slug",
26
30
  panopticon_id: @artefact.id
27
31
  )
28
- county_council = make_authority_providing("housing-benefit")
32
+ county_council = make_authority_providing(HOUSING_BENEFIT)
29
33
  refute bins_transaction.service_provided_by?(county_council.snac)
30
34
  end
31
35
 
32
36
  test "should be a transaction search format" do
33
37
  bins_transaction = LocalTransactionEdition.new(
34
- lgsl_code: "bins",
38
+ lgsl_code: BINS,
35
39
  title: "Transaction",
36
40
  slug: "slug",
37
41
  panopticon_id: @artefact.id
@@ -41,9 +45,9 @@ class LocalTransactionEditionTest < ActiveSupport::TestCase
41
45
 
42
46
 
43
47
  test "should validate on save that a LocalService exists for that lgsl_code" do
44
- s = LocalService.create!(lgsl_code: "bins", providing_tier: %w{county unitary})
48
+ s = LocalService.create!(lgsl_code: BINS, providing_tier: %w{county unitary})
45
49
 
46
- lt = LocalTransactionEdition.new(lgsl_code: "nonexistent", title: "Foo", slug: "foo", panopticon_id: @artefact.id)
50
+ lt = LocalTransactionEdition.new(lgsl_code: NONEXISTENT, title: "Foo", slug: "foo", panopticon_id: @artefact.id)
47
51
  lt.save
48
52
  assert !lt.valid?
49
53
 
@@ -15,4 +15,12 @@ class PartedTest < ActiveSupport::TestCase
15
15
  assert_equal({slug: ["can't be blank", "is invalid"]}, edition.errors[:parts][0]['54c10d4d759b743528000011:2'])
16
16
  assert_equal 2, edition.errors[:parts][0].length
17
17
  end
18
+
19
+ test "#whole_body returns ordered parts" do
20
+ edition = FactoryGirl.create(:guide_edition)
21
+ edition.parts.build(_id: '54c10d4d759b743528000010', order: '1', title: "Part 1", slug: "part_1")
22
+ edition.parts.build(_id: '54c10d4d759b743528000011', order: '3', title: "Part 3", slug: "part_3")
23
+ edition.parts.build(_id: '54c10d4d759b743528000012', order: '2', title: "Part 2", slug: "part_2")
24
+ assert_equal("# Part 1\n\n\n\n# Part 2\n\n\n\n# Part 3\n\n", edition.whole_body)
25
+ end
18
26
  end
@@ -15,11 +15,11 @@ module PrerenderedEntityTests
15
15
 
16
16
  def test_create_or_update_by_slug
17
17
  slug = "a-slug"
18
- original_body = "Original body"
18
+ original_title = "Original title"
19
19
 
20
20
  version1_attrs= {
21
21
  slug: slug,
22
- body: original_body,
22
+ title: original_title,
23
23
  }
24
24
 
25
25
  created = model_class.create_or_update_by_slug!(version1_attrs)
@@ -28,13 +28,13 @@ module PrerenderedEntityTests
28
28
  assert created.persisted?
29
29
 
30
30
  version2_attrs = version1_attrs.merge(
31
- body: "Updated body",
31
+ title: "Updated title",
32
32
  )
33
33
 
34
34
  version2 = model_class.create_or_update_by_slug!(version2_attrs)
35
35
 
36
36
  assert version2.persisted?
37
- assert_equal "Updated body", version2.body
37
+ assert_equal "Updated title", version2.title
38
38
  end
39
39
 
40
40
  def test_find_by_slug