govuk_content_models 20.2.0 → 21.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 21.0.0
2
+
3
+ * Remove diff-ing code from content models - diffs should now be calculated on the fly
4
+
1
5
  ## 20.2.0
2
6
 
3
7
  * Adds new `finder_email_signup` Artefact kind and validator for finder e-mail signups.
data/app/models/action.rb CHANGED
@@ -33,7 +33,6 @@ class Action
33
33
  field :approved, type: DateTime
34
34
  field :comment, type: String
35
35
  field :comment_sanitized, type: Boolean, default: false
36
- field :diff, type: String
37
36
  field :request_type, type: String
38
37
  field :email_addresses, type: String
39
38
  field :customised_message, type: String
@@ -275,15 +275,4 @@ class Edition
275
275
  Artefact.find(self.panopticon_id).destroy
276
276
  end
277
277
  end
278
-
279
- def previous_edition_differences
280
- return if version_number <= 1
281
-
282
- if in_progress?
283
- edition_changes.to_s # diff of current changes
284
- else
285
- actions.select { |a| a.request_type == 'publish' }.last.diff # diff with previous published version
286
- end
287
- end
288
-
289
278
  end
@@ -1,4 +1,3 @@
1
- require "differ"
2
1
  require "state_machine"
3
2
  require "action"
4
3
 
@@ -186,17 +185,6 @@ module Workflow
186
185
  self.previous_published_edition || false
187
186
  end
188
187
 
189
- def edition_changes
190
- if self.whole_body.blank?
191
- false
192
- else
193
- my_body, their_body = [self, self.published_edition].map do |edition|
194
- edition.whole_body.gsub("\r\n", "\n")
195
- end
196
- Differ.diff_by_line(my_body, their_body)
197
- end
198
- end
199
-
200
188
  def notify_siblings_of_new_edition
201
189
  siblings.update_all(sibling_in_progress: self.version_number)
202
190
  end
@@ -118,10 +118,6 @@ module WorkflowActor
118
118
  end
119
119
 
120
120
  def publish(edition, details)
121
- if edition.published_edition
122
- details.merge!({ diff: edition.edition_changes })
123
- end
124
-
125
121
  take_action(edition, __method__, details)
126
122
  end
127
123
 
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = GovukContentModels::VERSION
17
17
 
18
18
  gem.add_dependency "bson_ext"
19
- gem.add_dependency "differ"
20
19
  gem.add_dependency "gds-api-adapters", ">= 10.9.0"
21
20
 
22
21
  gem.add_dependency "gds-sso", ">= 7.0.0", "< 10.0.0"
@@ -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 = "20.2.0"
3
+ VERSION = "21.0.0"
4
4
  end
@@ -545,7 +545,6 @@ class EditionTest < ActiveSupport::TestCase
545
545
  end
546
546
 
547
547
  test "given multiple editions, can return the most recent published edition" do
548
-
549
548
  edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, slug: "hedgehog-topiary", state: "published")
550
549
 
551
550
  second_edition = edition.build_clone
@@ -569,31 +568,6 @@ class EditionTest < ActiveSupport::TestCase
569
568
  assert edition.new_action(user, "note", comment: "Something important")
570
569
  end
571
570
 
572
- test "first edition has no previous edition diffrences" do
573
- first_edition = template_published_answer
574
-
575
- assert_nil first_edition.previous_edition_differences
576
- end
577
-
578
- test "can access the changes since the last version" do
579
- second_edition = draft_second_edition_from(template_published_answer)
580
-
581
- assert_equal("{\"Lots of info\" >> \"Test Body 2\"}",
582
- second_edition.previous_edition_differences)
583
- end
584
-
585
- test "can show the differences between published editions" do
586
- second_edition = draft_second_edition_from(template_published_answer)
587
- second_edition.update_attribute(:state, "ready")
588
- second_edition.save!
589
-
590
- user = User.create(name: "bob")
591
- user.publish second_edition, comment: "Published comment"
592
-
593
- assert_equal("{\"Lots of info\" >> \"Test Body 2\"}",
594
- second_edition.previous_edition_differences)
595
- end
596
-
597
571
  test "status should not be affected by notes" do
