govuk_content_models 21.0.0 → 22.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,8 @@
1
+ ## 22.0.0
2
+
3
+ * Remove old unused `tags` field from Edition
4
+ * Add browse and topic collection associations to Edition
5
+
1
6
  ## 21.0.0
2
7
 
3
8
  * Remove diff-ing code from content models - diffs should now be calculated on the fly
@@ -19,9 +19,12 @@ class Edition
19
19
  field :slug, type: String
20
20
  field :department, type: String
21
21
  field :rejected_count, type: Integer, default: 0
22
- field :tags, type: String
23
22
  field :important_note, type: String
24
23
 
24
+ field :browse_pages, type: Array
25
+ field :primary_topic, type: String
26
+ field :additional_topics, type: Array
27
+
25
28
  field :assignee, type: String
26
29
  field :creator, type: String
27
30
  field :publisher, type: String
@@ -49,6 +52,7 @@ class Edition
49
52
  validates :panopticon_id, presence: true
50
53
  validates_with SafeHtml
51
54
  validates_with LinkValidator, on: :update
55
+ validates_with TopicValidator, BrowsePageValidator
52
56
 
53
57
  before_save :check_for_archived_artefact
54
58
  before_destroy :destroy_artefact
@@ -0,0 +1,9 @@
1
+ class BrowsePageValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ if (browse_pages = record.browse_pages)
4
+ if browse_pages.uniq.count < browse_pages.count
5
+ record.errors.add(:browse_pages, "can't have duplicates")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class TopicValidator < ActiveModel::Validator
2
+ def validate(record)
3
+ if (additional_topics = record.additional_topics)
4
+ if additional_topics.uniq.count < additional_topics.count
5
+ record.errors.add(:additional_topics, "can't have duplicates")
6
+ end
7
+
8
+ if additional_topics.include?(record.primary_topic)
9
+ record.errors.add(:base, "You can't have the primary topic set as an additional topic")
10
+ end
11
+ end
12
+ end
13
+ 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 = "21.0.0"
3
+ VERSION = "22.0.0"
4
4
  end
@@ -77,7 +77,7 @@ class EditionTest < ActiveSupport::TestCase
77
77
  end
78
78
 
79
79
  test "it should be able to find its previous siblings" do
80
- @artefact2 = FactoryGirl.create(:artefact)
80
+ @artefact2 = FactoryGirl.create(:artefact)
81
81
  g1 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 1)
82
82
  g2 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact2.id, version_number: 1)
83
83
  g3 = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, version_number: 2)
@@ -1028,4 +1028,51 @@ class EditionTest < ActiveSupport::TestCase
1028
1028
  end
1029
1029
  end
1030
1030
  end
1031
+
1032
+ context "Tagging to collections" do
1033
+ setup do
1034
+ @edition = FactoryGirl.create(:guide_edition)
1035
+ end
1036
+
1037
+ should "allow tagging to browse pages" do
1038
+ sample_browse_pages = [
1039
+ 'education/school-admissions-transport',
1040
+ 'driving/drivers-lorries-buses'
1041
+ ]
1042
+
1043
+ @edition.browse_pages = sample_browse_pages
1044
+ @edition.save!; @edition.reload
1045
+
1046
+ assert_equal sample_browse_pages, @edition.browse_pages
1047
+ end
1048
+
1049
+ should "allow tagging to a primary topic" do
1050
+ sample_primary_topic = 'oil-and-gas/carbon-capture-and-storage'
1051
+
1052
+ @edition.primary_topic = sample_primary_topic
1053
+ @edition.save!; @edition.reload
1054
+
1055
+ assert_equal sample_primary_topic, @edition.primary_topic
1056
+ end
1057
+
1058
+ should "allow tagging to multiple additional topics" do
1059
+ sample_additional_topics = [
1060
+ 'oil-and-gas/fields-and-wells',
1061
+ 'oil-and-gas/licensing'
1062
+ ]
1063
+
1064
+ @edition.additional_topics = sample_additional_topics
1065
+ @edition.save!; @edition.reload
1066
+
1067
+ assert_equal sample_additional_topics, @edition.additional_topics
1068
+ end
1069
+
1070
+ should "validates topics" do
1071
+ assert_includes Edition.validators.map(&:class), TopicValidator
1072
+ end
1073
+
1074
+ should "validates browse pages" do
1075
+ assert_includes Edition.validators.map(&:class), BrowsePageValidator
1076
+ end
1077
+ end
1031
1078
  end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+ require 'browse_page_validator'
