table_builder 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -68,10 +68,15 @@ module CalendarHelper
68
68
  end
69
69
 
70
70
  def objects_for_days objects
71
- objects = objects.group_by{ |o| yield(o).strftime "%Y-%m-%d" }
72
- each_day do |day|
73
- [day, objects[day.strftime("%Y-%m-%d")] || []]
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|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Petrik de Heus