govuk_content_models 10.2.0 → 10.2.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.
@@ -46,7 +46,7 @@ class Edition
46
46
  }
47
47
 
48
48
  validates :title, presence: true
49
- validates :version_number, presence: true
49
+ validates :version_number, presence: true, uniqueness: {scope: :panopticon_id}
50
50
  validates :panopticon_id, presence: true
51
51
  validates_with SafeHtml
52
52
 
@@ -54,7 +54,7 @@ class Edition
54
54
  before_destroy :destroy_artefact
55
55
 
56
56
  index "assigned_to_id"
57
- index "panopticon_id"
57
+ index [["panopticon_id", Mongo::ASCENDING], ["version_number", Mongo::ASCENDING]], :unique => true
58
58
  index "state"
59
59
 
60
60
  class << self; attr_accessor :fields_to_clone end
data/config/mongoid.yml CHANGED
@@ -3,3 +3,4 @@ test:
3
3
  database: govuk_content_shared_test
4
4
  logger: false
5
5
  use_activesupport_time_zone: true
6
+ autocreate_indexes: true
@@ -80,7 +80,11 @@ FactoryGirl.define do
80
80
 
81
81
  section "test:subsection test"
82
82
 
83
- association :assigned_to, factory: :user
83
+ after :build do |ed|
84
+ if previous = ed.series.order(version_number: "desc").first
85
+ ed.version_number = previous.version_number + 1
86
+ end
87
+ end
84
88
 
85
89
  trait :scheduled_for_publishing do
86
90
  state 'scheduled_for_publishing'
@@ -109,28 +113,15 @@ FactoryGirl.define do
109
113
  factory :business_support_edition, :parent => :edition, :class => "BusinessSupportEdition" do
110
114
  end
111
115
 
112
- factory :guide_edition do |ge|
113
- panopticon_id {
114
- a = create(:artefact)
115
- a.id
116
- }
117
- ge.sequence(:title) { |n| "Test guide #{n}" }
118
- ge.sequence(:slug) { |ns| "slug-#{ns}"}
119
- section { "test:subsection test" }
116
+ factory :guide_edition, :parent => :edition, :class => "GuideEdition" do
117
+ sequence(:title) { |n| "Test guide #{n}" }
120
118
  end
121
119
 
122
- factory :programme_edition do |edition|
123
- panopticon_id {
124
- a = create(:artefact)
125
- a.id
126
- }
127
- edition.sequence(:title) { |n| "Test programme #{n}" }
128
- edition.sequence(:slug) { |ns| "slug-#{ns}"}
129
- section { "test:subsection test" }
120
+ factory :programme_edition, :parent => :edition, :class => "ProgrammeEdition" do
121
+ sequence(:title) { |n| "Test programme #{n}" }
130
122
  end
131
123
 
132
124
  factory :programme_edition_with_multiple_parts, parent: :programme_edition do
133
- title "a title"
134
125
  after :create do |getp|
135
126
  getp.parts.build(title: "PART !", body: "This is some programme version text.",
136
127
  slug: "part-one")
@@ -141,7 +132,6 @@ FactoryGirl.define do
141
132
  end
142
133
 
143
134
  factory :guide_edition_with_two_parts, parent: :guide_edition do
144
- title "a title"
145
135
  after :create do |getp|
146
136
  getp.parts.build(title: "PART !", body: "This is some version text.",
147
137
  slug: "part-one")
@@ -152,7 +142,6 @@ FactoryGirl.define do
152
142
  end
153
143
 
154
144
  factory :guide_edition_with_two_govspeak_parts, parent: :guide_edition do
155
- title "A title for govspeak parts"
156
145
  after :create do |getp|
157
146
  getp.parts.build(title: "Some Part Title!",
158
147
  body: "This is some **version** text.", slug: "part-one")
@@ -162,26 +151,13 @@ FactoryGirl.define do
162
151
  end
163
152
  end
164
153
 
165
- factory :local_transaction_edition do |lte|
166
- panopticon_id {
167
- a = create(:artefact)
168
- a.id
169
- }
170
- title { "Test title" }
171
- version_number 1
172
- lte.sequence(:slug) { |ns| "slug-#{ns}"}
173
- lte.sequence(:lgsl_code) { |nlgsl| nlgsl }
154
+ factory :local_transaction_edition, :parent => :edition, :class => "LocalTransactionEdition" do
155
+ sequence(:lgsl_code) { |nlgsl| nlgsl }
174
156
  introduction { "Test introduction" }
175
157
  more_information { "This is more information" }
176
158
  end
177
159
 
178
- factory :transaction_edition do |te|
179
- panopticon_id {
180
- a = create(:artefact)
181
- a.id
182
- }
183
- title { "Test title" }
184
- version_number 1
160
+ factory :transaction_edition, :parent => :edition, :class => "TransactionEdition" do
185
161
  introduction { "Test introduction" }
186
162
  more_information { "This is more information" }
187
163
  link "http://continue.com"
@@ -279,11 +255,7 @@ FactoryGirl.define do
279
255
  case_state 'open'
280
256
  end
281
257
 
