schedular 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.document +7 -0
  2. data/.gitignore +25 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +57 -0
  6. data/VERSION +1 -0
  7. data/app/views/schedular/events/_calendar.html.erb +28 -0
  8. data/app/views/schedular/events/_form.html.erb +22 -0
  9. data/app/views/schedular/events/edit.html.erb +13 -0
  10. data/app/views/schedular/events/index.html.erb +26 -0
  11. data/app/views/schedular/events/new.html.erb +12 -0
  12. data/app/views/schedular/events/show.html.erb +29 -0
  13. data/config/routes.rb +5 -0
  14. data/generators/schedular_migrations/schedular_migrations_generator.rb +7 -0
  15. data/generators/schedular_migrations/templates/schedular_migrations.rb +27 -0
  16. data/generators/schedular_views/schedular_views_generator.rb +20 -0
  17. data/lib/schedular.rb +17 -0
  18. data/lib/schedular/event.rb +39 -0
  19. data/lib/schedular/events_controller.rb +93 -0
  20. data/lib/schedular/locale/schedular.es.yml +22 -0
  21. data/lib/schedular/time.rb +25 -0
  22. data/rails/init.rb +1 -0
  23. data/test/helper.rb +15 -0
  24. data/test/rails_app/README +243 -0
  25. data/test/rails_app/Rakefile +10 -0
  26. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  27. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  28. data/test/rails_app/app/views/layouts/application.html.erb +17 -0
  29. data/test/rails_app/config/boot.rb +110 -0
  30. data/test/rails_app/config/database.yml +22 -0
  31. data/test/rails_app/config/environment.rb +41 -0
  32. data/test/rails_app/config/environments/development.rb +17 -0
  33. data/test/rails_app/config/environments/production.rb +28 -0
  34. data/test/rails_app/config/environments/test.rb +28 -0
  35. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/rails_app/config/initializers/inflections.rb +10 -0
  37. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  38. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  39. data/test/rails_app/config/initializers/session_store.rb +15 -0
  40. data/test/rails_app/config/locales/en.yml +5 -0
  41. data/test/rails_app/config/routes.rb +43 -0
  42. data/test/rails_app/doc/README_FOR_APP +2 -0
  43. data/test/rails_app/lib/event.rb +3 -0
  44. data/test/rails_app/public/404.html +30 -0
  45. data/test/rails_app/public/422.html +30 -0
  46. data/test/rails_app/public/500.html +30 -0
  47. data/test/rails_app/public/favicon.ico +0 -0
  48. data/test/rails_app/public/images/rails.png +0 -0
  49. data/test/rails_app/public/index.html +275 -0
  50. data/test/rails_app/public/javascripts/application.js +2 -0
  51. data/test/rails_app/public/javascripts/controls.js +963 -0
  52. data/test/rails_app/public/javascripts/dragdrop.js +973 -0
  53. data/test/rails_app/public/javascripts/effects.js +1128 -0
  54. data/test/rails_app/public/javascripts/prototype.js +4320 -0
  55. data/test/rails_app/public/robots.txt +5 -0
  56. data/test/rails_app/script/about +4 -0
  57. data/test/rails_app/script/console +3 -0
  58. data/test/rails_app/script/dbconsole +3 -0
  59. data/test/rails_app/script/destroy +3 -0
  60. data/test/rails_app/script/generate +3 -0
  61. data/test/rails_app/script/performance/benchmarker +3 -0
  62. data/test/rails_app/script/performance/profiler +3 -0
  63. data/test/rails_app/script/plugin +3 -0
  64. data/test/rails_app/script/runner +3 -0
  65. data/test/rails_app/script/server +3 -0
  66. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  67. data/test/rails_app/test/test_helper.rb +38 -0
  68. data/test/rails_app/tmp/restart.txt +0 -0
  69. data/test/support/migrations.rb +22 -0
  70. data/test/test_event.rb +107 -0
  71. data/test/test_events_controller.rb +280 -0
  72. data/test/test_partials.rb +54 -0
  73. data/test/test_time.rb +62 -0
  74. metadata +217 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
