govuk_content_models 28.0.0 → 28.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/app/models/action.rb +0 -3
  3. data/app/models/answer_edition.rb +1 -1
  4. data/app/models/artefact.rb +0 -4
  5. data/app/models/artefact_action.rb +0 -4
  6. data/app/models/artefact_external_link.rb +0 -4
  7. data/app/models/business_support_edition.rb +1 -1
  8. data/app/models/campaign_edition.rb +2 -1
  9. data/app/models/completed_transaction_edition.rb +1 -1
  10. data/app/models/curated_list.rb +0 -3
  11. data/app/models/edition.rb +1 -3
  12. data/app/models/guide_edition.rb +1 -0
  13. data/app/models/help_page_edition.rb +1 -1
  14. data/app/models/licence_edition.rb +2 -2
  15. data/app/models/local_authority.rb +0 -3
  16. data/app/models/local_interaction.rb +0 -3
  17. data/app/models/local_service.rb +0 -3
  18. data/app/models/local_transaction_edition.rb +1 -1
  19. data/app/models/manual_change_history.rb +0 -3
  20. data/app/models/overview_dashboard.rb +0 -4
  21. data/app/models/place_edition.rb +1 -1
  22. data/app/models/programme_edition.rb +1 -0
  23. data/app/models/rendered_manual.rb +0 -3
  24. data/app/models/rendered_specialist_document.rb +0 -3
  25. data/app/models/simple_smart_answer_edition.rb +2 -1
  26. data/app/models/simple_smart_answer_edition/node.rb +0 -1
  27. data/app/models/tag.rb +0 -2
  28. data/app/models/transaction_edition.rb +1 -1
  29. data/app/models/user.rb +0 -4
  30. data/app/models/video_edition.rb +1 -1
  31. data/lib/govuk_content_models/version.rb +1 -1
  32. data/test/models/artefact_test.rb +2 -2
  33. data/test/models/edition_test.rb +14 -6
  34. data/test/models/prerendered_entity_tests.rb +1 -1
  35. data/test/validators/safe_html_validator_test.rb +2 -2
  36. metadata +4 -4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 28.0.1
2
+
3
+ - Skip LinkValidator for archived editions.
4
+
1
5
  ## 28.0.0
2
6
 
3
7
  - Removes `uses_government_gateway` and `minutes_to_complete` fields from
data/app/models/action.rb CHANGED
@@ -41,9 +41,6 @@ class Action
41
41
  field :customised_message, type: String
42
42
  field :created_at, type: DateTime, default: lambda { Time.zone.now }
43
43
 
44
- GOVSPEAK_FIELDS = []
45
- validates_with SafeHtml
46
-
47
44
  def container_class_name(edition)
48
45
  edition.container.class.name.underscore.humanize
49
46
  end
@@ -3,7 +3,7 @@ require "edition"
3
3
  class AnswerEdition < Edition
4
4
  field :body, type: String
5
5
 
6
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
6
+ GOVSPEAK_FIELDS = [:body]
7
7
 
8
8
  @fields_to_clone = [:body]
9
9
 
@@ -61,10 +61,6 @@ class Artefact
61
61
 
62
62
  scope :not_archived, where(:state.nin => ["archived"])
63
63
 
64
- GOVSPEAK_FIELDS = []
65
-
66
- validates_with SafeHtml
67
-
68
64
  MAXIMUM_RELATED_ITEMS = 8
69
65
 
70
66
  FORMATS_BY_DEFAULT_OWNING_APP = {
@@ -7,12 +7,8 @@ class ArtefactAction
7
7
  field "action_type", type: String
8
8
  field "snapshot", type: Hash
9
9
 
10
- GOVSPEAK_FIELDS = []
11
-
12
10
  embedded_in :artefact
13
11
 
14
- validates_with SafeHtml
15
-
16
12
  # Ideally we would like to use the UID field here, since that will be the
17
13
  # same across all applications, but Mongoid doesn't yet support using a
18
14
  # custom primary key on a related field
@@ -4,12 +4,8 @@ class ArtefactExternalLink
4
4
  field "title", type: String
5
5
  field "url", type: String
6
6
 
7
- GOVSPEAK_FIELDS = []
8
-
9
7
  embedded_in :artefact
10
8
 
11
- validates_with SafeHtml
12
-
13
9
  validates_presence_of :title
14
10
  validates :url, :presence => true, :format => { :with => URI::regexp(%w{http https}) }
15
11
  end
@@ -30,7 +30,7 @@ class BusinessSupportEdition < Edition
30
30
  field :end_date, type: Date
31
31
  field :areas, type: Array, default: []
32
32
 
33
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body, :eligibility, :evaluation, :additional_information]
33
+ GOVSPEAK_FIELDS = [:body, :eligibility, :evaluation, :additional_information]
34
34
 
