File: alarm_spec.rb

package info (click to toggle)
ruby-icalendar 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 492 kB
  • sloc: ruby: 2,868; makefile: 5
file content (113 lines) | stat: -rw-r--r-- 3,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'spec_helper'

describe Icalendar::Alarm do

  # currently no behavior in Alarm not tested other places
  describe '#valid?' do
    subject do
      described_class.new.tap do |a|
        a.trigger = Icalendar::Values::DateTime.new(Time.now.utc)
      end
    end
    context 'neither duration or repeat is set' do
      before(:each) { subject.action = 'AUDIO' }
      it { should be_valid }
    end
    context 'both duration and repeat are set' do
      before(:each) { subject.action = 'AUDIO' }
      before(:each) do
        subject.duration = 'PT15M'
        subject.repeat = 4
      end
      it { should be_valid }
    end
    context 'only duration is set' do
      before(:each) { subject.duration = 'PT15M' }
      it { should_not be_valid }
    end
    context 'only repeat is set' do
      before(:each) { subject.repeat = 4 }
      it { should_not be_valid }
    end

    context 'DISPLAY is set as default action' do
      it 'must be DISPLAY' do
        expect(subject.action).to eq 'DISPLAY'
      end
    end
    context 'display action' do
      it 'requires description' do
        expect(subject).to_not be_valid
        subject.description = 'Display Text'
        expect(subject).to be_valid
      end
    end

    context 'email action' do
      before(:each) { subject.action = 'EMAIL' }
      context 'requires subject and body' do
        before(:each) { subject.attendee = ['mailto:test@email.com'] }
        it 'requires description' do
          subject.summary = 'Email subject'
          expect(subject).to_not be_valid
          subject.description = 'Email Body'
          expect(subject).to be_valid
        end
        it 'requires summary' do
          subject.description = 'Email body'
          expect(subject).to_not be_valid
          subject.summary = 'Email subject'
          expect(subject).to be_valid
        end
      end
      context 'attendees are required' do
        before(:each) do
          subject.summary = 'subject'
          subject.description = 'body'
        end

        it 'must be present' do
          subject.attendee = nil
          expect(subject).to_not be_valid
        end

        it 'can be single' do
          subject.attendee << 'mailto:test@email.com'
          expect(subject).to be_valid
        end

        it 'can be multi' do
          subject.attendee << 'mailto:test@email.com'
          subject.attendee << 'mailto:email@test.com'
          expect(subject).to be_valid
        end
      end
    end

    context 'strict validations check parent' do
      subject do
        described_class.new.tap do |a|
          a.action = 'AUDIO'
          a.trigger = Icalendar::Values::DateTime.new(Time.now.utc)
        end
      end
      specify { expect(subject.valid? true).to be true }
      context 'with parent' do
        before(:each) { subject.parent = parent }
        context 'event' do
          let(:parent) { Icalendar::Event.new }
          specify { expect(subject.valid? true).to be true }
        end
        context 'todo' do
          let(:parent) { Icalendar::Todo.new }
          specify { expect(subject.valid? true).to be true }
        end
        context 'journal' do
          let(:parent) { Icalendar::Journal.new }
          specify { expect(subject.valid? true).to be false }
        end
      end
    end
  end

end