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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e57d325ccc96b7ded00251c5fba3ab51e74d58d
4
- data.tar.gz: 9bec9ac5c2b93270b66163442d8a771eb21e5398
3
+ metadata.gz: 92694115f4161b92997ef39dda8faf21ffe830fa
4
+ data.tar.gz: 16a4fc4c0c45804fe4d34ed799958f98e88d18ac
5
5
  SHA512:
6
- metadata.gz: 9a34f277be32a2a43a9e6aee4579bf5c66f80614b836db8b3bfcc46a4b7251c01967af251e37cb140c4a77557741cc3bdd945fa22ba777eedb2f9ba352d95b90
7
- data.tar.gz: 7cdf7ab729992789532203d469bacd8fd9bb53b66e298446406242067d8c506a55c2117310735961791b55ff3a0afe54f7f109cc5a0afd2f2e3c6493488d8766
6
+ metadata.gz: dfae23fecd0faa01072c0ba78e24206d747fa9a2d0823b6cdd5de88c42798d973242651058209d4cd903ecc31dfae8b356c037284349a8974516e11d7487902f
7
+ data.tar.gz: 304f70288d4261f7c5cd3ec21ecb2383c5dc6880b896df083df5e2df45a47bbb1286e8aa6d95c1e1c27445b6792d90a29d52bf0a0a17f77add414bb8ea88df09
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 35.0.0
4
+
5
+ - Upgrade to Mongoid 5.1 and Rails 4.2
6
+ - Add new done page promotion toggles
7
+
3
8
  ## 34.0.0
4
9
 
5
10
  - Removes `legacy_source` tag [#368](https://github.com/alphagov/govuk_content_models/pull/368)
@@ -49,17 +49,17 @@ class Artefact
49
49
  # - every future artefact will be created with a content id
50
50
  field "content_id", type: String
51
51
 
52
- index "slug", :unique => true
52
+ index({ slug: 1 }, unique: true)
53
53
 
54
54
  # This index allows the `relatable_artefacts` method to use an index-covered
55
55
  # query, so it doesn't have to load each of the artefacts.
56
- index [[:name, Mongo::ASCENDING],
57
- [:state, Mongo::ASCENDING],
58
- [:kind, Mongo::ASCENDING],
59
- [:_type, Mongo::ASCENDING],
60
- [:_id, Mongo::ASCENDING]]
56
+ index name: 1,
57
+ state: 1,
58
+ kind: 1,
59
+ _type: 1,
60
+ _id: 1
61
61
 
62
- scope :not_archived, where(:state.nin => ["archived"])
62
+ scope :not_archived, lambda { where(:state.nin => ["archived"]) }
63
63
 
64
64
  MAXIMUM_RELATED_ITEMS = 8
65
65
 
@@ -143,7 +143,7 @@ class Artefact
143
143
  }.tap { |h| h.default_proc = -> _, k { k } }.freeze
144
144
 
145
145
  has_and_belongs_to_many :related_artefacts, class_name: "Artefact"
146
- embeds_many :actions, class_name: "ArtefactAction", order: :created_at
146
+ embeds_many :actions, class_name: "ArtefactAction", order: { created_at: :asc }
147
147
 
148
148
  embeds_many :external_links, class_name: "ArtefactExternalLink"
149
149
  accepts_nested_attributes_for :external_links, :allow_destroy => true,
@@ -168,11 +168,11 @@ class Artefact
168
168
 
169
169
  scope :relatable_items, proc {
170
170
  where(:kind.ne => "completed_transaction", :state.ne => "archived")
171
- .order_by([[:name, :asc]])
171
+ .order_by(name: :asc)
172
172
  }
173
173
 
174
174
  def self.in_alphabetical_order
175
- order_by([[:name, :asc]])
175
+ order_by(name: :asc)
176
176
  end
177
177
 
178
178
  def self.find_by_slug(s)
@@ -302,8 +302,6 @@ class Artefact
302
302
 
303
303
  def self.from_param(slug_or_id)
304
304
  find_by_slug(slug_or_id) || find(slug_or_id)
305
- rescue BSON::InvalidObjectId
306
- raise Mongoid::Errors::DocumentNotFound.new(self, slug_or_id)
307
305
  end
308
306
 
309
307
  def update_attributes_as(user, *args)
@@ -371,7 +369,11 @@ class Artefact
371
369
  end
372
370
 
