#18 Add sql index for unpublished exercises

And remove spec for remove feature
This commit is contained in:
Maximilian Pass
2020-12-15 12:17:11 +01:00
committed by Felix Auringer
parent 2d2869765f
commit 028fc2989a
13 changed files with 148 additions and 1 deletions

View File

@ -0,0 +1,46 @@
require 'rails_helper'
describe RequestForCommentsController do
let(:user) { FactoryBot.create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
describe 'GET #index' do
it 'renders the index template' do
get :index
expect(response).to have_http_status :ok
expect(response).to render_template :index
end
it 'shows only rfc`s belonging to selected study group' do
my_study_group = FactoryBot.create(:study_group)
rfc_within_my_study_group = FactoryBot.create(:rfc, user: user)
user.update(study_groups: [my_study_group])
rfc_within_my_study_group.submission.update(study_group: my_study_group)
another_study_group = FactoryBot.create(:study_group)
rfc_other_study_group = FactoryBot.create(:rfc)
rfc_other_study_group.user.update(study_groups: [another_study_group])
rfc_other_study_group.submission.update(study_group: another_study_group)
get :index, params: {"q[submission_study_group_id_in][]": my_study_group.id}
expect(assigns(:request_for_comments)).to eq([rfc_within_my_study_group])
end
end
describe 'GET #get_my_comment_requests' do
before { get :get_my_comment_requests }
expect_status(200)
expect_template(:index)
end
describe 'GET #get_rfcs_with_my_comments' do
before { get :get_rfcs_with_my_comments }
expect_status(200)
expect_template(:index)
end
end

View File

@ -0,0 +1,11 @@
FactoryBot.define do
factory :rfc, class: RequestForComment do
association :user, factory: :external_user
association :submission
association :exercise, factory: :dummy
association :file
sequence :question do |n|
"test question #{n}"
end
end
end

View File

@ -0,0 +1,8 @@
FactoryBot.define do
factory :study_group, class: StudyGroup do
association :consumer
sequence :name do |n|
"TestGroup#{n}"
end
end
end

View File

@ -0,0 +1,32 @@
require 'rails_helper'
describe 'Request_for_Comments' do
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
let(:user) { FactoryBot.create(:teacher) }
before do
visit(sign_in_path)
fill_in('email', with: user.email)
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
click_button(I18n.t('sessions.new.link'))
end
it 'does not contain rfcs for unpublished exercises' do
unpublished_rfc = FactoryBot.create(:rfc)
unpublished_rfc.exercise.update(title: 'Unpublished Exercise')
unpublished_rfc.exercise.update(unpublished: true)
rfc = FactoryBot.create(:rfc)
rfc.exercise.update(title: 'Normal Exercise')
rfc.exercise.update(unpublished: false)
visit(request_for_comments_path)
expect(page).to have_content(rfc.exercise.title)
expect(page).not_to have_content(unpublished_rfc.exercise.title)
end
it 'contains a filter for study group in the view' do
visit(request_for_comments_path)
expect(page.find('#q_submission_study_group_id_in')).not_to be_nil
end
end