hiccup 0.0.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ require "rubygems"
2
+ require "rails"
3
+ require "rails/test_help"
4
+ require "active_support/core_ext"
5
+ require "turn"
6
+ require "hiccup/schedule"
@@ -0,0 +1,81 @@
1
+ require "test_helper"
2
+
3
+
4
+ class ValidatableTest < ActiveSupport::TestCase
5
+ include Hiccup
6
+
7
+
8
+
9
+ def test_invalid_recurrence
10
+ # Test nil weekly recurrence
11
+ r = Schedule.new(:kind => :weekly)
12
+ assert !r.valid?, "Recurrence should be invalid: pattern is empty"
13
+ assert r.errors[:pattern].any?, "pattern should be invalid if empty and kind is 'weekly'"
14
+
15
+ # Test nil monthly recurrence
16
+ r = Schedule.new(:kind => :monthly)
17
+ assert !r.valid?, "Recurrence should be invalid: pattern is empty"
18
+ assert r.errors[:pattern].any?, "pattern should be invalid if empty and kind is 'monthly'"
19
+
20
+ # Test invalid monthly recurrence
21
+ r = Schedule.new(:kind => :monthly, :pattern => [[2, "holiday"]])
22
+ assert !r.valid?, "Recurrence should be invalid: pattern is invalid"
23
+ assert r.errors[:pattern].any?, "pattern should be invalid: 'holiday' is not a valid MonthlyOccurrenceType"
24
+ end
25
+
26
+
27
+
28
+ def test_temporal_paradoxes
29
+ recurrence = Schedule.new({
30
+ :kind => :annually,
31
+ :ends => true,
32
+ :start_date => Date.today,
33
+ :end_date => 5.years.since(Date.today).to_date
34
+ })
35
+ assert_valid(recurrence)
36
+ recurrence = Schedule.new({
37
+ :kind => :annually,
38
+ :ends => true,
39
+ :start_date => Date.today,
40
+ :end_date => -5.years.since(Date.today).to_date
41
+ })
42
+ assert !recurrence.valid?, "Recurrence should be invalid: its recurrence ends before it starts"
43
+ end
44
+
45
+
46
+
47
+ def test_valid_weekly_recurrence
48
+ recurrence = Schedule.new(:kind => :weekly, :pattern => %w[Tuesday])
49
+ assert_valid(recurrence)
50
+ end
51
+
52
+
53
+
54
+ def test_valid_monthly_recurrence
55
+ recurrence = Schedule.new(:kind => :monthly, :pattern => [2])
56
+ assert_valid(recurrence)
57
+
58
+ recurrence = Schedule.new(:kind => :monthly, :pattern => [[2, "Thursday"]])
59
+ assert_valid(recurrence)
60
+ end
61
+
62
+
63
+
64
+ def test_valid_annual_recurrence
65
+ recurrence = Schedule.new(:kind => :annually)
66
+ assert_valid(recurrence)
67
+ end
68
+
69
+
70
+
71
+ private
72
+
73
+
74
+
75
+ def assert_valid(record)
76
+ assert record.valid?, record.errors.inspect
77
+ end
78
+
79
+
80
+
81
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hiccup
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bob Lail
@@ -10,10 +10,53 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-24 00:00:00 -05:00
13
+ date: 2011-08-25 00:00:00 -05:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: ri_cal
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rails
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: turn
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
17
60
  description: Recurrence features a-la-cart
18
61
  email:
19
62
  - bob.lailfamily@gmail.com
@@ -29,7 +72,22 @@ files:
29
72
  - Rakefile
30
73
  - hiccup.gemspec
31
74
  - lib/hiccup.rb
75
+ - lib/hiccup/convenience.rb
76
+ - lib/hiccup/core_ext/date.rb
77
+ - lib/hiccup/core_ext/duration.rb
78
+ - lib/hiccup/core_ext/fixnum.rb
79
+ - lib/hiccup/enumerable.rb
80
+ - lib/hiccup/humanizable.rb
81
+ - lib/hiccup/schedule.rb
82
+ - lib/hiccup/serializable/ical.rb
83
+ - lib/hiccup/serializers/ical.rb
84
+ - lib/hiccup/validatable.rb
32
85
  - lib/hiccup/version.rb
86
+ - test/enumerable_test.rb
87
+ - test/humanizable_test.rb
88
+ - test/ical_serializable_test.rb
89
+ - test/test_helper.rb
90
+ - test/validatable_test.rb
33
91
  has_rdoc: true
34
92
  homepage: http://boblail.github.com/hiccup/
35
93
  licenses: []
@@ -58,5 +116,9 @@ rubygems_version: 1.6.2
58
116
  signing_key:
59
117
  specification_version: 3
60
118
  summary: Recurrence features a-la-cart
61
- test_files: []
62
-
119
+ test_files:
120
+ - test/enumerable_test.rb
121
+ - test/humanizable_test.rb
122
+ - test/ical_serializable_test.rb
123
+ - test/test_helper.rb
124
+ - test/validatable_test.rb