114 lines
3.2 KiB
Ruby
114 lines
3.2 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe ApiFeedsController do
|
|
render_views
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
let(:music_session) {FactoryGirl.create(:music_session, creator: user) }
|
|
let(:claimed_recording) {FactoryGirl.create(:claimed_recording) }
|
|
|
|
before(:each) do
|
|
MusicSession.delete_all
|
|
MusicSessionHistory.delete_all
|
|
Recording.delete_all
|
|
end
|
|
|
|
it "returns nothing" do
|
|
get :index
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 0
|
|
end
|
|
|
|
|
|
it "returns a recording" do
|
|
claimed_recording.touch
|
|
# artifact of factory of :claimed_recording that this gets created
|
|
MusicSessionHistory.delete_all
|
|
|
|
get :index
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 1
|
|
|
|
claimed_recording = json[:entries][0]
|
|
claimed_recording[:type].should == 'recording'
|
|
end
|
|
|
|
it "returns a music session" do
|
|
music_session.touch
|
|
# artifact of factory of :claimed_recording that this gets created
|
|
|
|
get :index
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 1
|
|
|
|
|
|
music_session = json[:entries][0]
|
|
music_session[:type].should == 'music_session_history'
|
|
end
|
|
|
|
describe "time range" do
|
|
|
|
it "today and month find different results" do
|
|
music_session.music_session_history.touch
|
|
music_session.music_session_history.feed.created_at = 3.days.ago
|
|
music_session.music_session_history.feed.save!
|
|
|
|
get :index
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 1
|
|
|
|
get :index, { time_range:'today' }
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 0
|
|
end
|
|
end
|
|
|
|
describe "type filter" do
|
|
|
|
it "can filter by type" do
|
|
claimed_recording.touch
|
|
|
|
get :index
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 2
|
|
|
|
get :index, { type: 'recording'}
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 1
|
|
json[:entries][0][:type].should == 'recording'
|
|
|
|
get :index, { type: 'music_session_history'}
|
|
json = JSON.parse(response.body, :symbolize_names => true)
|
|
json[:entries].length.should == 1
|
|
json[:entries][0][:type].should == 'music_session_history'
|
|
end
|
|
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, { limit: 1, 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, { limit: 1, 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
|