* VRFS-28; raising Rollback exception to cause transaction to rollback in music_session_controller create
This commit is contained in:
parent
072be0062f
commit
e457f45dc6
|
|
@ -47,7 +47,6 @@ class ApiMusicSessionsController < ApplicationController
|
|||
@music_session.description = params[:description]
|
||||
genres = params[:genres]
|
||||
|
||||
|
||||
unless genres.nil?
|
||||
genres.each do |genre|
|
||||
loaded_genre = Genre.find_by_description!(genre)
|
||||
|
|
@ -55,11 +54,14 @@ class ApiMusicSessionsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
saved = @music_session.save
|
||||
@music_session.save
|
||||
|
||||
if saved
|
||||
unless @music_session.errors.any?
|
||||
# auto-join this user into the newly created session
|
||||
connection_manager.join_music_session(current_user.id, client_id, @music_session.id)
|
||||
else
|
||||
# rollback the transaction to make sure nothing is disturbed in the database
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -103,9 +103,12 @@ describe "Music Session API ", :type => :api do
|
|||
|
||||
it "should error with no genre specified" do
|
||||
# create the session
|
||||
original_count = MusicSession.all().length
|
||||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "3")
|
||||
post '/api/sessions.json', '{"description" : "a session", "client_id" : "' + client.client_id + '"}', "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(422)
|
||||
MusicSession.all().length.should == original_count
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -114,7 +117,6 @@ describe "Music Session API ", :type => :api do
|
|||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "3")
|
||||
post '/api/sessions.json', '{"description" : "a session", "client_id" : "' + client.client_id + '", "genres" : ["Junk"]}', "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(404)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue