merged updates

This commit is contained in:
Scott Comer 2014-02-24 15:22:26 -06:00
commit b33206683b
52 changed files with 602 additions and 194 deletions

View File

@ -122,3 +122,4 @@ scores_create_schemas_and_extensions.sql
scores_create_tables.sql
remove_is_downloadable.sql
scores_mod_connections2.sql
track_download_counts.sql

View File

@ -0,0 +1,5 @@
ALTER TABLE recorded_tracks ADD COLUMN download_count INTEGER NOT NULL DEFAULT 0;
ALTER TABLE recorded_tracks ADD COLUMN last_downloaded_at TIMESTAMP;
ALTER TABLE mixes ADD COLUMN download_count INTEGER NOT NULL DEFAULT 0;
ALTER TABLE mixes ADD COLUMN last_downloaded_at TIMESTAMP;

View File

@ -20,6 +20,7 @@ module JamRuby
validates_uniqueness_of :user_id, :scope => :recording_id
validate :user_belongs_to_recording
before_create :generate_share_token
SHARE_TOKEN_LENGTH = 8
@ -67,7 +68,6 @@ module JamRuby
!ClaimedRecording.find_by_user_id_and_recording_id(some_user.id, recording_id).nil?
end
def remove_non_alpha_num(token)
token.gsub(/[^0-9A-Za-z]/, '')
end

View File

@ -10,14 +10,24 @@ module JamRuby
attr_accessible :ogg_url, :should_retry, as: :admin
attr_accessor :is_skip_mount_uploader
attr_writer :current_user
belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :mixes, :foreign_key => 'recording_id'
validates :download_count, presence: true
validate :verify_download_count
skip_callback :save, :before, :store_picture!, if: :is_skip_mount_uploader
mount_uploader :ogg_url, MixUploader
def verify_download_count
if (self.download_count < 0 || self.download_count > APP_CONFIG.max_audio_downloads) && !@current_user.admin
errors.add(:download_count, "must be less than or equal to 100")
end
end
before_validation do
# this should be an activeadmin only path, because it's using the mount_uploader (whereas the client does something completely different)
if !is_skip_mount_uploader && ogg_url.present? && ogg_url.respond_to?(:file) && ogg_url_changed?
@ -67,7 +77,6 @@ module JamRuby
!ClaimedRecording.find_by_user_id_and_recording_id(some_user.id, recording_id).nil?
end
def errored(reason, detail)
self.error_reason = reason
self.error_detail = detail
@ -148,6 +157,11 @@ module JamRuby
Mix.construct_filename(self.created_at, self.recording_id, self.id, type)
end
def update_download_count(count=1)
self.download_count = self.download_count + count
self.last_downloaded_at = Time.now
end
private
def delete_s3_files

View File

@ -173,8 +173,6 @@ module JamRuby
hist.end_history if hist
puts "**************NOTIFICATION SESSION ENDED**************"
Notification.send_session_ended(session_id)
end

View File

@ -357,7 +357,6 @@ module JamRuby
# publish to all users who have a notification for this session
# TODO: do this in BULK or in async block
notifications.each do |n|
puts "*************SENDING SESSION_ENDED TO #{n.target_user_id}***************"
msg = @@message_factory.session_ended(n.target_user_id, session_id)
@@mq_router.publish_to_user(n.target_user_id, msg)
end

View File

@ -12,6 +12,7 @@ module JamRuby
attr_writer :is_skip_mount_uploader
attr_accessible :discard, :user, :user_id, :instrument_id, :sound, :client_id, :track_id, :client_track_id, :url, as: :admin
attr_writer :current_user
SOUND = %w(mono stereo)
MAX_PART_FAILURES = 3
@ -31,11 +32,13 @@ module JamRuby
validates :length, length: {minimum: 1, maximum: 1024 * 1024 * 256 }, if: :upload_starting? # 256 megs max. is this reasonable? surely...
validates :user, presence: true
validates :instrument, presence: true
validates :download_count, presence: true
before_destroy :delete_s3_files
validate :validate_fully_uploaded
validate :validate_part_complete
validate :validate_too_many_upload_failures
validate :verify_download_count
before_save :sanitize_active_admin
skip_callback :save, :before, :store_picture!, if: :is_skip_mount_uploader?
@ -97,6 +100,12 @@ module JamRuby
end
end
def verify_download_count
if (self.download_count < 0 || self.download_count > APP_CONFIG.max_audio_downloads) && !@current_user.admin
errors.add(:download_count, "must be less than or equal to 100")
end
end
def sanitize_active_admin
self.user_id = nil if self.user_id == ''
end
@ -187,6 +196,11 @@ module JamRuby
RecordedTrack.construct_filename(self.created_at, self.recording.id, self.client_track_id)
end
def update_download_count(count=1)
self.download_count = self.download_count + count
self.last_downloaded_at = Time.now
end
private
def delete_s3_files

View File