35
35
  validate :scheme_dates
36
36
  validate :min_must_be_less_than_max
@@ -12,7 +12,8 @@ class CampaignEdition < Edition
12
12
 
13
13
  attaches :large_image, :medium_image, :small_image
14
14
 
15
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
15
+ GOVSPEAK_FIELDS = [:body]
16
+
16
17
  @fields_to_clone = [
17
18
  :body, :large_image_id, :medium_image_id, :small_image_id,
18
19
  :organisation_formatted_name, :organisation_url, :organisation_brand_colour, :organisation_crest
@@ -3,7 +3,7 @@ require "edition"
3
3
  class CompletedTransactionEdition < Edition
4
4
  field :body, type: String
5
5
 
6
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
6
+ GOVSPEAK_FIELDS = [:body]
7
7
 
8
8
  @fields_to_clone = [:body]
9
9
 
@@ -13,10 +13,7 @@ class CuratedList
13
13
 
14
14
  index "slug"
15
15
 
16
- GOVSPEAK_FIELDS = []
17
-
18
16
  validates :slug, presence: true, uniqueness: true, slug: true
19
- validates_with SafeHtml
20
17
 
21
18
  def self.find_by_slug(slug)
22
19
  where(slug: slug).first
@@ -34,8 +34,6 @@ class Edition
34
34
  field :change_note, type: String
35
35
  field :review_requested_at, type: DateTime
36
36
 
37
- GOVSPEAK_FIELDS = []
38
-
39
37
  belongs_to :assigned_to, class_name: "User"
40
38
 
41
39
  # state_machine comes from Workflow
@@ -57,7 +55,7 @@ class Edition
57
55
  validates :version_number, presence: true, uniqueness: {scope: :panopticon_id}
58
56
  validates :panopticon_id, presence: true
59
57
  validates_with SafeHtml
60
- validates_with LinkValidator, on: :update
58
+ validates_with LinkValidator, on: :update, unless: :archived?
61
59
  validates_with TopicValidator, BrowsePageValidator, ReviewerValidator
62
60
  validates_presence_of :change_note, if: :major_change
63
61
 
@@ -7,6 +7,7 @@ class GuideEdition < Edition
7
7
  field :video_url, type: String
8
8
  field :video_summary, type: String
9
9
 
10
+ GOVSPEAK_FIELDS = []
10
11
  @fields_to_clone = [:video_url, :video_summary]
11
12
 
12
13
  def has_video?
@@ -3,7 +3,7 @@ require "edition"
3
3
  class HelpPageEdition < Edition
4
4
  field :body, type: String
5
5
 
6
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
6
+ GOVSPEAK_FIELDS = [:body]
7
7
 
8
8
  @fields_to_clone = [:body]
9
9
 
@@ -8,12 +8,12 @@ class LicenceEdition < Edition
8
8
  field :will_continue_on, :type => String
9
9
  field :continuation_link, :type => String
10
10
 
11
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:licence_overview]
11
+ GOVSPEAK_FIELDS = [:licence_overview]
12
12
 
13
13
  validates :licence_identifier, :presence => true
14
14
  validate :licence_identifier_unique
15
15
  validates_format_of :continuation_link, :with => URI::regexp(%w(http https)), :allow_blank => true
16
-
16
+
17
17
  @fields_to_clone = [:licence_identifier, :licence_short_description,
18
18
  :licence_overview, :will_continue_on, :continuation_link]
19
19
 
@@ -16,11 +16,8 @@ class LocalAuthority
16
16
  field :contact_phone, type: String
17
17
  field :contact_email, type: String
18
18
 
19
- GOVSPEAK_FIELDS = []
20
-
21
19
  validates_uniqueness_of :snac
