govuk_content_models 28.0.1 → 28.1.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
+ ## 28.1.0
2
+
3
+ - Add a `Downtime` model to represent downtime for an artefact.
4
+
1
5
  ## 28.0.1
2
6
 
3
7
  - Skip LinkValidator for archived editions.
@@ -0,0 +1,32 @@
1
+ class Downtime
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :message, type: String
6
+ field :start_time, type: DateTime
7
+ field :end_time, type: DateTime
8
+
9
+ belongs_to :artefact
10
+
11
+ validates_presence_of :message, :start_time, :end_time, :artefact
12
+ validate :end_time_is_in_future, on: :create
13
+ validate :start_time_precedes_end_time
14
+
15
+ def self.for(artefact)
16
+ where(artefact_id: artefact.id).first
17
+ end
18
+
19
+ def publicise?
20
+ Time.zone.now.between?(start_time.to_date - 1, end_time) # starting at midnight a day before start time
21
+ end
22
+
23
+ private
24
+
25
+ def end_time_is_in_future
26
+ errors.add(:end_time, "must be in the future") if end_time && ! end_time.future?
27
+ end
28
+
29
+ def start_time_precedes_end_time
30
+ errors.add(:start_time, "must be earlier than end time") if start_time && end_time && start_time >= end_time
31
+ end
32
+ end
@@ -19,6 +19,13 @@ FactoryGirl.define do
19
19
  disabled true
20
20
  end
21
21
 
22
+ factory :downtime do
23
+ message "This service will be unavailable from 3pm to 6pm tomorrow"
24
+ start_time (Date.today + 1).to_time + (15 * 60 * 60)
25
+ end_time (Date.today + 1).to_time + (18 * 60 * 60)
26
+ artefact
27
+ end
28
+
22
29
  factory :tag do
23
30
  sequence(:tag_id) { |n| "crime-and-justice-#{n}" }
24
31
  sequence(:title) { |n| "The title #{n}" }
@@ -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 = "28.0.1"
3
+ VERSION = "28.1.0"
4
4
  end
@@ -0,0 +1,92 @@
1
+ require "test_helper"
2
+
3
+ class DowntimeTest < ActiveSupport::TestCase
4
+ context "validations" do
5
+ should "validate presence of message" do
6
+ downtime = FactoryGirl.build(:downtime, message: nil)
7
+
8
+ refute downtime.valid?
9
+ assert_includes downtime.errors[:message], "can't be blank"
10
+ end
11
+
12
+ should "validate presence of start time" do
13
+ downtime = FactoryGirl.build(:downtime, start_time: nil)
14
+
15
+ refute downtime.valid?
16
+ assert_includes downtime.errors[:start_time], "can't be blank"
17
+ end
18
+
19
+ should "validate presence of end time" do
20
+ downtime = FactoryGirl.build(:downtime, end_time: nil)
21
+
22
+ refute downtime.valid?
23
+ assert_includes downtime.errors[:end_time], "can't be blank"
24
+ end
25
+
26
+ should "validate presence of artefact" do
27
+ downtime = FactoryGirl.build(:downtime, artefact: nil)
28
+
29
+ refute downtime.valid?
30
+ assert_includes downtime.errors[:artefact], "can't be blank"
31
+ end
32
+
33
+ should "validate end time is in future" do
34
+ downtime = FactoryGirl.build(:downtime, end_time: Date.today - 1)
35
+
36
+ refute downtime.valid?
37
+ assert_includes downtime.errors[:end_time], 'must be in the future'
38
+ end
39
+
40
+ should "validate end time is in future only on create" do
41
+ downtime = FactoryGirl.create(:downtime)
42
+ downtime.assign_attributes(start_time: Date.today - 3, end_time: Date.today - 1)
43
+
44
+ assert downtime.valid?
45
+ end
46
+
47
+ should "validate start time is earlier than end time" do
48
+ downtime = FactoryGirl.build(:downtime, start_time: Date.today + 2, end_time: Date.today + 1)
49
+
50
+ refute downtime.valid?
51
+ assert_includes downtime.errors[:start_time], "must be earlier than end time"
52
+ end
53
+ end
54
+
55
+ context "for an artefact" do
56
+ should "be returned if found" do
57
+ downtime = FactoryGirl.create(:downtime)
58
+ assert_equal downtime, Downtime.for(downtime.artefact)
59
+ end
60
+
61
+ should "be nil if not found" do
62
+ assert_nil Downtime.for(FactoryGirl.build(:artefact))
63
+ end
64
+ end
65
+
66
+ context "publicising downtime" do
67
+ should "start at midnight a day before it is scheduled" do
68
+ Timecop.freeze(Date.today) do # beginnning of today
69
+ downtime = FactoryGirl.build(:downtime)
70
+
71
+ downtime.start_time = (Date.today + 1).to_time + (3 * 60 * 60) # 3am tomorrow
72
+ assert downtime.publicise?
73
+
74
+ downtime.start_time = Date.today.to_time + (21 * 60 * 60) # 9pm today
75
+ assert downtime.publicise?
76
+
77
+ downtime.start_time = Date.today + 2 # day after tomorrow
78
+ refute downtime.publicise?
79
+ end
80
+ end
81
+
82
+ should "stop after scheduled end time" do
83
+ Timecop.freeze(Time.zone.now + 10) do
84
+ downtime = FactoryGirl.build(:downtime)
85
+
86
+ downtime.end_time = Time.zone.now
87
+ refute downtime.publicise?
88
+ end
89
+ end
90
+ end
91
+
92
+ 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: 28.0.1
4
+ version: 28.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: 2015-01-07 00:00:00.000000000 Z
12
+ date: 2015-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -347,6 +347,7 @@ files:
347
347
  - app/models/campaign_edition.rb
348
348
  - app/models/completed_transaction_edition.rb
349
349
  - app/models/curated_list.rb
350
+ - app/models/downtime.rb
350
351
  - app/models/edition.rb
351
352
  - app/models/guide_edition.rb
352
353
  - app/models/help_page_edition.rb
@@ -429,6 +430,7 @@ files:
429
430
  - test/models/business_support_edition_test.rb
430
431
  - test/models/campaign_edition_test.rb
431
432
  - test/models/curated_list_test.rb
433
+ - test/models/downtime_test.rb
432
434
  - test/models/edition_scheduled_for_publishing_test.rb
433
435
  - test/models/edition_test.rb
434
436
  - test/models/help_page_edition_test.rb
@@ -475,7 +477,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
475
477
  version: '0'
476
478
  segments:
477
479
  - 0
478
- hash: 1044253096296526038
480
+ hash: 1243140103051612447
479
481
  required_rubygems_version: !ruby/object:Gem::Requirement
480
482
  none: false
481
483
  requirements:
@@ -484,7 +486,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
486
  version: '0'
485
487
  segments:
486
488
  - 0
487
- hash: 1044253096296526038
489
+ hash: 1243140103051612447
488
490
  requirements: []
489
491
  rubyforge_project:
490
492
  rubygems_version: 1.8.23
@@ -510,6 +512,7 @@ test_files:
510
512
  - test/models/business_support_edition_test.rb
511
513
  - test/models/campaign_edition_test.rb
512
514
  - test/models/curated_list_test.rb
515
+ - test/models/downtime_test.rb
513
516
  - test/models/edition_scheduled_for_publishing_test.rb
514
517
  - test/models/edition_test.rb
515
518
  - test/models/help_page_edition_test.rb