diff --git a/spec/factories.rb b/spec/factories.rb index 1c74856eb..323d6c971 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -49,6 +49,7 @@ FactoryGirl.define do factory :connection, :class => JamRuby::Connection do sequence(:client_id) { |n| "Client#{n}" } + ip_address "1.1.1.1" as_musician true end diff --git a/spec/requests/music_sessions_api_spec.rb b/spec/requests/music_sessions_api_spec.rb index 3ba604daf..5e9e8c636 100644 --- a/spec/requests/music_sessions_api_spec.rb +++ b/spec/requests/music_sessions_api_spec.rb @@ -499,6 +499,47 @@ describe "Music Session API ", :type => :api do post "/api/sessions/#{music_session["id"]}/participants.json", { :client_id => client2.client_id, :as_musician => true, :tracks => [{"instrument_id" => "bass guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(201) end + + + + it "should allow create session and join session for creator" do + # this test was created to stop duplication of tracks + # but ultimately it should be fine to create a session, and then 'join' it with no ill effects + # https://jamkazam.atlassian.net/browse/VRFS-254 + client = FactoryGirl.create(:connection, :user => user) + post '/api/sessions.json', defopts.merge({:client_id => client.client_id}).to_json, "CONTENT_TYPE" => 'application/json' + last_response.status.should eql(201) + + # now fetch it's data + location_header = last_response.headers["Location"] + get location_header + music_session = JSON.parse(last_response.body) + + get "/api/sessions/#{music_session["id"]}.json" + last_response.status.should eql(200) + music_session["participants"].length.should == 1 + participant = music_session["participants"][0] + participant["client_id"].should == client.client_id + participant["tracks"].length.should == 1 + track = participant["tracks"][0] + track["instrument_id"].should == "electric guitar" + track["sound"].should == "mono" + + + post "/api/sessions/#{music_session["id"]}/participants.json", { :client_id => client.client_id, :as_musician => true, :tracks => [{"instrument_id" => "electric guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json' + + last_response.status.should eql(201) + + get "/api/sessions/#{music_session["id"]}.json" + music_session = JSON.parse(last_response.body) + music_session["participants"].length.should == 1 + participant = music_session["participants"][0] + participant["client_id"].should == client.client_id + participant["tracks"].length.should == 1 # there should only be one track, still + track = participant["tracks"][0] + track["instrument_id"].should == "electric guitar" + track["sound"].should == "mono" + end end it "Finds a single open session" do