event_calendar_engine 0.1.7 → 0.1.8

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 CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -1,6 +1,7 @@
1
1
  class EventsController < EventCalendar::ApplicationController
2
2
 
3
3
  # before_filter :load_and_authorize_current_user, :except => [:index, :show]
4
+ before_filter :parse_dates_from_params, :only => [:create, :update]
4
5
 
5
6
  private
6
7
  def events_to_json
@@ -17,6 +18,25 @@ class EventsController < EventCalendar::ApplicationController
17
18
  end
18
19
  json.to_json
19
20
  end
21
+
22
+ def parse_dates_from_params
23
+ params[:event].delete :"start_time(1i)"
24
+ params[:event].delete :"start_time(2i)"
25
+ params[:event].delete :"start_time(3i)"
26
+ params[:event].delete :"end_time(1i)"
27
+ params[:event].delete :"end_time(2i)"
28
+ params[:event].delete :"end_time(3i)"
29
+ start_hour = params[:event].delete :"start_time(4i)"
30
+ start_min = params[:event].delete :"start_time(5i)"
31
+ end_hour = params[:event].delete :"end_time(4i)"
32
+ end_min = params[:event].delete :"end_time(5i)"
33
+ start_date = Date.parse(params[:event][:start_date])
34
+ end_date = Date.parse(params[:event][:end_date])
35
+ params[:event][:start_on] = Time.local(start_date.year, start_date.month, start_date.day, start_hour, start_min)
36
+ params[:event][:end_on] = Time.local(end_date.year, end_date.month, end_date.day, end_hour, end_min)
37
+ params[:event][:start_time] = params[:event][:start_on]
38
+ params[:event][:end_time] = params[:event][:end_on]
39
+ end
20
40
  protected
21
41
  public
22
42
 
@@ -26,7 +46,7 @@ class EventsController < EventCalendar::ApplicationController
26
46
  if params[:start] && params[:end]
27
47
  @events = Event.between(Time.at(params[:start].to_i), Time.at(params[:end].to_i))
28
48
  else
29
- @events = Event.find :all
49
+ @events = Event.all
30
50
  end
31
51
 
32
52
  respond_to do |format|
@@ -68,14 +88,14 @@ class EventsController < EventCalendar::ApplicationController
68
88
  # GET /events/1/edit
69
89
  def edit
70
90
  @event = Event.find(params[:id])
91
+ Time.zone = @event.timezone
71
92
  end
72
93
 
73
94
  # POST /events
74
95
  # POST /events.xml
75
96
  def create
76
97
  @event = Event.new(params[:event])
77
- # @event.modified_by_user = current_user
78
-
98
+
79
99
  respond_to do |format|
80
100
  if @event.save
81
101
  flash[:notice] = 'Event was successfully created.'
data/app/models/event.rb CHANGED
@@ -3,17 +3,11 @@ class Event < ActiveRecord::Base
3
3
 
4
4
  include ActionView::Helpers::TextHelper
5
5
 
6
- has_many :attendees
7
- #has_many :contacts, :through => :attendees, :order => ["last_name, first_name"],
8
- # :conditions => {:revisable_is_current => true}
9
-
10
- #has_many :file_attachments
6
+ attr_accessor :start_time, :end_time, :start_date, :end_date
11
7
 
12
- #belongs_to :modified_by_user, :class_name => 'User'
8
+ has_many :attendees
13
9
 
14
10
  validates_presence_of :name, :event_type, :start_on
15
-
16
- # acts_as_stripped :name
17
11
 
18
12
  searchable_by :name, :event_type, :location, :description
19
13
 
@@ -22,12 +16,14 @@ class Event < ActiveRecord::Base
22
16
  scope :past, where(sanitize_sql_array(["end_on < '%s'", Date.current]))
23
17
  scope :future, where(sanitize_sql_array(["start_on > '%s'", Date.current]))
24
18
  scope :current, where(sanitize_sql_array(["end_on >= '%s' AND start_on <= '%s'", Date.current, Date.current]))
25
- scope :between, lambda{ |start_date, end_date|
19
+ scope :between, lambda{ |start_datetime, end_datetime|
26
20
  where(["start_on BETWEEN ? AND ? OR end_on BETWEEN ? AND ?",
27
- start_date, end_date, start_date, end_date])
21
+ start_datetime, end_datetime, start_datetime, end_datetime])
28
22
  }
29
23
 
30
24
  validate :sane_dates
25
+
26
+ before_save :set_timezone
31
27
 
32
28
  private
