trying to fix tests
This commit is contained in:
parent
5ba98b93ab
commit
a1828cd93d
|
|
@ -1,9 +1,9 @@
|
||||||
alter table music_sessions_comments drop constraint music_sessions_comments_music_session_id_fkey;
|
-- alter table music_sessions_comments drop constraint music_sessions_comments_music_session_id_fkey;
|
||||||
alter table music_sessions_comments add constraint ms_comments_ms_history_fkey foreign key (music_session_id)
|
alter table music_sessions_comments add constraint ms_comments_ms_history_fkey foreign key (music_session_id)
|
||||||
references music_sessions_history(music_session_id) match simple
|
references music_sessions_history(music_session_id) match simple
|
||||||
ON UPDATE NO ACTION ON DELETE CASCADE;
|
ON UPDATE NO ACTION ON DELETE CASCADE;
|
||||||
|
|
||||||
alter table music_sessions_likers drop constraint music_sessions_likers_music_session_id_fkey;
|
-- alter table music_sessions_likers drop constraint music_sessions_likers_music_session_id_fkey;
|
||||||
alter table music_sessions_likers add constraint ms_likers_ms_history_fkey foreign key (music_session_id)
|
alter table music_sessions_likers add constraint ms_likers_ms_history_fkey foreign key (music_session_id)
|
||||||
references music_sessions_history(music_session_id) match simple
|
references music_sessions_history(music_session_id) match simple
|
||||||
ON UPDATE NO ACTION ON DELETE CASCADE;
|
ON UPDATE NO ACTION ON DELETE CASCADE;
|
||||||
|
|
@ -579,7 +579,7 @@ module JamRuby
|
||||||
Follow.delete_all "(user_id = '#{followerId}' AND followable_id = '#{targetEntityId}')"
|
Follow.delete_all "(user_id = '#{followerId}' AND followable_id = '#{targetEntityId}')"
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_user_like(targetUserId)
|
def create_user_liking(targetUserId)
|
||||||
targetUser = User.find(targetUserId)
|
targetUser = User.find(targetUserId)
|
||||||
|
|
||||||
like = Like.new
|
like = Like.new
|
||||||
|
|
@ -588,7 +588,7 @@ module JamRuby
|
||||||
like.save
|
like.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_band_like(targetBandId)
|
def create_band_liking(targetBandId)
|
||||||
targetBand = Band.find(targetBandId)
|
targetBand = Band.find(targetBandId)
|
||||||
|
|
||||||
like = Like.new
|
like = Like.new
|
||||||
|
|
@ -597,28 +597,28 @@ module JamRuby
|
||||||
like.save
|
like.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_session_like(targetSessionId)
|
def self.delete_liking(likerId, targetEntityId)
|
||||||
targetSession = MusicSessionHistory.find(targetSessionId)
|
|
||||||
|
|
||||||
like = Like.new
|
|
||||||
like.likable = targetSession
|
|
||||||
like.user = self
|
|
||||||
like.save
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_recording_like(targetRecordingId)
|
|
||||||
targetRecording = Recording.find(targetRecordingId)
|
|
||||||
|
|
||||||
like = Like.new
|
|
||||||
like.likable = targetRecording
|
|
||||||
like.user = self
|
|
||||||
like.save
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.delete_like(likerId, targetEntityId)
|
|
||||||
Like.delete_all "(user_id = '#{liker_id}' AND likable_id = '#{targetEntityId}')"
|
Like.delete_all "(user_id = '#{liker_id}' AND likable_id = '#{targetEntityId}')"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def create_session_like(targetSessionId)
|
||||||
|
# targetSession = MusicSessionHistory.find(targetSessionId)
|
||||||
|
|
||||||
|
# like = Like.new
|
||||||
|
# like.likable = targetSession
|
||||||
|
# like.user = self
|
||||||
|
# like.save
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def create_recording_like(targetRecordingId)
|
||||||
|
# targetRecording = Recording.find(targetRecordingId)
|
||||||
|
|
||||||
|
# like = Like.new
|
||||||
|
# like.likable = targetRecording
|
||||||
|
# like.user = self
|
||||||
|
# like.save
|
||||||
|
# end
|
||||||
|
|
||||||
def self.finalize_update_email(update_email_token)
|
def self.finalize_update_email(update_email_token)
|
||||||
# updates the user model to have a new email address
|
# updates the user model to have a new email address
|
||||||
user = User.find_by_update_email_token!(update_email_token)
|
user = User.find_by_update_email_token!(update_email_token)
|
||||||
|
|
|
||||||
|
|
@ -424,14 +424,22 @@
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
url: "/api/users/" + id + "/likes",
|
url: "/api/users/" + id + "/likings",
|
||||||
data: JSON.stringify(options),
|
data: JSON.stringify(options),
|
||||||
processData: false
|
processData: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeLike(options) {
|
function removeLike(options) {
|
||||||
|
var id = getId(options);
|
||||||
|
return $.ajax({
|
||||||
|
type: "DELETE",
|
||||||
|
dataType: "json",
|
||||||
|
contentType: 'application/json',
|
||||||
|
url: "/api/users/" + id + "/likings",
|
||||||
|
data: JSON.stringify(options),
|
||||||
|
processData: false
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFollowing(options) {
|
function addFollowing(options) {
|
||||||
|
|
|
||||||
|
|
@ -185,23 +185,23 @@ class ApiUsersController < ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
###################### LIKES #########################
|
###################### LIKES #########################
|
||||||
def like_index
|
def liking_index
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def like_create
|
def liking_create
|
||||||
if !params[:user_id].nil?
|
if !params[:user_id].nil?
|
||||||
@user.create_user_like(params[:user_id])
|
@user.create_user_liking(params[:user_id])
|
||||||
|
|
||||||
elsif !params[:band_id].nil?
|
elsif !params[:band_id].nil?
|
||||||
@user.create_band_like(params[:band_id])
|
@user.create_band_liking(params[:band_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @user, responder: ApiResponder, :location => api_user_like_index_url(@user)
|
respond_with @user, responder: ApiResponder, :location => api_user_liking_index_url(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def like_destroy
|
def liking_destroy
|
||||||
User.delete_like(params[:id], params[:target_entity_id])
|
User.delete_liking(params[:id], params[:target_entity_id])
|
||||||
respond_with responder: ApiResponder, :status => 204
|
respond_with responder: ApiResponder, :status => 204
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,13 @@
|
||||||
object @user.likers
|
object @user.likers
|
||||||
|
|
||||||
attributes :liker_id => :user_id
|
attributes :user_id
|
||||||
|
|
||||||
node :first_name do |liker|
|
node :name do |liker|
|
||||||
liker.user.first_name
|
liker.user.name
|
||||||
end
|
end
|
||||||
|
|
||||||
node :last_name do |liker|
|
node :location do |liker|
|
||||||
liker.user.last_name
|
liker.user.location
|
||||||
end
|
|
||||||
|
|
||||||
node :city do |liker|
|
|
||||||
liker.user.city
|
|
||||||
end
|
|
||||||
|
|
||||||
node :state do |liker|
|
|
||||||
liker.user.state
|
|
||||||
end
|
|
||||||
|
|
||||||
node :country do |liker|
|
|
||||||
liker.user.country
|
|
||||||
end
|
end
|
||||||
|
|
||||||
node :musician do |liker|
|
node :musician do |liker|
|
||||||
|
|
|
||||||
|
|
@ -161,9 +161,9 @@ SampleApp::Application.routes.draw do
|
||||||
match '/users/:id/likers' => 'api_users#liker_index', :via => :get
|
match '/users/:id/likers' => 'api_users#liker_index', :via => :get
|
||||||
|
|
||||||
# user likes
|
# user likes
|
||||||
match '/users/:id/likes' => 'api_users#like_index', :via => :get, :as => 'api_user_like_index'
|
match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index'
|
||||||
match '/users/:id/likes' => 'api_users#like_create', :via => :post
|
match '/users/:id/likings' => 'api_users#liking_create', :via => :post
|
||||||
match '/users/:id/likes' => 'api_users#like_destroy', :via => :delete
|
match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete
|
||||||
|
|
||||||
# user followers
|
# user followers
|
||||||
match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index'
|
match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index'
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,15 @@ describe "User API", :type => :api do
|
||||||
end
|
end
|
||||||
|
|
||||||
########################## LIKES / LIKERS #########################
|
########################## LIKES / LIKERS #########################
|
||||||
def create_user_like(authenticated_user, source_user, target_user)
|
def create_user_liking(authenticated_user, source_user, target_user)
|
||||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||||
post "/api/users/#{source_user.id}/likes.json", { :user_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
post "/api/users/#{source_user.id}/likings.json", { :user_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||||
return last_response
|
return last_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user_likes(authenticated_user, source_user)
|
def get_user_likes(authenticated_user, source_user)
|
||||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||||
get "/api/users/#{source_user.id}/likes.json"
|
get "/api/users/#{source_user.id}/likings.json"
|
||||||
return last_response
|
return last_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -56,19 +56,19 @@ describe "User API", :type => :api do
|
||||||
|
|
||||||
def delete_user_like(authenticated_user, source_user, target_user)
|
def delete_user_like(authenticated_user, source_user, target_user)
|
||||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||||
delete "/api/users/#{source_user.id}/likes.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||||
return last_response
|
return last_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_band_like(authenticated_user, source_user, target_band)
|
def create_band_like(authenticated_user, source_user, target_band)
|
||||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||||
post "/api/users/#{source_user.id}/likes.json", { :band_id => target_band.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
post "/api/users/#{source_user.id}/likings.json", { :band_id => target_band.id }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||||
return last_response
|
return last_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_band_likes(authenticated_user, source_user)
|
def get_band_likes(authenticated_user, source_user)
|
||||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||||
get "/api/users/#{source_user.id}/likes.json"
|
get "/api/users/#{source_user.id}/likings.json"
|
||||||
return last_response
|
return last_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -311,7 +311,7 @@ describe "User API", :type => :api do
|
||||||
###################### LIKERS / LIKES ########################
|
###################### LIKERS / LIKES ########################
|
||||||
it "should allow user to like user" do
|
it "should allow user to like user" do
|
||||||
# create user like
|
# create user like
|
||||||
last_response = create_user_like(user, user, fan)
|
last_response = create_user_liking(user, user, fan)
|
||||||
last_response.status.should == 201
|
last_response.status.should == 201
|
||||||
|
|
||||||
# get likes
|
# get likes
|
||||||
|
|
@ -351,12 +351,12 @@ describe "User API", :type => :api do
|
||||||
|
|
||||||
it "should not allow user to create like for another user" do
|
it "should not allow user to create like for another user" do
|
||||||
dummy_user = FactoryGirl.create(:user)
|
dummy_user = FactoryGirl.create(:user)
|
||||||
last_response = create_user_like(user, dummy_user, fan)
|
last_response = create_user_liking(user, dummy_user, fan)
|
||||||
last_response.status.should == 403
|
last_response.status.should == 403
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow user to delete like" do
|
it "should allow user to delete like" do
|
||||||
last_response = create_user_like(user, user, fan)
|
last_response = create_user_liking(user, user, fan)
|
||||||
last_response.status.should == 201
|
last_response.status.should == 201
|
||||||
|
|
||||||
# get likes
|
# get likes
|
||||||
|
|
@ -379,7 +379,7 @@ describe "User API", :type => :api do
|
||||||
|
|
||||||
it "should not allow user to delete like of another user" do
|
it "should not allow user to delete like of another user" do
|
||||||
# create user like
|
# create user like
|
||||||
last_response = create_user_like(user, user, fan)
|
last_response = create_user_liking(user, user, fan)
|
||||||
last_response.status.should == 201
|
last_response.status.should == 201
|
||||||
|
|
||||||
# get likes
|
# get likes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue