VRFS-2597 : Fix some broken tests:
* Naming issues * Restore method that was caught by friendly fire in a cleanup session * Add a few new specs to properly exercise controller methods to catch errors sooner, i.e., not in feature specs. * Restore deleted route
This commit is contained in:
parent
d3b613c2dc
commit
2853c77b7e
|
|
@ -48,6 +48,34 @@ module JamRuby
|
|||
|
||||
accepts_nested_attributes_for :jam_track_tracks, allow_destroy: true
|
||||
|
||||
class << self
|
||||
def index(options = {})
|
||||
limit = options[:limit]
|
||||
limit ||= 20
|
||||
limit = limit.to_i
|
||||
|
||||
start = options[:start].presence
|
||||
start = start.to_i || 0
|
||||
|
||||
query = JamTrack.joins(:jam_track_tracks)
|
||||
.offset(start)
|
||||
.limit(limit)
|
||||
|
||||
query = query.where("jam_tracks.genre_id = '#{options[:genre]}'") unless options[:genre].blank?
|
||||
query = query.where("jam_track_tracks.instrument_id = '#{options[:instrument]}'") unless options[:instrument].blank?
|
||||
query = query.where("jam_tracks.sales_region = '#{options[:availability]}'") unless options[:availability].blank?
|
||||
query = query.group("jam_tracks.id")
|
||||
|
||||
if query.length == 0
|
||||
[query, nil]
|
||||
elsif query.length < limit
|
||||
[query, nil]
|
||||
else
|
||||
[query, start + limit]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# create storage directory that will house this jam_track, as well as
|
||||
def store_dir
|
||||
"jam_tracks/#{id}"
|
||||
|
|
|
|||
|
|
@ -2,11 +2,18 @@ class ApiJamTracksController < ApiController
|
|||
|
||||
# have to be signed in currently to see this screen
|
||||
before_filter :api_signed_in_user
|
||||
before_filter :lookup_jam_track, :only => [ :download ]
|
||||
before_filter :lookup_jam_track_right, :only => :download
|
||||
|
||||
respond_to :json
|
||||
|
||||
def list_downloads
|
||||
def index
|
||||
data = JamTrack.index(params)
|
||||
@jam_tracks, @next = data[0], data[1]
|
||||
|
||||
render "api_jam_tracks/index", :layout => nil
|
||||
end
|
||||
|
||||
def downloads
|
||||
begin
|
||||
render :json => JamTrack.list_downloads(current_user, params[:limit], params[:since]), :status => 200
|
||||
rescue
|
||||
|
|
@ -15,9 +22,7 @@ class ApiJamTracksController < ApiController
|
|||
end
|
||||
|
||||
def download
|
||||
if @jam_track_right.valid?
|
||||
puts "Success"
|
||||
|
||||
if @jam_track_right.valid?
|
||||
if (@jam_track_right && @jam_track_right.signed && @jam_track_right.url.present? &&@jam_track_right.url.file.exists?)
|
||||
@jam_track_right.update_download_count
|
||||
@jam_track_right.save!
|
||||
|
|
@ -27,15 +32,14 @@ class ApiJamTracksController < ApiController
|
|||
render :json => { :message => "not available, digitally signing Jam Track offline." }, :status => 202
|
||||
end
|
||||
else
|
||||
puts "#@jam_track_right.errors: #{@jam_track_right.errors.inspect}"
|
||||
render :json => { :message => "download limit surpassed" }, :status => 403
|
||||
render :json => { :message => "download limit surpassed", :errors=>@jam_track_right.errors }, :status => 403
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def lookup_jam_track
|
||||
@jam_track_right = JamTrackRight.where("jam_track_id=? AND user_id=?", params[:id], current_user).first
|
||||
def lookup_jam_track_right
|
||||
@jam_track_right = JamTrackRight.where("jam_track_id=? AND user_id=?", params[:id], current_user.id).first
|
||||
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @jam_track_right
|
||||
end
|
||||
|
||||
end
|
||||
end # class ApiJamTracksController
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@ node :next do |page|
|
|||
end
|
||||
|
||||
node :jamtracks do |page|
|
||||
partial "api_jamtracks/show", object: @jamtracks
|
||||
partial "api_jam_tracks/show", object: @jam_tracks
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
object @jamtrack
|
||||
object @jam_track
|
||||
|
||||
attributes :id, :name, :description, :recording_type, :original_artist, :songwriter, :publisher, :sales_region, :price
|
||||
|
||||
|
|
@ -191,7 +191,8 @@ SampleApp::Application.routes.draw do
|
|||
match '/music_notations/:id' => 'api_music_notations#download', :via => :get, :as => :download_music_notation
|
||||
|
||||
# Jamtracks
|
||||
match '/jamtracks/downloads' => 'api_jam_tracks#list_downloads', :via => :get, :as => 'api_jam_tracks_list_downloads'
|
||||
match '/jamtracks' => 'api_jam_tracks#index', :via => :get, :as => 'api_jam_tracks_list'
|
||||
match '/jamtracks/downloads' => 'api_jam_tracks#downloads', :via => :get, :as => 'api_jam_tracks_downloads'
|
||||
match '/jamtracks/:id/download' => 'api_jam_tracks#download', :via => :get, :as => 'api_jam_tracks_download'
|
||||
|
||||
# Shopping carts
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
require 'spec_helper'
|
||||
describe ApiJamTracksController do
|
||||
render_views
|
||||
include CarrierWave::Test::Matchers
|
||||
|
||||
before(:all) do
|
||||
original_storage = JamTrackTrackUploader.storage = :fog
|
||||
original_storage = JamTrackRightUploader.storage = :fog
|
||||
@original_storage = JamTrackTrackUploader.storage = :fog
|
||||
@original_storage_right = JamTrackRightUploader.storage = :fog
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
JamTrackTrackUploader.storage = @original_storage
|
||||
JamTrackRightUploader.storage = @original_storage
|
||||
JamTrackRightUploader.storage = @original_storage_right
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
|
|
@ -18,14 +19,46 @@ describe ApiJamTracksController do
|
|||
controller.current_user = @user
|
||||
end
|
||||
|
||||
describe "download" do
|
||||
it "list download" do
|
||||
describe "download functionality" do
|
||||
it "lists available tracks" do
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)#, :symbolize_names => true)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 1
|
||||
|
||||
jam_track2 = FactoryGirl.create(:jam_track)
|
||||
get :index
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)#, :symbolize_names => true)
|
||||
json["next"].should be_nil
|
||||
json["jamtracks"].length.should == 2
|
||||
end
|
||||
|
||||
it "lists owned tracks" do
|
||||
get :downloads
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)
|
||||
json['downloads'].should have(0).items
|
||||
|
||||
right = JamTrackRight.create(:user=>@user, :jam_track=>@jam_track)
|
||||
get :list_downloads
|
||||
get :downloads
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)
|
||||
json['downloads'].should have(1).items
|
||||
end
|
||||
|
||||
it "finds a download" do
|
||||
#get "/download/#{right.id}/"
|
||||
right = JamTrackRight.create(:user=>@user, :jam_track=>@jam_track)
|
||||
get :download, { :format => 'json', :id => @jam_track.id }
|
||||
|
||||
response.should be_success
|
||||
response.status.should == 202
|
||||
response.body.should =~ /not available.*/
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "with a JamTrack" do
|
||||
|
|
@ -46,7 +79,6 @@ describe ApiJamTracksController do
|
|||
end
|
||||
|
||||
it "download depends on rights" do
|
||||
pending "bleh "
|
||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||
get :download, :id => @jam_track.id
|
||||
response.status.should == 403
|
||||
|
|
@ -69,14 +101,6 @@ describe ApiJamTracksController do
|
|||
get :download, :id => @jam_track.id
|
||||
response.status.should == 302
|
||||
response.location.should =~ /.*#{Regexp.escape(right.filename)}.*/
|
||||
#response.should redirect_to(/.*#{Regexp.escape(right.filename)}.*/)
|
||||
#response.should redirect_to("%r{.*#{Regexp.escape(right.filename)}.*}")
|
||||
|
||||
#right.reload
|
||||
#s3.exists?(response.location).should be_true
|
||||
#puts "s3.length (response.location): #{s3.length (response.location)}"
|
||||
#s3.length (response.location).should > File.size?(@ogg_path)
|
||||
|
||||
right.reload
|
||||
right.download_count.should eq(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@ describe "JamTrack Shopping", :js => true, :type => :feature, :capybara_feature
|
|||
let(:jt_rock) { FactoryGirl.create(:jam_track, :name=>'jt_rock', genre: JamRuby::Genre.find('rock'), make_track: true) }
|
||||
let(:jt_blues) { FactoryGirl.create(:jam_track, :name=>'jt_blues', genre: JamRuby::Genre.find('blues'), make_track: true) }
|
||||
|
||||
before(:all) do
|
||||
Capybara.javascript_driver = :poltergeist
|
||||
Capybara.current_driver = Capybara.javascript_driver
|
||||
Capybara.default_wait_time = 30 # these tests are SLOOOOOW
|
||||
end
|
||||
|
||||
|
||||
before(:each) do
|
||||
ShoppingCart.delete_all
|
||||
JamTrack.delete_all
|
||||
|
|
|
|||
Loading…
Reference in New Issue