598
572
  user = User.create(name: "bob")
599
573
  edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "ready")
@@ -770,30 +744,6 @@ class EditionTest < ActiveSupport::TestCase
770
744
  assert_equal new_edition.version_number, edition.sibling_in_progress
771
745
  end
772
746
 
773
- test "a new guide edition with multiple parts creates a full diff when published" do
774
- user = User.create name: "Roland"
775
-
776
- edition_one = GuideEdition.new(title: "One", slug: "one", panopticon_id: @artefact.id)
777
- edition_one.parts.build title: "Part One", body:"Never gonna give you up", slug: "part-one"
778
- edition_one.parts.build title: "Part Two", body:"NYAN NYAN NYAN NYAN", slug: "part-two"
779
- edition_one.save!
780
-
781
- edition_one.state = :ready
782
- user.publish edition_one, comment: "First edition"
783
-
784
- edition_two = edition_one.build_clone
785
- edition_two.save!
786
- edition_two.parts.first.update_attribute :title, "Changed Title"
787
- edition_two.parts.first.update_attribute :body, "Never gonna let you down"
788
-
789
- edition_two.state = :ready
790
- user.publish edition_two, comment: "Second edition"
791
-
792
- publish_action = edition_two.actions.where(request_type: "publish").last
793
-
794
- assert_equal "{\"# Part One\" >> \"# Changed Title\"}\n\n{\"Never gonna give you up\" >> \"Never gonna let you down\"}\n\n# Part Two\n\nNYAN NYAN NYAN NYAN", publish_action.diff
795
- end
796
-
797
747
  test "a part's slug must be of the correct format" do
798
748
  edition_one = GuideEdition.new(title: "One", slug: "one", panopticon_id: @artefact.id)
799
749
  edition_one.parts.build title: "Part One", body:"Never gonna give you up", slug: "part-One-1"
@@ -825,28 +775,6 @@ class EditionTest < ActiveSupport::TestCase
825
775
  assert ! user.request_amendments(edition, {comment: "Well Done, but work harder"})
826
776
  end
827
777
 
828
- test "a new programme edition with multiple parts creates a full diff when published" do
829
- user = User.create name: "Mazz"
830
-
831
- edition_one = ProgrammeEdition.new(title: "Childcare", slug: "childcare", panopticon_id: @artefact.id)
832
- edition_one.parts.build title: "Part One", body:"Content for part one", slug: "part-one"
833
- edition_one.parts.build title: "Part Two", body:"Content for part two", slug: "part-two"
834
- edition_one.save!
835
-
836
- edition_one.state = :ready
837
- user.publish edition_one, comment: "First edition"
838
-
839
- edition_two = edition_one.build_clone
840
- edition_two.save!
841
- edition_two.parts.first.update_attribute :body, "Some other content"
842
- edition_two.state = :ready
843
- user.publish edition_two, comment: "Second edition"
844
-
845
- publish_action = edition_two.actions.where(request_type: "publish").last
846
-
847
- assert_equal "# Part One\n\n{\"Content for part one\" >> \"Some other content\"}\n\n# Part Two\n\nContent for part two", publish_action.diff
848
- end
849
-
850
778
  test "a published publication with a draft edition is in progress" do
851
779
  dummy_answer = template_published_answer
852
780
  assert !dummy_answer.has_sibling_in_progress?
@@ -52,27 +52,4 @@ class LocalTransactionEditionTest < ActiveSupport::TestCase
52
52
  assert lt.valid?
53
53
  assert lt.persisted?
54
54
  end
55
-
56
- test "should create a diff between the versions when publishing a new version" do
57
- make_service(149, %w{county unitary})
58
- edition_one = LocalTransactionEdition.new(title: "Transaction", slug: "transaction", lgsl_code: "149", panopticon_id: @artefact.id)
59
- user = User.create name: "Thomas"
60
-
61
- edition_one.introduction = "Test"
62
- edition_one.state = :ready
63
- edition_one.save!
64
-
65
- user.publish edition_one, comment: "First edition"
66
-
67
- edition_two = edition_one.build_clone
68
- edition_two.introduction = "Testing"
69
- edition_two.state = :ready
70
- edition_two.save!
71
-
72
- user.publish edition_two, comment: "Second edition"
73
-
74
- publish_action = edition_two.actions.where(request_type: "publish").last
75
-
76
- assert_equal "{\"Test\" >> \"Testing\"}", publish_action.diff
77
- end
78
55
  end
