VRFS-3276 : Hook calendar creation into user controller API. Add test to verify.
This commit is contained in:
parent
3a35002a46
commit
8023d6481c
|
|
@ -701,6 +701,20 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
# Build calendars using given parameter.
|
||||
# @param calendars (array of hash)
|
||||
def update_calendars(calendars)
|
||||
unless self.new_record?
|
||||
Calendar.where("user_id = ?", self.id).delete_all
|
||||
end
|
||||
|
||||
unless calendars.nil?
|
||||
calendars.each do |cal|
|
||||
self.calendars << self.calendars.create(cal)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# given an array of instruments, update a user's instruments
|
||||
def update_instruments(instruments)
|
||||
# delete all instruments for this user first
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class ApiUsersController < ApiController
|
|||
|
||||
@user.update_online_presences(params[:online_presences]) if params.has_key?(:online_presences)
|
||||
@user.update_performance_samples(params[:performance_samples]) if params.has_key?(:performance_samples)
|
||||
|
||||
@user.update_calendars(params[:calendars]) if params.has_key?(:calendars)
|
||||
@user.save
|
||||
|
||||
if @user.errors.any?
|
||||
|
|
|
|||
|
|
@ -59,6 +59,27 @@ describe ApiUsersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "calendars" do
|
||||
before :each do
|
||||
Calendar.destroy_all
|
||||
end
|
||||
|
||||
it "adds calendar via update" do
|
||||
cals = [{
|
||||
:name=>"Test Cal",
|
||||
:description=>"This is a test",
|
||||
:start_at=>(Time.now),
|
||||
:end_at=>Time.now,
|
||||
:trigger_delete=>true,
|
||||
:target_uid=>"2112"
|
||||
}]
|
||||
post :update, id:user.id, calendars: cals, :format=>'json'
|
||||
response.should be_success
|
||||
user.reload
|
||||
user.calendars.should have(1).items
|
||||
end
|
||||
end
|
||||
|
||||
describe "update mod" do
|
||||
it "empty mod" do
|
||||
post :update, id:user.id, mods: {}, :format=>'json'
|
||||
|
|
@ -83,13 +104,13 @@ describe ApiUsersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'site validation' do
|
||||
describe 'site validation' do
|
||||
|
||||
it 'checks valid and invalid site types' do
|
||||
it 'checks valid and invalid site types' do
|
||||
site_types = Utils::SITE_TYPES.clone << 'bandcamp-fan'
|
||||
site_types.each do |sitetype|
|
||||
rec_id = nil
|
||||
case sitetype
|
||||
case sitetype
|
||||
when 'url'
|
||||
valid, invalid = 'http://jamkazam.com', 'http://jamkazamxxx.com'
|
||||
when 'youtube'
|
||||
|
|
|
|||
Loading…
Reference in New Issue