33
29
 
@@ -37,9 +33,29 @@ class Event < ActiveRecord::Base
37
33
  end
38
34
  end
39
35
 
36
+ def set_timezone
37
+ Time.zone = timezone
38
+ end
39
+
40
40
  protected
41
41
  public
42
42
 
43
+ def start_time
44
+ @start_time ||= start_on
45
+ end
46
+
47
+ def end_time
48
+ @end_time ||= end_on
49
+ end
50
+
51
+ def start_date
52
+ @start_date ||= start_on.present? ? start_on.to_date : start_on
53
+ end
54
+
55
+ def end_date
56
+ @end_date ||= end_on.present? ? end_on.to_date : end_on
57
+ end
58
+
43
59
  def start_year
44
60
  start_on.year
45
61
  end
@@ -4,23 +4,26 @@
4
4
  </p>
5
5
 
6
6
  <p>
7
- <strong>When:</strong>
8
- <%= event_details.start_on %>
9
- <% if event_details.end_on %>
10
- - <%= event_details.end_on %>
11
- <% end %>
7
+ <strong>Starts</strong><br />
8
+ <%= event_details.start_on.in_time_zone(event_details.timezone).strftime('%A, %B %d %Y at %I:%M %p (%Z)') %>
12
9
  </p>
10
+ <% if event_details.end_on %>
11
+ <p>
12
+ <strong>Ends</strong><br />
13
+ <%= event_details.end_on.in_time_zone(event_details.timezone).strftime('%A, %B %d %Y at %I:%M %p (%Z)') %>
14
+ </p>
15
+ <% end %>
13
16
 
14
17
  <% unless event_details.location.blank? %>
15
18
  <p>
16
- <strong>Where:</strong><br/>
19
+ <strong>Location</strong><br/>
17
20
  <%= textilize_without_paragraph event_details.location %>
18
21
  </p>
19
22
  <% end %>
20
23
 
21
24
  <% unless event_details.description.blank? %>
22
25
  <p>
23
- <strong>Description/Other Details:</strong>
26
+ <strong>Description/Other Details</strong><br />
24
27
  <%= textilize_without_paragraph event_details.description %>
25
28
  </p>
26
29
  <% end %>
@@ -4,10 +4,13 @@
4
4
  <%= form.inputs do %>
5
5
  <%= form.input :name, :hint => "the name of the event" %>
6
6
  <%= form.input :event_type, :hint => "conference, meeting, training, etc" %>
7
- <%= form.input :start_on, :required => false, :label => "Starting date of event", :as => :string,
8
- :input_html => { :value => @event.start_on.to_s } %>
9
- <%= form.input :end_on, :required => false, :label => "Ending date of event", :as => :string,
10
- :input_html => { :value => @event.end_on.to_s } %>
7
+ <%= form.input :start_time, :as => :time, :minute_step => 15 %>
8
+ <%= form.input :start_date, :required => false, :as => :string,
9
+ :input_html => { :value => @event.start_date.to_s } %>
10
+ <%= form.input :end_time, :as => :time, :minute_step => 15 %>
11
+ <%= form.input :end_date, :required => false, :as => :string,
12
+ :input_html => { :value => @event.end_date.to_s } %>
13
+ <%= form.input :timezone, :as => :time_zone, :priority_zones => /^(Eastern|Central|Mountain|Pacific) Time/ %>
11
14
  <%= form.input :location, :required => false, :label => 'Location' %>
12
15
  <%= form.input :description, :required => false, :label => 'Description' %>
13
16
  <% unless @event.new_record? %>
@@ -28,8 +31,8 @@
28
31
 
29
32
  $('form.formtastic fieldset ol li.text textarea').attach(TextareaExpander, 40, 300);
30
33
 
31
- $('#event_start_on').datepicker();
32
- $('#event_end_on').datepicker();
34
+ $('#event_start_date').datepicker();
35
+ $('#event_end_date').datepicker();
33
36
  });
34
37
  </script>
35
38
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  <%= render :partial => 'event_details', :object => @event %>
5
5
 
6
+ <!--
6
7
  <h3>Attendees/Participants</h3>
7
8
 
8
9
  <%
@@ -33,4 +34,5 @@
33
34
  <%
34
35
  #end
35
36
  %>
37
+ -->
36
38
  </div>