3
+
4
+ class BrowsePageValidatorTest < ActiveSupport::TestCase
5
+ class Record
6
+ include Mongoid::Document
7
+
8
+ field :browse_pages, type: Array
9
+
10
+ validates_with BrowsePageValidator
11
+ end
12
+
13
+ should "allow tagging to a variety of unique browse pages" do
14
+ record = Record.new(
15
+ browse_pages: [
16
+ 'business/tax',
17
+ 'housing/safety-environment'
18
+ ]
19
+ )
20
+
21
+ assert record.valid?
22
+ end
23
+
24
+ should "be invalid if there's duplicates in the browse page list" do
25
+ record = Record.new(
26
+ browse_pages: [
27
+ 'housing/safety-environment',
28
+ 'housing/safety-environment'
29
+ ]
30
+ )
31
+
32
+ refute record.valid?
33
+ end
34
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'topic_validator'
3
+
4
+ class TopicValidatorTest < ActiveSupport::TestCase
5
+ class Record
6
+ include Mongoid::Document
7
+
8
+ field :primary_topic, type: String
9
+ field :additional_topics, type: Array
10
+
11
+ validates_with TopicValidator
12
+ end
13
+
14
+ should "allow tagging to a variety of unique topics" do
15
+ record = Record.new(
16
+ primary_topic: 'oil-and-gas/exploration',
17
+ additional_topics: [
18
+ 'oil-and-gas/fields-and-wells',
19
+ 'oil-and-gas/licensing'
20
+ ]
21
+ )
22
+
23
+ assert record.valid?
24
+ end
25
+
26
+ should "be invalid if there's duplicates in the additional topic list" do
27
+ record = Record.new(
28
+ additional_topics: [
29
+ 'oil-and-gas/fields-and-wells',
30
+ 'oil-and-gas/fields-and-wells'
31
+ ]
32
+ )
33
+
34
+ refute record.valid?
35
+ end
36
+
37
+ should "be invalid if the primary topic is in the additional topic list" do
38
+ record = Record.new(
39
+ primary_topic: 'oil-and-gas/fields-and-wells',
40
+ additional_topics: [
41
+ 'oil-and-gas/fields-and-wells',
42
+ 'oil-and-gas/licensing'
43
+ ]
44
+ )
45
+
46
+ refute record.valid?
47
+ end
48
+ end
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: 21.0.0
4
+ version: 22.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-24 00:00:00.000000000 Z
12
+ date: 2014-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -368,10 +368,12 @@ files:
368
368
  - app/models/workflow_actor.rb
369
369
  - app/traits/attachable.rb
370
370
  - app/traits/taggable.rb
371
+ - app/validators/browse_page_validator.rb
371
372
  - app/validators/link_validator.rb
372
373
  - app/validators/safe_html.rb
373
374
  - app/validators/slug_validator.rb
374
375
  - app/validators/tag_id_validator.rb
376
+ - app/validators/topic_validator.rb
375
377
  - config/mongoid.yml
376
378
  - govuk_content_models.gemspec
377
379
  - jenkins.sh
@@ -425,10 +427,12 @@ files:
425
427
  - test/test_helper.rb
426
428
  - test/traits/attachable_test.rb
427
429
  - test/traits/taggable_test.rb
430
+ - test/validators/browse_page_validator_test.rb
428
431
  - test/validators/link_validator_test.rb
429
432
  - test/validators/safe_html_validator_test.rb
430
433
  - test/validators/slug_validator_test.rb
431
434
  - test/validators/tag_id_validator_test.rb
435
+ - test/validators/topic_validator_test.rb
432
436
  homepage: https://github.com/alphagov/govuk_content_models
433
437
  licenses: []
434
438
  post_install_message:
@@ -444,7 +448,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
444
448
  version: '0'
445
449
  segments:
446
450
  - 0
447
- hash: -3126132501408854274
451
+ hash: 2932545422585521271
448
452
  required_rubygems_version: !ruby/object:Gem::Requirement
449
453
  none: false
450
454
  requirements:
@@ -453,7 +457,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
457
  version: '0'
454
458
  segments:
455
459
  - 0
456
- hash: -3126132501408854274
460
+ hash: 2932545422585521271
457
461
  requirements: []
458
462
  rubyforge_project:
459
463
  rubygems_version: 1.8.23
@@ -504,7 +508,9 @@ test_files:
504
508
  - test/test_helper.rb
505
509
  - test/traits/attachable_test.rb
506
510
  - test/traits/taggable_test.rb
511
+ - test/validators/browse_page_validator_test.rb
507
512
  - test/validators/link_validator_test.rb
508
513
  - test/validators/safe_html_validator_test.rb
509
514
  - test/validators/slug_validator_test.rb
510
515
  - test/validators/tag_id_validator_test.rb
516
+ - test/validators/topic_validator_test.rb