table_builder 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/table_builder/calendar_helper.rb +8 -3
- data/test/calendar_helper_test.rb +19 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -68,10 +68,15 @@ module CalendarHelper
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def objects_for_days objects
|
71
|
-
|
72
|
-
|
73
|
-
[
|
71
|
+
grouped = {}
|
72
|
+
objects.each do |obj|
|
73
|
+
[*yield(obj)].each do |val|
|
74
|
+
key = val.strftime("%Y-%m-%d")
|
75
|
+
grouped.has_key?(key) ? grouped[key] << obj : grouped[key] = [obj]
|
76
|
+
end
|
74
77
|
end
|
78
|
+
|
79
|
+
each_day { |day| [day, grouped[day.strftime("%Y-%m-%d")] || []] }
|
75
80
|
end
|
76
81
|
|
77
82
|
def days
|
@@ -8,6 +8,10 @@ class CalendarHelperTest < ActionView::TestCase
|
|
8
8
|
Event.new(3, 'Jimmy Page', DateTime.civil(2008, 12, 26, 1)), # In case is an hour of that day
|
9
9
|
Event.new(4, 'Robert Plant', Date.civil(2008, 12, 26))
|
10
10
|
]
|
11
|
+
@events2 = [
|
12
|
+
Event.new(3, 'Jimmy Page', [DateTime.civil(2008, 12, 26, 1), DateTime.civil(2008, 12, 27, 1)]), # In case is an hour of that day
|
13
|
+
Event.new(4, 'Robert Plant', Date.civil(2008, 12, 26))
|
14
|
+
]
|
11
15
|
end
|
12
16
|
|
13
17
|
should 'raise error if called without array' do
|
@@ -22,13 +26,27 @@ class CalendarHelperTest < ActionView::TestCase
|
|
22
26
|
end
|
23
27
|
|
24
28
|
should 'return objects_for_days with days and events' do
|
25
|
-
calendar = CalendarHelper::Calendar.new :year=> 2008, :month => 12
|
29
|
+
calendar = CalendarHelper::Calendar.new :year => 2008, :month => 12
|
26
30
|
objects_for_days = (Date.civil(2008, 11, 30)..Date.civil(2009, 1, 3)).map do |day|
|
27
31
|
[day, Date.civil(2008, 12, 26) == day ? @events : []]
|
28
32
|
end
|
29
33
|
assert_equal objects_for_days, calendar.objects_for_days(@events, &:date)
|
30
34
|
end
|
31
35
|
|
36
|
+
should 'return objects_for_days with days and events when event has multiple dates' do
|
37
|
+
calendar = CalendarHelper::Calendar.new :year => 2008, :month => 12
|
38
|
+
objects_for_days = (Date.civil(2008, 11, 30)..Date.civil(2009, 1, 3)).map do |day|
|
39
|
+
object =
|
40
|
+
case day
|
41
|
+
when DateTime.civil(2008, 12, 26, 1) then @events2
|
42
|
+
when DateTime.civil(2008, 12, 27, 1) then [@events2.first]
|
43
|
+
else [] end
|
44
|
+
[day, object]
|
45
|
+
end
|
46
|
+
assert_equal objects_for_days, calendar.objects_for_days(@events2, &:date)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
32
50
|
should 'return objects_for_days with days accepting a block' do
|
33
51
|
calendar = CalendarHelper::Calendar.new :year=> 2008, :month => 12
|
34
52
|
objects_for_days = (Date.civil(2008, 11, 30)..Date.civil(2009, 1, 3)).map do |day|
|