@@ -0,0 +1,11 @@
1
+ class ChangeStartOnEndOnToTimestamp < ActiveRecord::Migration
2
+ def self.up
3
+ change_column :event_calendar_events, :start_on, :datetime
4
+ change_column :event_calendar_events, :end_on, :datetime
5
+ end
6
+
7
+ def self.down
8
+ change_column :event_calendar_events, :start_on, :date
9
+ change_column :event_calendar_events, :end_on, :date
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class AddTimezoneToEvents < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :event_calendar_events, :timezone, :string
4
+ end
5
+
6
+ def self.down
7
+ remove_column :event_calendar_events, :timezone
8
+ end
9
+ end
data/db/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20101011200048) do
13
+ ActiveRecord::Schema.define(:version => 20101223233354) do
14
14
 
15
15
  create_table "event_calendar_attendees", :force => true do |t|
16
16
  t.integer "event_id"
@@ -24,8 +24,8 @@ ActiveRecord::Schema.define(:version => 20101011200048) do
24
24
  create_table "event_calendar_events", :force => true do |t|
25
25
  t.string "name"
26
26
  t.string "event_type"
27
- t.date "start_on"
28
- t.date "end_on"
27
+ t.datetime "start_on"
28
+ t.datetime "end_on"
29
29
  t.text "location"
30
30
  t.text "description"
31
31
  t.text "notes"
@@ -40,6 +40,7 @@ ActiveRecord::Schema.define(:version => 20101011200048) do
40
40
  t.datetime "revisable_revised_at"
41
41
  t.datetime "revisable_deleted_at"
42
42
  t.boolean "revisable_is_current", :default => true
43
+ t.string "timezone"
43
44
  end
44
45
 
45
46
  end
@@ -381,14 +381,6 @@ table.fc-header {width:100%;}
381
381
  #calendar_front_page h2 {font-size:1.3em
382
382
  ;}
