fixing time zone issue

pull/1/head
Jared Cosulich 9 years ago
parent 1e5c7fb5bf
commit 7602258da3

@ -3,6 +3,7 @@ class SchedulesController < ApplicationController
before_action :set_school
before_action :verify_admin
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
before_action :set_time, only: [:create, :update]
# GET schools/1/schedules/1
def show
@ -56,7 +57,12 @@ class SchedulesController < ApplicationController
# Only allow a trusted parameter "white list" through.
def schedule_params
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id)
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id)
end
def set_time
return unless schedule_params.include?(:time)
params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER)
end
end

@ -42,7 +42,8 @@ RSpec.describe SchedulesController, type: :controller do
recipient_list_id: recipient_list.id,
question_list_id: question_list.id,
name: 'Parents Schedule',
description: 'Schedule for parent questions'
description: 'Schedule for parent questions',
time: (8 * 60)
}
}
@ -97,6 +98,12 @@ RSpec.describe SchedulesController, type: :controller do
expect(assigns(:schedule)).to be_persisted
end
it "updates the schedule's time to UTC from EST" do
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
expect(assigns(:schedule)).to be_a(Schedule)
expect(assigns(:schedule).time).to eq(60 * 12)
end
it "redirects to the created schedule" do
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
expect(response).to redirect_to([school, Schedule.last])

@ -50,7 +50,7 @@ describe "survey:attempt_questions" do
describe 'First attempt not at specified time' do
before :each do
now = DateTime.now
date = ActiveSupport::TimeZone["America/New_York"].parse(now.strftime("%Y-%m-%dT19:00:00%z"))
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z"))
Timecop.freeze(date) { subject.invoke }
end
@ -64,7 +64,7 @@ describe "survey:attempt_questions" do
before :each do
now = DateTime.now
date = ActiveSupport::TimeZone["America/New_York"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
Timecop.freeze(date) { subject.invoke }
end
@ -126,7 +126,7 @@ describe "survey:attempt_questions" do
recipients[1].update_attributes(opted_out: true)
now = DateTime.now
date = ActiveSupport::TimeZone["America/New_York"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
Timecop.freeze(date) { subject.invoke }
end

@ -40,7 +40,7 @@ RSpec.describe RecipientSchedule, type: :model do
describe 'ready' do
before :each do
now = DateTime.now
date = ActiveSupport::TimeZone["America/New_York"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
Timecop.freeze(date)
end
@ -103,7 +103,7 @@ RSpec.describe RecipientSchedule, type: :model do
it 'should update next_attempt_at' do
now = DateTime.now
date = ActiveSupport::TimeZone["America/New_York"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
time = date.to_time.to_i + (60 * 60 * 24 * 7)
expect(recipient_schedule.next_attempt_at.to_i).to eq(time)

Loading…
Cancel
Save