@@ -307,51 +307,6 @@ class WorkflowTest < ActiveSupport::TestCase
307
307
  refute user.new_version(edition)
308
308
  end
309
309
 
310
- test "a new edition of an answer creates a diff when published" do
311
- without_metadata_denormalisation(AnswerEdition) do
312
- edition_one = AnswerEdition.new(title: "Chucking wood", slug: "woodchuck", panopticon_id: @artefact.id)
313
- edition_one.body = "A woodchuck would chuck all the wood he could chuck if a woodchuck could chuck wood."
314
- edition_one.state = :ready
315
- edition_one.save!
316
-
317
- user = User.create name: "Michael"
318
- user.publish edition_one, comment: "First edition"
319
-
320
- edition_two = edition_one.build_clone
321
- edition_two.body = "A woodchuck would chuck all the wood he could chuck if a woodchuck could chuck wood.\nAlthough no more than 361 cubic centimetres per day."
322
- edition_two.state = :ready
323
- edition_two.save!
324
-
325
- user.publish edition_two, comment: "Second edition"
326
-
327
- publish_action = edition_two.actions.where(request_type: "publish").last
328
-
329
- assert_equal "A woodchuck would chuck all the wood he could chuck if a woodchuck could chuck wood.{+\"\\nAlthough no more than 361 cubic centimetres per day.\"}", publish_action.diff
330
- end
331
- end
332
-
333
- test "handles inconsistent newlines" do
334
- # Differ tries to be smart when calculating changes, by searching for a matching line
335
- # later in the texts. When we have predominantly Windows-style new lines (\r\n) with
336
- # a few Unix-style new lines (\n), a Unix-style new line later in one document will be
337
- # matched to a Unix-style new line in the other, causing large swathes of spurious diff.
338
-
339
- edition_one = AnswerEdition.new(title: "Chucking wood", slug: "woodchuck", panopticon_id: @artefact.id)
340
- edition_one.body = "badger\n\nmushroom\r\n\r\nsnake\n\nend"
341
-
342
- edition_two = AnswerEdition.new(title: "Chucking wood", slug: "woodchuck", panopticon_id: @artefact.id)
343
- edition_two.body = "badger\r\n\r\nmushroom\r\n\r\nsnake\n\nend"
344
- edition_two.stubs(:published_edition).returns(edition_one)
345
-
346
- # Test that the diff output is simply the (normalised) string, with no diff markers
347
- assert_equal "badger\n\nmushroom\n\nsnake\n\nend", edition_two.edition_changes.to_s
348
- end
349
-
350
- test "edition_changes should return false if the whole body is nil" do
351
- edition = FactoryGirl.create(:completed_transaction_edition, body: nil)
352
- refute edition.edition_changes
353
- end
354
-
355
310
  test "an edition can be moved into archive state" do
356
311
  user, other_user = template_users
357
312
 
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: 20.2.0
4
+ version: 21.0.0
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-09-18 00:00:00.000000000 Z
12
+ date: 2014-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -27,22 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: differ
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
30
  - !ruby/object:Gem::Dependency
47
31
  name: gds-api-adapters
48
32
  requirement: !ruby/object:Gem::Requirement
@@ -460,7 +444,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
460
444
  version: '0'
461
445
  segments:
462
446
  - 0
463
- hash: -4078975284747344059
447
+ hash: -3126132501408854274
464
448
  required_rubygems_version: !ruby/object:Gem::Requirement
465
449
  none: false
466
450
  requirements:
@@ -469,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
469
453
  version: '0'
470
454
  segments:
471
455
  - 0
472
- hash: -4078975284747344059
456
+ hash: -3126132501408854274
473
457
  requirements: []
474
458
  rubyforge_project:
475
459
  rubygems_version: 1.8.23