@ -171,10 +171,28 @@ FactoryGirl.define do
association :user, factory: :user
before(:create) { |claimed_recording|
claimed_recording.recording = FactoryGirl.create(:recording_with_track, owner: claimed_recording.user) unless claimed_recording.recording
}
end
factory :mix, :class => JamRuby::Mix do
started_at Time.now
completed_at Time.now
ogg_md5 'abc'
ogg_length 1
sequence(:ogg_url) { |n| "recordings/ogg/#{n}" }
mp3_md5 'abc'
mp3_length 1
sequence(:mp3_url) { |n| "recordings/mp3/#{n}" }
completed true
before(:create) {|mix|
user = FactoryGirl.create(:user)
mix.recording = FactoryGirl.create(:recording_with_track, owner: user)
mix.recording.claimed_recordings << FactoryGirl.create(:claimed_recording, user: user, recording: mix.recording)
}
end
factory :musician_instrument, :class => JamRuby::MusicianInstrument do

View File

@ -63,6 +63,16 @@ describe Mix do
recordings.length.should == 0
end
describe "download count" do
it "will fail if too high" do
mix = FactoryGirl.create(:mix)
mix.current_user = mix.recording.owner
mix.update_download_count(APP_CONFIG.max_audio_downloads + 1)
mix.save
mix.errors[:download_count].should == ["must be less than or equal to 100"]
end
end
end

View File

@ -13,6 +13,9 @@ SpecDb::recreate_database
# initialize ActiveRecord's db connection
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"])
# so jam_ruby models that use APP_CONFIG in metadata will load. this is later stubbed pre test run
APP_CONFIG = app_config
require 'jam_ruby'
require 'factory_girl'
require 'rubygems'

View File

@ -101,6 +101,10 @@ def app_config
'315576000'
end
def max_audio_downloads
100
end
private
def audiomixer_workspace_path

View File

@ -209,7 +209,7 @@
var password_confirmation_errors = context.JK.format_errors("password_confirmation", errors)
if(current_password_errors != null) {
$('#account-edit-password-form #account-forgot-password').closest('div.field').addClass('error').end().after(current_password_errors);
$('#account-edit-password-form input[name=current_password]').closest('div.field').addClass('error').end().after(current_password_errors);
}
if(password_errors != null) {

View File

@ -47,55 +47,53 @@
/****************** MAIN PORTION OF SCREEN *****************/
function addFollowing(isBand, id) {
var newFollowing = {};
var newFollowing = {};
if (!isBand) {
newFollowing.user_id = id;
}
else {
newFollowing.band_id = id;
}
if (!isBand) {
newFollowing.user_id = id;
}
else {
newFollowing.band_id = id;
}
rest.addFollowing(newFollowing)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) + 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(true);
}
else {
configureMemberFollowingButton(true, id);
}
})
.fail(app.ajaxError);
rest.addFollowing(newFollowing)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) + 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(true);
}
else {
configureMemberFollowingButton(true, id);
}
renderActive();
})
.fail(app.ajaxError);
}
function removeFollowing(isBand, id) {
var following = {};
following.target_entity_id = id;
rest.removeFollowing(following)
.done(function() {
renderActive(); // refresh stats
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) - 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(false);
}
else {
configureMemberFollowingButton(false, id);
}
})
.fail(app.ajaxError);
rest.removeFollowing(id)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) - 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(false);
}
else {
configureMemberFollowingButton(false, id);
}
renderActive();
})
.fail(app.ajaxError);
}
function configureBandFollowingButton(following) {
$('#btn-follow-band').unbind("click");
if (following) {
$('#btn-follow-band').text('STOP FOLLOWING');
$('#btn-follow-band').text('UNFOLLOW');
$('#btn-follow-band').click(function() {
removeFollowing(true, bandId);
return false;
@ -121,7 +119,7 @@
$btnFollowMember.unbind("click");
if (following) {
$btnFollowMember.text('UN-FOLLOW');
$btnFollowMember.text('UNFOLLOW');
$btnFollowMember.click(function() {
removeFollowing(false, userId);
return false;

View File

@ -487,7 +487,7 @@
* Load available drivers and populate the driver select box.
*/
function loadAudioDrivers() {
var drivers = jamClient.FTUEGetDevices();
var drivers = jamClient.FTUEGetDevices(false);
var driverOptionFunc = function (driverKey, index, list) {
optionsHtml += '<option title="' + drivers[driverKey] + '"value="' + driverKey + '">' +

View File

@ -49,20 +49,23 @@
});
var bandHtml = context.JK.fillTemplate(template, {
avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url),
name: response.name,
location: response.location,
genres: genres.join(', '),
musicians: musicianHtml,
like_count: response.liker_count,
follower_count: response.follower_count,
recording_count: response.recording_count,
session_count: response.session_count,
biography: response.biography,
profile_url: "/client#/bandProfile/" + response.id
bandId: response.id,
avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url),
name: response.name,
location: response.location,
genres: genres.join(', '),
musicians: musicianHtml,
like_count: response.liker_count,
follower_count: response.follower_count,
recording_count: response.recording_count,
session_count: response.session_count,
biography: response.biography,
followAction: response.is_following ? "removeBandFollowing" : "addBandFollowing",
profile_url: "/client#/bandProfile/" + response.id
});
$(hoverSelector).append('<h2>Band Detail</h2>' + bandHtml);
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -77,6 +80,20 @@
});
};
function configureActionButtons(band) {
var btnFollowSelector = "#btnFollow";
// if unauthenticated or authenticated user is viewing his own profile
if (!context.JK.currentUserId) {
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (band.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
}
}
}
this.hideBubble = function() {
$(hoverSelector).hide();
};

View File

@ -56,12 +56,15 @@
location: response.location,
friend_count: response.friend_count,
follower_count: response.follower_count,
friendAction: response.is_friend ? "removeFanFriend" : (response.pending_friend_request ? "" : "sendFanFriendRequest"),
followAction: response.is_following ? "removeFanFollowing" : "addFanFollowing",
biography: response.biography,
followings: response.followings && response.followings.length > 0 ? followingHtml : "<tr><td>N/A</td></tr>",
profile_url: "/client#/profile/" + response.id
});
$(hoverSelector).append('<h2>Fan Detail</h2>' + fanHtml);
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -76,6 +79,33 @@
});
};
function configureActionButtons(user) {
var btnFriendSelector = "#btnFriend";
var btnFollowSelector = "#btnFollow";
if (!context.JK.currentUserId || context.JK.currentUserId === user.id) {
$(btnFriendSelector, hoverSelector).hide();
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (user.is_friend) {
$(btnFriendSelector, hoverSelector).html('DISCONNECT');
}
if (user.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
$(btnFollowSelector, hoverSelector).click(function(evt) {
rest.removeFollowing(user.id);
});
}
if (user.pending_friend_request) {
$(btnFriendSelector, hoverSelector).hide();
}
}
}
this.hideBubble = function() {
$(hoverSelector).hide();
};

View File

@ -75,12 +75,15 @@
session_count: response.session_count,
session_display: sessionDisplayStyle,
session_id: sessionId,
friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"),
followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing",
biography: response.biography,
followings: response.followings && response.followings.length > 0 ? followingHtml : "<tr><td>N/A</td></tr>",
profile_url: "/client#/profile/" + response.id
});
$(hoverSelector).append('<h2>Musician Detail</h2>' + musicianHtml);
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -95,6 +98,28 @@
});
};
function configureActionButtons(user) {
var btnFriendSelector = "#btnFriend";
var btnFollowSelector = "#btnFollow";
// if unauthenticated or authenticated user is viewing his own profile
if (!context.JK.currentUserId || context.JK.currentUserId === user.id) {
$(btnFriendSelector, hoverSelector).hide();
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (user.is_friend) {
$(btnFriendSelector, hoverSelector).html('DISCONNECT');
}
if (user.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
}
if (user.pending_friend_request) {
$(btnFriendSelector, hoverSelector).hide();
}
}
}
this.hideBubble = function() {
$(hoverSelector).hide();
};

View File

@ -55,6 +55,7 @@
});
$(hoverSelector).append('<h2>Recording Detail</h2>' + recordingHtml);
toggleActionButtons();
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -69,6 +70,13 @@
});
};
function toggleActionButtons() {
if (!context.JK.currentUserId) {
$("#btnLike", hoverSelector).hide();
$("#btnShare", hoverSelector).hide();
}
}
this.hideBubble = function() {
$(hoverSelector).hide();
};

View File

@ -50,6 +50,7 @@
});
$(hoverSelector).append('<h2>Session Detail</h2>' + sessionHtml);
toggleActionButtons();
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -64,6 +65,13 @@
});
};
function toggleActionButtons() {
if (!context.JK.currentUserId) {
$("#btnLike", hoverSelector).hide();
$("#btnShare", hoverSelector).hide();
}
}
this.hideBubble = function() {
$(hoverSelector).hide();
};

View File

@ -451,7 +451,7 @@
});
}
function removeLike(options) {
function removeLike(likableId, options) {
var id = getId(options);
return $.ajax({
type: "DELETE",
@ -476,15 +476,13 @@
});
}
function removeFollowing(options) {
function removeFollowing(followableId, options) {
var id = getId(options);
return $.ajax({
type: "DELETE",
dataType: "json",
contentType: 'application/json',
url: "/api/users/" + id + "/followings",
data: JSON.stringify(options),
url: "/api/users/" + id + "/followings/" + followableId,
processData: false
});
}

View File

@ -500,6 +500,8 @@
var accepted = screenEvent(previousScreen, 'beforeHide', data);
if(accepted === false) return;
logger.debug("Changing screen to " + currentScreen);
screenEvent(currentScreen, 'beforeShow', data);
// For now -- it seems we want it open always.

View File

@ -193,10 +193,10 @@
function configureFriendButton() {
if (isFriend()) {
$('#btn-add-friend').text('REMOVE FRIEND');
$('#btn-add-friend').text('DISCONNECT');
}
else {
$('#btn-add-friend').text('ADD FRIEND');
$('#btn-add-friend').text('CONNECT');
}
}
@ -213,10 +213,7 @@
}
function removeFollowing(isBand, id) {
var following = {};
following.target_entity_id = id;
rest.removeFollowing(following)
rest.removeFollowing(id)
.done(function() {
if (!isBand) {
updateFollowingCount(-1);
@ -242,7 +239,7 @@
function configureFollowingButton() {
if (isFollowing()) {
$('#btn-follow-user').text('STOP FOLLOWING');
$('#btn-follow-user').text('UNFOLLOW');
}
else {
$('#btn-follow-user').text('FOLLOW');

View File

@ -117,23 +117,23 @@
selector = isSidebar ? '#sidebar-search-results' : '#search-results';
$(selector).append(invitationSentHtml);
// wire up button click handler if search result is not a friend or the current use
// wire up button click handler if search result is not a friend or the current user
if (isSidebar) {
var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']');
if (!val.is_friend && val.id !== context.JK.currentUserId) {
$sidebar.find('.btn-connect-friend').click(sendFriendRequest);
if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) {
// hide the button if the search result is already a friend
$sidebar.find('.btn-connect-friend').hide();
}
else {
// hide the button if the search result is already a friend
$sidebar.find('.btn-connect-friend').hide();
$sidebar.find('.btn-connect-friend').click(sendFriendRequest);
}
}
else {
if (!val.is_friend && val.id !== context.JK.currentUserId) {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest);
if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide();
}
else {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide();
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest);
}
}
resultDivVisibility(val, isSidebar);

View File

@ -12,13 +12,6 @@
var entity = null;
var remainingCap = 140 - 22 - 1; // 140 tweet max, minus 22 for link size, minus 1 for space
var textMap = {
LIVE_SESSION: "LIVE SESSION",
SESSION: "SESSION",
RECORDING: "RECORDING",
RECORDED: "RECORDED"
};
function showSpinner() {
$(dialogId + ' .dialog-inner').hide();
var spinner = $('<div class="spinner spinner-large"></div>')

View File

@ -1,5 +1,5 @@
@charset "UTF-8";
@import "compass/utilities/text/replacement";
@import "compass/typography/text/replacement";
.header {
height: 55px;

View File

@ -55,4 +55,8 @@
position:absolute;
top:3px;
right:4px;
}
#btnPlayPause {
position: relative;
}

View File

@ -16,4 +16,8 @@
font-size:15px;
color:#cccc00;
margin-left:20px;
}*/
}*/
#btnPlayPause {
position: relative;
}

View File

@ -33,8 +33,7 @@ class ApiController < ApplicationController
def respond_with_model(model, options = {})
if model.errors.any?
response.status = :unprocessable_entity
respond_with model, layout: nil
respond_with model, status: :unprocessable_entity, layout: nil
else
status = options[:new] && options[:new] == true ? 201 : 200
redirect_on_success = options[:location]

View File

@ -24,9 +24,18 @@ class ApiMixesController < ApiController
def download
@mix = Mix.find(params[:id])
raise PermissionError, "You can only download a mix you didn't claim" unless @mix.can_download? current_user
raise PermissionError, "You can only download a mix you have claimed" unless @mix.can_download? current_user
redirect_to @mix.sign_url
@mix.current_user = current_user
@mix.update_download_count
@mix.valid?
if !@mix.errors.any?
@mix.save!
redirect_to @mix.sign_url
else
render :json => { :message => "download limit surpassed" }, :status => 404
end
end
private

View File

@ -38,7 +38,18 @@ class ApiRecordingsController < ApiController
def download
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @recorded_track.can_download?(current_user)
redirect_to @recorded_track.sign_url
@recorded_track.current_user = current_user
@recorded_track.update_download_count
@recorded_track.valid?
if !@recorded_track.errors.any?
@recorded_track.save!
redirect_to @recorded_track.sign_url
else
render :json => { :message => "download limit surpassed" }, :status => 404
end
end
def start

View File

@ -1,6 +1,6 @@
class ApiUsersController < ApiController
before_filter :api_signed_in_user, :except => [:create, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring]
before_filter :api_signed_in_user, :except => [:create, :show, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring]
before_filter :auth_user, :only => [:session_settings_show, :session_history_index, :session_user_history_index, :update, :delete,
:liking_create, :liking_destroy, # likes
:following_create, :following_show, :following_destroy, # followings
@ -202,7 +202,7 @@ class ApiUsersController < ApiController
end
def liking_destroy
User.delete_liking(params[:id], params[:target_entity_id])
User.delete_liking(params[:id], params[:likable_id])
respond_with responder: ApiResponder, :status => 204
end
@ -230,7 +230,7 @@ class ApiUsersController < ApiController
end
def following_destroy
User.delete_following(params[:id], params[:target_entity_id])
User.delete_following(params[:id], params[:followable_id])
respond_with responder: ApiResponder, :status => 204
end

View File

@ -0,0 +1 @@
object @mix

View File

@ -23,14 +23,15 @@ if @search.musicians_text_search?
musician.friends?(current_user)
end
node :pending_friend_request do |musician|
musician.pending_friend_request?(current_user)
end
child :musician_instruments => :instruments do
attributes :instrument_id, :description, :proficiency_level, :priority
end
}
end
if @search.musicians_filter_search?
node :city do |user|
current_user.try(:location)
end
@ -50,6 +51,10 @@ if @search.musicians_filter_search?
@search.is_follower?(musician)
end
node :pending_friend_request do |musician|
musician.pending_friend_request?(musician)
end
node :biography do |musician|
musician.biography.nil? ? "" : musician.biography
end
@ -112,6 +117,10 @@ if @search.fans_text_search?
node :is_friend do |fan|
fan.friends?(current_user)
end
node :pending_friend_request do |fan|
fan.pending_friend_request?(current_user)
end
}
end

