Merge branch 'slemmer-121211' into slemmer_20121211

This commit is contained in:
Mike Slemmer 2012-12-14 12:29:29 -08:00
commit 9a063cfc85
29 changed files with 129 additions and 186 deletions

View File

@ -69,8 +69,8 @@ end
group :test do
gem 'capybara', '1.1.2'
gem 'cucumber-rails', '1.3.0', :require => false
gem 'factory_girl_rails', '4.1.0'
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
@ -80,3 +80,5 @@ group :test do
# gem 'growl', '1.0.3'
end

View File

@ -7,10 +7,10 @@
var logger = context.JK.logger;
logger.info("*** Fake JamClient instance initialized. ***");
function testLatency(client, callbackFunctionName) {
logger.debug("Fake JamClient: testLatency called with client, " + client + " and callback function name: " + callbackFunctionName);
function testLatency(clientID, callbackFunctionName) {
logger.debug("Fake JamClient: testLatency called with client, " + clientID + " and callback function name: " + callbackFunctionName);
var response = {
id: client.id,
clientID: clientID,
latency: 50
};
var js = callbackFunctionName + "(" + JSON.stringify(response) + ");";

View File

@ -48,9 +48,15 @@
var rowTemplate = $('#template-findSession-row').html();
var session = sessions[sessionId];
var latencyInfo = sessionLatency.sessionInfo(sessionId);
var audience = "Open to Fans";
if (!(session.fan_access)) {
audience = "Musicians Only";
}
var vals = {
id: session.id,
genres: session.genres.join (','),
audience: audience,
averageLatency: latencyInfo.averageLatency,
sortScore: latencyInfo.sortScore,
participants: session.participants.length,
description: session.description || "(No description)"

View File

@ -48,19 +48,19 @@
function sessionPings(session) {
setInitialSortScore(session);
$.each(session.participants, function(index, participant) {
var client = { id: participant.client_id };
clientsToSessions[client.id] = session.id;
var clientID = participant.client_id;
clientsToSessions[clientID] = session.id;
if (!(session.id in sessionPingsOut)) {
sessionPingsOut[session.id] = 0;
}
sessionPingsOut[session.id]++;
var jsFunction = "JK.Callbacks.clientPingResponse";
jamClient.TestLatency(client, jsFunction);
jamClient.TestLatency(clientID, jsFunction);
});
}
function clientPingResponse(response) {
var sessionId = clientsToSessions[response.id];
var sessionId = clientsToSessions[response.clientID];
sessionPingsOut[sessionId]--;
updateSessionLatency(sessionId, response);
for (var k in subscribers) {
@ -73,7 +73,7 @@
function updateSessionLatency(sessionId, latencyResponse) {
ensureSessionLatencyEntry(sessionId);
var sl = sessionLatency[sessionId];
sl.clientLatencies[latencyResponse.id] = latencyResponse.latency;
sl.clientLatencies[latencyResponse.clientID] = latencyResponse.latency;
sl.averageLatency = latencyAverage(sl.clientLatencies);
sl.sortScore = updateSortScore(sessionId, sl.averageLatency);
}

View File

@ -84,7 +84,7 @@
function latencyResponse(response) {
logger.debug("latencyResponse, called from jamClient: " + response);
var latency = response.latency;
var latency = JSON.stringify(response);
$(selectors.testLatencyResponse).html(latency);
}

View File

@ -0,0 +1,5 @@
div[layout-id="findSession"] {
th, td { margin: 4px; padding:4px; }
}

View File

@ -29,9 +29,11 @@ class ApiController < ApplicationController
end
protected
def auth_user(id)
unless current_user.id == id
def auth_user
unless current_user.id == params[:id]
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@user = User.find(params[:id])
end
end

View File

@ -1,6 +1,10 @@
class ApiUsersController < ApiController
before_filter :api_signed_in_user, :except => [:create, :signup_confirm, :auth_session_create]
before_filter :auth_user, :only => [:session_settings_show, :update, :delete, :following_create, :following_destroy,
:recording_destroy, :favorite_create, :favorite_destroy, :friend_request_index, :friend_request_show,
:friend_request_create, :friend_destroy, :band_invitation_index, :band_invitation_show,
:band_invitation_update, :set_password]
respond_to :json
@ -54,20 +58,17 @@ class ApiUsersController < ApiController
end
def session_settings_show
auth_user(params[:id])
@user = User.find(params[:id])
respond_with @user.my_session_settings, responder: ApiResponder
end
def update
auth_user(params[:id])
@user = User.save(params[:id],
current_user.id,
params[:first_name],
params[:last_name],
params[:email],
params[:password],
params[:password_confirmation],
nil, # Don't allow changing password here, since we want to prompt again for the old password
nil,
params[:musician],
params[:gender],
params[:birth_date],
@ -81,9 +82,17 @@ class ApiUsersController < ApiController
respond_with @user, responder: ApiResponder, :status => 200
end
def set_password
begin
@user.set_password(params[:old_password], params[:new_password], params[:new_password_confirm])
rescue JamRuby::JamArgumentError
render :json => { :message => ValidationMessages::OLD_PASSWORD_DOESNT_MATCH }, :status => 403
end
respond_with responder: ApiResponder, :status => 204
end
def delete
@user = User.find(params[:id])
auth_user @user.destroy # required to make 'tire' integration work
@user.destroy # required to make 'tire' integration work
respond_with responder: ApiResponder, :status => 204
end
@ -104,8 +113,6 @@ class ApiUsersController < ApiController
def following_create
id = params[:id]
auth_user(id)
@user = User.find(id)
if !params[:user_id].nil?
User.create_user_following(params[:user_id], id)
@ -118,8 +125,6 @@ class ApiUsersController < ApiController
end
def following_destroy
auth_user(params[:id])
if !params[:user_id].nil?
User.delete_following(params[:user_id], nil, params[:id])
@ -197,7 +202,6 @@ class ApiUsersController < ApiController
end
def recording_destroy
auth_user(params[:id])
@recording = Recording.find(params[:recording_id])
@recording.delete
respond_with responder: ApiResponder, :status => 204
@ -211,7 +215,6 @@ class ApiUsersController < ApiController
end
def favorite_create
auth_user(params[:id])
@favorite = UserFavorite.new()
User.create_favorite(params[:id], params[:recording_id])
@ -220,27 +223,23 @@ class ApiUsersController < ApiController
end
def favorite_destroy
auth_user(params[:id])
User.delete_favorite(params[:id], params[:recording_id])
respond_with responder: ApiResponder, :status => 204
end
###################### FRIENDS (TODO: refactor resource paths) ##########################
def friend_request_index
auth_user(params[:id])
# get all outgoing and incoming friend requests
@friend_requests = FriendRequest.where("(friend_id='#{params[:id]}' OR user_id='#{params[:id]}') AND accepted is null")
end
def friend_request_show
auth_user(params[:id])
@friend_request = FriendRequest.find(params[:id])
end
def friend_request_create
auth_user(params[:user_id])
@friend_request = FriendRequest.new()
@friend_request.user_id = params[:user_id]
@friend_request.user_id = params[:id]
@friend_request.friend_id = params[:friend_id]
@friend_request.save
respond_with @friend_request, responder: ApiResponder, :location => api_friend_request_detail_url(@friend_request)
@ -275,7 +274,6 @@ class ApiUsersController < ApiController
end
def friend_destroy
auth_user(params[:id])
# clean up both records representing this "friendship"
JamRuby::Friendship.delete_all "(user_id = '#{params[:id]}' AND friend_id = '#{params[:friend_id]}') OR (user_id = '#{params[:friend_id]}' AND friend_id = '#{params[:id]}')"
respond_with responder: ApiResponder, :status => 204
@ -283,15 +281,12 @@ class ApiUsersController < ApiController
##################### BAND INVITATIONS ##################
def band_invitation_index
auth_user(params[:id])
@user = current_user
@invitations = @user.received_band_invitations#.merge(@user.sent_band_invitations)
respond_with @invitations, responder: ApiResponder, :status => 200
end
def band_invitation_show
auth_user(params[:id])
begin
@invitation = BandInvitation.find(params[:invitation_id])
respond_with @invitation, responder: ApiResponder, :status => 200
@ -302,8 +297,6 @@ class ApiUsersController < ApiController
end
def band_invitation_update
auth_user(params[:id])
begin
@invitation = BandInvitation.save(params[:invitation_id],
nil,

View File

@ -22,9 +22,9 @@
<td>{genres}</td>
<td>{description}</td>
<td>{participants}</td>
<td>TODO Audience</td>
<td>TODO Latency</td>
<td>TODO Listen</td>
<td>{audience}</td>
<td>{averageLatency}</td>
<td>TODO</td>
<td><a href="#/session/{id}">Join</a></td>
</tr>
</script>

View File

@ -2,6 +2,9 @@
<!-- logo -->
<h1>Jamkazam</h1>
<a href="/#/testBridge">Test Javascript Bridge Page</a>
<a onclick="window.location.reload();">Refresh</a>
<!-- profile area -->
<div id="profile" class="userinfo">

View File

@ -14,6 +14,7 @@
<%= stylesheet_link_tag "client/dialog", media: "all" %>
<%= stylesheet_link_tag "client/sidebar", media: "all" %>
<%= stylesheet_link_tag "client/home", media: "all" %>
<%= stylesheet_link_tag "client/findSession", media: "all" %>
<%= stylesheet_link_tag "client/session", media: "all" %>
<%= stylesheet_link_tag "client/search", media: "all" %>
<%= stylesheet_link_tag "client/lato", media: "all" %>

11
build
View File

@ -35,5 +35,16 @@ else
exit 1
fi
echo "running cucumber tests"
DISPLAY=":99" bundle exec cucumber
if [ "$?" = "0" ]; then
echo "success: cucumber tests completed"
else
echo "running cucumber tests failed"
exit 1
fi
echo "build complete"

View File

@ -51,6 +51,7 @@ SampleApp::Application.routes.draw do
match '/users' => 'api_users#index', :via => :get
match '/users/:id' => 'api_users#show', :via => :get, :as => 'api_user_detail'
#match '/users' => 'api_users#create', :via => :post
match '/users/:id/set_password' => 'api_users#set_password', :via => :put
match '/users/:id' => 'api_users#update', :via => :post
match '/users/:id' => 'api_users#destroy', :via => :delete
match '/users/confirm/:signup_token' => 'api_users#signup_confirm', :via => :post, :as => 'api_signup_confirmation'

View File

@ -1,10 +0,0 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end

View File

@ -1,5 +0,0 @@
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true
end
end

View File

@ -1,5 +0,0 @@
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end

View File

@ -1,6 +0,0 @@
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end

View File

@ -1,5 +0,0 @@
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
end
end

View File

@ -1,11 +0,0 @@
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.string :content
t.integer :user_id
t.timestamps
end
add_index :microposts, [:user_id, :created_at]
end
end

View File

@ -1,14 +0,0 @@
class CreateRelationships < ActiveRecord::Migration
def change
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id
t.timestamps
end
add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], unique: true
end
end

View File

@ -11,39 +11,6 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120308215846) do
create_table "microposts", :force => true do |t|
t.string "content"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "microposts", ["user_id", "created_at"], :name => "index_microposts_on_user_id_and_created_at"
create_table "relationships", :force => true do |t|
t.integer "follower_id"
t.integer "followed_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "relationships", ["followed_id"], :name => "index_relationships_on_followed_id"
add_index "relationships", ["follower_id", "followed_id"], :name => "index_relationships_on_follower_id_and_followed_id", :unique => true
add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
ActiveRecord::Schema.define(:version => 0) do
end

View File

@ -0,0 +1,9 @@
Feature: Viewer can use the home page
In order to use the rest of the service
As a viewer
I want to see the home page of the service
@javascript
Scenario: View home page
Given I am on the home page
Then I should see "Sign In"

View File

@ -1,13 +0,0 @@
Feature: Signing in
Scenario: Unsuccessful signin
Given a user visits the signin page
When he submits invalid signin information
Then he should see an error message
Scenario: Successful signin
Given a user visits the signin page
And the user has an account
And the user submits valid signin information
Then he should see his profile page
And he should see a signout link

View File

@ -1,31 +0,0 @@
Given /^a user visits the signin page$/ do
visit signin_path
end
When /^he submits invalid signin information$/ do
click_button "Sign in"
end
Then /^he should see an error message$/ do
page.should have_selector('div.alert.alert-error')
end
Given /^the user has an account$/ do
@user = User.create(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
When /^the user submits valid signin information$/ do
visit signin_path
fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_button "Sign in"
end
Then /^he should see his profile page$/ do
page.should have_selector('title', text: @user.name)
end
Then /^he should see a signout link$/ do
page.should have_link('Sign out', href: signout_path)
end

View File

@ -0,0 +1,8 @@
Given /^I am on the home page$/ do
visit root_path
end
Then /^I should see "(.*?)"$/ do |content|
page.find("div.landing").should have_content content
end

View File

@ -0,0 +1,21 @@
require 'active_record'
require 'action_mailer'
require 'jam_db'
require 'jam_ruby'
require File.expand_path('../../../spec/spec_db', __FILE__)
include JamRuby
# put this in a class, so that multiple loads of this file
# don't cause the database to be recreated multiple times
class BeforeCucumber
def initialize
# recreate test database and migrate it
db_config = YAML::load(File.open('config/database.yml'))["cucumber"]
SpecDb::recreate_database(db_config)
# put ActionMailer into test mode
ActionMailer::Base.delivery_method = :test
end
end

View File

@ -4,8 +4,14 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
# SETH: ADDED TO FORCE OUR OWN DB LOADING
require File.expand_path('../before_cucumber', __FILE__)
BeforeCucumber.new
require 'cucumber/rails'
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
@ -32,7 +38,9 @@ ActionController::Base.allow_rescue = false
# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :transaction
#DatabaseCleaner.strategy = :transaction
#DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres] }
#DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres] })
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
@ -41,7 +49,10 @@ end
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
# # { :except => [:widgets] } may not do what you expect here
# # as tCucumber::Rails::Database.javascript_strategy overrides
# # this setting.
# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
@ -49,8 +60,11 @@ end
# end
#
Capybara.javascript_driver = :selenium
# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation

View File

@ -12,8 +12,8 @@
};
var jamClientFake = {
TestLatency: function(client, fnName) {
var js = fnName + '(' + JSON.stringify({id: client.id, latency: 50}) + ');';
TestLatency: function(clientID, fnName) {
var js = fnName + '(' + JSON.stringify({clientID: clientID, latency: 50}) + ');';
eval(js);
}
};

View File

@ -21,21 +21,21 @@
];
var callCount = 0;
var testLatencyResponses = {
"1": {id: "1", latency: 35},
"2": {id: "2", latency: 50},
"3": {id: "3", latency: 150},
"4": {id: "4", latency: 200},
"5": {id: "5", latency: 100},
"6": {id: "6", latency: 10},
"7": {id: "7", latency: 10}
"1": {clientID: "1", latency: 35},
"2": {clientID: "2", latency: 50},
"3": {clientID: "3", latency: 150},
"4": {clientID: "4", latency: 200},
"5": {clientID: "5", latency: 100},
"6": {clientID: "6", latency: 10},
"7": {clientID: "7", latency: 10}
};
beforeEach(function() {
callCount = 0;
sessionLatency = new context.JK.SessionLatency(fakeJamClient);
spyOn(fakeJamClient, "TestLatency").andCallFake(function(client, callbackName) {
spyOn(fakeJamClient, "TestLatency").andCallFake(function(clientID, callbackName) {
var js = callbackName + '(' + JSON.stringify(testLatencyResponses[client.id]) + ');';
var js = callbackName + '(' + JSON.stringify(testLatencyResponses[clientID]) + ');';
eval(js);
//callback(testLatencyResponses[client.id]);
callCount++;