govuk_content_models 42.0.0 → 42.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/app/traits/attachable.rb +2 -2
  4. data/govuk_content_models.gemspec +1 -2
  5. data/lib/govuk_content_models/version.rb +1 -1
  6. metadata +3 -83
  7. data/test/fixtures/uploads/image.jpg +0 -0
  8. data/test/models/action_test.rb +0 -13
  9. data/test/models/artefact_action_test.rb +0 -130
  10. data/test/models/artefact_external_link_test.rb +0 -32
  11. data/test/models/artefact_test.rb +0 -482
  12. data/test/models/business_support/business_size_test.rb +0 -25
  13. data/test/models/business_support/business_type_test.rb +0 -25
  14. data/test/models/business_support/location_test.rb +0 -25
  15. data/test/models/business_support/purpose_test.rb +0 -29
  16. data/test/models/business_support/sector_test.rb +0 -25
  17. data/test/models/business_support/stage_test.rb +0 -25
  18. data/test/models/business_support/support_type_test.rb +0 -25
  19. data/test/models/business_support_edition_test.rb +0 -282
  20. data/test/models/campaign_edition_test.rb +0 -91
  21. data/test/models/completed_transaction_edition_test.rb +0 -56
  22. data/test/models/downtime_test.rb +0 -93
  23. data/test/models/edition_scheduled_for_publishing_test.rb +0 -91
  24. data/test/models/edition_test.rb +0 -1185
  25. data/test/models/help_page_edition_test.rb +0 -43
  26. data/test/models/licence_edition_test.rb +0 -105
  27. data/test/models/local_service_test.rb +0 -6
  28. data/test/models/local_transaction_edition_test.rb +0 -37
  29. data/test/models/overview_dashboard_test.rb +0 -46
  30. data/test/models/parted_test.rb +0 -26
  31. data/test/models/prerendered_entity_tests.rb +0 -46
  32. data/test/models/rendered_manual_test.rb +0 -10
  33. data/test/models/simple_smart_answer_edition_test.rb +0 -211
  34. data/test/models/simple_smart_answer_node_test.rb +0 -134
  35. data/test/models/simple_smart_answer_option_test.rb +0 -97
  36. data/test/models/time_zone_test.rb +0 -48
  37. data/test/models/transaction_edition_test.rb +0 -36
  38. data/test/models/travel_advice_edition_test.rb +0 -469
  39. data/test/models/user_test.rb +0 -155
  40. data/test/models/video_edition_test.rb +0 -64
  41. data/test/models/workflow_test.rb +0 -498
  42. data/test/test_helper.rb +0 -61
  43. data/test/traits/attachable_test.rb +0 -244
  44. data/test/validators/link_validator_test.rb +0 -86
  45. data/test/validators/safe_html_validator_test.rb +0 -83
  46. data/test/validators/slug_validator_test.rb +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bacf08397308954506f1db7f3367eff5bb87825
4
- data.tar.gz: d87f23b5972b468378aeb9085dc3241ffe2de61f
3
+ metadata.gz: 3235aab91ee5afad9c8fcb1520da2a2f5189656c
4
+ data.tar.gz: 87a4c14074f2d3dd0c76488858508e350a56eedc
5
5
  SHA512:
6
- metadata.gz: 74dcfde7b33e6dfd7b17af36967cfe065fe299a79c74e6d1d4024e0d100eacfbcaa4504b8f3a3d1bbf107b9bcfae117050da7181c6fa5a1a975ed97c44cca180
7
- data.tar.gz: d0df800cf739c23c95372ce124df316b08d0a5feac079a4d90ce1e5cb167c235bb6c17ac11dc91fe182c346851923ed1d72cc909bcb52ae755012605b532876b
6
+ metadata.gz: 7b18bd52ae7fb325759105abd9d26bbd7c468221486590869a578021383e7e47ce6ef2157de62972008924798da718c41f0b80e0b331680583fea8a142d2f925
7
+ data.tar.gz: 89ba877b57e0d6e7fc643428f7108d4fac1d48e9487285a73c16d46e1ffa647c709f1a8795567dd02bcceb6fc3fb28660daa38f135a7e76a787f98208a418009
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 42.0.1
4
+
5
+ - Fix bug in Attachable which prevents the upload of attachments.
6
+ - Remove test files from the built gem.
7
+
3
8
  ## 42.0.0
4
9
 
5
10
  - Remove everything related to tagging and related links. We now use the content
@@ -59,10 +59,10 @@ module Attachable
59
59
  response = Attachable.asset_api_client.update_asset(self.send("#{field}_id"), file: instance_variable_get("@#{field}_file"))
60
60
  else
61
61
  response = Attachable.asset_api_client.create_asset(:file => instance_variable_get("@#{field}_file"))
62
- self.send("#{field}_id=", response.id.split('/').last)
62
+ self.send("#{field}_id=", response["id"].split('/').last)
63
63
  end
64
64
 
65
- self.send("#{field}_url=", response.file_url) if self.respond_to?("#{field}_url=")
65
+ self.send("#{field}_url=", response["file_url"]) if self.respond_to?("#{field}_url=")
66
66
  rescue StandardError
67
67
  errors.add("#{field}_id".to_sym, "could not be uploaded")
68
68
  end
@@ -8,9 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.summary = %q{Shared models for Panopticon and Publisher, as a Rails Engine}
9
9
  gem.homepage = "https://github.com/alphagov/govuk_content_models"
10
10
 
11
- gem.files = `git ls-files`.split($\)
11
+ gem.files = `git ls-files`.split($\).reject { |f| f.include?('test/') }
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
13
  gem.name = "govuk_content_models"
15
14
  gem.require_paths = ["lib", "app"]
16
15
  gem.version = GovukContentModels::VERSION
@@ -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 = "42.0.0"
3
+ VERSION = "42.0.1"
4
4
  end
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: 42.0.0
4
+ version: 42.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson_ext
@@ -393,46 +393,6 @@ files:
393
393
  - lib/govuk_content_models/test_helpers/local_services.rb
394
394
  - lib/govuk_content_models/version.rb
395
395
  - lib/mongoid/monkey_patches.rb
396
- - test/fixtures/uploads/image.jpg
397
- - test/models/action_test.rb
398
- - test/models/artefact_action_test.rb
399
- - test/models/artefact_external_link_test.rb
400
- - test/models/artefact_test.rb
401
- - test/models/business_support/business_size_test.rb
402
- - test/models/business_support/business_type_test.rb
403
- - test/models/business_support/location_test.rb
404
- - test/models/business_support/purpose_test.rb
405
- - test/models/business_support/sector_test.rb
406
- - test/models/business_support/stage_test.rb
407
- - test/models/business_support/support_type_test.rb
408
- - test/models/business_support_edition_test.rb
409
- - test/models/campaign_edition_test.rb
410
- - test/models/completed_transaction_edition_test.rb
411
- - test/models/downtime_test.rb
412
- - test/models/edition_scheduled_for_publishing_test.rb
413
- - test/models/edition_test.rb
414
- - test/models/help_page_edition_test.rb
415
- - test/models/licence_edition_test.rb
416
- - test/models/local_service_test.rb
417
- - test/models/local_transaction_edition_test.rb
418
- - test/models/overview_dashboard_test.rb
419
- - test/models/parted_test.rb
420
- - test/models/prerendered_entity_tests.rb
421
- - test/models/rendered_manual_test.rb
422
- - test/models/simple_smart_answer_edition_test.rb
423
- - test/models/simple_smart_answer_node_test.rb
424
- - test/models/simple_smart_answer_option_test.rb
425
- - test/models/time_zone_test.rb
426
- - test/models/transaction_edition_test.rb
427
- - test/models/travel_advice_edition_test.rb
428
- - test/models/user_test.rb
429
- - test/models/video_edition_test.rb
430
- - test/models/workflow_test.rb
431
- - test/test_helper.rb
432
- - test/traits/attachable_test.rb
433
- - test/validators/link_validator_test.rb
434
- - test/validators/safe_html_validator_test.rb
435
- - test/validators/slug_validator_test.rb
436
396
  homepage: https://github.com/alphagov/govuk_content_models
437
397
  licenses: []
438
398
  metadata: {}
@@ -457,44 +417,4 @@ rubygems_version: 2.2.5
457
417
  signing_key:
458
418
  specification_version: 4
459
419
  summary: Shared models for Panopticon and Publisher, as a Rails Engine
460
- test_files:
461
- - test/fixtures/uploads/image.jpg
462
- - test/models/action_test.rb
463
- - test/models/artefact_action_test.rb
464
- - test/models/artefact_external_link_test.rb
465
- - test/models/artefact_test.rb
466
- - test/models/business_support/business_size_test.rb
467
- - test/models/business_support/business_type_test.rb
468
- - test/models/business_support/location_test.rb
469
- - test/models/business_support/purpose_test.rb
470
- - test/models/business_support/sector_test.rb
471
- - test/models/business_support/stage_test.rb
472
- - test/models/business_support/support_type_test.rb
473
- - test/models/business_support_edition_test.rb
474
- - test/models/campaign_edition_test.rb
475
- - test/models/completed_transaction_edition_test.rb
476
- - test/models/downtime_test.rb
477
- - test/models/edition_scheduled_for_publishing_test.rb
478
- - test/models/edition_test.rb
479
- - test/models/help_page_edition_test.rb
480
- - test/models/licence_edition_test.rb
481
- - test/models/local_service_test.rb
482
- - test/models/local_transaction_edition_test.rb
483
- - test/models/overview_dashboard_test.rb
484
- - test/models/parted_test.rb
485
- - test/models/prerendered_entity_tests.rb
486
- - test/models/rendered_manual_test.rb
487
- - test/models/simple_smart_answer_edition_test.rb
488
- - test/models/simple_smart_answer_node_test.rb
489
- - test/models/simple_smart_answer_option_test.rb
490
- - test/models/time_zone_test.rb
491
- - test/models/transaction_edition_test.rb
492
- - test/models/travel_advice_edition_test.rb
493
- - test/models/user_test.rb
494
- - test/models/video_edition_test.rb
495
- - test/models/workflow_test.rb
496
- - test/test_helper.rb
497
- - test/traits/attachable_test.rb
498
- - test/validators/link_validator_test.rb
499
- - test/validators/safe_html_validator_test.rb
500
- - test/validators/slug_validator_test.rb
420
+ test_files: []
Binary file
@@ -1,13 +0,0 @@
1
- require "test_helper"
2
-
3
- class ActionTest < ActiveSupport::TestCase
4
- test "#to_s should return the humanized version of the request type" do
5
- assert_equal "Approve review", Action.new(request_type: 'approve_review').to_s
6
- end
7
-
8
- test "#to_s should contain the scheduled time when request type is SCHEDULE_FOR_PUBLISHING" do
9
- assert_equal "Scheduled for publishing on 12/12/2014 00:00",
10
- Action.new(:request_type => 'schedule_for_publishing',
11
- :request_details => { 'scheduled_time' => Date.parse('12/12/2014').to_time.utc }).to_s
12
- end
13
- end
@@ -1,130 +0,0 @@
1
- require "test_helper"
2
-
3
- def merge_attributes(original, *update_hashes)
4
- # Merge multiple attribute hashes: this also differs from Hash#merge in that
5
- # it converts symbolic keys to strings
6
- if update_hashes.empty?
7
- return original
8
- else
9
- first_update, *other_updates = update_hashes
10
- updated = first_update.reduce(original) do |old, pair|
11
- key, value = pair
12
- old.merge(key.to_s => value)
13
- end
14
- merge_attributes(updated, *other_updates)
15
- end
16
- end
17
-
18
- class ArtefactActionTest < ActiveSupport::TestCase
19
-
20
- DEFAULTS = {
21
- "active" => false,
22
- "need_ids" => [],
23
- "state" => "draft",
24
- "paths" => [],
25
- "prefixes" => [],
26
- "language" => "en",
27
- }
28
-
29
- def base_fields
30
- {
31
- slug: "an-artefact",
32
- name: "An artefact",
33
- kind: "answer",
34
- owning_app: "publisher"
35
- }
36
- end
37
-
38
- def setup
39
- @artefact = Artefact.create!(base_fields)
40
- end
41
-
42
- test "a new artefact should have a create action" do
43
- @artefact.reload
44
-
45
- assert_equal 1, @artefact.actions.size
46
- action = @artefact.actions.first
47
- assert_equal "create", action[:action_type]
48
- assert_equal merge_attributes(DEFAULTS, base_fields), action.snapshot
49
- assert action.created_at, "Action has no creation timestamp"
50
- end
51
-
52
- test "an updated artefact should have two actions" do
53
- @artefact.description = "An artefact of shining wonderment."
54
- @artefact.save!
55
- @artefact.reload
56
-
57
- assert_equal 2, @artefact.actions.size
58
- assert_equal ["create", "update"], @artefact.actions.map(&:action_type)
59
- create_snapshot = merge_attributes(DEFAULTS, base_fields)
60
- update_snapshot = create_snapshot.merge("description" => @artefact.description)
61
- assert_equal create_snapshot, @artefact.actions[0].snapshot
62
- assert_equal update_snapshot, @artefact.actions[1].snapshot
63
- @artefact.actions.each do |action|
64
- assert action.created_at, "Action has no creation timestamp"
65
- end
66
- end
67
-
68
- test "saving with no tracked changes will not create a new snapshot" do
69
- @artefact.updated_at = Time.zone.now + 5.minutes
70
- @artefact.save!
71
- assert_equal 1, @artefact.actions.size
72
- end
73
-
74
- test "updating attributes as a user should record a user action" do
75
- user = FactoryGirl.create :user
76
- updates = {description: "Shiny shiny description"}
77
- @artefact.update_attributes_as user, updates
78
- @artefact.reload
79
-
80
- assert_equal "Shiny shiny description", @artefact.description
81
- assert_equal 2, @artefact.actions.size
82
- assert_equal ["create", "update"], @artefact.actions.map(&:action_type)
83
- assert_equal user, @artefact.actions.last.user
84
- assert_equal(
85
- merge_attributes(DEFAULTS, base_fields, updates),
86
- @artefact.actions.last.snapshot
87
- )
88
- end
89
-
90
- test "saving a task should record the task action" do
91
- @artefact.description = "Updated automatically"
92
- @artefact.save_as_task!('TaggingUpdater')
93
- @artefact.reload
94
-
95
- assert_equal 2, @artefact.actions.size
96
- assert_equal ["create", "update"], @artefact.actions.map(&:action_type)
97
-
98
- assert_equal 'TaggingUpdater', @artefact.actions.last.task_performed_by
99
- assert_equal nil, @artefact.actions.last.user
100
- end
101
-
102
- test "saving as a user should record a user action" do
103
- user = FactoryGirl.create :user
104
- updates = {description: "Shiny shiny description"}
105
- @artefact.description = updates[:description]
106
- @artefact.save_as user
107
- @artefact.reload
108
-
109
- assert_equal "Shiny shiny description", @artefact.description
110
- assert_equal 2, @artefact.actions.size
111
- assert_equal ["create", "update"], @artefact.actions.map(&:action_type)
112
- assert_equal user, @artefact.actions.last.user
113
- assert_equal(
114
- merge_attributes(DEFAULTS, base_fields, updates),
115
- @artefact.actions.last.snapshot
116
- )
117
- end
118
-
119
- test "saving as a user with an action type" do
120
- user = FactoryGirl.create :user
121
- updates = {description: "Shiny shiny description"}
122
- @artefact.description = updates[:description]
123
- @artefact.save_as user, action_type: "awesome"
124
- @artefact.reload
125
-
126
- assert_equal user, @artefact.actions.last.user
127
- assert_equal "awesome", @artefact.actions.last.action_type
128
- end
129
-
130
- end
@@ -1,32 +0,0 @@
1
- require "test_helper"
2
-
3
- class ArtefactExternalLinkTest < ActiveSupport::TestCase
4
- context "validating a link" do
5
- should "not be valid without a title or URL" do
6
- refute ArtefactExternalLink.new.valid?
7
- end
8
-
9
- should "not be valid with URL missing" do
10
- refute ArtefactExternalLink.new(:title => "Foo").valid?
11
- end
12
-
13
- should "not be valid with title missing" do
14
- refute ArtefactExternalLink.new(:url => "http://bar.com").valid?
15
- end
16
-
17
- should "be valid with both fields supplied" do
18
- link = ArtefactExternalLink.new(:title => "Foo", :url => "http://bar.com")
19
- assert link.valid?
20
- end
21
-
22
- should "only be valid if the URL is valid" do
23
- link = ArtefactExternalLink.new(:title => "Foo", :url => "notreal://foo.com")
24
- refute link.valid?
25
- end
26
-
27
- should "be valid with an https URL" do
28
- link = ArtefactExternalLink.new(:title => "Foo", :url => "https://bar.com")
29
- assert link.valid?
30
- end
31
- end
32
- end
@@ -1,482 +0,0 @@
1
- require "test_helper"
2
-
3
- class ArtefactTest < ActiveSupport::TestCase
4
- context "validating slug" do
5
- should "allow nice clean slugs" do
6
- a = FactoryGirl.build(:artefact, slug: "its-a-nice-day")
7
- assert a.valid?
8
- end
9
-
10
- should "not allow apostrophes in slugs" do
11
- a = FactoryGirl.build(:artefact, slug: "it's-a-nice-day")
12
- refute a.valid?
13
- assert a.errors[:slug].any?
14
- end
15
-
16
- should "not allow spaces in slugs" do
17
- a = FactoryGirl.build(:artefact, slug: "it is-a-nice-day")
18
- refute a.valid?
19
- assert a.errors[:slug].any?
20
- end
21
-
22
- should "allow slashes in slugs when the namespace is 'done'" do
23
- a = FactoryGirl.build(:artefact, slug: "done/its-a-nice-day")
24
- assert a.valid?
25
- end
26
-
27
- should "not allow slashes in slugs when the namespace is not 'done'" do
28
- a = FactoryGirl.build(:artefact, slug: "something-else/its-a-nice-day")
29
- refute a.valid?
30
- assert a.errors[:slug].any?
31
- end
32
-
33
- should "allow travel-advice to have a slug prefixed with 'foreign-travel-advice/'" do
34
- a = FactoryGirl.build(:artefact, slug: "foreign-travel-advice/aruba", kind: "travel-advice")
35
- assert a.valid?
36
- end
37
-
38
- should "not allow multiple slashes in travel-advice artefacts" do
39
- a = FactoryGirl.build(:artefact, slug: "foreign-travel-advice/aruba/foo", kind: "travel-advice")
40
- refute a.valid?
41
- assert a.errors[:slug].any?
42
- end
43
-
44
- should "not allow a foreign-travel-advice prefix for non-travel-advice artefacts" do
45
- a = FactoryGirl.build(:artefact, slug: "foreign-travel-advice/aruba", kind: "answer")
46
- refute a.valid?
47
- assert a.errors[:slug].any?
48
- end
49
-
50
- should "allow a government prefix for Inside Government artefacts" do
51
- a = FactoryGirl.build(:artefact, slug: "government/slug", kind: "case_study")
52
- assert a.valid?
53
- end
54
-
55
- should "allow a government prefix and multiple path parts for Inside Government artefacts" do
56
- a = FactoryGirl.build(:artefact, slug: "government/something/somewhere/somehow/slug", kind: "case_study")
57
- assert a.valid?
58
- end
59
-
60
- should "not allow a government prefix with invalid path parts" do
61
- a = FactoryGirl.build(:artefact, slug: "government/SomeThing/some.where/somehow/slug", kind: "case_study")
62
- refute a.valid?
63
- end
64
-
65
- should "require a government prefix for Inside Government artefacts" do
66
- a = FactoryGirl.build(:artefact, slug: "slug", kind: "case_study")
67
- refute a.valid?
68
- end
69
-
70
- should "not require a government prefix for Detailed Guides" do
71
- a = FactoryGirl.build(:artefact, slug: "slug", kind: "detailed_guide")
72
- assert a.valid?
73
- end
74
-
75
- context "help page special case" do
76
- should "allow a help page to have a help/ prefix on the slug" do
77
- a = FactoryGirl.build(:artefact, :slug => "help/foo", :kind => "help_page")
78
- assert a.valid?
79
- end
80
-
81
- should "require a help page to have a help/ prefix on the slug" do
82
- a = FactoryGirl.build(:artefact, :slug => "foo", :kind => "help_page")
83
- refute a.valid?
84
- assert_equal 1, a.errors[:slug].count
85
- end
86
-
87
- should "not allow other kinds to have a help/ prefix" do
88
- a = FactoryGirl.build(:artefact, :slug => "help/foo", :kind => "answer")
89
- refute a.valid?
90
- assert_equal 1, a.errors[:slug].count
91
- end
92
- end
93
- end
94
-
95
- context "#need_ids" do
96
- should "be empty by default" do
97
- assert_empty FactoryGirl.build(:artefact).need_ids
98
- end
99
-
100
- should "do validations if nil" do
101
- artefact = FactoryGirl.create(:artefact, need_ids: ["100001"])
102
- artefact.need_ids = nil
103
-
104
- assert_nothing_raised { artefact.valid? }
105
- end
106
-
107
- should "filter out empty strings" do
108
- artefact = FactoryGirl.create(:artefact, need_ids: ["", "100002"])
109
- assert_equal ["100002"], artefact.reload.need_ids
110
- end
111
-
112
- should "store multiple needs related to an artefact" do
113
- artefact = FactoryGirl.create(:artefact, need_ids: ["100001", "100002"])
114
- assert_equal ["100001", "100002"], artefact.reload.need_ids
115
- end
116
-
117
- should "be six-digit integers" do
118
- artefact = FactoryGirl.build(:artefact, need_ids: ["B1231"])
119
-
120
- refute artefact.valid?
121
- assert_includes artefact.errors[:need_ids], "must be six-digit integer strings"
122
- end
123
-
124
- should "not validate need ids that were migrated from the singular need_id field" do
125
- artefact = FactoryGirl.create(:artefact)
126
- # simulate what happened during migration
127
- artefact.set(need_ids: ['As an employer
128
- I need to know which type of DBS check an employee needs
129
- so that I can apply for the correct one'])
130
-
131
- artefact.need_ids << "100045"
132
-
133
- assert artefact.valid?
134
- end
135
-
136
- context "for backwards compatibility" do
137
- setup do
138
- @artefact = FactoryGirl.create(:artefact)
139
- end
140
-
141
- should "append to need_ids when need_id is assigned" do
142
- @artefact.need_id = "100045"
143
-
144
- assert_equal "100045", @artefact.need_id
145
- assert_includes @artefact.need_ids, "100045"
146
- end
147
-
148
- should "append to existing need_ids when need_id is assigned" do
149
- @artefact.set(need_ids: ["100044"])
150
- @artefact.set(need_id: "100044")
151
-
152
- @artefact.need_id = "100045"
153
-
154
- assert_equal "100045", @artefact.need_id
155
- assert_equal %w(100044 100045), @artefact.need_ids
156
- end
157
-
158
- # this should only matter till the time we have both fields
159
- # need_id and need_ids. can delete this test once we unset need_id.
160
- should "keep need_ids unchanged when need_id is removed" do
161
- @artefact.set(need_ids: %w(100044 100045))
162
- @artefact.set(need_id: "100044")
163
-
164
- @artefact.need_id = nil
165
-
166
- assert_equal nil, @artefact.need_id
167
- assert_equal %w(100044 100045), @artefact.need_ids
168
- end
169
- end
170
- end
171
-
172
- context "validating paths and prefixes" do
173
- setup do
174
- @a = FactoryGirl.build(:artefact)
175
- end
176
-
177
- should "be valid when empty" do
178
- @a.paths = []
179
- @a.prefixes = []
180
- assert @a.valid?
181
-
182
- @a.paths = nil
183
- @a.prefixes = nil
184
- assert @a.valid?
185
- end
186
-
187
- should "be valid when set to array of absolute URL paths" do
188
- @a.paths = ["/foo.json"]
189
- @a.prefixes = ["/foo", "/bar"]
190
- assert @a.valid?
191
- end
192
-
193
- should "be invalid if an entry is not a valid absolute URL path" do
194
- [
195
- "not a URL path",
196
- "http://foo.example.com/bar",
197
- "bar/baz",
198
- "/foo/bar?baz=qux",
199
- ].each do |path|
200
- @a.paths = ["/foo.json", path]
201
- @a.prefixes = ["/foo", path]
202
- refute @a.valid?
203
- assert_equal 1, @a.errors[:paths].count
204
- assert_equal 1, @a.errors[:prefixes].count
205
- end
206
- end
207
-
208
- should "be invalid with consecutive or trailing slashes" do
209
- [
210
- "/foo//bar",
211
- "/foo/bar///",
212
- "//bar/baz",
213
- "//",
214
- "/foo/bar/",
215
- ].each do |path|
216
- @a.paths = ["/foo.json", path]
217
- @a.prefixes = ["/foo", path]
218
- refute @a.valid?
219
- assert_equal 1, @a.errors[:paths].count
220
- assert_equal 1, @a.errors[:prefixes].count
221
- end
222
- end
223
-
224
- should "skip validating these if they haven't changed" do
225
- # This validation can be expensive, so skip it where unnecessary.
226
- @a.paths = ["foo"]
227
- @a.prefixes = ["bar"]
228
- @a.save :validate => false
229
-
230
- assert @a.valid?
231
- end
232
- end
233
-
234
- should "validate redirect_url" do
235
- artefact = FactoryGirl.create(:artefact)
236
-
237
- artefact.redirect_url = "foobar"
238
- refute artefact.valid?
239
-
240
- artefact.redirect_url = "/foobar"
241
- assert artefact.valid?
242
-
243
- artefact.redirect_url = "/foobar?an=argument"
244
- assert artefact.valid?
245
-
246
- artefact.redirect_url = "/foobar#chapter"
247
- assert artefact.valid?
248
-
249
- artefact.redirect_url = "http://foo.bar/"
250
- refute artefact.valid?
251
-
252
- [
253
- "\jkhsdfgjkhdjskfgh//fdf#th",
254
- "not a URL path",
255
- "bar/baz",
256
- "/foo//bar",
257
- ].each do |invalid_path|
258
- artefact.redirect_url = invalid_path
259
- refute artefact.valid?
260
- end
261
- end
262
-
263
- test "should translate kind into internally normalised form" do
264
- a = Artefact.new(kind: "benefit / scheme")
265
- a.normalise
266
- assert_equal "programme", a.kind
267
- end
268
-
269
- test "should not translate unknown kinds" do
270
- a = Artefact.new(kind: "other")
271
- a.normalise
272
- assert_equal "other", a.kind
273
- end
274
-
275
- test "should raise a not found exception if the slug doesn't match" do
276
- assert_raise Mongoid::Errors::DocumentNotFound do
277
- Artefact.from_param("something-fake")
278
- end
279
- end
280
-
281
- should "update the edition's slug when a draft artefact is saved" do
282
- artefact = FactoryGirl.create(:draft_artefact)
283
- edition = FactoryGirl.create(:answer_edition, panopticon_id: artefact.id)
284
-
285
- artefact.slug = "something-something-draft"
286
- artefact.save!
287
-
288
- edition.reload
289
- assert_equal artefact.slug, edition.slug
290
- end
291
-
292
- should "not touch the updated_at field on the editions when the artefact is saved but the slug hasn't changed" do
293
- artefact = FactoryGirl.create(:draft_artefact)
294
- edition = FactoryGirl.create(:answer_edition, panopticon_id: artefact.id)
295
- old_updated_at = 2.days.ago.to_time
296
- edition.set(updated_at: old_updated_at)
297
-
298
- artefact.language = "cy"
299
- artefact.save!
300
-
301
- edition.reload
302
- assert_equal old_updated_at.utc.iso8601, edition.updated_at.utc.iso8601
303
- end
304
-
305
- should "not update the edition's slug when a live artefact is saved" do
306
- artefact = FactoryGirl.create(:live_artefact, slug: "something-something-live")
307
- edition = FactoryGirl.create(:answer_edition, panopticon_id: artefact.id, slug: "something-else")
308
-
309
- artefact.save!
310
-
311
- edition.reload
312
- assert_equal "something-else", edition.slug
313
- end
314
-
315
- should "not update the edition's slug when an archived artefact is saved" do
316
- artefact = FactoryGirl.create(:live_artefact, slug: "something-something-live")
317
- edition = FactoryGirl.create(:answer_edition, panopticon_id: artefact.id, slug: "something-else")
318
-
319
- artefact.state = 'archived'
320
- artefact.save!
321
-
322
- edition.reload
323
- assert_equal "something-else", edition.slug
324
- end
325
-
326
- test "should not let you edit the slug if the artefact is live" do
327
- artefact = FactoryGirl.create(:artefact,
328
- slug: "too-late-to-edit",
329
- kind: "answer",
330
- name: "Foo bar",
331
- owning_app: "publisher",
332
- state: "live"
333
- )
334
-
335
- artefact.slug = "belated-correction"
336
- refute artefact.save
337
-
338
- assert_equal "too-late-to-edit", artefact.reload.slug
339
- end
340
-
341
- # should continue to work in the way it has been:
342
- # i.e. you can edit everything but the name/title for published content in panop
343
- test "on save title should not be applied to already published content" do
344
- artefact = FactoryGirl.create(:artefact,
345
- slug: "foo-bar",
346
- kind: "answer",
347
- name: "Foo bar",
348
- owning_app: "publisher",
349
- )
350
-
351
- user1 = FactoryGirl.create(:user)
352
- edition = AnswerEdition.find_or_create_from_panopticon_data(artefact.id, user1)
353
- edition.state = "published"
354
- edition.save!
355
-
356
- assert_equal artefact.name, edition.title
357
-
358
- artefact.name = "Babar"
359
- artefact.save
360
-
361
- edition.reload
362
- assert_not_equal artefact.name, edition.title
363
- end
364
-
365
- test "should indicate when any editions have been published for this artefact" do
366
- artefact = FactoryGirl.create(:artefact,
367
- slug: "foo-bar",
368
- kind: "answer",
369
- name: "Foo bar",
370
- owning_app: "publisher",
371
- )
372
- user1 = FactoryGirl.create(:user)
373
- edition = AnswerEdition.find_or_create_from_panopticon_data(artefact.id, user1)
374
-
375
- refute artefact.any_editions_published?
376
-
377
- edition.state = "published"
378
- edition.save!
379
-
380
- assert artefact.any_editions_published?
381
- end
382
-
383
- test "should have 'video' as a supported FORMAT" do
384
- assert_includes Artefact::FORMATS, "video"
385
- end
386
-
387
- test "should find the default owning_app for a format" do
388
- assert_equal "publisher", Artefact.default_app_for_format("guide")
389
- end
390
-
391
- test "should allow creation of artefacts with 'video' as the kind" do
392
- artefact = Artefact.create!(slug: "omlette-du-fromage", name: "Omlette du fromage", kind: "video", owning_app: "Dexter's Lab")
393
-
394
- refute artefact.nil?
395
- assert_equal "video", artefact.kind
396
- end
397
-
398
- test "should archive all editions when archived" do
399
- artefact = FactoryGirl.create(:artefact, state: "live")
400
- editions = ["draft", "ready", "published", "archived"].map { |state|
401
- FactoryGirl.create(:programme_edition, panopticon_id: artefact.id, state: state)
402
- }
403
- user1 = FactoryGirl.create(:user)
404
-
405
- artefact.update_attributes_as(user1, state: "archived")
406
- artefact.save!
407
-
408
- editions.each(&:reload)
409
- editions.each do |edition|
410
- assert_equal "archived", edition.state
411
- end
412
- # remove the previously already archived edition, as no note will have been added
413
- editions.pop
414
- editions.each do |edition|
415
- assert_equal "Artefact has been archived. Archiving this edition.", edition.actions.first.comment
416
- end
417
- end
418
-
419
- test "should not run validations on editions when archiving" do
420
- artefact = FactoryGirl.create(:artefact, state: "live")
421
- edition = FactoryGirl.create(:help_page_edition, panopticon_id: artefact.id, state: 'published')
422
- user1 = FactoryGirl.create(:user)
423
-
424
- # Make the edition invalid, check that it persisted the invalid state
425
- edition.update_attribute(:title, nil)
426
- assert_equal(nil, edition.reload.title)
427
-
428
- artefact.update_attributes_as(user1, state: "archived")
429
- artefact.save!
430
-
431
- assert_equal("archived", edition.reload.state)
432
- end
433
-
434
- test "should restrict what attributes can be updated on an edition that has an archived artefact" do
435
- artefact = FactoryGirl.create(:artefact, state: "live")
436
- edition = FactoryGirl.create(:programme_edition, panopticon_id: artefact.id, state: "published")
437
- artefact.state = "archived"
438
- artefact.save
439
- assert_raise RuntimeError do
440
- edition.update_attributes({state: "archived", title: "Shabba", slug: "do-not-allow"})
441
- end
442
- end
443
-
444
- should "not remove double dashes in a Detailed Guide slug" do
445
- a = FactoryGirl.create(:artefact, slug: "duplicate-slug--1", kind: "detailed_guide")
446
- a.reload
447
-
448
- assert_equal "duplicate-slug--1", a.slug
449
- end
450
-
451
- context "artefact language" do
452
- should "return english by default" do
453
- a = FactoryGirl.create(:artefact)
454
-
455
- assert_equal 'en', a.language
456
- end
457
-
458
- should "accept welsh language" do
459
- a = FactoryGirl.build(:artefact)
460
- a.language = 'cy'
461
- a.save
462
-
463
- a = Artefact.first
464
- assert_equal 'cy', a.language
465
- end
466
-
467
- should "reject a language which is not english or welsh" do
468
- a = FactoryGirl.build(:artefact)
469
- a.language = 'pirate'
470
-
471
- assert ! a.valid?
472
- end
473
- end
474
-
475
- should "have an archived? helper method" do
476
- published_artefact = FactoryGirl.create(:artefact, :slug => "scooby", :state => "live")
477
- archived_artefact = FactoryGirl.create(:artefact, :slug => "doo", :state => "archived")
478
-
479
- refute published_artefact.archived?
480
- assert archived_artefact.archived?
481
- end
482
- end