View File

@ -1,5 +1,5 @@
<!-- Account Summary Dialog -->
<div layout="screen" layout-id="account/identity" class="screen secondary">
<div layout="screen" layout-id="account/identity" class="screen secondary" id="account-identity">
<!-- header -->
<div class="content-head">
<!-- icon -->

View File

@ -5,25 +5,49 @@
<script type="text/javascript">
var rest = JK.Rest();
function addLike(bandId) {
rest.addLike({band_id: bandId})
// function addLike(bandId) {
// rest.addLike({band_id: bandId})
// .done(function(response) {
// $("#spnLikeCount", "#band-hover").html(parseInt($("#spnLikeCount", "#band-hover").text()) + 1);
// var $btnLikeSelector = $("#btnLike", "#band-hover");
// $btnLikeSelector.unbind("click");
// $btnLikeSelector.html("LIKED");
// });
// }
function addBandFollowing(bandId) {
rest.addFollowing({band_id: bandId})
.done(function(response) {
$("#spnLikeCount", "#band-hover").html(parseInt($("#spnLikeCount", "#band-hover").text()) + 1);
var $btnLikeSelector = $("#btnLike", "#band-hover");
$btnLikeSelector.unbind("click");
$btnLikeSelector.html("LIKED");
adjustBandFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeBandFollowing(bandId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function addFollowing(bandId) {
rest.addFollowing({band_id: bandId})
function removeBandFollowing(bandId) {
rest.removeFollowing(bandId)
.done(function(response) {
$("#spnFollowCount", "#band-hover").html(parseInt($("#spnFollowCount", "#band-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("STOP FOLLOWING");
adjustBandFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addBandFollowing(bandId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustBandFollowingCount(value) {
$("#spnFollowCount", "#band-hover").text(parseInt($("#spnFollowCount", "#band-hover").text()) + value);
}
</script>
<script type="text/template" id="template-hover-band">
@ -33,7 +57,6 @@
<h3>{name}</h3>
<small>{location}<br /><strong>{genres}</strong></small><br />
<br clear="all" />
<span id="spnLikeCount">{like_count}</span> <img src="/assets/content/icon_like.png" align="absmiddle" />&nbsp;&nbsp;&nbsp;
<span id="spnFollowCount">{follower_count}</span> <img src="/assets/content/icon_followers.png" width="22" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;
{recording_count} <img src="/assets/content/icon_recordings.png" width="12" height="13" align="absmiddle" />&nbsp;&nbsp;&nbsp;
{session_count} <img src="/assets/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" />
@ -47,8 +70,8 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a class="button-orange">LIKE</a></div>
<div class="left"><a class="button-orange">FOLLOW</a></div>
<div class="left" style="display:none;"><a class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{bandId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -5,19 +5,58 @@
<script type="text/javascript">
var rest = JK.Rest();
function addFollowing(userId) {
function addFanFollowing(userId) {
rest.addFollowing({user_id: userId})
.done(function(response) {
$("#spnFollowCount", "#fan-hover").html(parseInt($("#spnFollowCount", "#fan-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("STOP FOLLOWING");
adjustFanFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeFanFollowing(userId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function sendFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
function removeFanFollowing(userId) {
rest.removeFollowing(userId)
.done(function(response) {
adjustFanFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addFanFollowing(userId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustFanFollowingCount(value) {
$("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value);
}
function sendFanFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
$("#btnFriend", "#fan-hover").hide();
}
function removeFanFriend(userId) {
rest.removeFriend({friend_id: userId})
.done(function() {
var $btnFriendSelector = $("#btnFriend", "#fan-hover");
$btnFriendSelector.unbind("click");
$btnFriendSelector.attr('onclick', '');
$btnFriendSelector.html("CONNECT");
$btnFriendSelector.click(function() {
sendFanFriendRequest(userId);
});
});
}
</script>
<script type="text/template" id="template-hover-fan">
@ -38,8 +77,8 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a id="btnFriend" onclick="sendFriendRequest('{userId}');" class="button-orange">FRIEND</a></div>
<div class="left"><a id="btnFollow" onclick="addFollowing('{userId}');" class="button-orange">FOLLOW</a></div>
<div class="left"><a id="btnFriend" onclick="{friendAction}('{userId}');" class="button-orange">CONNECT</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{userId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -5,28 +5,66 @@
<script type="text/javascript">
var rest = JK.Rest();
function addLike(userId) {
rest.addLike({user_id: userId})
.done(function(response) {
$("#spnLikeCount", "#musician-hover").html(parseInt($("#spnLikeCount", "#musician-hover").text()) + 1);
var $btnLikeSelector = $("#btnLike", "#musician-hover");
$btnLikeSelector.unbind("click");
$btnLikeSelector.html("LIKED");
});
}
// function addLike(userId) {
// rest.addLike({user_id: userId})
// .done(function(response) {
// $("#spnLikeCount", "#musician-hover").text(parseInt($("#spnLikeCount", "#musician-hover").text()) + 1);
// var $btnLikeSelector = $("#btnLike", "#musician-hover");
// $btnLikeSelector.unbind("click");
// $btnLikeSelector.html("LIKED");
// });
// }
function addFollowing(userId) {
function addMusicianFollowing(userId) {
rest.addFollowing({user_id: userId})
.done(function(response) {
$("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("UNFOLLOW");
adjustMusicianFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeMusicianFollowing(userId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function sendFriendRequest(userId) {
function removeMusicianFollowing(userId) {
rest.removeFollowing(userId)
.done(function(response) {
adjustMusicianFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addMusicianFollowing(userId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustMusicianFollowingCount(value) {
$("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value);
}
function sendMusicianFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
$("#btnFriend", "#musician-hover").hide();
}
function removeMusicianFriend(userId) {
rest.removeFriend({friend_id: userId})
.done(function() {
var $btnFriendSelector = $("#btnFriend", "#musician-hover");
$btnFriendSelector.unbind("click");
$btnFriendSelector.attr('onclick', '');
$btnFriendSelector.html("CONNECT");
$btnFriendSelector.click(function() {
sendMusicianFriendRequest(userId);
});
});
}
</script>
@ -54,9 +92,9 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a id="btnLike" onclick="addLike('{userId}');" class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFriend" onclick="sendFriendRequest('{userId}');" class="button-orange">FRIEND</a></div>
<div class="left"><a id="btnFollow" onclick="addFollowing('{userId}');" class="button-orange">FOLLOW</a></div>
<div class="left" style="display:none;"><a id="btnLike" onclick="addLike('{userId}');" class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFriend" onclick="{friendAction}('{userId}');" class="button-orange">CONNECT</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{userId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -69,7 +69,6 @@
</div>
<%= render "clients/invitationDialog" %>
<%= render "clients/shareDialog" %>
<%= render "users/signupDialog" %>
<%= render "users/signinDialog" %>
<%= render "users/videoDialog" %>

View File

@ -53,7 +53,7 @@
<div class="w100">
<div class="recording-controls">
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %>
<a class="left mr20" href="#">
<a id="btnPlayPause" class="left mr20">
<%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %>
</a>
<% end %>

View File

@ -52,7 +52,7 @@
<div class="w100">
<div class="recording-controls">
<% if @claimed_recording.has_mix? %>
<a id="btnPlayPause" class="left" href="#">
<a id="btnPlayPause" class="left">
<%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %>
</a>
<% end %>

View File

@ -204,6 +204,8 @@ if defined?(Bundler)
config.twitter_app_id = ENV['TWITTER_APP_ID'] || 'nQj2oEeoJZxECC33tiTuIg'
config.twitter_app_secret = ENV['TWITTER_APP_SECRET'] || 'Azcy3QqfzYzn2fsojFPYXcn72yfwa0vG6wWDrZ3KT8'
config.autocheck_create_session_agreement = false;
config.autocheck_create_session_agreement = false
config.max_audio_downloads = 100
end
end

View File

@ -161,7 +161,7 @@ SampleApp::Application.routes.draw do
# user likes
match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index'
match '/users/:id/likings' => 'api_users#liking_create', :via => :post
match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete
match '/users/:id/likings/:likable_id' => 'api_users#liking_destroy', :via => :delete
# user followers
match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index'
@ -169,7 +169,7 @@ SampleApp::Application.routes.draw do
# user followings
match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index'
match '/users/:id/followings' => 'api_users#following_create', :via => :post
match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete
match '/users/:id/followings/:followable_id' => 'api_users#following_destroy', :via => :delete
# favorites
match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index'

View File

@ -3,7 +3,6 @@ require 'spec_helper'
describe ApiCorporateController do
render_views
before(:each) do
CorpMailer.deliveries.clear
end

View File

@ -0,0 +1,53 @@
require 'spec_helper'
describe ApiMixesController do
render_views
let(:mix) { FactoryGirl.create(:mix) }
before(:each) do
controller.current_user = nil
end
describe "download" do
it "is possible" do
controller.current_user = mix.recording.owner
get :download, {id: mix.id}
response.status.should == 302
mix.reload
mix.download_count.should == 1
get :download, {id: mix.id}
response.status.should == 302
mix.reload
mix.download_count.should == 2
end
it "prevents download after limit is reached" do
mix.download_count = APP_CONFIG.max_audio_downloads
mix.save!
controller.current_user = mix.recording.owner
get :download, {format:'json', id: mix.id}
response.status.should == 404
JSON.parse(response.body, symbolize_names: true)[:message].should == "download limit surpassed"
end
it "lets admins surpass limit" do
mix.download_count = APP_CONFIG.max_audio_downloads
mix.save!
mix.recording.owner.admin = true
mix.recording.owner.save!
controller.current_user = mix.recording.owner
get :download, {format:'json', id: mix.id}
response.status.should == 302
mix.reload
mix.download_count.should == 101
end
end
end

View File

@ -101,6 +101,8 @@ describe ApiRecordingsController do
end
describe "download" do
let(:mix) { FactoryGirl.create(:mix) }
it "should only allow a user to download a track if they have claimed the recording" do
post :start, { :format => 'json', :music_session_id => @music_session.id }
response_body = JSON.parse(response.body)
@ -108,5 +110,51 @@ describe ApiRecordingsController do
post :stop, { :format => 'json', :id => recording.id }
response.should be_success
end
it "is possible" do
mix.touch
recorded_track = mix.recording.recorded_tracks[0]
controller.current_user = mix.recording.owner
get :download, {id: recorded_track.recording.id, track_id: recorded_track.client_track_id}
response.status.should == 302
recorded_track.reload
recorded_track.download_count.should == 1
get :download, {id: recorded_track.recording.id, track_id: recorded_track.client_track_id}
response.status.should == 302
recorded_track.reload
recorded_track.download_count.should == 2
end
it "prevents download after limit is reached" do
mix.touch
recorded_track = mix.recording.recorded_tracks[0]
recorded_track.download_count = APP_CONFIG.max_audio_downloads
recorded_track.save!
controller.current_user = recorded_track.user
get :download, {format:'json', id: recorded_track.recording.id, track_id: recorded_track.client_track_id}
response.status.should == 404
JSON.parse(response.body, symbolize_names: true)[:message].should == "download limit surpassed"
end
it "lets admins surpass limit" do
mix.touch
recorded_track = mix.recording.recorded_tracks[0]
recorded_track.download_count = APP_CONFIG.max_audio_downloads
recorded_track.save!
recorded_track.user.admin = true
recorded_track.user.save!
controller.current_user = recorded_track.user
get :download, {format:'json', id: recorded_track.recording.id, track_id: recorded_track.client_track_id}
response.status.should == 302
recorded_track.reload
recorded_track.download_count.should == 101
end
end
end

View File

@ -374,4 +374,23 @@ FactoryGirl.define do
factory :music_session_like, :class => JamRuby::MusicSessionLiker do
end
factory :mix, :class => JamRuby::Mix do
started_at Time.now
completed_at Time.now
ogg_md5 'abc'
ogg_length 1
sequence(:ogg_url) { |n| "recordings/ogg/#{n}" }
mp3_md5 'abc'
mp3_length 1
sequence(:mp3_url) { |n| "recordings/mp3/#{n}" }
completed true
before(:create) {|mix|
user = FactoryGirl.create(:user)
mix.recording = FactoryGirl.create(:recording_with_track, owner: user)
mix.recording.claimed_recordings << FactoryGirl.create(:claimed_recording, user: user, recording: mix.recording)
}
end
end

View File

@ -28,7 +28,7 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do
end
it {
should have_selector('h2', text: 'identity:' )
find('#account-identity h2', text: 'identity:')
should have_selector('form#account-edit-email-form h4', text: 'Update your email address:')
should have_selector('form#account-edit-password-form h4', text: 'Update your password:')
}
@ -46,7 +46,7 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do
end
it {
should have_selector('h1', text: 'my account');
find('h1', text: 'my account')
should have_selector('#notification h2', text: 'Confirmation Email Sent')
}
end
@ -68,58 +68,60 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do
describe "unsuccessfully" do
before(:each) do
find('#account-identity h2', text: 'identity:')
find("#account-edit-password-submit").trigger(:click)
end
it {
should have_selector('h2', text: 'identity:')
should have_selector('div.field.error input[name=current_password] ~ ul li', text: "can't be blank")
should have_selector('div.field.error input[name=password] ~ ul li', text: "is too short (minimum is 6 characters)")
should have_selector('div.field.error input[name=password_confirmation] ~ ul li', text: "can't be blank")
find('#account-identity h2', text: 'identity:')
find('#account-identity div.field.error input[name=current_password] ~ ul li', text: "can't be blank")
find('#account-identity div.field.error input[name=password] ~ ul li', text: "is too short (minimum is 6 characters)")
find('#account-identity div.field.error input[name=password_confirmation] ~ ul li', text: "can't be blank")
}
end
end
describe "profile"
before(:each) do
find("#account-edit-profile-link").trigger(:click)
find('a.small', text: 'Change Avatar')
end
describe "successfully" do
describe "profile" do
before(:each) do
fill_in "first_name", with: "Bobby"
fill_in "last_name", with: "Toes"
find('input[name=subscribe_email]').set(false)
find("#account-edit-profile-submit").trigger(:click)
find("#account-edit-profile-link").trigger(:click)
find('a.small', text: 'Change Avatar')
end
it {
user.subscribe_email.should be_true
should have_selector('h1', text: 'my account')
should have_selector('#notification h2', text: 'Profile Changed')
user.reload
user.subscribe_email.should be_false
user.first_name.should == "Bobby"
user.last_name.should == "Toes"
}
end
describe "successfully" do
describe "unsuccessfully" do
before(:each) do
fill_in "first_name", with: "Bobby"
fill_in "last_name", with: "Toes"
find('input[name=subscribe_email]').set(false)
find("#account-edit-profile-submit").trigger(:click)
end
before(:each) do
fill_in "first_name", with: ""
fill_in "last_name", with: ""
find("#account-edit-profile-submit").trigger(:click)
it {
user.subscribe_email.should be_true
should have_selector('h1', text: 'my account')
should have_selector('#notification h2', text: 'Profile Changed')
user.reload
user.subscribe_email.should be_false
user.first_name.should == "Bobby"
user.last_name.should == "Toes"
}
end
it {
should have_selector('h2', text: 'profile:')
should have_selector('div.field.error input[name=first_name] ~ ul li', text: "can't be blank")
should have_selector('div.field.error input[name=last_name] ~ ul li', text: "can't be blank")
}
describe "unsuccessfully" do
before(:each) do
fill_in "first_name", with: ""
fill_in "last_name", with: ""
find("#account-edit-profile-submit").trigger(:click)
end
it {
should have_selector('h2', text: 'profile:')
should have_selector('div.field.error input[name=first_name] ~ ul li', text: "can't be blank")
should have_selector('div.field.error input[name=last_name] ~ ul li', text: "can't be blank")
}
end
end
end
end

View File

@ -36,6 +36,12 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature
# confirms that a formal leave (by hitting the 'Leave' button) will result in a good recording
it "creator starts and then leaves" do
start_recording_with(creator, [joiner1])
in_client(creator) do
find('#session-leave').trigger(:click)
find('#btn-accept-leave-session').trigger(:click)
expect(page).to have_selector('h2', text: 'feed')
end
formal_leave_by creator
check_recording_finished_for [creator, joiner1]
end
@ -67,6 +73,7 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature
it "creator starts with session leave to stop, with 3 total participants" do
start_recording_with(creator, [joiner1, joiner2])
formal_leave_by creator
check_recording_finished_for [creator, joiner1, joiner2]
end

View File

@ -524,6 +524,7 @@ describe "Music Session API ", :type => :api 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
user.admin = true
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)
@ -543,7 +544,6 @@ describe "Music Session API ", :type => :api do
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", "client_track_id" => "client_track_guid"}]}.to_json, "CONTENT_TYPE" => 'application/json'
last_response.status.should eql(201)

View File

@ -56,7 +56,7 @@ describe "User API", :type => :api do
def delete_user_like(authenticated_user, source_user, target_user)
login(authenticated_user.email, authenticated_user.password, 200, true)
delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
delete "/api/users/#{source_user.id}/likings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json'
return last_response
end
@ -99,7 +99,7 @@ describe "User API", :type => :api do
def delete_user_following(authenticated_user, source_user, target_user)
login(authenticated_user.email, authenticated_user.password, 200, true)
delete "/api/users/#{source_user.id}/followings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json'
return last_response
end

View File

@ -1,6 +1,6 @@
require 'simplecov'
require 'rubygems'
require 'spork'
#require 'spork'
require 'omniauth'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
@ -40,7 +40,7 @@ Thread.new {
end
}
Spork.prefork do
#Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
@ -155,12 +155,12 @@ Spork.prefork do
wipe_s3_test_bucket
end
end
end
#end
Spork.each_run do
#Spork.each_run do
# This code will be run each time you run your specs.
end
#end