* VRFS-1869 - use offset

This commit is contained in:
Seth Call 2014-07-10 22:08:03 -05:00
parent 74b2f19460
commit 55aea1109f
3 changed files with 65 additions and 5 deletions

View File

@ -263,7 +263,6 @@ module JamRuby
ms.band = band
ms.legal_policy = options[:legal_policy]
ms.language = options[:language]
ms.scheduled_start = options[:start]
ms.scheduled_duration = options[:duration].to_i * 1.minutes if options[:duration]
ms.recurring_mode = options[:recurring_mode] if options[:recurring_mode]
ms.timezone = options[:timezone] if options[:timezone]
@ -271,6 +270,8 @@ module JamRuby
ms.open_rsvps = options[:open_rsvps] if options[:open_rsvps]
ms.creator = user
ms.is_unstructured_rsvp = options[:isUnstructuredRsvp] if options[:isUnstructuredRsvp]
ms.scheduled_start = options[:start]
ms.scheduled_start = parse_scheduled_start(ms.scheduled_start, ms.timezone)
ms.save
@ -707,6 +708,23 @@ module JamRuby
[music_sessions, user_scores]
end
# converts the passed scheduled_start into the UTC using the specified timezone offset.
# timezone comes in as TIMEZONE DISPLAY, TIMEZONE ID
def self.parse_scheduled_start(scheduled_start, timezone_param)
result = scheduled_start
if timezone_param
index = timezone_param.rindex(',')
if index
tz_identifier = timezone_param[(index + 1)..-1]
timezone = TZInfo::Timezone.get(tz_identifier)
result = timezone.local_to_utc(scheduled_start, true)
end
end
result
end
private
def generate_share_token

View File

@ -47,6 +47,32 @@ describe MusicSession do
end
end
describe "create" do
it "scheduled session" do
session = MusicSession.create(creator, {
name: "session 1",
description: "my session",
genres: ['ambient'],
musician_access: true,
fan_access: true,
approval_required: true,
fan_chat: true,
legal_policy: 'Standard',
language: 'eng',
start: "Thu Jul 10 2014 10:00 PM",
timezone: "Central Time (US & Canada),America/Chicago",
open_rsvps: true,
legal_terms: true,
recurring_mode: 'once',
isUnstructuredRsvp: true,
rsvp_slots: [{ instrument_id: "other", proficiency_level: 1, approve: true}]
})
session.valid?.should be_true
# verify that scheduled_start is now 5 hours ahead of what was specified (CST during summer is -5 offset)
session.scheduled_start.utc.should == DateTime.new(2014,07,11,3,00,0)
end
end
describe "nindex" do
it "nindex orders two sessions by created_at starting with most recent" do
creator = FactoryGirl.create(:user)
@ -266,6 +292,23 @@ describe MusicSession do
end
end
describe "parse_scheduled_start" do
it "converts correctly" do
# CST has -5 offset in summery
time = DateTime.new(2004,10,15,1,30,0)
converted = MusicSession.parse_scheduled_start(time, 'Central Time (US & Canada),America/Chicago')
converted.should == DateTime.new(2004,10,15,6,30,0)
# CST has -6 offset in winter
time = DateTime.new(2004,11,15,1,30,0)
converted = MusicSession.parse_scheduled_start(time, 'Central Time (US & Canada),America/Chicago')
converted.should == DateTime.new(2004,11,15,7,30,0)
end
end
describe "scheduled" do
it "excludes based on time-range" do
session = FactoryGirl.create(:music_session, scheduled_start: Time.now)

View File

@ -94,15 +94,14 @@ describe "Scheduled Music Session API ", :type => :api do
last_response.status.should eql(201)
delete "/api/sessions/#{music_sessions[0]["id"]}.json"
last_response.status.should eql(404)
JSON.parse(last_response.body)["message"].should == ValidationMessages::PERMISSION_VALIDATION_ERROR
last_response.status.should eql(204)
delete "/api/sessions/#{music_sessions[1]["id"]}.json"
last_response.status.should eql(204)
login(user2)
delete "/api/sessions/#{music_sessions[2]["id"]}.json"
last_response.status.should eql(404)
last_response.status.should eql(403)
JSON.parse(last_response.body)["message"].should == ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@ -126,7 +125,7 @@ describe "Scheduled Music Session API ", :type => :api do
login(user2)
post "/api/sessions/#{music_session["id"]}.json", {:name => "changed name"}.to_json
last_response.status.should eql(404)
last_response.status.should eql(403)
JSON.parse(last_response.body)["message"].should == ValidationMessages::PERMISSION_VALIDATION_ERROR
end
end