* VRFS-1200 - api for toggling favorite is done

This commit is contained in:
Seth Call 2014-02-20 22:56:00 +00:00
parent f3c09f65c2
commit a6b3abdc3a
3 changed files with 25 additions and 6 deletions

View File

@ -43,7 +43,7 @@ class ApiController < ApplicationController
raise "location must return something" unless location # development time error
respond_with model, responder: ApiResponder, status: status, location: location, layout: nil
else
respond_with model, responder: ApiResponder, status: status, layout: nil
respond_with model, responder: ApiResponder, status: status, location:nil
end
end
end

View File

@ -6,8 +6,8 @@ describe ApiFavoritesController do
let(:user) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:band) { FactoryGirl.create(:band) }
let(:music_session) {FactoryGirl.create(:music_session, creator: user) }
let(:claimed_recording) {FactoryGirl.create(:claimed_recording) }
let(:music_session) { FactoryGirl.create(:music_session, creator: user) }
let(:claimed_recording) { FactoryGirl.create(:claimed_recording) }
before(:each) do
RecordingLiker.delete_all
@ -15,7 +15,6 @@ describe ApiFavoritesController do
controller.current_user = nil
end
describe "index" do
it "insists on login" do
get :index
@ -57,12 +56,32 @@ describe ApiFavoritesController do
response.status.should == 403
end
it "requires user param" do
it "404 if no like for record" do
controller.current_user = user
post :update, {id: claimed_recording.id}
response.status.should == 404
end
it "no favorite specified leaves record alone" do
controller.current_user = user
like = FactoryGirl.create(:recording_like, user: user, claimed_recording: claimed_recording, recording: claimed_recording.recording, favorite: true)
post :update, {:format => 'json', id: claimed_recording.id}
response.status.should == 200
like.reload
like.favorite.should be_true
end
it "can set favorite to false" do
controller.current_user = user
like = FactoryGirl.create(:recording_like, user: user, claimed_recording: claimed_recording, recording: claimed_recording.recording, favorite: true)
post :update, {:format => 'json', id: claimed_recording.id, favorite:false}
response.status.should == 200
like.reload
like.favorite.should be_false
end
end
end

View File

@ -19,7 +19,7 @@ db_config = YAML::load(File.open('config/database.yml'))["test"]
# initialize ActiveRecord's db connection\
SpecDb::recreate_database(db_config)
ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"])
puts "0"
#puts "0"
require 'jam_ruby'
# uncomment this to see active record logs