govuk_content_models 6.0.3 → 6.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -166,11 +166,15 @@ class Edition
166
166
  new_edition[attr] = read_attribute(attr)
167
167
  end
168
168
 
169
- if edition_class == AnswerEdition and self.class == GuideEdition
169
+ if edition_class == AnswerEdition and %w(GuideEdition ProgrammeEdition TransactionEdition).include?(self.class.name)
170
170
  new_edition.body = whole_body
171
171
  end
172
172
 
173
- if edition_class == GuideEdition and self.class == AnswerEdition
173
+ if edition_class == TransactionEdition and %w(AnswerEdition GuideEdition ProgrammeEdition).include?(self.class.name)
174
+ new_edition.more_information = whole_body
175
+ end
176
+
177
+ if edition_class == GuideEdition and self.is_a?(AnswerEdition)
174
178
  new_edition.parts.build(title: "Part One", body: whole_body,
175
179
  slug: "part-one")
176
180
  end
@@ -23,6 +23,6 @@ class TransactionEdition < Edition
23
23
  end
24
24
 
25
25
  def whole_body
26
- [ self.link, self.introduction, self.more_information ].join("\n\n")
26
+ [ self.link, self.introduction, self.more_information, self.alternate_methods ].join("\n\n")
27
27
  end
28
28
  end
@@ -85,6 +85,17 @@ FactoryGirl.define do
85
85
  section { "test:subsection test" }
86
86
  end
87
87
 
88
+ factory :programme_edition_with_multiple_parts, parent: :programme_edition do
89
+ title "a title"
90
+ after :create do |getp|
91
+ getp.parts.build(title: "PART !", body: "This is some programme version text.",
92
+ slug: "part-one")
93
+ getp.parts.build(title: "PART !!",
94
+ body: "This is some more programme version text.",
95
+ slug: "part-two")
96
+ end
97
+ end
98
+
88
99
  factory :guide_edition_with_two_parts, parent: :guide_edition do
89
100
  title "a title"
90
101
  after :create do |getp|
@@ -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 = "6.0.3"
3
+ VERSION = "6.0.4"
4
4
  end
@@ -130,7 +130,8 @@ class EditionTest < ActiveSupport::TestCase
130
130
  assert_equal clone1.version_number, 3
131
131
  end
132
132
 