22
20
  validates_presence_of :snac, :local_directgov_id, :name, :tier
23
- validates_with SafeHtml
24
21
 
25
22
  scope :for_snacs, ->(snacs) { any_in(snac: snacs) }
26
23
 
@@ -10,11 +10,8 @@ class LocalInteraction
10
10
  field :lgil_code, type: Integer
11
11
  field :url, type: String
12
12
 
13
- GOVSPEAK_FIELDS = []
14
-
15
13
  embedded_in :local_authority
16
14
 
17
15
  validates_presence_of :url, :lgil_code, :lgsl_code
18
16
  validates_uniqueness_of :lgil_code, :scope => :lgsl_code
19
- validates_with SafeHtml
20
17
  end
@@ -9,14 +9,11 @@ class LocalService
9
9
  field :lgsl_code, type: Integer
10
10
  field :providing_tier, type: Array
11
11
 
12
- GOVSPEAK_FIELDS = []
13
-
14
12
  validates_presence_of :lgsl_code, :providing_tier
15
13
  validates_uniqueness_of :lgsl_code
16
14
  validates :providing_tier, inclusion: {
17
15
  in: [%w{county unitary}, %w{district unitary}, %w{district unitary county}]
18
16
  }
19
- validates_with SafeHtml
20
17
 
21
18
  def self.find_by_lgsl_code(lgsl_code)
22
19
  LocalService.where(lgsl_code: lgsl_code).first
@@ -8,7 +8,7 @@ class LocalTransactionEdition < Edition
8
8
  field :more_information, type: String
9
9
  field :need_to_know, type: String
10
10
 
11
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:introduction, :more_information, :need_to_know]
11
+ GOVSPEAK_FIELDS = [:introduction, :more_information, :need_to_know]
12
12
 
13
13
  @fields_to_clone = [
14
14
  :lgsl_code, :introduction, :more_information, :need_to_know
@@ -12,7 +12,4 @@ class ManualChangeHistory
12
12
  index "slug", unique: true
13
13
 
14
14
  validates :slug, uniqueness: true
15
- validates_with SafeHtml
16
-
17
- GOVSPEAK_FIELDS = []
18
15
  end
@@ -17,8 +17,4 @@ class OverviewDashboard
17
17
  field :fact_check, type: Integer
18
18
  field :published, type: Integer
19
19
  field :archived, type: Integer
20
-
21
- GOVSPEAK_FIELDS = []
22
-
23
- validates_with SafeHtml
24
20
  end
@@ -6,7 +6,7 @@ class PlaceEdition < Edition
6
6
  field :need_to_know, type: String
7
7
  field :place_type, type: String
8
8
 
9
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:introduction, :more_information, :need_to_know]
9
+ GOVSPEAK_FIELDS = [:introduction, :more_information, :need_to_know]
10
10
 
11
11
  @fields_to_clone = [:introduction, :more_information, :place_type, :need_to_know]
12
12
 
@@ -6,6 +6,7 @@ class ProgrammeEdition < Edition
6
6
 
7
7
  before_save :setup_default_parts, on: :create
8
8
 
9
+ GOVSPEAK_FIELDS = []
9
10
  @fields_to_clone = []
10
11
 
11
12
  DEFAULT_PARTS = [
@@ -13,8 +13,5 @@ class RenderedManual
13
13
 
14
14
  index "slug", unique: true
15
15
 
16
- GOVSPEAK_FIELDS = []
17
-
18
- validates_with SafeHtml
19
16
  validates_uniqueness_of :slug
20
17
  end
@@ -15,8 +15,5 @@ class RenderedSpecialistDocument
15
15
 
16
16
  index "slug", unique: true
17
17
 
18
- GOVSPEAK_FIELDS = []
19
-
20
18
  validates :slug, uniqueness: true
21
- validates_with SafeHtml
22
19
  end
@@ -11,7 +11,8 @@ class SimpleSmartAnswerEdition < Edition
11
11
 
12
12
  accepts_nested_attributes_for :nodes, allow_destroy: true
13
13
 
14
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
14
+ GOVSPEAK_FIELDS = [:body]
15
+
15
16
  @fields_to_clone = [:body]
16
17
 
17
18
  def whole_body
@@ -28,7 +28,6 @@ class SimpleSmartAnswerEdition < Edition
28
28
  validates :slug, :presence => true, :format => {:with => /\A[a-z0-9-]+\z/}
29
29
 
30
30
  validate :outcomes_have_no_options
31
-
32
31
  validates_with SafeHtml
33
32
 
34
33
  private
data/app/models/tag.rb CHANGED
@@ -13,7 +13,6 @@ class Tag
13
13
  field :parent_id, type: String
14
14
  field :state, type: String, default: 'draft'
15
15
 
16
- GOVSPEAK_FIELDS = []
17
16
  STATES = ['draft', 'live']
18
17
 
19
18
  index :tag_id
@@ -23,7 +22,6 @@ class Tag
23
22
  validates_presence_of :tag_id, :title, :tag_type
24
23
  validates_uniqueness_of :tag_id, scope: :tag_type
25
24
  validates_with TagIdValidator
26
- validates_with SafeHtml
27
25
 
28
26
  attr_protected :state
29
27
 
@@ -8,7 +8,7 @@ class TransactionEdition < Edition
8
8
  field :need_to_know, type: String
9
9
  field :alternate_methods, type: String
10
10
 
11
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:introduction, :more_information, :alternate_methods, :need_to_know]
11
+ GOVSPEAK_FIELDS = [:introduction, :more_information, :alternate_methods, :need_to_know]
12
12
 
13
13
  @fields_to_clone = [:introduction, :will_continue_on, :link,
14
14
  :more_information, :alternate_methods,
data/app/models/user.rb CHANGED
@@ -26,8 +26,6 @@ class User
26
26
  index "uid", unique: true
27
27
  index "disabled"
28
28
 
29
- GOVSPEAK_FIELDS = []
30
-
31
29
  # Setup accessible (or protected) attributes for your model
32
30
  attr_accessible :email, :name, :uid
33
31
  attr_accessible :email, :name, :uid, :permissions, as: :oauth
@@ -36,8 +34,6 @@ class User
36
34
  scope :enabled, any_of({ :disabled.exists => false },
37
35
  { :disabled.in => [false, nil] })
38
36
 
39
- validates_with SafeHtml
40
-
41
37
  def to_s
42
38
  name || email || ""
43
39
  end
@@ -8,7 +8,7 @@ class VideoEdition < Edition
8
8
  field :video_summary, type: String
9
9
  field :body, type: String
10
10
 
11
- GOVSPEAK_FIELDS = Edition::GOVSPEAK_FIELDS + [:body]
11
+ GOVSPEAK_FIELDS = [:body]
12
12
 
13
13
  @fields_to_clone = [:video_url, :video_summary, :body]
14
14
 
@@ -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 = "28.0.0"
3
+ VERSION = "28.0.1"
4
4
  end
@@ -286,11 +286,11 @@ class ArtefactTest < ActiveSupport::TestCase
286
286
  parent = Artefact.create!(slug: "parent", name: "Parent", kind: "guide", owning_app: "x")
287
287
 
288
288
  a = Artefact.create!(slug: "a", name: "has no published editions", kind: "guide", owning_app: "publisher")
289
- Edition.create!(panopticon_id: a.id, title: "Unpublished", state: "draft")
289
+ GuideEdition.create!(panopticon_id: a.id, title: "Unpublished", state: "draft")
290
290
  parent.related_artefacts << a
291
291
 
292
292
  b = Artefact.create!(slug: "b", name: "has a published edition", kind: "guide", owning_app: "publisher")
293
- Edition.create!(panopticon_id: b.id, title: "Published", state: "published")
293
+ GuideEdition.create!(panopticon_id: b.id, title: "Published", state: "published")
294
294
  parent.related_artefacts << b
295
295
 
296
296
  c = Artefact.create!(slug: "c", name: "not a publisher artefact", kind: "place", owning_app: "x")
@@ -106,34 +106,42 @@ class EditionTest < ActiveSupport::TestCase
106
106
  refute edition.valid?
107
107
  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.\\""]>
108
108
  end
109
+
110
+ should "allow archiving an edition with invalid links" do
111
+ edition = FactoryGirl.create(:answer_edition, state: 'published', body: 'abc [foobar](http://foobar.com "hover")')
112
+
113
+ assert_difference 'AnswerEdition.archived.count', 1 do
114
+ edition.archive!
115
+ end
116
+ end
109
117
  end