373
371
  def snapshot
374
- attributes.except "_id", "created_at", "updated_at", "actions"
372
+ attributes
373
+ .except("_id", "created_at", "updated_at", "actions")
374
+ .merge(
375
+ "related_artefact_ids" => self.related_artefact_ids
376
+ )
375
377
  end
376
378
 
377
379
  def need_id=(new_need_id)
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -4,7 +4,7 @@ module BusinessSupport
4
4
 
5
5
  field :name, type: String
6
6
  field :slug, type: String
7
- index :slug, unique: true
7
+ index({ slug: 1 }, unique: true)
8
8
 
9
9
  validates_presence_of :name
10
10
  validates_uniqueness_of :name
@@ -2,9 +2,6 @@
2
2
  require "edition"
3
3
 
4
4
  class BusinessSupportEdition < Edition
5
-
6
- include Mongoid::MultiParameterAttributes
7
-
8
5
  field :short_description, type: String
9
6
  field :body, type: String
10
7
  field :min_value, type: Integer
@@ -40,7 +37,7 @@ class BusinessSupportEdition < Edition
40
37
  validates :min_value, :max_value, :max_employees, :numericality => {:allow_nil => true, :only_integer => true}
41
38
 
42
39
  scope :for_facets, lambda { |facets|
43
- where({ "$and" => facets_criteria(facets) }).order_by([:priority, :desc], [:title, :asc])
40
+ where("$and" => facets_criteria(facets)).order_by(priority: :desc, title: :asc)
44
41
  }
45
42
 
46
43
 
@@ -11,7 +11,7 @@ class CuratedList
11
11
  field "slug", type: String
12
12
  has_and_belongs_to_many :artefacts, class_name: "Artefact"
13
13
 
14
- index "slug"
14
+ index slug: 1
15
15
 
16
16
  validates :slug, presence: true, uniqueness: true, slug: true
17
17
 
@@ -1,4 +1,3 @@
1
- require "traits/recordable_actions"
2
1
  require "workflow"
3
2
 
4
3
  class Edition
@@ -36,10 +35,10 @@ class Edition
36
35
 
37
36
  # state_machine comes from Workflow
38
37
  state_machine.states.map(&:name).each do |state|
39
- scope state, where(state: state)
38
+ scope state, lambda { where(state: state) }
40
39
  end
