From f3c09f65c2a8748b6ccff698f0abb06bd87f5a84 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 20 Feb 2014 22:23:44 +0000 Subject: [PATCH] * allowing tests to be skipped, and mostly done with VRFS-1200 --- db/up/music_session_history_public.sql | 3 +- ruby/build | 12 ++-- ruby/lib/jam_ruby/models/recording_liker.rb | 1 + web/app/assets/javascripts/jam_rest.js | 11 +++ web/app/controllers/api_controller.rb | 6 +- .../controllers/api_favorites_controller.rb | 9 ++- web/config/routes.rb | 1 + .../api_favorites_controller_spec.rb | 72 ++++++++++++------- web/spec/spec_helper.rb | 27 +++---- 9 files changed, 93 insertions(+), 49 deletions(-) diff --git a/db/up/music_session_history_public.sql b/db/up/music_session_history_public.sql index cbff9b62a..d6bcc9d70 100644 --- a/db/up/music_session_history_public.sql +++ b/db/up/music_session_history_public.sql @@ -1 +1,2 @@ -ALTER TABLE music_sessions_history ADD COLUMN fan_access BOOLEAN NOT NULL; \ No newline at end of file + +ALTER TABLE music_sessions_history ADD COLUMN fan_access BOOLEAN NOT NULL DEFAULT TRUE; \ No newline at end of file diff --git a/ruby/build b/ruby/build index f405937d2..22a88c008 100755 --- a/ruby/build +++ b/ruby/build @@ -3,14 +3,18 @@ echo "updating dependencies" bundle install --path vendor/bundle -echo "running rspec tests" -bundle exec rspec +if [ -z $SKIP_TESTS ]; then + echo "running rspec tests" + bundle exec rspec -if [ "$?" = "0" ]; then + if [ "$?" = "0" ]; then echo "tests completed" -else + else echo "tests failed." exit 1 + fi +else + echo "skipping tests" fi echo "build complete" diff --git a/ruby/lib/jam_ruby/models/recording_liker.rb b/ruby/lib/jam_ruby/models/recording_liker.rb index 7c997d401..78ceaa0ea 100644 --- a/ruby/lib/jam_ruby/models/recording_liker.rb +++ b/ruby/lib/jam_ruby/models/recording_liker.rb @@ -9,5 +9,6 @@ module JamRuby belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording", :foreign_key => "claimed_recording_id" belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_id" + validates :favorite, :inclusion => {:in => [true, false]} end end \ No newline at end of file diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index effd7c262..92fe43939 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -103,6 +103,16 @@ }); } + function updateFavorite(claimedRecordingId, favorite) { + return $.ajax({ + url: '/api/favorites/' + claimedRecordingId, + type: "POST", + data : JSON.stringify({favorite: favorite}), + dataType : 'json', + contentType: 'application/json' + }); + } + function validateBand(band) { return $.ajax({ type: "POST", @@ -906,6 +916,7 @@ this.getBandPhotoFilepickerPolicy = getBandPhotoFilepickerPolicy; this.getBand = getBand; this.validateBand = validateBand; + this.updateFavorite = updateFavorite; this.createBandInvitation = createBandInvitation; this.updateBandInvitation = updateBandInvitation; this.removeBandMember = removeBandMember; diff --git a/web/app/controllers/api_controller.rb b/web/app/controllers/api_controller.rb index 6c7ac8b58..58607623e 100644 --- a/web/app/controllers/api_controller.rb +++ b/web/app/controllers/api_controller.rb @@ -34,16 +34,16 @@ class ApiController < ApplicationController def respond_with_model(model, options = {}) if model.errors.any? response.status = :unprocessable_entity - respond_with model + respond_with model, layout: nil else status = options[:new] && options[:new] == true ? 201 : 200 redirect_on_success = options[:location] if redirect_on_success location = redirect_on_success.call raise "location must return something" unless location # development time error - respond_with model, responder: ApiResponder, status: status, location: location + respond_with model, responder: ApiResponder, status: status, location: location, layout: nil else - respond_with model, responder: ApiResponder, status: status + respond_with model, responder: ApiResponder, status: status, layout: nil end end end diff --git a/web/app/controllers/api_favorites_controller.rb b/web/app/controllers/api_favorites_controller.rb index 49389b866..9ca6dacec 100644 --- a/web/app/controllers/api_favorites_controller.rb +++ b/web/app/controllers/api_favorites_controller.rb @@ -15,7 +15,12 @@ class ApiFavoritesController < ApiController render "api_favorites/index", :layout => nil end - def remove_favorite - RecordingLiker.find_by_liker_id_and_claimed_recording_id(curren_user.id, params[:claimed_recording_id]) + def update + id = params[:id] + like = RecordingLiker.find_by_liker_id_and_claimed_recording_id!(current_user.id, id) + like.favorite = params[:favorite] if params.has_key? :favorite + like.save + + respond_with_model(like) end end \ No newline at end of file diff --git a/web/config/routes.rb b/web/config/routes.rb index 472e40143..1ce6640b2 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -348,6 +348,7 @@ SampleApp::Application.routes.draw do # favorites match '/favorites' => 'api_favorites#index', :via => :get + match '/favorites/:id' => 'api_favorites#update', :via => :post end end diff --git a/web/spec/controllers/api_favorites_controller_spec.rb b/web/spec/controllers/api_favorites_controller_spec.rb index ff634a23a..452bd1fb5 100644 --- a/web/spec/controllers/api_favorites_controller_spec.rb +++ b/web/spec/controllers/api_favorites_controller_spec.rb @@ -10,39 +10,59 @@ describe ApiFavoritesController do let(:claimed_recording) {FactoryGirl.create(:claimed_recording) } before(:each) do + RecordingLiker.delete_all ClaimedRecording.delete_all controller.current_user = nil end - it "insists on login" do - get :index - response.status.should == 403 + describe "index" do + it "insists on login" do + get :index + response.status.should == 403 + end + + it "requires user param" do + controller.current_user = user + expect { get :index }.to raise_error "user must be specified" + end + + it "can return nothing" do + controller.current_user = user + get :index, { user: user} + + json = JSON.parse(response.body, :symbolize_names => true) + json[:entries].length.should == 0 + json[:since].should be_nil + end + + it "returns one thing" do + claimed_recording.touch + like = FactoryGirl.create(:recording_like, user: user, claimed_recording: claimed_recording, recording: claimed_recording.recording, favorite: true) + + controller.current_user = user + get :index, { user: user} + + json = JSON.parse(response.body, :symbolize_names => true) + json[:entries].length.should == 1 + json[:since].should be_nil + end end - it "requires user param" do - controller.current_user = user - expect { get :index }.to raise_error "user must be specified" + + describe "update" do + + it "insists on login" do + post :update, {id: '1'} + response.status.should == 403 + end + + it "requires user param" do + controller.current_user = user + post :update, {id: claimed_recording.id} + response.status.should == 404 + end + end - it "can return nothing" do - controller.current_user = user - get :index, { user: user} - - json = JSON.parse(response.body, :symbolize_names => true) - json[:entries].length.should == 0 - json[:since].should be_nil - end - - it "returns one thing" do - claimed_recording.touch - like = FactoryGirl.create(:recording_like, user: user, claimed_recording: claimed_recording, recording: claimed_recording.recording, favorite: true) - - controller.current_user = user - get :index, { user: user} - - json = JSON.parse(response.body, :symbolize_names => true) - json[:entries].length.should == 1 - json[:since].should be_nil - end end diff --git a/web/spec/spec_helper.rb b/web/spec/spec_helper.rb index b6cf25056..8bdc80d80 100644 --- a/web/spec/spec_helper.rb +++ b/web/spec/spec_helper.rb @@ -25,31 +25,32 @@ require 'jam_ruby' # uncomment this to see active record logs # ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base) -puts "1" + +#puts "1" include JamRuby -puts "2" +#puts "2" # put ActionMailer into test mode ActionMailer::Base.delivery_method = :test -puts "3" +#puts "3" RecordedTrack.observers.disable :all # only a few tests want this observer active -puts "4" +#puts "4" # a way to kill tests if they aren't running. capybara is hanging intermittently, I think tests_started = false -Thread.new { - puts "thread starting" - sleep 30 - puts "thread waking" - unless tests_started - puts "tests are hung. exiting..." - exit 20 - end -} +#Thread.new { +# puts "thread starting" +# sleep 30 +# puts "thread waking" +# unless tests_started + # puts "tests are hung. exiting..." + # exit 20 + # end +#} Spork.prefork do # Loading more in this block will cause your tests to run faster. However,