File without changes
@@ -0,0 +1,22 @@
1
+ ActiveRecord::Migration.verbose = false
2
+ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
3
+
4
+ ActiveRecord::Schema.define :version => 1 do
5
+
6
+ create_table :schedular_events do |t|
7
+ t.string :name
8
+ t.string :dates
9
+ t.text :description
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :schedular_times do |t|
14
+ t.datetime :value
15
+ t.boolean :all_day
16
+ end
17
+
18
+ create_table :schedular_events_times, :id => false do |t|
19
+ t.integer :time_id
20
+ t.integer :event_id
21
+ end
22
+ end
@@ -0,0 +1,107 @@
1
+ require 'helper'
2
+
3
+ class Schedular::EventTest < Test::Unit::TestCase
4
+ context 'event' do
5
+ setup do
6
+ Schedular::Event.destroy_all
7
+ Schedular::Time.destroy_all
8
+ @event = Schedular::Event.new :dates => 'enero 2010', :name => 'evento 1'
9
+ end
10
+ subject { @event }
11
+
12
+ should_validate_presence_of :name
13
+ # should_validate_presence_of :dates
14
+
15
+ should 'not accept bad date' do
16
+ event = Schedular::Event.new :dates => 'bad dates', :name => 'evento 1'
17
+ assert_equal false, event.valid?
18
+ assert_equal I18n.t('activerecord.errors.messages.invalid'), event.errors[:dates]
19
+ end
20
+
21
+ context 'times without time' do
22
+ should 'have 31 times' do
23
+ assert_equal 31, @event.times.size
24
+ end
25
+
26
+ should 'be all_day for all times' do
27
+ assert_equal [true]*31, @event.times.map(&:all_day)
28
+ end
29
+
30
+ should 'save all times and use existing' do
31
+ @event.save
32
+ assert_equal 31, Schedular::Time.count
33
+ @event2 = Schedular::Event.new :dates => 'enero 2010', :name => 'evento 1'
34
+ @event2.save
35
+ assert_equal 31, Schedular::Time.count
36
+ end
37
+ end
38
+
39
+ context 'times with time' do
40
+ setup { @event = Schedular::Event.new :dates => 'enero 2010 a las 13:00', :name => 'evento 1' }
41
+
42
+ should 'have 31 times' do
43
+ assert_equal 31, @event.times.size
44
+ end
45
+
46
+ should 'not be all_day for all times' do
47
+ assert_equal [false]*31, @event.times.map(&:all_day)
48
+ end
49
+
50
+ should 'map times' do
51
+ assert_equal [13]*31, @event.times.map{ |d| d.value.hour }
52
+ end
53
+
54
+ should 'save all times and use existing' do
55
+ @event.save
56
+ assert_equal 31, Schedular::Time.count
57
+ @event2 = Schedular::Event.new :dates => 'enero 2010 a las 13:00', :name => 'evento 1'
58
+ @event2.save
59
+ assert_equal 31, Schedular::Time.count
60
+ end
61
+ end
62
+
63
+ context 'named scopes' do
64
+ setup do
65
+ @event = Schedular::Event.create :dates => 'enero y febrero 2010', :name => 'evento 1'
66
+ @event2 = Schedular::Event.create :dates => '2 de enero del 2010', :name => 'evento 2'
67
+ @event3 = Schedular::Event.create :dates => '2 de marzo del 2010', :name => 'evento 3'
68
+ end
69
+
70
+ should 'have 60 times' do
71
+ assert_equal 60, Schedular::Time.count
72
+ end
73
+
74
+ should 'find by month' do
75
+ assert_equal [@event, @event2], Schedular::Event.by_time_or_period(Date.civil(2010)..Date.civil(2010, 2))
76
+ end
77
+
78
+ should 'find by day' do
79
+ assert_equal [@event3], Schedular::Event.by_time_or_period(Date.civil(2010, 3, 2))
80
+ end
81
+
82
+ should 'find by params without date' do
83
+ assert_equal [@event, @event2], Schedular::Event.by_params(:year => '2010', :month => '1')
84
+ end
85
+
86
+ should 'find by params with month' do
87
+ assert_equal [@event, @event2, @event3], Schedular::Event.by_params({})
88
+ end
89
+
90
+ should 'find by params with day' do
91
+ assert_equal [@event3], Schedular::Event.by_params(:year => '2010', :month => '3', :day => '2')
92
+ end
93
+
94
+ # should 'find by params with no year' do
95
+ # assert_equal Schedular::Event.find(:all), Schedular::Event.by_params(:year => nil)
96
+ # end
97
+ end
98
+
99
+ should 'allways order times by value' do
100
+ Schedular::Time.destroy_all
101
+ times = [Date.today << 1, Date.today, Date.today >> 1]
102
+ @event.times = times.sort_by{rand}.map{ |t| Schedular::Time.create(:value => t) }
103
+ @event.save! and @event.reload
104
+ assert_equal times.map(&:month), @event.times.map{ |d| d.value.month }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,280 @@
1
+ require 'helper'
2
+
3
+ class Schedular::EventsControllerTest < ActionController::TestCase
4
+ should_route :get, '/events', :controller => 'schedular/events', :action => :index
5
+ should_route :post, '/events', :controller => 'schedular/events', :action => :create
6
+ should_route :put, '/events/1', :controller => 'schedular/events', :action => :update, :id => '1'
7
+ should_route :get, '/events/1/edit', :controller => 'schedular/events', :action => :edit, :id => '1'
8
+ should_route :get, '/events/1', :controller => 'schedular/events', :action => :show, :id => '1'
9
+ should_route :get, '/events/2009/1/29', :controller => 'schedular/events', :action => :index, :year => '2009', :month => '1', :day => '29'
10
+ should_route :get, '/events/2009/1/29.xml', :controller => 'schedular/events', :action => :index, :year => '2009', :month => '1', :day => '29', :format => 'xml'
11
+ should_route :get, '/events/2009/1', :controller => 'schedular/events', :action => :index, :year => '2009', :month => '1'
12
+ should_route :get, '/events/2009/1.xml', :controller => 'schedular/events', :action => :index, :year => '2009', :month => '1', :format => 'xml'
13
+
14
+ context 'controller actions' do
15
+ setup do
16
+ Schedular::Event.destroy_all
17
+ Schedular::Time.destroy_all
18
+ @today = Date.today
19
+ @event1 = Schedular::Event.create! :dates => 'enero', :name => 'evento 1'
20
+ @event2 = Schedular::Event.create! :dates => '1 de febrero', :name => 'evento 2'
21
+ @event3 = Schedular::Event.create! :dates => '2 de febrero', :name => 'evento 2'
22
+ end
23
+
24
+ context 'GET index' do
25
+ context 'redirection' do
26
+ context 'with no options' do
27
+ setup { get :index }
28
+ should_redirect_to('current month'){ monthly_schedule_path :year => @today.year, :month => @today.month }
29
+ end
30
+
31
+ context 'with just year' do
32
+ setup { get :index, :year => '2009' }
33
+ should_redirect_to('current month'){ monthly_schedule_path :year => '2009', :month => @today.month }
34
+ end
35
+ end
36
+
37
+ def self.with_format format
38
+ context "with format #{format}" do
39
+ setup do
40
+ @params = {:year => @today.year, :month => '1'}
41
+ @params.merge!(:format => format) if format
42
+ @day = Date.civil(@today.year)
43
+ end
44
+
45
+ context 'with month' do
46
+ setup { get :index, @params }
47
+ should_respond_with :success
48
+ should_assign_to(:events){ [@event1] }
49
+ should_assign_to(:month_events){ [@event1] }
50
+ should 'set session[:current_month]' do
51
+ assert_equal Date.civil(@today.year, 1), @request.session[:current_month]
52
+ end
53
+ yield if block_given?
54
+ end
55
+
56
+ context 'with month and day' do
57
+ setup do
58
+ @day = Date.civil(@params[:year], 2, 1)
59
+ get :index, @params.merge(:month => @day.month, :day => @day.day)
60
+ end
61
+ should_respond_with :success
62
+ should_assign_to(:events){ [@event2] }
63
+ should_assign_to(:month_events){ [@event2, @event3] }
64
+ should 'set session[:current_month]' do
65
+ assert_equal Date.civil(@day.year, @day.month), @request.session[:current_month]
66
+ end
67
+ yield if block_given?
68
+ end
69
+ end
70
+ end
71
+
72
+ with_format nil do
73
+ # should_render_template :index
74
+ should_respond_with_content_type 'text/html'
75
+ # should 'render with template' do
76
+ # assert_equal "layouts/application", @controller.active_layout._unmemoized_path_without_format_and_extension
77
+ # end
78
+ end
79
+
80
+ with_format 'xml' do
81
+ should_respond_with_content_type 'application/xml'
82
+ end
83
+
84
+ with_format 'json' do
85
+ should_respond_with_content_type 'application/json'
86
+ end
87
+ end
88
+
89
+ context 'GET show' do
90
+ def self.with_format format
91
+ context "with format #{format}" do
92
+ setup do
93
+ @params = {:id => @event1.id}
94
+ @params.merge!(:format => format) if format
95
+ get :show, @params
96
+ end
97
+ should_respond_with :success
98
+ should_assign_to(:event){ @event1 }
99
+ yield
100
+ end
101
+ end
102
+
103
+ with_format nil do
104
+ # should_render_template :index
105
+ should_respond_with_content_type 'text/html'
106
+ end
107
+ with_format 'xml' do
108
+ should_respond_with_content_type 'application/xml'
109
+ end
110
+ with_format 'json' do
111
+ should_respond_with_content_type 'application/json'
112
+ end
113
+ end
114
+
115
+ context 'GET new' do
116
+ def self.with_format format
117
+ context "with format #{format}" do
118
+ setup do
119
+ @params = {}
120
+ @params.merge!(:format => format) if format
121
+ get :new, @params
122
+ end
123
+ should_respond_with :success
124
+ should_assign_to(:event)
125
+ should('be a new record') { assert assigns(:event).new_record? }
126
+ yield
127
+ end
128
+ end
129
+
130
+ with_format nil do
131
+ should_respond_with_content_type 'text/html'
132
+ end
133
+ with_format 'xml' do
134
+ should_respond_with_content_type 'application/xml'
135
+ end
136
+ with_format 'json' do
137
+ should_respond_with_content_type 'application/json'
138
+ end
139
+ end
140
+
141
+ context 'GET edit' do
142
+ setup do
143
+ get :edit, :id => @event1.id
144
+ end
145
+ should_respond_with :success
146
+ should_assign_to(:event){ @event1 }
147
+ # should_render_template :edit
148
+ end
149
+
150
+ context 'POST create' do
151
+ def self.with_format format
152
+ context "with format #{format}" do
153
+ setup do
154
+ @params = { :schedular_event => {:dates => 'enero', :name => 'Evento 1'}}
155
+ @params.merge!(:format => format) if format
156
+ end
157
+
158
+ context "with valid attributes" do
159
+ setup { post :create, @params }
160
+ should_assign_to(:event)
161
+ should('set dates'){ assert_equal 'enero', assigns(:event).dates }
162
+ should('not be new record') { assert_equal false, assigns(:event).new_record? }
163
+ yield
164
+ if format
165
+ should_respond_with :created
166
+ else
167
+ should('redirect to created event'){ assert_redirected_to assigns(:event) }
168
+ end
169
+ end
170
+
171
+ context "with invalid attributes" do
172
+ setup do
173
+ @params[:schedular_event].merge!(:name => nil)
174
+ post :create, @params
175
+ end
176
+ should_assign_to(:event)
177
+ should('set dates'){ assert_equal 'enero', assigns(:event).dates }
178
+ should('be new record') { assert assigns(:event).new_record? }
179
+ yield
180
+ if format
181
+ should_respond_with :unprocessable_entity
182
+ else
183
+ # should('render new'){ assert_template :new }
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ with_format nil do
190
+ should_respond_with_content_type 'text/html'
191
+ end
192
+ with_format 'xml' do
193
+ should_respond_with_content_type 'application/xml'
194
+
195
+ end
196
+ with_format 'json' do
197
+ should_respond_with_content_type 'application/json'
198
+ end
199
+ end
200
+
201
+ context 'PUT update' do
202
+ def self.with_format format
203
+ context "with format #{format}" do
204
+ setup do
205
+ @params = { :schedular_event => {:dates => 'febrero', :name => 'Evento 1'}, :id => @event1.id }
206
+ @params.merge!(:format => format) if format
207
+ end
208
+
209
+ context "with valid attributes" do
210
+ setup { put :update, @params }
211
+ should_assign_to(:event)
212
+ should('set dates'){ assert_equal 'febrero', assigns(:event).dates }
213
+ yield
214
+ if format
215
+ should_respond_with :ok
216
+ else
217
+ should('redirect to created event'){ assert_redirected_to assigns(:event) }
218
+ end
219
+ end
220
+
221
+ context "with invalid attributes" do
222
+ setup do
223
+ @params[:schedular_event].merge!(:name => nil)
224
+ put :update, @params
225
+ end
226
+ should_assign_to(:event)
227
+ should('set dates'){ assert_equal 'febrero', assigns(:event).dates }
228
+ yield
229
+ if format
230
+ should_respond_with :unprocessable_entity
231
+ else
232
+ # should('render new'){ assert_template :edit }
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ with_format nil do
239
+ should_respond_with_content_type 'text/html'
240
+ end
241
+ with_format 'xml' do
242
+ should_respond_with_content_type 'application/xml'
243
+
244
+ end
245
+ with_format 'json' do
246
+ should_respond_with_content_type 'application/json'
247
+ end
248
+ end
249
+
250
+ context 'DELETE destroy' do
251
+ def self.with_format format
252
+ context "with format #{format}" do
253
+ setup do
254
+ @params = {:id => @event1.id}
255
+ @params.merge!(:format => format) if format
256
+ assert_difference('Schedular::Event.count', -1) do
257
+ delete :destroy, @params
258
+ end
259
+ end
260
+
261
+ should_assign_to(:event){ @event1 }
262
+ yield
263
+ end
264
+ end
265
+
266
+ with_format nil do
267
+ should_respond_with_content_type 'text/html'
268
+ should_redirect_to('events'){ schedular_events_path }
269
+ end
270
+ with_format 'xml' do
271
+ should_respond_with_content_type 'application/xml'
272
+ should_respond_with :ok
273
+ end
274
+ with_format 'json' do
275
+ should_respond_with_content_type 'application/json'
276
+ should_respond_with :ok
277
+ end
278
+ end
279
+ end
280
+ end