2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-25 14:53:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Explore::ProjectsController do
|
2019-08-21 06:13:45 -04:00
|
|
|
shared_examples 'explore projects' do
|
|
|
|
describe 'GET #index.json' do
|
|
|
|
render_views
|
2019-03-18 20:01:49 -04:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
before do
|
|
|
|
get :index, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:success) }
|
2019-03-18 20:01:49 -04:00
|
|
|
end
|
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
describe 'GET #trending.json' do
|
|
|
|
render_views
|
2019-03-18 20:01:49 -04:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
before do
|
|
|
|
get :trending, format: :json
|
|
|
|
end
|
2019-03-18 20:01:49 -04:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #starred.json' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :starred, format: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:success) }
|
2019-03-18 20:01:49 -04:00
|
|
|
end
|
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
describe 'GET #trending' do
|
|
|
|
context 'sorting by update date' do
|
|
|
|
let(:project1) { create(:project, :public, updated_at: 3.days.ago) }
|
|
|
|
let(:project2) { create(:project, :public, updated_at: 1.day.ago) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:trending_project, project: project1)
|
|
|
|
create(:trending_project, project: project2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by last updated' do
|
|
|
|
get :trending, params: { sort: 'updated_desc' }
|
|
|
|
|
|
|
|
expect(assigns(:projects)).to eq [project2, project1]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts by oldest updated' do
|
|
|
|
get :trending, params: { sort: 'updated_asc' }
|
|
|
|
|
|
|
|
expect(assigns(:projects)).to eq [project1, project2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-18 20:01:49 -04:00
|
|
|
end
|
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
context 'when user is signed in' do
|
|
|
|
let(:user) { create(:user) }
|
2019-03-18 20:01:49 -04:00
|
|
|
|
|
|
|
before do
|
2019-08-21 06:13:45 -04:00
|
|
|
sign_in(user)
|
2019-03-18 20:01:49 -04:00
|
|
|
end
|
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
include_examples 'explore projects'
|
2019-03-18 20:01:49 -04:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
context 'user preference sorting' do
|
|
|
|
let(:project) { create(:project) }
|
2017-01-25 14:53:29 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
it_behaves_like 'set sort order from user preference' do
|
|
|
|
let(:sorting_param) { 'created_asc' }
|
2017-01-27 11:57:06 -05:00
|
|
|
end
|
2019-08-21 06:13:45 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-25 14:53:29 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
context 'when user is not signed in' do
|
|
|
|
include_examples 'explore projects'
|
2017-01-27 11:57:06 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
context 'user preference sorting' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:sorting_param) { 'created_asc' }
|
2017-01-25 14:53:29 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
it 'does not set sort order from user preference' do
|
|
|
|
expect_any_instance_of(UserPreference).not_to receive(:update)
|
2017-01-27 11:57:06 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
get :index, params: { sort: sorting_param }
|
2017-01-25 14:53:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|