* list sessions has correct sort order VRFS-31
This commit is contained in:
parent
6925eb89c3
commit
1c095f77f2
|
|
@ -65,7 +65,7 @@ class ApiInvitationsController < ApiController
|
|||
end
|
||||
|
||||
def delete
|
||||
@invitation = Invitation.find(params[:id], :conditions => ["receiver_id = ? or sender_id = ?", current_user.id, current_user.id])
|
||||
@invitation = Invitation.find(params[:id], :conditions => ["sender_id = ?", current_user.id])
|
||||
@invitation.delete
|
||||
|
||||
respond_with @invitation, responder => ApiResponder
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class ApiMusicSessionsController < ApiController
|
||||
|
||||
|
||||
# have to be signed in currently to see this screen
|
||||
before_filter :signed_in_user
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ class ApiMusicSessionsController < ApiController
|
|||
end
|
||||
|
||||
def index
|
||||
@music_sessions = MusicSession.paginate(page: params[:page])
|
||||
@music_sessions = MusicSession.index(current_user)
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
@ -27,6 +27,7 @@ class ApiMusicSessionsController < ApiController
|
|||
@music_session = MusicSession.new()
|
||||
@music_session.creator = current_user
|
||||
@music_session.description = params[:description]
|
||||
@music_session.musician_access = params[:musician_access]
|
||||
genres = params[:genres]
|
||||
|
||||
unless genres.nil?
|
||||
|
|
@ -35,7 +36,7 @@ class ApiMusicSessionsController < ApiController
|
|||
@music_session.genres << loaded_genre
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@music_session.save
|
||||
|
||||
unless @music_session.errors.any?
|
||||
|
|
@ -58,10 +59,19 @@ class ApiMusicSessionsController < ApiController
|
|||
|
||||
def show
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
unless @music_session.can_see? current_user
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
unless @music_session.can_delete? current_user
|
||||
raise ActiveRecord::RecordNotound
|
||||
end
|
||||
|
||||
@music_session.delete
|
||||
|
||||
respond_with @music_session, responder: ApiResponder
|
||||
|
|
@ -78,10 +88,6 @@ class ApiMusicSessionsController < ApiController
|
|||
ConnectionManager.active_record_transaction do |connection_manager|
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
if @music_session.nil?
|
||||
raise JamArgumentError, "no session found"
|
||||
end
|
||||
|
||||
client_id = params[:client_id]
|
||||
|
||||
connection_manager.join_music_session(current_user.id, client_id, @music_session.id)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
object @music_session
|
||||
|
||||
attributes :id, :description
|
||||
attributes :id, :description, :musician_access
|
||||
|
||||
node :genres do |item|
|
||||
item.genres.map(&:description)
|
||||
|
|
@ -9,4 +9,12 @@ end
|
|||
child(:connections => :participants) {
|
||||
collection @music_sessions, :object_root => false
|
||||
attributes :ip_address, :client_id
|
||||
node(:user_id, :if => lambda { |connection| connection.user.friends?(current_user) }) do |connection|
|
||||
connection.user_id
|
||||
end
|
||||
}
|
||||
|
||||
child(:invitations => :invitations) {
|
||||
collection @music_sessions, :object_root => false
|
||||
attributes :id, :sender_id
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ FactoryGirl.define do
|
|||
|
||||
factory :music_session, :class => JamRuby::MusicSession do
|
||||
sequence(:description) { |n| "Music Session #{n}" }
|
||||
musician_access true
|
||||
end
|
||||
|
||||
factory :connection, :class => JamRuby::Connection do
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ describe "Invitation API ", :type => :api do
|
|||
|
||||
other_user = FactoryGirl.create(:user) # in the music session
|
||||
# starting condition; valid session and current user is already in it
|
||||
music_session = FactoryGirl.create(:music_session, :creator => other_user)
|
||||
music_session = FactoryGirl.create(:music_session, :creator => user)
|
||||
FactoryGirl.create(:connection, :user => other_user, :music_session => music_session)
|
||||
FactoryGirl.create(:connection, :user => user, :music_session => music_session)
|
||||
FactoryGirl.create(:friendship, :user => user, :friend => other_user)
|
||||
|
|
@ -166,7 +166,6 @@ describe "Invitation API ", :type => :api do
|
|||
FactoryGirl.create(:friendship, :user => other_user, :friend => other_user2)
|
||||
invitation = FactoryGirl.create(:invitation, :sender => other_user2, :receiver => other_user, :music_session => music_session)
|
||||
|
||||
|
||||
# then check that there is one invitation sent by us
|
||||
get '/api/invitations.json?sender=' + other_user.id
|
||||
last_response.status.should eql(500)
|
||||
|
|
|
|||
|
|
@ -6,14 +6,18 @@ describe "Music Session API ", :type => :api do
|
|||
|
||||
subject { page }
|
||||
|
||||
def login(user)
|
||||
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
|
||||
rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
|
||||
end
|
||||
|
||||
describe "profile page" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
#sign_in user
|
||||
MusicSession.delete_all
|
||||
|
||||
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
|
||||
rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
|
||||
login(user)
|
||||
end
|
||||
|
||||
it "should list no sessions" do
|
||||
|
|
@ -26,7 +30,7 @@ describe "Music Session API ", :type => :api do
|
|||
# create a client connection
|
||||
|
||||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "1")
|
||||
post '/api/sessions.json', '{"description" : "a session", "client_id" : "' + client.client_id + '", "genres" : ["Classical"]}', "CONTENT_TYPE" => 'application/json'
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Classical"], :musician_access => true}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
|
||||
# now fetch it's data
|
||||
|
|
@ -37,6 +41,10 @@ describe "Music Session API ", :type => :api do
|
|||
list = JSON.parse(last_response.body)
|
||||
|
||||
list[0]["id"].should == music_session["id"]
|
||||
list[0]["musician_access"].should == true
|
||||
list[0]["invitations"].should == []
|
||||
list[0]["participants"].length.should == 1
|
||||
list[0]["participants"][0].should == {"ip_address" => "1.1.1.1", "client_id" => "1"}
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -48,7 +56,7 @@ describe "Music Session API ", :type => :api do
|
|||
|
||||
# create the session
|
||||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "2")
|
||||
post '/api/sessions.json', '{"description" : "a session", "client_id" : "' + client.client_id + '", "genres" : ["Classical"]}', "CONTENT_TYPE" => 'application/json'
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Classical"], :musician_access => true}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
|
||||
# now fetch it's data
|
||||
|
|
@ -71,7 +79,7 @@ describe "Music Session API ", :type => :api do
|
|||
it "should add/remove member from session" do
|
||||
# create the session
|
||||
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" : ["Classical"]}', "CONTENT_TYPE" => 'application/json'
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Classical"], :musician_access => true}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
|
||||
# now fetch it's data
|
||||
|
|
@ -105,7 +113,7 @@ describe "Music Session API ", :type => :api 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'
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :musician_access => true}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(422)
|
||||
MusicSession.all().length.should == original_count
|
||||
|
||||
|
|
@ -115,10 +123,100 @@ describe "Music Session API ", :type => :api do
|
|||
it "should error with invalid genre specified" do
|
||||
# create the session
|
||||
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'
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Junk"], :musician_access => true}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(404)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
it "can see user_id of friend in session" do
|
||||
# create the session
|
||||
user2 = FactoryGirl.create(:user) # in the music session
|
||||
|
||||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "6")
|
||||
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Classical"], :musician_access => false}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
session = JSON.parse(last_response.body)
|
||||
|
||||
FactoryGirl.create(:friendship, :user => user, :friend => user2)
|
||||
FactoryGirl.create(:friendship, :user => user2, :friend => user)
|
||||
|
||||
login(user2)
|
||||
get '/api/sessions.json'
|
||||
last_response.status.should eql(200)
|
||||
list = JSON.parse(last_response.body)
|
||||
|
||||
|
||||
list[0]["id"].should == session["id"]
|
||||
list[0]["musician_access"].should == false
|
||||
list[0]["invitations"].should == []
|
||||
list[0]["participants"].length.should == 1
|
||||
list[0]["participants"][0].should == {"ip_address" => "1.1.1.1", "client_id" => "6", "user_id" => user.id}
|
||||
end
|
||||
|
||||
it "can see invitation_id associatied with hidden session" do
|
||||
# create the session
|
||||
user2 = FactoryGirl.create(:user) # in the music session
|
||||
|
||||
client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1", :client_id => "7")
|
||||
|
||||
post '/api/sessions.json', { :description => "a session", :client_id => client.client_id, :genres => ["Classical"], :musician_access => false}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
session = JSON.parse(last_response.body)
|
||||
|
||||
FactoryGirl.create(:friendship, :user => user, :friend => user2)
|
||||
FactoryGirl.create(:friendship, :user => user2, :friend => user)
|
||||
invitation = FactoryGirl.create(:invitation, :sender => user, :receiver => user2, :music_session_id => session["id"] )
|
||||
|
||||
login(user2)
|
||||
get '/api/sessions.json'
|
||||
last_response.status.should eql(200)
|
||||
list = JSON.parse(last_response.body)
|
||||
|
||||
|
||||
list[0]["id"].should == session["id"]
|
||||
list[0]["musician_access"].should == false
|
||||
list[0]["invitations"].length.should == 1
|
||||
list[0]["invitations"][0]["id"].should == invitation.id
|
||||
list[0]["participants"].length.should == 1
|
||||
list[0]["participants"][0].should == {"ip_address" => "1.1.1.1", "client_id" => "7", "user_id" => user.id}
|
||||
end
|
||||
|
||||
|
||||
|
||||
it "can't join closed music session with no invitation" do
|
||||
# create the session
|
||||
user2 = FactoryGirl.create(:user) # in the music session
|
||||
|
||||
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 => ["Classical"], :musician_access => false}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
session = JSON.parse(last_response.body)
|
||||
|
||||
client2 = FactoryGirl.create(:connection, :user => user2)
|
||||
|
||||
FactoryGirl.create(:friendship, :user => user, :friend => user2)
|
||||
FactoryGirl.create(:friendship, :user => user2, :friend => user)
|
||||
|
||||
# users are friends, but no invitation... so we shouldn't be able to join as user 2
|
||||
login(user2)
|
||||
post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id }.to_json
|
||||
last_response.status.should eql(500)
|
||||
join_response = JSON.parse(last_response.body)
|
||||
join_response["type"].should == "PermissionError"
|
||||
|
||||
# but let's make sure if we then invite, that we can then join'
|
||||
login(user)
|
||||
post '/api/invitations.json', { :music_session => session["id"], :receiver => user2.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
|
||||
login(user2)
|
||||
post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue