govuk_content_models 31.0.0 → 31.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f180214b4c41e4eeeca68831ad6ba2ca55f1ef7f
4
- data.tar.gz: c3620788cedec2c668987ae8d8b563e527e080e3
3
+ metadata.gz: 3bb0e2f37d9ec79613e1e92088da6d20b8f221f4
4
+ data.tar.gz: 83b14b0586ef58599e8b466336d109aa54e25753
5
5
  SHA512:
6
- metadata.gz: acf06907c1430d183ac52ae67cc858f67d68cab01f6963a406683fbcd8738c15595016aed443495e3310b0068f4eaea003214a4a2bfc48fc94950c7f0398eb54
7
- data.tar.gz: 4b276c0907a6b77a0f0201c7e2e27d4e4c852a3e611f09f46d07e284a8f294270caab42e98745a54dd06159cc2ffc2d96b653f914cd926fc4136a9c37aa64349
6
+ metadata.gz: 720600bc3dadd0332f123af6b84cd9dfd65d4a3f1ac32a039e844fecb201e4a46d4b5710813205023fde049fcea3d3d5b31062dd4a87f6a71c3c14c464d02f70
7
+ data.tar.gz: 0b05a4bbf7acd75fdb9f947a1f8c8d1eb0f70d3c0dd5324745c004342738d198e1b7119ad47480cb3e98300c6781f43be5699b4cfcc92dd6f1c9aa3871aa193d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 31.1.0
4
+
5
+ - `area_gss_codes` field for BusinessSupportEdition
6
+ - Explicitly support conversion between any edition types
7
+
3
8
  ## 31.0.0
4
9
 
5
10
  - `Edition.find_or_create_from_panopticon_data` no longer takes a third
@@ -29,6 +29,7 @@ class BusinessSupportEdition < Edition
29
29
  field :start_date, type: Date
30
30
  field :end_date, type: Date
31
31
  field :areas, type: Array, default: []
32
+ field :area_gss_codes, type: Array, default: []
32
33
 
33
34
  GOVSPEAK_FIELDS = [:body, :eligibility, :evaluation, :additional_information]
34
35
 
@@ -171,20 +171,11 @@ class Edition
171
171
  # we are changing the type of the edition, any fields other than the base
172
172
  # fields will likely be meaningless.
173
173
  def fields_to_copy(target_class)
174
- return_value = [
175
- :title,
176
- :panopticon_id,
177
- :overview,
178
- :slug,
179
- :browse_pages,
180
- :primary_topic,
181
- :additional_topics
182
- ]
183
174
  if target_class == self.class
184
- type_specific_keys = self.fields.keys - Edition.fields.keys
185
- return_value += type_specific_keys
175
+ base_field_keys + type_specific_field_keys
176
+ else
177
+ base_field_keys
186
178
  end
187
- return_value
188
179
  end
189
180
 
190
181
  def build_clone(target_class=nil)
@@ -209,21 +200,33 @@ class Edition
209
200
  # Where the type is not changing, the body will already have been copied
210
201
  # above.
211
202
  #
212
- # We don't need to copy parts between Parted types here, because the Parted
213
- # module does that.
214
- if target_class != self.class
215
- if new_edition.respond_to?(:parts) and !self.respond_to?(:parts)
216
- new_edition.parts.build(title: "Part One", body: whole_body, slug: "part-one")
217
- elsif new_edition.respond_to?(:more_information=)
218
- new_edition.more_information = whole_body
219
- elsif new_edition.respond_to?(:body=)
220
- new_edition.body = whole_body
221
- end
203
+ # We don't need to copy parts between Parted types here, because the
204
+ # Parted module does that.
205
+ if target_class != self.class && !cloning_between_parted_types?(new_edition)
206
+ new_edition.clone_whole_body_from(self)
222
207
  end
223
208
 
224
209
  new_edition
225
210
  end
226
211
 
212
+ def clone_whole_body_from(origin_edition)
213
+ if self.respond_to?(:parts)
214
+ self.parts.build(title: "Part One", body: origin_edition.whole_body, slug: "part-one")
215
+ elsif self.respond_to?(:more_information=)
216
+ self.more_information = origin_edition.whole_body
217
+ elsif self.respond_to?(:body=)
218
+ self.body = origin_edition.whole_body
219
+ elsif self.respond_to?(:licence_overview=)
220
+ self.licence_overview = origin_edition.whole_body
221
+ else
222
+ raise "Nowhere to copy whole_body content for conversion from: #{origin_edition.class} to: #{self.class}"
223
+ end
224
+ end
225
+
226
+ def cloning_between_parted_types?(new_edition)
227
+ self.respond_to?(:parts) && new_edition.respond_to?(:parts)
228
+ end
229
+
227
230
  def self.find_or_create_from_panopticon_data(panopticon_id, importing_user)
228
231
  existing_publication = Edition.where(panopticon_id: panopticon_id)
229
232
  .order_by([:version_number, :desc]).first
@@ -321,4 +324,21 @@ class Edition
321
324
  Artefact.find(self.panopticon_id).destroy
322
325
  end
323
326
  end
327
+
328
+ private
329
+ def base_field_keys
330
+ [
331
+ :title,
332
+ :panopticon_id,
333
+ :overview,
334
+ :slug,
335
+ :browse_pages,
336
+ :primary_topic,
337
+ :additional_topics,
338
+ ]
339
+ end
340
+
341
+ def type_specific_field_keys
342
+ (self.fields.keys - Edition.fields.keys).map(&:to_sym)
343
+ end
324
344
  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 = "31.0.0"
3
+ VERSION = "31.1.0"
4
4
  end
@@ -7,7 +7,10 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  should "have custom fields" do
10
- support = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
10
+ support = FactoryGirl.create(
11
+ :business_support_edition,
12
+ panopticon_id: @artefact.id,
13
+ )
11
14
  support.short_description = "The short description"
12
15
  support.body = "The body"
13
16
  support.eligibility = "The eligibility"
@@ -23,6 +26,7 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
23
26
 
24
27
  support.priority = 2
25
28
  support.areas = ["123","345","45","9"]
29
+ support.area_gss_codes = ["G123","G345","G45","G9"]
26
30
  support.business_sizes << "up-to-249"
27
31
  support.business_types << "charity"
28
32
  support.locations = ["scotland", "england"]
@@ -52,6 +56,7 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
52
56
  assert_equal 2, support.priority
53
57
 
54
58
  assert_equal ["123","345","45","9"], support.areas
59
+ assert_equal ["G123","G345","G45","G9"], support.area_gss_codes
55
60
  assert_equal ["up-to-249"], support.business_sizes
56
61
  assert_equal ["charity"], support.business_types
57
62
  assert_equal ["scotland", "england"], support.locations
@@ -64,7 +69,10 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
64
69
  end
65
70
 
66
71
  should "not allow max_value to be less than min_value" do
67
- support = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
72
+ support = FactoryGirl.create(
73
+ :business_support_edition,
74
+ panopticon_id: @artefact.id,
75
+ )
68
76
  support.min_value = 100
69
77
  support.max_value = 50
70
78
 
@@ -106,7 +114,10 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
106
114
  context "continuation_link validation" do
107
115
 
108
116
  setup do
109
- @bs = FactoryGirl.create(:business_support_edition, panopticon_id: @artefact.id)
117
+ @bs = FactoryGirl.create(
118
+ :business_support_edition,
119
+ panopticon_id: @artefact.id,
120
+ )
110
121
  end
111
122
 
112
123
  should "not validate the continuation link when blank" do
@@ -125,31 +136,34 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
125
136
  end
126
137
 
127
138
  should "clone extra fields when cloning edition" do
128
- support = FactoryGirl.create(:business_support_edition,
129
- :panopticon_id => @artefact.id,
130
- :state => "published",
131
- :short_description => "Short description of support format",
132
- :body => "Body to be cloned",
133
- :min_value => 1,
134
- :max_value => 2,
135
- :max_employees => 3,
136
- :organiser => "Organiser to be cloned",
137
- :eligibility => "Eligibility to be cloned",
138
- :evaluation => "Evaluation to be cloned",
139
- :additional_information => "Additional info to be cloned",
140
- :will_continue_on => "Continuation text to be cloned",
141
- :continuation_link => "http://www.gov.uk",
142
- :contact_details => "Contact details to be cloned",
143
- :priority => 2,
144
- :areas => ['123','9999'],
145
- :business_sizes => ['up-to-249'],
146
- :locations => ['london'],
147
- :purposes => ['start-up'],
148
- :sectors => ['agriculture','manufacturing'],
149
- :stages => ['grow-and-sustain'],
150
- :support_types => ['grant','loan'],
151
- :start_date => 1.year.ago(Date.today),
152
- :end_date => 1.year.since(Date.today))
139
+ support = FactoryGirl.create(
140
+ :business_support_edition,
141
+ :panopticon_id => @artefact.id,
142
+ :state => "published",
143
+ :short_description => "Short description of support format",
144
+ :body => "Body to be cloned",
145
+ :min_value => 1,
146
+ :max_value => 2,
147
+ :max_employees => 3,
148
+ :organiser => "Organiser to be cloned",
149
+ :eligibility => "Eligibility to be cloned",
150
+ :evaluation => "Evaluation to be cloned",
151
+ :additional_information => "Additional info to be cloned",
152
+ :will_continue_on => "Continuation text to be cloned",
153
+ :continuation_link => "http://www.gov.uk",
154
+ :contact_details => "Contact details to be cloned",
155
+ :priority => 2,
156
+ :areas => ['123','9999'],
157
+ :area_gss_codes => ['G123','G9999'],
158
+ :business_sizes => ['up-to-249'],
159
+ :locations => ['london'],
160
+ :purposes => ['start-up'],
161
+ :sectors => ['agriculture','manufacturing'],
162
+ :stages => ['grow-and-sustain'],
163
+ :support_types => ['grant','loan'],
164
+ :start_date => 1.year.ago(Date.today),
165
+ :end_date => 1.year.since(Date.today),
166
+ )
153
167
 
154
168
  new_support = support.build_clone
155
169
 
@@ -168,6 +182,7 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
168
182
 
169
183
  assert_equal support.priority, new_support.priority
170
184
  assert_equal support.areas, new_support.areas
185
+ assert_equal support.area_gss_codes, new_support.area_gss_codes
171
186
  assert_equal support.business_sizes, new_support.business_sizes
172
187
  assert_equal support.locations, new_support.locations
173
188
  assert_equal support.purposes, new_support.purposes
@@ -180,47 +195,82 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
180
195
 
181
196
  context "for facets" do
182
197
  setup do
183
- @e1 = FactoryGirl.create(:business_support_edition,
184
- :areas => ['2345', '1234'],
185
- :business_sizes => ['1', 'up-to-1000000'],
186
- :locations => ['narnia'], :purposes => ['world-domination'],
187
- :sectors => ['agriculture', 'healthcare'],
188
- :stages => ['pivoting'], :support_types => ['award', 'grant', 'loan'])
189
- @e2 = FactoryGirl.create(:business_support_edition,
190
- :areas => ['1212', '1234', '999'],
191
- :business_sizes => ['1', 'up-to-1000000'],
192
- :locations => ['hades', 'narnia'], :purposes => ['business-growth-and-expansion'],
193
- :sectors => ['education', 'healthcare'],
194
- :stages => ['start-up', 'pivoting'], :support_types => ['grant', 'loan', 'equity'])
195
- @e3 = FactoryGirl.create(:business_support_edition,
196
- :areas => ['1234'],
197
- :business_sizes => ['up-to-249', 'up-to-1000000'],
198
- :locations => ['hades', 'chicken-town'], :purposes => ['making-the-most-of-the-internet'],
199
- :sectors => ['utilities'], :stages => ['start-up'], :support_types => ['grant'])
198
+ @e1 = FactoryGirl.create(
199
+ :business_support_edition,
200
+ :areas => ['2345', '1234'],
201
+ :area_gss_codes => ['G2345', 'G1234'],
202
+ :business_sizes => ['1', 'up-to-1000000'],
203
+ :locations => ['narnia'],
204
+ :purposes => ['world-domination'],
205
+ :sectors => ['agriculture', 'healthcare'],
206
+ :stages => ['pivoting'],
207
+ :support_types => ['award', 'grant', 'loan'],
208
+ )
209
+ @e2 = FactoryGirl.create(
210
+ :business_support_edition,
211
+ :areas => ['1212', '1234', '999'],
212
+ :area_gss_codes => ['G1212', 'G1234', 'G999'],
213
+ :business_sizes => ['1', 'up-to-1000000'],
214
+ :locations => ['hades', 'narnia'],
215
+ :purposes => ['business-growth-and-expansion'],
216
+ :sectors => ['education', 'healthcare'],
217
+ :stages => ['start-up', 'pivoting'],
218
+ :support_types => ['grant', 'loan', 'equity'],
219
+ )
220
+ @e3 = FactoryGirl.create(
221
+ :business_support_edition,
222
+ :areas => ['1234'],
223
+ :area_gss_codes => ['G1234'],
224
+ :business_sizes => ['up-to-249', 'up-to-1000000'],
225
+ :locations => ['hades', 'chicken-town'],
226
+ :purposes => ['making-the-most-of-the-internet'],
227
+ :sectors => ['utilities'],
228
+ :stages => ['start-up'],
229
+ :support_types => ['grant'],
230
+ )
200
231
  end
201
232
 
202
233
  should "only return editions matching the facet values provided" do
203
- editions = BusinessSupportEdition.for_facets({:purposes => 'business-growth-and-expansion', :support_types => 'equity'})
234
+ editions = BusinessSupportEdition.for_facets({
235
+ :purposes => 'business-growth-and-expansion',
236
+ :support_types => 'equity',
237
+ })
204
238
  assert_equal [@e2], editions
205
- editions = BusinessSupportEdition.for_facets({:business_sizes => '1,up-to-1000000', :locations => 'narnia'})
239
+ editions = BusinessSupportEdition.for_facets({
240
+ :business_sizes => '1,up-to-1000000',
241
+ :locations => 'narnia',
242
+ })
206
243
  assert_equal [@e1, @e2], editions
207
244
  end
208
245
  should "support searching with all the facet values" do
209
- editions = BusinessSupportEdition.for_facets({:areas => '1234', :business_sizes => 'up-to-1000000', :locations => 'narnia,hades,chicken-town',
210
- :purposes => 'business-growth-and-expansion,making-the-most-of-the-internet,world-domination',
211
- :sectors => 'agriculture,healthcare,utilities', :stages => 'pivoting,start-up',
212
- :support_types => 'award,grant,loan'})
246
+ editions = BusinessSupportEdition.for_facets({
247
+ :areas => '1234',
248
+ :area_gss_codes => 'G1234',
249
+ :business_sizes => 'up-to-1000000',
250
+ :locations => 'narnia,hades,chicken-town',
251
+ :purposes => 'business-growth-and-expansion,making-the-most-of-the-internet,world-domination',
252
+ :sectors => 'agriculture,healthcare,utilities',
253
+ :stages => 'pivoting,start-up',
254
+ :support_types => 'award,grant,loan',
255
+ })
213
256
  assert_equal [@e1, @e2, @e3], editions
214
257
  end
215
258
  should "return nothing where no facet values match" do
216
- editions = BusinessSupportEdition.for_facets({:business_sizes => 'up-to-a-bizillion', :locations => 'ecclefechan'})
259
+ editions = BusinessSupportEdition.for_facets({
260
+ :business_sizes => 'up-to-a-bizillion',
261
+ :locations => 'ecclefechan',
262
+ })
217
263
  assert_empty editions
218
264
  end
219
265
  end
220
266
 
221
267
  context "scheme dates" do
222
268
  should "should have year with 4 digits length" do
223
- invalid_edition = FactoryGirl.build(:business_support_edition, start_date: Date.new(99, 12, 31), end_date: Date.new(99, 12, 31))
269
+ invalid_edition = FactoryGirl.build(
270
+ :business_support_edition,
271
+ start_date: Date.new(99, 12, 31),
272
+ end_date: Date.new(99, 12, 31),
273
+ )
224
274
 
225
275
  refute invalid_edition.valid?
226
276
 
@@ -230,7 +280,11 @@ class BusinessSupportEditionTest < ActiveSupport::TestCase
230
280
  end
231
281
 
232
282
  should "have start date earlier than end date" do
233
- invalid_edition = FactoryGirl.build(:business_support_edition, start_date: 1.week.ago, end_date: 2.weeks.ago)
283
+ invalid_edition = FactoryGirl.build(
284
+ :business_support_edition,
285
+ start_date: 1.week.ago,
286
+ end_date: 2.weeks.ago,
287
+ )
234
288
 
235
289
  refute invalid_edition.valid?
236
290
  assert_includes invalid_edition.errors.full_messages, "Start date can't be later than end date"
@@ -198,6 +198,21 @@ class EditionTest < ActiveSupport::TestCase
198
198
  end
199
199
 
200
200
  # test cloning into different edition types
201
+ Edition.subclasses.permutation(2).each do |source_class, destination_class|
202
+ test "it should be possible to clone from a #{source_class} to a #{destination_class}" do
203
+ # Note that the new edition won't necessarily be valid - for example the
204
+ # new type might have required fields that the old just doesn't have.
205
+ # This is OK because when Publisher saves the clone, it already skips
206
+ # validations. The user will then be required to populate those values
207
+ # before they save the edition again.
208
+ source_edition = FactoryGirl.create(:edition, _type: source_class.to_s, state: "published")
209
+
210
+ assert_nothing_raised do
211
+ new_edition = source_edition.build_clone(destination_class)
212
+ end
213
+ end
214
+ end
215
+
201
216
  test "Cloning from GuideEdition into AnswerEdition" do
202
217
  edition = FactoryGirl.create(
203
218
  :guide_edition,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_content_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 31.0.0
4
+ version: 31.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson_ext