41
- scope :archived_or_published, where(:state.in => ["archived", "published"])
42
- scope :in_progress, where(:state.nin => ["archived", "published"])
40
+ scope :archived_or_published, lambda { where(:state.in => %w(archived published)) }
41
+ scope :in_progress, lambda { where(:state.nin => %w(archived published)) }
43
42
  scope :assigned_to, lambda { |user|
44
43
  if user
45
44
  where(assigned_to_id: user.id)
@@ -50,7 +49,7 @@ class Edition
50
49
  scope :major_updates, lambda { where(major_change: true) }
51
50
 
52
51
  validates :title, presence: true
53
- validates :version_number, presence: true, uniqueness: {scope: :panopticon_id}
52
+ validates :version_number, presence: true, uniqueness: { scope: :panopticon_id }
54
53
  validates :panopticon_id, presence: true
55
54
  validates_with SafeHtml
56
55
  validates_with LinkValidator, on: :update, unless: :archived?
@@ -60,11 +59,11 @@ class Edition
60
59
  before_save :check_for_archived_artefact
61
60
  before_destroy :destroy_artefact
62
61
 
63
- index "assigned_to_id"
64
- index [["panopticon_id", Mongo::ASCENDING], ["version_number", Mongo::ASCENDING]], :unique => true
65
- index "state"
66
- index "created_at"
67
- index "updated_at"
62
+ index assigned_to_id: 1
63
+ index({ panopticon_id: 1, version_number: 1 }, unique: true)
64
+ index state: 1
65
+ index created_at: 1
66
+ index updated_at: 1
68
67
 
69
68
  alias_method :admin_list_title, :title
70
69
 
@@ -81,11 +80,11 @@ class Edition
81
80
  end
82
81
 
83
82
  def previous_siblings
84
- siblings.where(:version_number.lt => version_number)
83
+ siblings.where(:version_number.lt => version_number).order(version_number: "asc")
85
84
  end
86
85
 
87
86
  def subsequent_siblings
88
- siblings.where(:version_number.gt => version_number)
87
+ siblings.where(:version_number.gt => version_number).order(version_number: "asc")
89
88
  end
90
89
 
91
90
  def latest_edition?
@@ -230,7 +229,7 @@ class Edition
230
229
 
231
230
  def self.find_or_create_from_panopticon_data(panopticon_id, importing_user)
232
231
  existing_publication = Edition.where(panopticon_id: panopticon_id)
233
- .order_by([:version_number, :desc]).first
232
+ .order_by(version_number: :desc).first
234
233
  return existing_publication if existing_publication
235
234
 
236
235
  raise "Artefact not found" unless metadata = Artefact.find(panopticon_id)
@@ -245,11 +244,11 @@ class Edition
245
244
  scope = where(slug: slug)
246
245
 
247
246
  if edition.present? and edition == "latest"
248
- scope.order_by(:version_number).last
247
+ scope.order_by(version_number: :asc).last
249
248
  elsif edition.present?
250
249
  scope.where(version_number: edition).first
251
250
  else
252
- scope.where(state: "published").order(version_number: "desc").first
251
+ scope.where(state: "published").order(version_number: :desc).first
253
252
  end
254
253
  end
255
254
 
@@ -24,8 +24,11 @@ class LicenceEdition < Edition
24
24
 
25
25
  private
26
26
  def licence_identifier_unique
27
- if self.class.without_state('archived').where(:licence_identifier => licence_identifier,
28
- :panopticon_id.ne => panopticon_id).any?
27
+ if self.class.where(
28
+ :state.ne => 'archived',
29
+ :licence_identifier => licence_identifier,
30
+ :panopticon_id.ne => panopticon_id
31
+ ).any?
29
32
  errors.add(:licence_identifier, :taken)
30
33
  end
31
34
  end
@@ -46,7 +46,7 @@ class LocalAuthority
46
46
  else
47
47
  interactions.excludes(
48
48
  lgil_code: LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION
49
- ).order_by([:lgil_code, :asc]).first ||
49
+ ).order_by(lgil_code: :asc).first ||
50
50
  interactions.where(
51
51
  lgil_code: LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION
52
52
  ).first
@@ -7,7 +7,7 @@ class OverviewDashboard
7
7
  UNASSIGNED_KEY = "**UNASSIGNED**"
8
8
 
9
9
  field :dashboard_type, type: String
10
- field :result_group, type: Integer
10
+ field :result_group, type: String
11
11
  field :count, type: Integer
12
12
  field :draft, type: Integer
13
13
  field :amends_needed, type: Integer
data/app/models/part.rb CHANGED
@@ -7,7 +7,7 @@ class Part
7
7
  embedded_in :programme_edition
8
8
  embedded_in :business_support_edition
9
9
 
10
- scope :in_order, order_by(:order, :asc)
10
+ scope :in_order, lambda { order_by(order: :asc) }
11
11
 
12
12
  field :order, type: Integer
13
13
  field :title, type: String
@@ -20,7 +20,7 @@ class Part
20
20
  validates_presence_of :title
21
21
  validates_presence_of :slug
22
22
  validates_exclusion_of :slug, in: ["video"], message: "Can not be video"
23
- validates_format_of :slug, with: /^[a-z0-9\-]+$/i
23
+ validates_format_of :slug, with: /\A[a-z0-9\-]+\Z/i
24
24
  validates_with SafeHtml
25
25
  validates_with LinkValidator
26
26
  end
data/app/models/parted.rb CHANGED
@@ -28,7 +28,7 @@ module Parted
28
28
  end
29
29
 
30
30
  def whole_body
