govuk_content_models 8.3.0 → 8.3.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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 8.3.1
2
+
3
+ Added `Edition#locked_for_edits?`
4
+
1
5
  ## 8.3.0
2
6
 
3
7
  Add `editors_note` field to the edition model
@@ -48,7 +48,6 @@ class Edition
48
48
  validates :title, presence: true
49
49
  validates :version_number, presence: true
50
50
  validates :panopticon_id, presence: true
51
- validate :publish_at_is_in_the_future
52
51
  validates_with SafeHtml
53
52
 
54
53
  before_save :check_for_archived_artefact
@@ -100,7 +99,7 @@ class Edition
100
99
  end
101
100
 
102
101
  def can_create_new_edition?
103
- subsequent_siblings.in_progress.empty?
102
+ !scheduled_for_publishing? && subsequent_siblings.in_progress.empty?
104
103
  end
105
104
 
106
105
  def meta_data
@@ -285,10 +284,4 @@ class Edition
285
284
  Artefact.find(self.panopticon_id).destroy
286
285
  end
287
286
  end
288
-
289
- private
290
-
291
- def publish_at_is_in_the_future
292
- errors.add(:publish_at, "can't be a time in the past") if publish_at.present? && publish_at < Time.zone.now
293
- end
294
287
  end
@@ -90,6 +90,7 @@ module Workflow
90
90
 
91
91
  state :scheduled_for_publishing do
92
92
  validates_presence_of :publish_at
93
+ validate :publish_at_is_in_the_future
93
94
  end
94
95
  end
95
96
  end
@@ -211,24 +212,31 @@ module Workflow
211
212
  ! ["archived", "published"].include? self.state
212
213
  end
213
214
 
215
+ def locked_for_edits?
216
+ scheduled_for_publishing? || published?
217
+ end
218
+
219
+ def error_description
220
+ published? ? 'Published editions' : 'Editions scheduled for publishing'
221
+ end
222
+
214
223
  private
215
224
 
225
+ def publish_at_is_in_the_future
226
+ errors.add(:publish_at, "can't be a time in the past") if publish_at.present? && publish_at < Time.zone.now
227
+ end
228
+
216
229
  def not_editing_published_item
217
- if changed? and ! state_changed?
218
- if archived?
219
- errors.add(:base, "Archived editions can't be edited")
220
- end
221
- if scheduled_for_publishing? || published?
222
- changes_allowed_when_published = ["slug", "section",
223
- "department", "business_proposition"]
224
- illegal_changes = changes.keys - changes_allowed_when_published
225
- if illegal_changes.empty?
226
- # Allow it
227
- else
228
- edition_description = published? ? 'Published editions' : 'Editions scheduled for publishing'
229
- errors.add(:base, "#{edition_description} can't be edited")
230
- end
231
- end
232
- end
230
+ return if changes.none? || state_changed?
231
+
232
+ errors.add(:base, "Archived editions can't be edited") if archived?
233
+
234
+ return unless locked_for_edits?
235
+ errors.add(:base, "#{error_description} can't be edited") if disallowable_change?
236
+ end
237
+
238
+ def disallowable_change?
239
+ allowed_to_change = %w(slug section publish_at department business_proposition)
240
+ (changes.keys - allowed_to_change).present?
233
241
  end
234
242
  end
@@ -86,6 +86,10 @@ FactoryGirl.define do
86
86
  state 'scheduled_for_publishing'
87
87
  publish_at 1.day.from_now
88
88
  end
89
+
90
+ trait :published do
91
+ state 'published'
92
+ end
89
93
  end
90
94
  factory :answer_edition, parent: :edition do
91
95
  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 = "8.3.0"
3
+ VERSION = "8.3.1"
4
4
  end
@@ -6,7 +6,6 @@ class EditionScheduledForPublishingTest < ActiveSupport::TestCase
6
6
  setup do
7
7
  @edition = FactoryGirl.create(:edition, state: 'ready')
8
8
  @edition.schedule_for_publishing
9
- @edition.reload
10
9
  end
11
10
 
12
11
  should "return an error" do
@@ -34,6 +33,14 @@ class EditionScheduledForPublishingTest < ActiveSupport::TestCase
34
33
  assert_equal 'scheduled_for_publishing', @edition.state
35
34
  end
36
35
  end
36
+
37
+ should "not allow scheduling at a time in the past" do
38
+ edition = FactoryGirl.create(:edition, state: 'ready')
39
+
40
+ edition.schedule_for_publishing(1.hour.ago)
41
+
42
+ assert_includes edition.errors[:publish_at], "can't be a time in the past"
43
+ end
37
44
  end