110
118
 
111
119
  context "change note" do
112
120
  should "be a minor change by default" do
113
- refute Edition.new.major_change
121
+ refute AnswerEdition.new.major_change
114
122
  end
115
123
  should "not be valid for major changes with a blank change note" do
116
- edition = Edition.new(major_change: true, change_note: "")
124
+ edition = AnswerEdition.new(major_change: true, change_note: "")
117
125
  refute edition.valid?
118
126
  assert edition.errors.has_key?(:change_note)
119
127
  end
120
128
  should "be valid for major changes with a change note" do
121
- edition = Edition.new(title: "Edition", version_number: 1, panopticon_id: 123, major_change: true, change_note: "Changed")
129
+ edition = AnswerEdition.new(title: "Edition", version_number: 1, panopticon_id: 123, major_change: true, change_note: "Changed")
122
130
  assert edition.valid?
123
131
  end
124
132
  should "be valid when blank for minor changes" do
125
- edition = Edition.new(title: "Edition", version_number: 1, panopticon_id: 123, change_note: "")
133
+ edition = AnswerEdition.new(title: "Edition", version_number: 1, panopticon_id: 123, change_note: "")
126
134
  assert edition.valid?
127
135
  end
128
136
  should "be valid when populated for minor changes" do
129
- edition = Edition.new(title: "Edition", version_number: 1, panopticon_id: 123, change_note: "Changed")
137
+ edition = AnswerEdition.new(title: "Edition", version_number: 1, panopticon_id: 123, change_note: "Changed")
130
138
  assert edition.valid?
131
139
  end
132
140
  end
133
141
 
134
142
  test "reviewer cannot be the assignee" do
135
143
  user = FactoryGirl.create(:user)
136
- edition = Edition.new(title: "Edition", version_number: 1, panopticon_id: 123,
144
+ edition = AnswerEdition.new(title: "Edition", version_number: 1, panopticon_id: 123,
137
145
  state: "in_review", review_requested_at: Time.zone.now, assigned_to: user)
138
146
  edition.reviewer = user.name
139
147
  refute edition.valid?
@@ -10,7 +10,7 @@ module PrerenderedEntityTests
10
10
  end
11
11
 
12
12
  def test_has_no_govspeak_fields
13
- assert_equal [], model_class::GOVSPEAK_FIELDS
13
+ refute model_class.const_defined?(:GOVSPEAK_FIELDS)
14
14
  end
15
15
 
16
16
  def test_create_or_update_by_slug
@@ -65,7 +65,7 @@ class SafeHtmlTest < ActiveSupport::TestCase
65
65
  assert dummy.invalid?
66
66
  end
67
67
 
68
- should "all models should use this validator" do
68
+ should "all models that have govspeak fields should use this validator" do
69
69
  models_dir = File.expand_path("../../app/models/*", File.dirname(__FILE__))
70
70
 
71
71
  classes = Dir[models_dir]
@@ -73,7 +73,7 @@ class SafeHtmlTest < ActiveSupport::TestCase
73
73
  File.basename(file, ".rb").camelize.constantize
74
74
  }
75
75
  .select { |klass|
76
- klass.included_modules.include?(Mongoid::Document)
76
+ klass.included_modules.include?(Mongoid::Document) && klass.const_defined?(:GOVSPEAK_FIELDS)
77
77
  }
78
78
  .each { |klass|
79
79
  assert_includes klass.validators.map(&:class), SafeHtml, "#{klass} must be validated with SafeHtml"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_content_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 28.0.0
4
+ version: 28.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-17 00:00:00.000000000 Z
12
+ date: 2015-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -475,7 +475,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
475
475
  version: '0'
476
476
  segments:
477
477
  - 0
478
- hash: 1468707527952155644
478
+ hash: 1044253096296526038
479
479
  required_rubygems_version: !ruby/object:Gem::Requirement
480
480
  none: false
481
481
  requirements:
@@ -484,7 +484,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
484
  version: '0'
485
485
  segments:
486
486
  - 0
487
- hash: 1468707527952155644
487
+ hash: 1044253096296526038
488
488
  requirements: []
489
489
  rubyforge_project:
490
490
  rubygems_version: 1.8.23