282
- factory :simple_smart_answer_edition do
283
- panopticon_id {
284
- a = create(:artefact)
285
- a.id
286
- }
258
+ factory :simple_smart_answer_edition, :parent => :edition, :class => "SimpleSmartAnswerEdition" do
287
259
  title "Simple smart answer"
288
260
  body "Introduction to the smart answer"
289
261
  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 = "10.2.0"
3
+ VERSION = "10.2.1"
4
4
  end
@@ -505,7 +505,7 @@ class EditionTest < ActiveSupport::TestCase
505
505
  stub_request(:get, %r{http://panopticon\.test\.gov\.uk/artefacts/.*\.js}).
506
506
  to_return(status: 200, body: "{}", headers: {})
507
507
 
508
- a, b = 2.times.map { |i| GuideEdition.create!(panopticon_id: @artefact.id, title: "Guide #{i}", slug: "guide-#{i}") }
508
+ a, b = 2.times.map { |i| FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id) }
509
509
 
510
510
  alice, bob, charlie = %w[ alice bob charlie ].map { |s|
511
511
  FactoryGirl.create(:user, name: s)
@@ -916,27 +916,27 @@ class EditionTest < ActiveSupport::TestCase
916
916
 
917
917
  test "should update previous editions when new edition is added" do
918
918
  @user = FactoryGirl.create(:user)
919
- @edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "ready")
919
+ @edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "archived")
920
920
  @published_edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "published")
921
921
  @new_edition = @published_edition.build_clone
922
- @new_edition.save
922
+ @new_edition.save!
923
923
  @published_edition.reload
924
924
 
925
- assert_equal 2, @new_edition.version_number
926
- assert_equal 2, @published_edition.sibling_in_progress
925
+ assert_equal 3, @new_edition.version_number
926
+ assert_equal 3, @published_edition.sibling_in_progress
927
927
  end
928
928
 
929
929
  test "should update previous editions when new edition is published" do
930
930
  @user = FactoryGirl.create(:user)
931
- @edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "ready")
931
+ @edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "archived")
932
932
  @published_edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "published")
933
933
  @new_edition = @published_edition.build_clone
934
- @new_edition.save
934
+ @new_edition.save!
935
935
  @new_edition.update_attribute(:state, "ready")
936
936
  @user.publish(@new_edition, comment: "Publishing this")
937
937
  @published_edition.reload
938
938
 
939
- assert_equal 2, @new_edition.version_number
939
+ assert_equal 3, @new_edition.version_number
940
940
  assert_nil @new_edition.sibling_in_progress
941
941
  assert_nil @published_edition.sibling_in_progress
942
942
  end
@@ -982,6 +982,40 @@ class EditionTest < ActiveSupport::TestCase
982
982
  assert_equal "Foo bar", template_published_answer.artefact.name
983
983
  end
984
984
 
985
+ context "validating version_number" do
986
+ should "be required" do
987
+ ed = FactoryGirl.build(:edition, :panopticon_id => @artefact.id)
988
+ ed.version_number = nil
989
+ assert ! ed.valid?, "Expected edition not to be valid with no version_number"
990
+ end
991
+
992
+ should "be unique" do
993
+ ed1 = FactoryGirl.create(:edition, :panopticon_id => @artefact.id)
994
+ ed2 = FactoryGirl.build(:edition, :panopticon_id => @artefact.id)
995
+ ed2.version_number = ed1.version_number
996
+
997
+ assert ! ed2.valid?, "Expected edition not to be valid with conflicting version_number"
998
+ end
999
+
1000
+ should "allow editions belonging to different artefacts to have matching version_numbers" do
1001
+ ed1 = FactoryGirl.create(:edition, :panopticon_id => @artefact.id)
1002
+ ed2 = FactoryGirl.build(:edition, :panopticon_id => FactoryGirl.create(:artefact).id)
1003
+ ed2.version_number = ed1.version_number
1004
+
1005
+ assert ed2.valid?, "Expected edition to be valid"
1006
+ end
1007
+
1008
+ should "have a database-level constraint on the uniqueness" do
1009
+ ed1 = FactoryGirl.create(:edition, :panopticon_id => @artefact.id)
1010
+ ed2 = FactoryGirl.build(:edition, :panopticon_id => @artefact.id)
1011
+ ed2.version_number = ed1.version_number
1012
+
1013
+ assert_raises Mongo::OperationFailure do
1014
+ ed2.safely.save! :validate => false
1015
+ end
1016
+ end
1017
+ end
1018
+
985
1019
  context "indexable_content" do
986
1020
  context "editions with a 'body'" do
987
1021
  should "include the body with markup removed" do
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: 10.2.0
4
+ version: 10.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -465,7 +465,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
465
465
  version: '0'
466
466
  segments:
467
467
  - 0
468
- hash: 1908367784692454141
468
+ hash: 2178874985606860121
469
469
  required_rubygems_version: !ruby/object:Gem::Requirement
470
470
  none: false
471
471
  requirements:
@@ -474,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
474
474
  version: '0'
475
475
  segments:
476
476
  - 0
477
- hash: 1908367784692454141
477
+ hash: 2178874985606860121
478
478
  requirements: []
479
479
  rubyforge_project:
480
480
  rubygems_version: 1.8.23