event_calendar_engine 0.2.1 → 0.2.2

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.1
1
+ 0.2.2
@@ -106,7 +106,7 @@ class EventsController < EventCalendar::ApplicationController
106
106
  # POST /events.xml
107
107
  def create
108
108
  @event = Event.new(params[:event])
109
-
109
+ @event.adjust_to_utc = true
110
110
  respond_to do |format|
111
111
  if @event.save
112
112
  flash[:notice] = 'Event was successfully created.'
@@ -124,7 +124,7 @@ class EventsController < EventCalendar::ApplicationController
124
124
  # PUT /events/1.xml
125
125
  def update
126
126
  @event = Event.find(params[:id])
127
-
127
+ @event.adjust_to_utc = true
128
128
  respond_to do |format|
129
129
  if @event.update_attributes(params[:event])
130
130
  flash[:notice] = 'Event was successfully updated.'
@@ -11,14 +11,6 @@ module EventCalendar::ApplicationHelper
11
11
  link_text = link_options.delete(:link_text) || path
12
12
  highlight = wrapper_options.delete(:highlight)
13
13
 
14
- unless path.blank?
15
- if current_page?(path) && (highlight.nil? || highlight)
16
- wrapper_options.merge!({
17
- :class => (wrapper_options[:class] || '') + " nav_highlight"
18
- })
19
- end
20
- end
21
-
22
14
  unless wrapper_options.delete(:no_wrapper)
23
15
  return content_tag(tag, wrapper_options) do
24
16
  link_to(link_text, path, link_options)
@@ -145,6 +137,14 @@ module EventCalendar::ApplicationHelper
145
137
  }.merge!(link_options))
146
138
  end
147
139
 
140
+ def link_to_new_link(event, wrapper_options={}, link_options={})
141
+ return unless has_authorization?(:create, Link.new)
142
+ link_wrapper(new_event_link_path(event), wrapper_options, {
143
+ :link_text => 'New link',
144
+ :class => 'fake_button'
145
+ }.merge!(link_options))
146
+ end
147
+
148
148
  def link_to_edit_link(event, link, wrapper_options={}, link_options={})
149
149
  return unless has_authorization?(:update, link)
150
150
  link_wrapper(edit_event_link_path(event, link), {
data/app/models/event.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  class Event < ActiveRecord::Base
2
2
  set_table_name "event_calendar_events"
3
3
 
4
+ attr_accessor :adjust_to_utc
5
+
4
6
  include ActionView::Helpers::TextHelper
5
7
 
6
8
  include EventInstanceMethods
@@ -44,7 +46,7 @@ class Event < ActiveRecord::Base
44
46
  end
45
47
 
46
48
  def adjust_to_utc_from_timezone
47
- return true if deleted?
49
+ return true unless adjust_to_utc
48
50
  tz_offset = start_on.in_time_zone(timezone).utc_offset
49
51
  self.start_on = self.start_on - tz_offset
50
52
  self.end_on = self.end_on - tz_offset
@@ -1,6 +1,6 @@
1
1
  <p><strong>Materials/Resources</strong></p>
2
2
  <div id="links" class="links">
3
3
  <%= render @event.links.all %>
4
- <p class="new"><%= link_to 'New Link', new_event_link_path(@event), :class => 'fake_button' %></p>
4
+ <%= link_to_new_link(@event, {:class => 'new'}) %>
5
5
  <%= render :partial => 'links/form' %>
6
6
  </div>
@@ -11,7 +11,8 @@ describe EventsController do
11
11
  :timezone => 'Pacific Time (US & Canada)',
12
12
  :description => 'Some Description',
13
13
  :location => 'Some City',
14
- :links => mock('Relation', :build => mock_model(Link))
14
+ :links => mock('Relation', :build => mock_model(Link)),
15
+ :adjust_to_utc= => nil
15
16
  })
16
17
  end
17
18
  let(:params) do
@@ -78,6 +79,7 @@ describe EventsController do
78
79
  end
79
80
  before(:each) do
80
81
  event.stub(:save){ true }
82
+ event.stub(:adjust_to_utc=){ true }
81
83
  subject.stub(:new){ event }
82
84
  end
83
85
  describe "with valid params" do
@@ -85,7 +87,10 @@ describe EventsController do
85
87
  post :create, params
86
88
  assigns(:event).should eq event
87
89
  end
88
-
90
+ it "sets adjust_to_utc to true" do
91
+ event.should_receive(:adjust_to_utc=).with(true)
92
+ post :create, params
93
+ end
89
94
  it "redirects to the created event" do
90
95
  post :create, params
91
96
  response.should redirect_to event_url event
@@ -122,13 +127,21 @@ describe EventsController do
122
127
  before(:each) do
123
128
  subject.stub(:find).with("37"){ event }
124
129
  event.stub(:update_attributes){ nil }
