schedular 0.1.13 → 0.1.14
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/schedular/time.rb +10 -2
- data/test/test_event.rb +0 -4
- data/test/test_time.rb +24 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
data/lib/schedular/time.rb
CHANGED
@@ -10,15 +10,23 @@ module Schedular
|
|
10
10
|
named_scope :joins_events, :joins => :events
|
11
11
|
named_scope :include_events, :include => :events
|
12
12
|
named_scope :order_by_value, :order => 'value asc'
|
13
|
-
|
13
|
+
|
14
|
+
named_scope :by_event, lambda { |event|
|
15
|
+
{ :conditions => {:'schedular_events.id' => event}}
|
16
|
+
}
|
17
|
+
|
14
18
|
named_scope :by_time_or_period, lambda{ |time|
|
15
19
|
time = Range === time || DateTime === time ? time : (time..time+1)
|
16
20
|
{ :conditions => {:value => time} }
|
17
21
|
}
|
18
22
|
|
19
23
|
named_scope :order_by_closest_to, lambda { |date|
|
20
|
-
{:
|
24
|
+
{:order => %{ABS(strftime('%s', "#{date.to_formatted_s(:db)}") - strftime('%s', value)) asc} }
|
21
25
|
}
|
26
|
+
|
27
|
+
# named_scope :order_by_following_closest_to, lambda { |date|
|
28
|
+
# {:order => %{(strftime('%s', "#{date.to_formatted_s(:db)}") - strftime('%s', value)) asc} }
|
29
|
+
# }
|
22
30
|
|
23
31
|
named_scope :all_day, lambda{ |bool| {:conditions => {'all_day' => (bool.nil? ? true : bool)} }}
|
24
32
|
|
data/test/test_event.rb
CHANGED
@@ -100,10 +100,6 @@ class Schedular::EventTest < Test::Unit::TestCase
|
|
100
100
|
should 'find by params with no year' do
|
101
101
|
assert_equal Schedular::Event.find(:all), Schedular::Event.by_params(:year => nil)
|
102
102
|
end
|
103
|
-
|
104
|
-
should 'find closest prior date' do
|
105
|
-
assert_equal Schedular::Time.by_time_or_period(Date.civil(2010, 1, -1)), Schedular::Event.closest_dates(Date.civil(2010, 3), 1)
|
106
|
-
end
|
107
103
|
end
|
108
104
|
|
109
105
|
should 'allways order times by value' do
|
data/test/test_time.rb
CHANGED
@@ -71,10 +71,32 @@ class Schedular::TimeTest < Test::Unit::TestCase
|
|
71
71
|
day = Date.civil(2010, 3, 2)
|
72
72
|
assert_equal Schedular::Time.by_time_or_period(day..day + 1), Schedular::Time.by_params(:year => '2010', :month => '3', :day => '2')
|
73
73
|
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'scopes' do
|
77
|
+
setup do
|
78
|
+
Schedular::Event.destroy_all
|
79
|
+
@jan1_10am = Schedular::Time.create! :value => DateTime.civil(2010, 1, 1, 10), :duration => 60, :all_day => false
|
80
|
+
@jan1 = Schedular::Time.create! :value => DateTime.civil(2010, 1, 1), :all_day => true
|
81
|
+
@jan3 = Schedular::Time.create! :value => DateTime.civil(2010, 1, 3), :all_day => true
|
82
|
+
@jan3_10am = Schedular::Time.create! :value => DateTime.civil(2010, 1, 3, 10), :duration => 60, :all_day => false
|
83
|
+
end
|
74
84
|
|
75
|
-
should '
|
76
|
-
assert_equal
|
85
|
+
should 'order by closest to' do
|
86
|
+
assert_equal [@jan1_10am, @jan1, @jan3, @jan3_10am], Schedular::Time.order_by_closest_to(DateTime.civil(2010, 1, 2))
|
77
87
|
end
|
88
|
+
|
89
|
+
should 'find by event' do
|
90
|
+
event = Schedular::Event.create! :name => 'evento', :dates => '1 de diciembre del 2009'
|
91
|
+
event.times = [@jan1]
|
92
|
+
assert_equal [@jan1], event.times
|
93
|
+
assert_equal [@jan1], Schedular::Time.joins_events.by_event(event)
|
94
|
+
assert_equal [@jan1], Schedular::Time.joins_events.by_event(event.id)
|
95
|
+
end
|
96
|
+
|
97
|
+
# should 'order by following closest to' do
|
98
|
+
# assert_equal [@jan3, @jan3_10am, @jan1_10am, @jan1], Schedular::Time.order_by_following_closest_to(DateTime.civil(2010, 1, 2))
|
99
|
+
# end
|
78
100
|
end
|
79
101
|
|
80
102
|
should 'allways order by value' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schedular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 14
|
10
|
+
version: 0.1.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Macario Ortega
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-05 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|