schedular 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.7
@@ -10,6 +10,7 @@ class SchedularMigrations < ActiveRecord::Migration
10
10
  create_table :schedular_times do |t|
11
11
  t.datetime :value
12
12
  t.boolean :all_day
13
+ t.integer :duration
13
14
  t.timestamps
14
15
  end
15
16
 
@@ -8,7 +8,7 @@ module Schedular
8
8
 
9
9
  named_scope :all, {}
10
10
  named_scope :include_times, :include => :times
11
- named_scope :by_time_or_period, lambda{ |time|
11
+ named_scope :by_time_or_period, lambda { |time|
12
12
  time = Range === time || DateTime === time ? time : (time..time+1)
13
13
  {:conditions => {'schedular_times.value' => time}, :include => :times }
14
14
  }
@@ -18,9 +18,16 @@ module Schedular
18
18
 
19
19
  if parsed
20
20
  self.times = parsed.map do |time|
21
+ all_day = time.class == Date
22
+
23
+ if Range === time
24
+ duration = ((time.last.to_f - time.first.to_f) / 60).to_i
25
+ time = time.first
26
+ else
27
+ duration = nil
28
+ end
21
29
  # TODO: This method is soooo uneficient
22
- all_day = !(DateTime === time)
23
- Schedular::Time.all_day(all_day).by_time_or_period(time).first || Schedular::Time.new(:value => time, :all_day => all_day)
30
+ Schedular::Time.by_time_or_period(time).all_day(all_day).duration(duration).first || Schedular::Time.new(:value => time, :all_day => all_day, :duration => duration)
24
31
  end
25
32
  else
26
33
  self.times = []
@@ -16,6 +16,10 @@ module Schedular
16
16
 
17
17
  named_scope :all_day, lambda{ |bool| {:conditions => {'all_day' => (bool.nil? ? true : bool)} }}
18
18
 
19
+ named_scope :duration, lambda{ |duration| {:conditions => {:duration => duration}} }
20
+ named_scope :duration_less_or_equal, lambda{ |duration| {:conditions => ['duration <= ?', duration]} }
21
+ named_scope :duration_more_or_equal, lambda{ |duration| {:conditions => ['duration >= ?', duration]} }
22
+
19
23
  def self.by_params params
20
24
  return if params[:year].nil? and params[:month].nil? #TODO: By year
21
25
  day = Date.civil params[:year].to_i, params[:month].to_i, (params[:day] || 1).to_i
@@ -13,6 +13,7 @@ ActiveRecord::Schema.define :version => 1 do
13
13
  create_table :schedular_times do |t|
14
14
  t.datetime :value
15
15
  t.boolean :all_day
16
+ t.integer :duration
16
17
  end
17
18
 
18
19
  create_table :schedular_events_times, :id => false do |t|
data/test/test_event.rb CHANGED
@@ -10,7 +10,12 @@ class Schedular::EventTest < Test::Unit::TestCase
10
10
  subject { @event }
11
11
 
12
12
  should_validate_presence_of :name
13
- # should_validate_presence_of :dates
13
+
14
+ should 'accept time ranges' do
15
+ @event.dates = '1 de enero del 2010 de las 15:00 a las 16:00 y de las 17:00 a las 19:00'
16
+ assert_equal [DateTime.civil(2010, 1, 1, 15), DateTime.civil(2010, 1, 1, 17)], @event.times.map(&:value)
17
+ assert_equal [60, 120], @event.times.map(&:duration)
18
+ end
14
19
 
15
20
  should 'not accept bad date' do
16
21
  @event.dates = 'bad dates'
@@ -12,6 +12,17 @@ class PartialsTest < ActionView::TestCase
12
12
  html = <<-HTML
13
13
  <table id="events-calendar">
14
14
  <thead>
15
+ <tr class="links">
16
+ <th colspan="2">
17
+ <a href="/events/2009/12">&lt;&lt;</a>
18
+ </th>
19
+ <th colspan="3">
20
+ <a href="/events/2010/1">Ene 2010</a>
21
+ </th>
22
+ <th colspan="2">
23
+ <a href="/events/2010/2">&gt;&gt;</a>
24
+ </th>
25
+ </tr>
15
26
  <tr><th>dom</th><th>lun</th><th>mar</th><th>mie</th><th>jue</th><th>vie</th><th>sab</th></tr>
16
27
  </thead>
17
28
  <tbody>
@@ -25,13 +36,24 @@ class PartialsTest < ActionView::TestCase
25
36
  </table>
26
37
  HTML
27
38
 
28
- assert_dom_equal html, render('schedular/events/month', :events => [], :year => 2010, :month => 1)
39
+ assert_dom_equal html, render('schedular/events/calendar', :events => [], :year => 2010, :month => 1)
29
40
  end
30
41
 
31
42
  should 'render day numbers with events' do
32
43
  html = <<-HTML
33
44
  <table id="events-calendar">
34
45
  <thead>
46
+ <tr class="links">
47
+ <th colspan="2">
48
+ <a href="/events/2009/12">&lt;&lt;</a>
49
+ </th>
50
+ <th colspan="3">
51
+ <a href="/events/2010/1">Ene 2010</a>
52
+ </th>
53
+ <th colspan="2">
54
+ <a href="/events/2010/2">&gt;&gt;</a>
55
+ </th>
56
+ </tr>
35
57
  <tr><th>dom</th><th>lun</th><th>mar</th><th>mie</th><th>jue</th><th>vie</th><th>sab</th></tr>
36
58
  </thead>
37
59
  <tbody>
@@ -45,7 +67,7 @@ class PartialsTest < ActionView::TestCase
45
67
  </table>
46
68
  HTML
47
69
 
48
- assert_dom_equal html, render('schedular/events/month', :events => [@event], :year => 2010, :month => 1)
70
+ assert_dom_equal html, render('schedular/events/calendar', :events => [@event], :year => 2010, :month => 1)
49
71
  end
50
72
  end
51
73
 
data/test/test_time.rb CHANGED
@@ -9,28 +9,32 @@ class Schedular::TimeTest < Test::Unit::TestCase
9
9
  end
10
10
  subject { @time }
11
11
 
12
- should_have_and_belong_to_many :events
12
+ should have_and_belong_to_many :events
13
+
14
+ should 'validate all day not null'
15
+
13
16
 
14
17
  context 'named scopes' do
15
18
  setup do
16
- @event = Schedular::Event.create! :dates => '1 de enero 2010 a las 10:00', :name => 'Evento 1'
17
- @event2 = Schedular::Event.create! :dates => 'enero y febrero 2010', :name => 'Evento 2'
19
+ Schedular::Time.create! :value => DateTime.civil(2010, 1, 1, 10), :duration => 60, :all_day => false
20
+ Schedular::Time.create! :value => DateTime.civil(2010, 1, 1, 10), :duration => 120, :all_day => false
21
+ Schedular::Event.create! :dates => 'enero y febrero 2010', :name => 'Evento 2'
18
22
  end
19
23
 
20
24
  should 'have 60 times' do
21
- assert_equal 60, Schedular::Time.count
25
+ assert_equal 61, Schedular::Time.count
22
26
  end
23
27
 
24
28
  should 'find by time or period (Range)' do
25
- assert_equal 32, Schedular::Time.by_time_or_period(Date.civil(2010)..Date.civil(2010, 2)).size
29
+ assert_equal 33, Schedular::Time.by_time_or_period(Date.civil(2010)..Date.civil(2010, 2)).size
26
30
  end
27
31
 
28
32
  should 'find by time or period (Date)' do
29
- assert_equal 2, Schedular::Time.by_time_or_period(Date.civil(2010)).size
33
+ assert_equal 3, Schedular::Time.by_time_or_period(Date.civil(2010)).size
30
34
  end
31
35
 
32
36
  should 'find by time or period (DateTime)' do
33
- assert_equal 1, Schedular::Time.by_time_or_period(DateTime.civil(2010, 1, 1, 10)).size
37
+ assert_equal 2, Schedular::Time.by_time_or_period(DateTime.civil(2010, 1, 1, 10)).size
34
38
  end
35
39
 
36
40
  should 'find by all day' do
@@ -38,7 +42,26 @@ class Schedular::TimeTest < Test::Unit::TestCase
38
42
  end
39
43
 
40
44
  should 'find by not all day' do
41
- assert_equal 1, Schedular::Time.all_day(false).size
45
+ assert_equal 2, Schedular::Time.all_day(false).size
46
+ end
47
+
48
+ should 'find by duration' do
49
+ assert_equal 1, Schedular::Time.duration(60).size
50
+ assert_equal 1, Schedular::Time.duration(120).size
51
+ end
52
+
53
+ should 'find by duration less than' do
54
+ assert_equal 2, Schedular::Time.duration_less_or_equal(120).size
55
+ assert_equal 2, Schedular::Time.duration_less_or_equal(121).size
56
+ assert_equal 1, Schedular::Time.duration_less_or_equal(60).size
57
+ assert_equal 1, Schedular::Time.duration_less_or_equal(61).size
58
+ end
59
+
60
+ should 'find by duration more than' do
61
+ assert_equal 2, Schedular::Time.duration_more_or_equal(59).size
62
+ assert_equal 2, Schedular::Time.duration_more_or_equal(60).size
63
+ assert_equal 1, Schedular::Time.duration_more_or_equal(119).size
64
+ assert_equal 1, Schedular::Time.duration_more_or_equal(120).size
42
65
  end
43
66
 
44
67
  should 'find by params with month' do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Macario Ortega
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-22 00:00:00 -05:00
17
+ date: 2010-09-24 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -128,7 +128,6 @@ files:
128
128
  - test/rails_app/lib/event.rb
129
129
  - test/rails_app/log/production.log
130
130
  - test/rails_app/log/server.log
131
- - test/rails_app/log/test.log
132
131
  - test/rails_app/public/404.html
133
132
  - test/rails_app/public/422.html
134
133
  - test/rails_app/public/500.html