125
- end
126
- it "updates the requested event" do
130
+ event.stub(:adjust_to_utc=){ true }
131
+ end
132
+ it "loads the @event" do
127
133
  Event.should_receive(:find).with("37"){ event }
134
+ put :update, params
135
+ assigns(:event).should eq event
136
+ end
137
+ it "sets adjust_to_utc to true" do
138
+ event.should_receive(:adjust_to_utc=).with(true)
139
+ put :update, params
140
+ end
141
+ it "updates the requested event" do
128
142
  event.should_receive(:update_attributes)
129
143
  put :update, params
130
144
  end
131
-
132
145
  it "assigns the requested event as @event" do
133
146
  put :update, params
134
147
  assigns(:event).should eq event
@@ -15,4 +15,13 @@ restorable_event:
15
15
  location: "Portland, Oregon"
16
16
  start_on: 2011-02-04 14:00:00.000000
17
17
  end_on: 2011-02-04 15:00:00.000000
18
+ timezone: 'Pacific Time (US & Canada)'
19
+
20
+ linkable_event:
21
+ id: <%= Fixtures.identify :linkable_event %>
22
+ name: Linkable Event
23
+ event_type: Meeting
24
+ location: "Portland, Oregon"
25
+ start_on: 2011-02-04 14:00:00.000000
26
+ end_on: 2011-02-04 15:00:00.000000
18
27
  timezone: 'Pacific Time (US & Canada)'
@@ -1,3 +1,3 @@
1
- editable_event_editable_link:
2
- event_id: <%= Fixtures.identify :editable_event %>
1
+ linkable_event_editable_link:
2
+ event_id: <%= Fixtures.identify :linkable_event %>
3
3
  link_id: <%= Fixtures.identify :editable_link %>
@@ -48,29 +48,23 @@ describe Event do
48
48
  event.should_not be_valid
49
49
  end
50
50
 
51
- context "setting default end_on of start_on + 1.hour if start_on is present and" do
52
- before(:each) do
53
- Time.zone = 'Pacific Time (US & Canada)'
54
- end
55
- let(:event) do
56
- Event.new(@valid_attributes.merge!({
57
- :timezone => 'Pacific Time (US & Canada)',
58
- :start_on => 1.hour.from_now,
59
- :end_on => nil
60
- }))
61
- end
62
-
63
- it "end_on is blank" do
64
- event.one_day?.should be_true
65
- event.valid?
66
- event.end_on.should eq event.start_on + 1.hour
67
- end
68
- it "end_on <= start_on" do
69
- event.end_on = 4.hours.ago
70
- event.one_day?.should be_true
71
- event.valid?
72
- event.end_on.should eq event.start_on + 1.hour
73
- end
51
+ it "adjusts start_on and end_on to utc from timezone when adjust_to_utc == true" do
52
+ Time.zone = 'Pacific Time (US & Canada)' # mimic default rails behavior
53
+ f = '%A %B %d %Y @ %H%M'
54
+ pac_start = 2.hours.from_now
55
+ pac_end = 4.hours.from_now
56
+ event = Event.new(@valid_attributes.merge!({
57
+ :timezone => 'Pacific Time (US & Canada)',
58
+ :start_on => pac_start,
59
+ :end_on => pac_end
60
+ }))
61
+ event.save!
62
+ event.start_on.strftime(f).should eq pac_start.strftime(f)
63
+ event.end_on.strftime(f).should eq pac_end.strftime(f)
64
+ event.adjust_to_utc = true
65
+ event.save!
66
+ event.start_on.strftime(f).should eq pac_start.utc.strftime(f)
67
+ event.end_on.strftime(f).should eq pac_end.utc.strftime(f)
74
68
  end
75
69
 
76
70
  it "should find event types" do
@@ -101,5 +95,28 @@ describe Event do
101
95
  event.save
102
96
  event.revision_number.should == 0
103
97
  end
104
-
98
+ context "setting default end_on of start_on + 1.hour if start_on is present and" do
99
+ before(:each) do
100
+ Time.zone = 'Pacific Time (US & Canada)'
101
+ end
102
+ let(:event) do
103
+ Event.new(@valid_attributes.merge!({
104
+ :timezone => 'Pacific Time (US & Canada)',
105
+ :start_on => 1.hour.from_now,
106
+ :end_on => nil
107
+ }))
108
+ end
109
+
110
+ it "end_on is blank" do
111
+ event.one_day?.should be_true
112
+ event.valid?
113
+ event.end_on.should eq event.start_on + 1.hour
114
+ end
115
+ it "end_on <= start_on" do
116
+ event.end_on = 4.hours.ago
117
+ event.one_day?.should be_true
118
+ event.valid?
119
+ event.end_on.should eq event.start_on + 1.hour
120
+ end
121
+ end
105
122
  end
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: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
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: 2011-02-06 00:00:00 -08:00
19
+ date: 2011-02-07 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency