govuk_content_models 13.2.1 → 13.3.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
+ ## 13.3.0
2
+
3
+ * Adds a `state` field to `Tag`.
4
+
1
5
  ## 13.2.1
2
6
 
3
7
  * Assigning an edition doesn't require the entire edition
data/app/models/tag.rb CHANGED
@@ -3,15 +3,17 @@ require 'tag_id_validator'
3
3
 
4
4
  class Tag
5
5
  include Mongoid::Document
6
- field :tag_id, type: String
7
- field :title, type: String
8
- field :tag_type, type: String #TODO: list of accepted types?
9
- field :description, type: String
6
+
7
+ field :tag_id, type: String
8
+ field :title, type: String
9
+ field :tag_type, type: String #TODO: list of accepted types?
10
+ field :description, type: String
10
11
  field :short_description, type: String
11
-
12
- field :parent_id, type: String
12
+ field :parent_id, type: String
13
+ field :state, type: String, default: 'live'
13
14
 
14
15
  GOVSPEAK_FIELDS = []
16
+ STATES = ['draft', 'live']
15
17
 
16
18
  index :tag_id
17
19
  index [ [:tag_id, Mongo::ASCENDING], [:tag_type, Mongo::ASCENDING] ], unique: true
@@ -22,6 +24,8 @@ class Tag
22
24
  validates_with TagIdValidator
23
25
  validates_with SafeHtml
24
26
 
27
+ validates :state, inclusion: { in: STATES }
28
+
25
29
  class MissingTags < RuntimeError
26
30
  attr_reader :tag_ids
27
31
 
@@ -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 = "13.2.1"
3
+ VERSION = "13.3.0"
4
4
  end
@@ -115,4 +115,38 @@ class TagTest < ActiveSupport::TestCase
115
115
  test "should validate with TagIdValidator" do
116
116
  assert_includes Tag.validators.map(&:class), TagIdValidator
117
117
  end
118
+
119
+ context "state" do
120
+ setup do
121
+ @atts = { tag_type: 'section', tag_id: 'test', title: 'Test' }
122
+ end
123
+
124
+ should "be created in live state" do
125
+ tag = Tag.create(@atts.merge(state: 'live'))
126
+
127
+ assert tag.persisted?
128
+ assert_equal 'live', tag.state
129
+ end
130
+
131
+ should "be created in draft state" do
132
+ tag = Tag.create(@atts.merge(state: 'draft'))
133
+
134
+ assert tag.persisted?
135
+ assert_equal 'draft', tag.state
136
+ end
137
+
138
+ should "not be created in another state" do
139
+ tag = Tag.create(@atts.merge(state: 'foo'))
140
+
141
+ assert !tag.valid?
142
+ assert tag.errors.has_key?(:state)
143
+ end
144
+
145
+ should "be created in live state by default" do
146
+ tag = Tag.create(@atts)
147
+
148
+ assert tag.persisted?
149
+ assert_equal 'live', tag.state
150
+ end
151
+ end
118
152
  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: 13.2.1
4
+ version: 13.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -468,7 +468,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
468
468
  version: '0'
469
469
  segments:
470
470
  - 0
471
- hash: -2244656321309357788
471
+ hash: 199219386487384018
472
472
  required_rubygems_version: !ruby/object:Gem::Requirement
473
473
  none: false
474
474
  requirements:
@@ -477,7 +477,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
477
477
  version: '0'
478
478
  segments:
479
479
  - 0
480
- hash: -2244656321309357788
480
+ hash: 199219386487384018
481
481
  requirements: []
482
482
  rubyforge_project:
483
483
  rubygems_version: 1.8.23