* in progress on next parameter VRFS-1135

This commit is contained in:
Seth Call 2014-02-17 00:30:08 +00:00
parent 82ab90f007
commit 5ef630cf86
8 changed files with 69 additions and 5 deletions

View File

@ -108,4 +108,5 @@ recordings_via_admin_web.sql
relax_band_model_varchar.sql
add_piano.sql
feed.sql
feed_use_recording.sql
feed_use_recording.sql
feed_autoincrement_primary_key.sql

View File

@ -0,0 +1,9 @@
DROP TABLE feeds;
CREATE TABLE feeds (
id BIGSERIAL PRIMARY KEY,
recording_id VARCHAR(64) UNIQUE REFERENCES recordings(id) ON DELETE CASCADE,
music_session_id VARCHAR(64) UNIQUE REFERENCES music_sessions_history(id) ON DELETE CASCADE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

View File

@ -12,7 +12,7 @@ module JamRuby
has_many :comments, :class_name => "JamRuby::RecordingComment", :foreign_key => "recording_id"
has_many :likes, :class_name => "JamRuby::RecordingLiker", :foreign_key => "recording_id"
has_many :plays, :class_name => "JamRuby::RecordingPlay", :foreign_key => "recording_id"
has_one :feed, :class_name => "JamRuby::Feed", :inverse_of => :recording, :foreign_key => 'recording_id', :dependent => :destroy
has_one :feed, :class_name => "JamRuby::Feed", :inverse_of => :recording, :foreign_key => 'recording', :dependent => :destroy
belongs_to :owner, :class_name => "JamRuby::User", :inverse_of => :owned_recordings, :foreign_key => 'owner_id'
belongs_to :band, :class_name => "JamRuby::Band", :inverse_of => :recordings

View File

@ -35,4 +35,26 @@ describe Feed do
feeds[0].music_session_history == music_session.music_session_history
end
describe "pagination" do
it "supports pagination" do
claimed_recording = FactoryGirl.create(:claimed_recording)
claimed_recording.recording.created_at = 3.days.ago
claimed_recording.recording.save!
options = {limit: 1}
feeds = Feed.index(options)
feeds.length.should == 1
feeds[0].recording.should == claimed_recording.recording
options[:start] = 1
feeds = Feed.index(options)
feeds.length.should == 1
feeds[0].music_session_history.should == claimed_recording.recording.music_session.music_session_history
options[:start] = 2
feeds = Feed.index(options)
feeds.length.should == 0
end
end
end

View File

@ -1,6 +1,9 @@
class ApiFeedsController < ApiController
respond_to :json
def index
puts params.inspect
# parse out since parameter
since = params[:since]
if since
@ -12,13 +15,17 @@ class ApiFeedsController < ApiController
limit = 20
end
limit = params[:limit].to_i if params[:limit] # override limit if specified
@feeds = Feed.index({user: current_user, start: start, limit: limit})
if @feeds.length < limit
@next = nil
else
@next = "#{start + limit}:#{limit}"
end
@feeds
render "api_feeds/index", :layout => nil
end
end

View File

@ -1,4 +1,4 @@
class ApiInvitedUsersController < ApiController
class ApiInvitedUsersController < ApiController
# have to be signed in currently to see this screen
before_filter :api_signed_in_user

View File

@ -1,4 +1,3 @@
node :next do |page|
@next
end

View File

@ -46,4 +46,30 @@ describe ApiFeedsController do
music_session[:type].should == 'music_session_history'
end
describe "pagination" do
it "since parameter" do
claimed_recording.touch
claimed_recording.recording.created_at = 3.days.ago
claimed_recording.recording.save!
get :index, { limit: 1 }
json = JSON.parse(response.body, :symbolize_names => true)
json[:entries].length.should == 1
_next = json[:next]
_next.should_not be_nil
get :index, { since: _next }
json = JSON.parse(response.body, :symbolize_names => true)
json[:entries].length.should == 1
_next = json[:next]
_next.should_not be_nil
get :index, { since: _next }
json = JSON.parse(response.body, :symbolize_names => true)
json[:entries].length.should == 0
_next = json[:next]
_next.should be_nil
end
end
end