383
383
  div.select_popper_box ul li:hover {background:#EEE;}
384
- form.formtastic li {width:380px;margin-right:40px;}
385
- form.formtastic fieldset ol li {vertical-align:top;}
386
- form.formtastic fieldset ol li label {width:30%;}
387
- form.formtastic fieldset ol li.string input {width:69%;}
388
- form.formtastic fieldset ol li.string input {width:69%;}
389
- form.formtastic fieldset ol li.text textarea {width:69%;height:70px;}
390
- form.formtastic fieldset ol li.check_boxes fieldset ol li label {font-weight:normal;padding-left:40px;}
391
- form.formtastic fieldset ol li p.inline-hints {color:#666666;font-size:11px;margin:0.3em 0 0 25%;}
392
384
  #event_start_on_input label {width:49%
393
385
  ;}
394
386
  #event_start_on {width:50%
@@ -446,6 +438,14 @@ input[type="checkbox"], input[type="radio"], input.checkbox, input.radio {top:0
446
438
  ;}
447
439
  .error, .notice, .success {margin:10px;}
448
440
  .caps {font-size:1em;font-variant:normal;letter-spacing:0;padding:0;text-transform:none;}
441
+ form.formtastic li {width:380px;margin-right:40px;}
442
+ form.formtastic fieldset ol li {vertical-align:top;}
443
+ form.formtastic fieldset ol li label {width:30%;}
444
+ form.formtastic fieldset ol li.string input {width:69%;}
445
+ form.formtastic fieldset ol li.string input {width:69%;}
446
+ form.formtastic fieldset ol li.text textarea {width:69%;height:70px;}
447
+ form.formtastic fieldset ol li.check_boxes fieldset ol li label {font-weight:normal;padding-left:40px;}
448
+ form.formtastic fieldset ol li p.inline-hints {color:#666666;font-size:11px;margin:0.3em 0 0 25%;}
449
449
  .base_content {background:#fff;}
450
450
  .inner_content {padding:16px;}
451
451
  .top-banner {background:#336;-webkit-border-bottom-left-radius:8px;-moz-border-radius-bottomleft:8px;border-bottom-left-radius:8px;}
@@ -12,3 +12,6 @@ The following style may be *conditionally* included for improved support on olde
12
12
  form.formtastic fieldset ol li fieldset legend { margin-left: -6px;}
13
13
 
14
14
  --------------------------------------------------------------------------------------------------*/
15
+ form.formtastic fieldset > ol > li {
16
+ overflow: hidden;
17
+ }
@@ -1,27 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe require 'spec_helper'
4
-
5
- describe EventsController do
6
-
3
+ describe EventsController do
4
+ subject{ Event }
5
+ let(:event) do
6
+ mock_model(Event, {
7
+ :name => 'Some Event',
8
+ :start_on => Date.yesterday,
9
+ :end_on => Date.tomorrow,
10
+ :timezone => 'Pacific Time (US & Canada)',
11
+ :description => 'Some Description',
12
+ :location => 'Some City'
13
+ })
14
+ end
15
+ let(:params) do
16
+ {
17
+ :id => "37"
18
+ }
19
+ end
20
+ before(:each) do
21
+ subject.stub(:find).with("37"){ event }
22
+ end
23
+
7
24
  describe "GET index" do
8
25
  it "assigns all events as @events" do
9
- Event.stub(:find).with(:all).and_return([mock_event])
26
+ subject.stub(:all){ [event] }
10
27
  get :index
11
- assigns[:events].should == [mock_event]
28
+ assigns(:events).should eq [event]
12
29
  end
13
30
  end
14
31
 
15
32
  describe "GET index as json" do
16
33
  it "renders @events as json" do
17
- mock_event({
18
- :name => 'Some Event',
19
- :start_on => Date.yesterday,
20
- :end_on => Date.tomorrow,
21
- :description => 'Some Description',
22
- :location => 'Some City'
23
- })
24
- Event.stub(:between).and_return([mock_event])
34
+ subject.stub(:between).and_return([event])
25
35
  get :index, :format => 'js'
26
36
  response.should be_success
27
37
  end
@@ -29,54 +39,63 @@ describe EventsController do
29
39
 
30
40
  describe "GET show" do
31
41
  it "assigns the requested event as @event" do
32
- Event.stub(:find).with("37").and_return(mock_event)
33
- get :show, :id => "37"
34
- assigns[:event].should equal(mock_event)
42
+ get :show, params
43
+ assigns(:event).should eq event
35
44
  end
36
45
  end
37
46
 
38
47
  describe "GET new" do
39
48
  it "assigns a new event as @event" do
40
- Event.stub(:new).and_return(mock_event)
49
+ subject.stub(:new){ event }
41
50
  get :new
42
- assigns[:event].should equal(mock_event)
51
+ assigns(:event).should eq event
43
52
  end
44
53
  end
45
54
 
46
55
  describe "GET edit" do
47
56
  it "assigns the requested event as @event" do
48
- Event.stub(:find).with("37").and_return(mock_event)
49
- get :edit, :id => "37"
50
- assigns[:event].should equal(mock_event)
57
+ subject.stub(:find).with("37").and_return(event)
58
+ get :edit, params
59
+ assigns(:event).should eq event
51
60
  end
52
61
  end
53
62
 
54
63
  describe "POST create" do
55
-
64
+ let :params do
65
+ {
66
+ :event => {
67
+ :start_date => Date.yesterday.to_s,
68
+ :end_date => Date.tomorrow.to_s
69
+ }
70
+ }
71
+ end
72
+ before(:each) do
73
+ event.stub(:save){ true }
74
+ subject.stub(:new){ event }
75
+ end
56
76
  describe "with valid params" do
57
77
  it "assigns a newly created event as @event" do
58
- Event.stub(:new).with({'these' => 'params'}).and_return(mock_event(:save => true, :modified_by_user= => nil))
59
- post :create, :event => {:these => 'params'}
60
- assigns[:event].should equal(mock_event)
78
+ post :create, params
79
+ assigns(:event).should eq event
61
80
  end
62
81
 
63
82
  it "redirects to the created event" do
64
- Event.stub(:new).and_return(mock_event(:save => true, :modified_by_user= => nil))
65
- post :create, :event => {}
66
- response.should redirect_to(event_url(mock_event))
83
+ post :create, params
84
+ response.should redirect_to event_url event
67
85
  end
68
86
  end
69
87
 
70
88
  describe "with invalid params" do
89
+ before(:each) do
90
+ event.stub(:save){ false }
91
+ end
71
92
  it "assigns a newly created but unsaved event as @event" do
72
- Event.stub(:new).with({'these' => 'params'}).and_return(mock_event(:save => false, :modified_by_user= => nil))
73
- post :create, :event => {:these => 'params'}
74
- assigns[:event].should equal(mock_event)
93
+ post :create, params
94
+ assigns(:event).should eq event
75
95
  end
76
96
 
77
97
  it "re-renders the 'new' template" do
78
- Event.stub(:new).and_return(mock_event(:save => false, :modified_by_user= => nil))
79
- post :create, :event => {}
98
+ post :create, params
80
99
  response.should render_template('new')
81
100
  end
82
101
  end
@@ -84,48 +103,52 @@ describe EventsController do
84
103
  end
85
104
 
86
105
  describe "PUT update" do
106
+ let :params do
107
+ {
108
+ :id => "37",
109
+ :event => {
110
+ :start_date => Date.yesterday.to_s,
111
+ :end_date => Date.tomorrow.to_s
112
+ }
113
+ }
114
+ end
115
+ before(:each) do
116
+ subject.stub(:find).with("37"){ event }
117
+ event.stub(:update_attributes){ nil }
118
+ end
119
+ it "updates the requested event" do
120
+ Event.should_receive(:find).with("37"){ event }
121
+ event.should_receive(:update_attributes)
122
+ put :update, params
123
+ end
87
124
 
125
+ it "assigns the requested event as @event" do
126
+ put :update, params
127
+ assigns(:event).should eq event
128
+ end
129
+
88
130
  describe "with valid params" do
89
- it "updates the requested event" do
90
- Event.should_receive(:find).with("37").and_return(mock_event)
91
- # mock_event.should_receive(:update_attributes).with({'these' => 'params',
92
- # 'modified_by_user' => mock_admin_user})
93
-
94
- mock_event.should_receive(:update_attributes).with({'these' => 'params'})
95
- put :update, :id => "37", :event => {:these => 'params'}
131
+ before(:each) do
132
+ event.stub(:update_attributes){ true }
96
133
  end
97
-
98
- it "assigns the requested event as @event" do
99
- Event.stub(:find).and_return(mock_event(:update_attributes => true))
100
- put :update, :id => "1", :event => {}
101
- assigns[:event].should equal(mock_event)
134
+
135
+ it "sets a flash[:notice]" do
136
+ put :update, params
137
+ flash[:notice].should_not be_nil
102
138
  end
103
-
104
139
  it "redirects to the event" do
105
- Event.stub(:find).and_return(mock_event(:update_attributes => true))
106
- put :update, :id => "1", :event => {}
107
- response.should redirect_to(event_url(mock_event))
140
+ put :update, params
141
+ response.should redirect_to event_url event
108
142
  end
109
143
  end
110
144
 
111
145
  describe "with invalid params" do
112
- it "updates the requested event" do
113
- Event.should_receive(:find).with("37").and_return(mock_event)
114
- mock_event.should_receive(:update_attributes).with({'these' => 'params'})
115
- # mock_event.should_receive(:update_attributes).with({'these' => 'params',
116
- # 'modified_by_user' => mock_admin_user })
117
- put :update, :id => "37", :event => { :these => 'params'}
118
- end
119
-
120
- it "assigns the event as @event" do
121
- Event.stub(:find).and_return(mock_event(:update_attributes => false))
122
- put :update, :id => "1", :event => { 'these' => 'params'}
123
- assigns[:event].should equal(mock_event)
146
+ before(:each) do
147
+ event.stub(:update_attributes){ false }
124
148
  end
125
149
 
126
150
  it "re-renders the 'edit' template" do
127
- Event.stub(:find).and_return(mock_event(:update_attributes => false))
128
- put :update, :id => "1", :event => { 'these' => 'params'}
151
+ put :update, params
129
152
  response.should render_template('edit')
130
153
  end
131
154
  end
@@ -134,15 +157,13 @@ describe EventsController do
134
157
 
135
158
  describe "DELETE destroy" do
136
159
  it "destroys the requested event" do
137
- Event.should_receive(:find).with("37").and_return(mock_event)
138
- mock_event.should_receive(:destroy)
139
- delete :destroy, :id => "37"
160
+ event.should_receive(:destroy)
161
+ delete :destroy, params
140
162
  end
141
163
 
142
164
  it "redirects to the events list" do
143
- Event.stub(:find).and_return(mock_event(:destroy => true))
144
- delete :destroy, :id => "1"
145
- response.should redirect_to(events_url)
165
+ delete :destroy, params
166
+ response.should redirect_to events_url
146
167
  end
147
168
  end
148
169
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_calendar_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason LaPier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-23 00:00:00 -08:00
19
+ date: 2011-01-06 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -445,6 +445,8 @@ files:
445
445
  - db/migrate/20101011142543_create_events.rb
446
446
  - db/migrate/20101011172027_create_attendees.rb
447
447
  - db/migrate/20101011200048_make_events_revisable.rb
448
+ - db/migrate/20101223221015_change_start_on_end_on_to_timestamp.rb
449
+ - db/migrate/20101223233354_add_timezone_to_events.rb
448
450
  - db/schema.rb
449
451
  - db/seeds.rb
450
452
  - lib/event_calendar.rb