govuk_content_models 15.0.0 → 15.1.0
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 +9 -0
- data/app/models/tag.rb +19 -6
- data/app/traits/taggable.rb +1 -7
- data/lib/govuk_content_models/version.rb +1 -1
- data/test/models/tag_test.rb +22 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 15.1.0
|
|
2
|
+
* Add draft tag functionality to `Tag.by_tag_id/s`.
|
|
3
|
+
* Permit tag type to be provided via an options
|
|
4
|
+
hash, while retaining backwards compatibility.
|
|
5
|
+
|
|
6
|
+
## 15.0.0
|
|
7
|
+
* Refactor tags.
|
|
8
|
+
* Provide draft functionality in the `taggable` trait.
|
|
9
|
+
|
|
1
10
|
## 14.1.1
|
|
2
11
|
* Use another way to transition Editions without
|
|
3
12
|
validation
|
data/app/models/tag.rb
CHANGED
|
@@ -65,12 +65,24 @@ class Tag
|
|
|
65
65
|
title
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
def self.by_tag_id(tag_id,
|
|
69
|
-
by_tag_ids([tag_id],
|
|
68
|
+
def self.by_tag_id(tag_id, tag_type_or_options = nil)
|
|
69
|
+
by_tag_ids([tag_id], tag_type_or_options).first
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
def self.by_tag_ids(tag_id_list,
|
|
73
|
-
|
|
72
|
+
def self.by_tag_ids(tag_id_list, tag_type_or_options = nil)
|
|
73
|
+
if tag_type_or_options.is_a?(String)
|
|
74
|
+
# Providing the type as a string argument is deprecated in favour of providing the type as an option
|
|
75
|
+
options = {type: tag_type_or_options}
|
|
76
|
+
else
|
|
77
|
+
options = tag_type_or_options || {}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
tag_scope = options[:type] ? Tag.where(tag_type: options[:type]) : Tag
|
|
81
|
+
|
|
82
|
+
unless options[:draft]
|
|
83
|
+
tag_scope = tag_scope.where(:state.ne => 'draft')
|
|
84
|
+
end
|
|
85
|
+
|
|
74
86
|
tag_scope = tag_scope.any_in(tag_id: tag_id_list)
|
|
75
87
|
|
|
76
88
|
# Sort by id list because MongoID 2.x doesn't preserve order
|
|
@@ -85,9 +97,10 @@ class Tag
|
|
|
85
97
|
any_of(list)
|
|
86
98
|
end
|
|
87
99
|
|
|
88
|
-
#
|
|
100
|
+
# Validate a list of tags by tag ID. Any missing tags raise an exception.
|
|
101
|
+
# Draft tags are considered present for internal validation.
|
|
89
102
|
def self.validate_tag_ids(tag_id_list, tag_type = nil)
|
|
90
|
-
found_tags = by_tag_ids(tag_id_list, tag_type)
|
|
103
|
+
found_tags = by_tag_ids(tag_id_list, type: tag_type, draft: true)
|
|
91
104
|
missing_tag_ids = tag_id_list - found_tags.map(&:tag_id)
|
|
92
105
|
raise MissingTags.new(missing_tag_ids) if missing_tag_ids.any?
|
|
93
106
|
end
|
data/app/traits/taggable.rb
CHANGED
|
@@ -95,12 +95,6 @@ module Taggable
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
def tags(include_draft = false)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if include_draft
|
|
101
|
-
all_tags
|
|
102
|
-
else
|
|
103
|
-
all_tags.reject {|tag| tag.state == 'draft' }
|
|
104
|
-
end
|
|
98
|
+
Tag.by_tag_ids(tag_ids, draft: include_draft)
|
|
105
99
|
end
|
|
106
100
|
end
|
data/test/models/tag_test.rb
CHANGED
|
@@ -37,9 +37,14 @@ class TagTest < ActiveSupport::TestCase
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
test "should load by tag ID and type" do
|
|
40
|
+
# This form is deprecated in favour of providing the type as an option
|
|
40
41
|
assert_equal "Crime", Tag.by_tag_id("crime", "section").title
|
|
41
42
|
end
|
|
42
43
|
|
|
44
|
+
test "accepts the tag type as an option" do
|
|
45
|
+
assert_equal "Crime", Tag.by_tag_id("crime", type: "section").title
|
|
46
|
+
end
|
|
47
|
+
|
|
43
48
|
test "should not load an incorrectly-typed tag" do
|
|
44
49
|
assert_nil Tag.by_tag_id("crime", "keyword")
|
|
45
50
|
end
|
|
@@ -62,6 +67,23 @@ class TagTest < ActiveSupport::TestCase
|
|
|
62
67
|
assert_equal %w(crime business housing), tags.map(&:tag_id)
|
|
63
68
|
end
|
|
64
69
|
|
|
70
|
+
test "should not return draft tags unless requested" do
|
|
71
|
+
draft_tag = FactoryGirl.create(:tag,
|
|
72
|
+
tag_id: "draft-tag",
|
|
73
|
+
tag_type: "section",
|
|
74
|
+
title: "A draft tag",
|
|
75
|
+
state: "draft"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
tag_ids = %w(crime business draft-tag housing)
|
|
79
|
+
|
|
80
|
+
assert_equal %w(crime business housing).to_set, Tag.by_tag_ids(tag_ids).map(&:tag_id).to_set
|
|
81
|
+
assert_equal %w(crime business draft-tag housing).to_set, Tag.by_tag_ids(tag_ids, draft: true).map(&:tag_id).to_set
|
|
82
|
+
|
|
83
|
+
assert_nil Tag.by_tag_id('draft-tag')
|
|
84
|
+
assert_equal draft_tag, Tag.by_tag_id('draft-tag', draft: true)
|
|
85
|
+
end
|
|
86
|
+
|
|
65
87
|
test "should return nil for tags of the wrong type" do
|
|
66
88
|
tag_ids = %w(crime business pie batman)
|
|
67
89
|
tags = Tag.by_tag_ids(tag_ids, "section")
|
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: 15.
|
|
4
|
+
version: 15.1.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-07-
|
|
12
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bson_ext
|
|
@@ -466,7 +466,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
466
466
|
version: '0'
|
|
467
467
|
segments:
|
|
468
468
|
- 0
|
|
469
|
-
hash: -
|
|
469
|
+
hash: -630092204464727193
|
|
470
470
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
471
471
|
none: false
|
|
472
472
|
requirements:
|
|
@@ -475,7 +475,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
475
475
|
version: '0'
|
|
476
476
|
segments:
|
|
477
477
|
- 0
|
|
478
|
-
hash: -
|
|
478
|
+
hash: -630092204464727193
|
|
479
479
|
requirements: []
|
|
480
480
|
rubyforge_project:
|
|
481
481
|
rubygems_version: 1.8.23
|