31
- self.parts.map {|i| %Q{\# #{i.title}\n\n#{i.body}} }.join("\n\n")
31
+ self.parts.in_order.map { |i| %(\# #{i.title}\n\n#{i.body}) }.join("\n\n")
32
32
  end
33
33
 
34
34
  private
@@ -11,7 +11,7 @@ class RenderedManual
11
11
  field :summary, type: String
12
12
  field :section_groups, type: Array
13
13
 
14
- index "slug", unique: true
14
+ index({ slug: 1 }, unique: true)
15
15
 
16
16
  validates_uniqueness_of :slug
17
17
  end
@@ -12,7 +12,7 @@ class SimpleSmartAnswerEdition < Edition
12
12
  field :next_node, type: String
13
13
  field :order, type: Integer
14
14
 
15
- default_scope order_by([:order, :asc])
15
+ default_scope lambda { order_by(order: :asc) }
16
16
 
17
17
  validates :label, :next_node, presence: true
18
18
  validates :slug, :format => {:with => /\A[a-z0-9-]+\z/}
@@ -14,7 +14,7 @@ class SimpleSmartAnswerEdition < Edition
14
14
  field :order, type: Integer
15
15
  field :kind, type: String
16
16
 
17
- default_scope order_by([:order, :asc])
17
+ default_scope lambda { order_by(order: :asc) }
18
18
 
19
19
  GOVSPEAK_FIELDS = [:body]
20
20
 
@@ -33,7 +33,7 @@ class SimpleSmartAnswerEdition < Edition
33
33
 
34
34
 
35
35
  # Workaround mongoid conflicting mods error
36
- # See https://github.com/mongoid/mongoid/issues/1219
36
+ # See https://jira.mongodb.org/browse/MONGOID-1220
37
37
  # Override update_attributes so that nested nodes are updated individually.
38
38
  # This get around the problem of mongoid issuing a query with conflicting modifications
39
39
  # to the same document.
@@ -63,6 +63,6 @@ class SimpleSmartAnswerEdition < Edition
63
63
  end
64
64
 
65
65
  def destroy_in_attrs?(attrs)
66
- attrs['_destroy'] == '1'
66
+ attrs.delete('_destroy') == '1'
67
67
  end
68
68
  end
data/app/models/tag.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "safe_html"
2
2
  require 'tag_id_validator'
3
- require 'state_machine'
3
+ require 'state_machines-mongoid'
4
4
 
5
5
  class Tag
6
6
  include Mongoid::Document
@@ -16,16 +16,14 @@ class Tag
16
16
 
17
17
  STATES = ['draft', 'live']
18
18
 
19
- index :tag_id
20
- index [ [:tag_id, Mongo::ASCENDING], [:tag_type, Mongo::ASCENDING] ], unique: true
21
- index :tag_type
19
+ index tag_id: 1
20
+ index({ tag_id: 1, tag_type: 1 }, unique: true)
21
+ index tag_type: 1
22
22
 
23
23
  validates_presence_of :tag_id, :title, :tag_type
24
24
  validates_uniqueness_of :tag_id, scope: :tag_type
25
25
  validates_with TagIdValidator
26
26
 
27
- attr_protected :state
28
-
29
27
  validates :state, inclusion: { in: STATES }
30
28
 
31
29
  class MissingTags < RuntimeError
@@ -1,6 +1,6 @@
1
1
  require 'attachable'
2
2
  require 'parted'
3
- require 'state_machine'
3
+ require 'state_machines-mongoid'
4
4
  require 'safe_html'
5
5
 
6
6
  class TravelAdviceEdition
@@ -25,7 +25,7 @@ class TravelAdviceEdition
25
25
 
26
26
  embeds_many :actions
27
27
 
28
- index [[:country_slug, Mongo::ASCENDING], [:version_number, Mongo::DESCENDING]], :unique => true
28
+ index({ country_slug: 1, version_number: -1 }, unique: true)
29
29
 
30
30
  attaches :image, :document
31
31
 
@@ -37,23 +37,23 @@ class TravelAdviceEdition
37
37
  "avoid_all_travel_to_whole_country",
38
38
  ]
39
39
 
40
- before_validation :populate_version_number, :on => :create
40
+ before_validation :populate_version_number, on: :create
41
41
 
42
42
  validates_presence_of :country_slug, :title
43
43
  validate :state_for_slug_unique
44
- validates :version_number, :presence => true, :uniqueness => { :scope => :country_slug }
44
+ validates :version_number, presence: true, uniqueness: { scope: :country_slug }
45
45
  validate :alert_status_contains_valid_values
46
46
  validate :first_version_cant_be_minor_update
47
47
  validates_with SafeHtml
48
48
  validates_with LinkValidator
49
49
 
50
- scope :published, where(:state => "published")
50
+ scope :published, lambda { where(state: "published") }
51
51
 
52
52
  class << self; attr_accessor :fields_to_clone end
53
53
  @fields_to_clone = [:title, :country_slug, :overview, :alert_status, :summary, :image_id, :document_id, :synonyms]
54
54
 
55
55
  state_machine initial: :draft do
56
- before_transition :draft => :published do |edition, transition|
56
+ before_transition draft: :published do |edition, _|
57
57
  if edition.minor_update
58
58
  previous = edition.previous_version
59
59
  edition.published_at = previous.published_at
@@ -73,12 +73,12 @@ class TravelAdviceEdition
73
73
  end
74
74
 
75
75
  event :archive do
76
- transition all => :archived, :unless => :archived?
76
+ transition all => :archived, unless: :archived?
77
77
  end
78
78
 
79
79
  state :published do
80
80
  validate :cannot_edit_published
81
- validates_presence_of :change_description, :unless => :minor_update, :message => "can't be blank on publish"
81
+ validates_presence_of :change_description, unless: :minor_update, message: "can't be blank on publish"
82
82
  end
83
83
  state :archived do
84
84
  validate :cannot_edit_archived
@@ -104,7 +104,7 @@ class TravelAdviceEdition
104
104
  end
105
105
 
106
106
  def build_action_as(user, action_type, comment = nil)
107
- actions.build(:requester => user, :request_type => action_type, :comment => comment)
107
+ actions.build(requester: user, request_type: action_type, comment: comment)
108
108
  end
109
109
 
110
110
  def publish_as(user)
@@ -113,7 +113,7 @@ class TravelAdviceEdition
113
113
  end
114
114
 
115
115
  def previous_version
116
- self.class.where(:country_slug => self.country_slug, :version_number.lt => self.version_number).order_by([:version_number, :desc]).first
116
+ self.class.where(country_slug: self.country_slug, :version_number.lt => self.version_number).order_by(version_number: :desc).first
117
117
  end
118
118
 
119
119
  private
@@ -121,19 +121,20 @@ class TravelAdviceEdition
121
121
  def state_for_slug_unique
122
122
  if %w(published draft).include?(self.state) and
123
123
  self.class.where(:_id.ne => id,
124
- :country_slug => country_slug,
125
- :state => state).any?
124
+ country_slug: country_slug,
125
+ state: state).any?
126
126
  errors.add(:state, :taken)
127
127
  end
128
128
  end
129
129
 
130
130
  def populate_version_number
131
131
  if self.version_number.nil? and ! self.country_slug.nil? and ! self.country_slug.empty?
132
- if latest_edition = self.class.where(:country_slug => self.country_slug).order_by([:version_number, :desc]).first
133
- self.version_number = latest_edition.version_number + 1
134
- else
135
- self.version_number = 1
136
- end
132
+ latest_edition = self.class.where(country_slug: self.country_slug).order_by(version_number: :desc).first
133
+ self.version_number = if latest_edition
134
+ latest_edition.version_number + 1
135
+ else
136
+ 1
137
+ end
137
138
  end
138
139
  end
139
140
 
data/app/models/user.rb CHANGED
@@ -24,16 +24,14 @@ class User
24
24
  field "disabled", type: Boolean, default: false
25
25
  field "organisation_content_id", type: String
26
26
 
27
- index "uid", unique: true
28
- index "disabled"
29
-
30
- # Setup accessible (or protected) attributes for your model
31
- attr_accessible :email, :name, :uid
32
- attr_accessible :email, :name, :uid, :permissions, as: :oauth
33
-
34
- scope :alphabetized, order_by(name: :asc)
35
- scope :enabled, any_of({ :disabled.exists => false },
36
- { :disabled.in => [false, nil] })
27
+ index({ uid: 1 }, unique: true)
28
+ index disabled: 1
29
+
30
+ scope :alphabetized, lambda { order_by(name: :asc) }
31
+ scope :enabled, lambda {
32
+ any_of({ :disabled.exists => false },
33
+ { :disabled.in => [false, nil] }) # rubocop:disable Style/BracesAroundHashParameters
34
+ }
37
35
 
38
36
  def to_s
39
37
  name || email || ""
@@ -1,4 +1,4 @@
1
- require "state_machine"
1
+ require "state_machines-mongoid"
2
2
 
3
3
  module Workflow
4
4
  class CannotDeletePublishedPublication < RuntimeError; end
@@ -117,7 +117,7 @@ module Workflow
117
117
 
118
118
  def denormalise_users!
119
119
  new_assignee = assigned_to.try(:name)
120
- set(:assignee, new_assignee) unless new_assignee == assignee
120
+ set(assignee: new_assignee) unless new_assignee == assignee
121
121
  update_user_action("creator", [Action::CREATE, Action::NEW_VERSION])
122
122
  update_user_action("publisher", [Action::PUBLISH])
123
123
  update_user_action("archiver", [Action::ARCHIVE])
@@ -133,7 +133,7 @@ module Workflow
133
133
  end
134
134
 
135
135
  def mark_as_rejected
136
- self.inc(:rejected_count, 1)
136
+ self.inc(rejected_count: 1)
137
137
  end
138
138
 
139
139
  def previous_edition
@@ -185,7 +185,7 @@ module Workflow
185
185
  # collections, but share a model and relationships with eg actions.
186
186
  # Therefore, Panopticon might not find a user for an action.
187
187
  if action.requester
188
- set(property, action.requester.name)
188
+ set(property => action.requester.name)
189
189
  end
190
190
  end
191
191
  end
@@ -52,8 +52,7 @@ module Taggable
52
52
  klass.field :tag_ids, type: Array, default: []
53
53
  klass.field :tags, type: Array, default: []
54
54
 
55
- klass.index :tag_ids
56
- klass.attr_protected :tags, :tag_ids
55
+ klass.index tag_ids: 1
57
56
  klass.__send__ :private, :tag_ids=
58
57
  end
59
58
 
data/config/mongoid.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  test:
2
- host: localhost
3
- database: govuk_content_shared_test
4
- logger: false
5
- use_activesupport_time_zone: true
6
- autocreate_indexes: true
2
+ clients:
3
+ default:
4
+ database: govuk_content_shared_test
5
+ hosts:
6
+ - localhost
7
+ options:
8
+ use_activesupport_time_zone: true
9
+ log_level: :error
@@ -20,22 +20,24 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_dependency "gds-sso", "~> 11.2"
22
22
  gem.add_dependency "govspeak", "~> 3.1"
23
- # Mongoid 2.5.0 supports the newer 1.7.x and 1.8.x Mongo drivers
24
- gem.add_dependency "mongoid", "~> 2.5"
23
+ gem.add_dependency "mongoid", "~> 5.1"
24
+ gem.add_dependency "state_machines", "~> 0.4"
25
+ gem.add_dependency "state_machines-mongoid", "~> 0.1"
25
26
  gem.add_dependency "plek"
26
- gem.add_dependency "state_machine"
27
27
 
28
- gem.add_development_dependency "database_cleaner", "0.7.2"
29
- gem.add_development_dependency "factory_girl", "3.3.0"
28
+ gem.add_development_dependency "database_cleaner", "1.5.1"
29
+ gem.add_development_dependency "factory_girl", "4.5.0"
30
30
  gem.add_development_dependency "gem_publisher", "1.2.0"
31
- gem.add_development_dependency "mocha", "0.13.3"
31
+ gem.add_development_dependency "mocha", "1.1.0"
32
32
  gem.add_development_dependency "multi_json"
33
33
  gem.add_development_dependency "rake", "0.9.2.2"
34
- gem.add_development_dependency "webmock", "1.8.7"
35
- gem.add_development_dependency "shoulda-context", "1.0.0"
34
+ gem.add_development_dependency "webmock", "1.22.6"
35
+ gem.add_development_dependency "shoulda-context", "1.2.1"
36
36
  gem.add_development_dependency "timecop", "0.5.9.2"
37
+ gem.add_development_dependency 'govuk-lint', '~> 0.5.1'
38
+ gem.add_development_dependency 'pry-byebug'
37
39
 
38
40
  # The following are added to help bundler resolve dependencies
39
- gem.add_development_dependency "rack", "~> 1.4.4"
40
- gem.add_development_dependency "rails", "= 3.2.17"
41
+ gem.add_development_dependency "rack", "~> 1.6.4"
42
+ gem.add_development_dependency "rails", "= 4.2.5.1"
41
43
  end
data/jenkins.sh CHANGED
@@ -4,6 +4,9 @@ rm -f Gemfile.lock
4
4
  bundle install --path "${HOME}/bundles/${JOB_NAME}"
5
5
  export GOVUK_APP_DOMAIN=dev.gov.uk
6
6
  bundle exec rake
7
+
8
+ bundle exec govuk-lint-ruby --diff --cached --format clang app config lib test
9
+
7
10
  if [[ -n "$PUBLISH_GEM" ]]; then
8
11
  bundle exec rake publish_gem
9
12
  fi