38
45
 
39
46
  context "when scheduled_for_publishing" do
@@ -56,29 +63,38 @@ class EditionScheduledForPublishingTest < ActiveSupport::TestCase
56
63
  end
57
64
 
58
65
  should "return false for #can_destroy?" do
59
- edition = FactoryGirl.create(:edition, :scheduled_for_publishing)
66
+ edition = FactoryGirl.build(:edition, :scheduled_for_publishing)
60
67
  refute edition.can_destroy?
61
68
  end
62
69
 
70
+ should "return false for #can_create_new_edition?" do
71
+ edition = FactoryGirl.build(:edition, :scheduled_for_publishing)
72
+ refute edition.can_create_new_edition?
73
+ end
74
+
63
75
  should "allow transition to published state" do
64
- edition = FactoryGirl.create(:edition, :scheduled_for_publishing)
76
+ edition = FactoryGirl.build(:edition, :scheduled_for_publishing)
65
77
  assert edition.can_publish?
66
78
  end
67
79
  end
68
80
 
69
81
  context "#cancel_scheduled_publishing" do
70
- setup do
71
- @edition = FactoryGirl.create(:edition, :scheduled_for_publishing)
72
- @edition.cancel_scheduled_publishing
73
- @edition.reload
74
- end
82
+ should "remove the publish_at stored against the edition and transition back to ready" do
83
+ edition = FactoryGirl.create(:edition, :scheduled_for_publishing)
84
+ edition.cancel_scheduled_publishing
85
+ edition.reload
75
86
 
76
- should "remove the publish_at stored against the edition" do
77
- assert_nil @edition.publish_at
87
+ assert_nil edition.publish_at
88
+ assert_equal 'ready', edition.state
78
89
  end
79
90
 
80
- should "complete the transition back to ready" do
81
- assert_equal 'ready', @edition.state
91
+ should "work with editions that have passed publish_at time" do
92
+ edition = FactoryGirl.create(:edition, :scheduled_for_publishing)
93
+ edition.update_attribute :publish_at, 2.days.ago
94
+
95
+ edition.cancel_scheduled_publishing
96
+
97
+ assert_equal 'ready', edition.reload.state
82
98
  end
83
99
  end
84
100
  end
@@ -46,15 +46,6 @@ class EditionTest < ActiveSupport::TestCase
46
46
  assert a.errors[:title].any?
47
47
  end
48
48
 
49
- context "#publish_at" do
50
- should "not be a time in the past" do
51
- edition = FactoryGirl.build(:edition, publish_at: 1.minute.ago)
52
-
53
- refute edition.valid?
54
- assert_includes edition.errors[:publish_at], "can't be a time in the past"
55
- end
56
- end
57
-
58
49
  test "it should give a friendly (legacy supporting) description of its format" do
59
50
  a = LocalTransactionEdition.new
60
51
  assert_equal "LocalTransaction", a.format
@@ -69,6 +69,17 @@ class WorkflowTest < ActiveSupport::TestCase
69
69
  end
70
70
  end
71
71
 
72
+ context "#locked_for_edit?" do
73
+ should "return true if edition is scheduled for publishing for published" do
74
+ assert FactoryGirl.build(:edition, :scheduled_for_publishing).locked_for_edits?
75
+ assert FactoryGirl.build(:edition, :published).locked_for_edits?
76
+ end
77
+
78
+ should "return false if in draft state" do
79
+ refute FactoryGirl.build(:edition, state: 'draft').locked_for_edits?
80
+ end
81
+ end
82
+
72
83
  test "permits the creation of new editions" do
73
84
  user, transaction = template_user_and_published_transaction
74
85
  assert transaction.persisted?
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: 8.3.0
4
+ version: 8.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -458,7 +458,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
458
458
  version: '0'
459
459
  segments:
460
460
  - 0
461
- hash: 273183051789129622
461
+ hash: 1454853110289158325
462
462
  required_rubygems_version: !ruby/object:Gem::Requirement
463
463
  none: false
464
464
  requirements:
@@ -467,7 +467,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
467
467
  version: '0'
468
468
  segments:
469
469
  - 0
470
- hash: 273183051789129622
470
+ hash: 1454853110289158325
471
471
  requirements: []
472
472
  rubyforge_project:
473
473
  rubygems_version: 1.8.23