133
- test "Cloning into a different edition type" do
133
+ # test cloning into different edition types
134
+ test "Cloning from GuideEdition into AnswerEdition" do
134
135
  edition = FactoryGirl.create(
135
136
  :guide_edition,
136
137
  state: "published",
@@ -150,18 +151,156 @@ class EditionTest < ActiveSupport::TestCase
150
151
  assert_equal new_edition.department, "Test dept"
151
152
  assert_equal new_edition.overview, "I am a test overview"
152
153
  assert_equal new_edition.alternative_title, "Alternative test title"
154
+ assert_equal new_edition.whole_body, edition.whole_body
155
+ end
156
+
157
+ test "Cloning from ProgrammeEdition into AnswerEdition" do
158
+ edition = FactoryGirl.create(
159
+ :programme_edition,
160
+ state: "published",
161
+ panopticon_id: @artefact.id,
162
+ version_number: 1,
163
+ department: "Test dept",
164
+ overview: "I am a test overview",
165
+ alternative_title: "Alternative test title"
166
+ )
167
+ new_edition = edition.build_clone AnswerEdition
168
+
169
+ assert_equal new_edition.class, AnswerEdition
170
+ assert_equal new_edition.version_number, 2
171
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
172
+ assert_equal new_edition.state, "lined_up"
173
+ assert_equal new_edition.department, "Test dept"
174
+ assert_equal new_edition.overview, "I am a test overview"
175
+ assert_equal new_edition.alternative_title, "Alternative test title"
176
+ assert_equal new_edition.whole_body, edition.whole_body
177
+ end
178
+
179
+ test "Cloning from TransactionEdition into AnswerEdition" do
180
+ edition = FactoryGirl.create(
181
+ :transaction_edition,
182
+ state: "published",
183
+ panopticon_id: @artefact.id,
184
+ version_number: 1,
185
+ department: "Test dept",
186
+ overview: "I am a test overview",
187
+ alternative_title: "Alternative test title",
188
+ more_information: "More information",
189
+ alternate_methods: "Alternate methods"
190
+ )
191
+ new_edition = edition.build_clone AnswerEdition
192
+
193
+ assert_equal new_edition.class, AnswerEdition
194
+ assert_equal new_edition.version_number, 2
195
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
196
+ assert_equal new_edition.state, "lined_up"
197
+ assert_equal new_edition.department, "Test dept"
198
+ assert_equal new_edition.overview, "I am a test overview"
199
+ assert_equal new_edition.alternative_title, "Alternative test title"
200
+ assert_equal new_edition.whole_body, edition.whole_body
201
+ end
202
+
203
+ test "Cloning from AnswerEdition into TransactionEdition" do
204
+ edition = FactoryGirl.create(
205
+ :answer_edition,
206
+ state: "published",
207
+ panopticon_id: @artefact.id,
208
+ version_number: 1,
209
+ department: "Test dept",
210
+ overview: "I am a test overview",
211
+ alternative_title: "Alternative test title",
212
+ body: "Test body"
213
+ )
214
+ new_edition = edition.build_clone TransactionEdition
215
+
216
+ assert_equal new_edition.class, TransactionEdition
217
+ assert_equal new_edition.version_number, 2
218
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
219
+ assert_equal new_edition.state, "lined_up"
220
+ assert_equal new_edition.department, "Test dept"
221
+ assert_equal new_edition.overview, "I am a test overview"
222
+ assert_equal new_edition.alternative_title, "Alternative test title"
223
+ assert_equal new_edition.more_information, "Test body"
224
+ end
225
+
226
+ test "Cloning from GuideEdition into TransactionEdition" do
227
+ edition = FactoryGirl.create(
228
+ :guide_edition,
229
+ state: "published",
230
+ panopticon_id: @artefact.id,
231
+ version_number: 1,
232
+ department: "Test dept",
233
+ overview: "I am a test overview",
234
+ alternative_title: "Alternative test title",
235
+ video_url: "http://www.youtube.com/watch?v=dQw4w9WgXcQ"
236
+ )
237
+ new_edition = edition.build_clone TransactionEdition
238
+
239
+ assert_equal new_edition.class, TransactionEdition
240
+ assert_equal new_edition.version_number, 2
241
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
242
+ assert_equal new_edition.state, "lined_up"
243
+ assert_equal new_edition.department, "Test dept"
244
+ assert_equal new_edition.overview, "I am a test overview"
245
+ assert_equal new_edition.alternative_title, "Alternative test title"
246
+ assert_equal new_edition.more_information, edition.whole_body
247
+ end
248
+
249
+ test "Cloning from ProgrammeEdition into TransactionEdition" do
250
+ edition = FactoryGirl.create(
251
+ :programme_edition,
252
+ state: "published",
253
+ panopticon_id: @artefact.id,
254
+ version_number: 1,
255
+ department: "Test dept",
256
+ overview: "I am a test overview",
257
+ alternative_title: "Alternative test title"
258
+ )
259
+ new_edition = edition.build_clone TransactionEdition
260
+
261
+ assert_equal new_edition.class, TransactionEdition
262
+ assert_equal new_edition.version_number, 2
263
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
264
+ assert_equal new_edition.state, "lined_up"
265
+ assert_equal new_edition.department, "Test dept"
266
+ assert_equal new_edition.overview, "I am a test overview"
267
+ assert_equal new_edition.alternative_title, "Alternative test title"
268
+ assert_equal new_edition.more_information, edition.whole_body
269
+ end
270
+
271
+ test "Cloning from AnswerEdition into GuideEdition" do
272
+ edition = FactoryGirl.create(
273
+ :answer_edition,
274
+ state: "published",
275
+ panopticon_id: @artefact.id,
276
+ version_number: 1,
277
+ department: "Test dept",
278
+ overview: "I am a test overview",
279
+ alternative_title: "Alternative test title"
280
+ )
281
+ new_edition = edition.build_clone GuideEdition
282
+
283
+ assert_equal new_edition.class, GuideEdition
284
+ assert_equal new_edition.version_number, 2
285
+ assert_equal new_edition.panopticon_id, @artefact.id.to_s
286
+ assert_equal new_edition.state, "lined_up"
287
+ assert_equal new_edition.department, "Test dept"
288
+ assert_equal new_edition.overview, "I am a test overview"
289
+ assert_equal new_edition.alternative_title, "Alternative test title"
153
290
  end
154
291
 
155
292
  test "Cloning between types with parts" do
156
- edition = FactoryGirl.create(:programme_edition,
293
+ edition = FactoryGirl.create(:programme_edition_with_multiple_parts,
157
294
  panopticon_id: @artefact.id,
158
295
  state: "published",
159
296
  version_number: 1,
160
- overview: "I am a shiny programme")
297
+ overview: "I am a shiny programme",
298
+ )
161
299
  new_edition = edition.build_clone GuideEdition
162
300
 
163
301
  assert_equal(new_edition.parts.map {|part| part.title },
164
302
  edition.parts.map {|part| part.title })
303
+ assert_equal 7, new_edition.parts.size #there are 5 'default' parts plus an additional two created by the factory
165
304
  end
166
305
 
167
306
  test "edition finder should return the published edition when given an empty edition parameter" do
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: 6.0.3
4
+ version: 6.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -452,7 +452,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
452
452
  version: '0'
453
453
  segments:
454
454
  - 0
455
- hash: 903394278691268012
455
+ hash: -4288275942381521382
456
456
  required_rubygems_version: !ruby/object:Gem::Requirement
457
457
  none: false
458
458
  requirements:
@@ -461,7 +461,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
461
461
  version: '0'
462
462
  segments:
463
463
  - 0
464
- hash: 903394278691268012
464
+ hash: -4288275942381521382
465
465
  requirements: []
466
466
  rubyforge_project:
467
467
  rubygems_version: 1.8.23