sped up some tests
This commit is contained in:
@ -9,7 +9,7 @@ describe SubmissionScoring do
|
|||||||
let(:submission) { FactoryGirl.create(:submission, cause: 'submit') }
|
let(:submission) { FactoryGirl.create(:submission, cause: 'submit') }
|
||||||
before(:each) { controller.instance_variable_set(:@current_user, FactoryGirl.create(:external_user)) }
|
before(:each) { controller.instance_variable_set(:@current_user, FactoryGirl.create(:external_user)) }
|
||||||
|
|
||||||
describe '#score_submission', docker: true do
|
describe '#score_submission' do
|
||||||
let(:score_submission) { Proc.new { controller.score_submission(submission) } }
|
let(:score_submission) { Proc.new { controller.score_submission(submission) } }
|
||||||
before(:each) { score_submission.call }
|
before(:each) { score_submission.call }
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ describe SubmissionScoring do
|
|||||||
|
|
||||||
it 'executes the teacher-defined test cases' do
|
it 'executes the teacher-defined test cases' do
|
||||||
submission.collect_files.select(&:teacher_defined_test?).each do |file|
|
submission.collect_files.select(&:teacher_defined_test?).each do |file|
|
||||||
expect_any_instance_of(DockerClient).to receive(:execute_test_command).with(submission, file.name_with_extension).and_call_original
|
expect_any_instance_of(DockerClient).to receive(:execute_test_command).with(submission, file.name_with_extension).and_return({})
|
||||||
end
|
end
|
||||||
score_submission.call
|
score_submission.call
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :team do
|
factory :team do
|
||||||
internal_users { build_list :teacher, 10 }
|
internal_users { build_pair :teacher }
|
||||||
name 'A-Team'
|
name 'A-Team'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,20 +3,22 @@ require 'rails_helper'
|
|||||||
describe ExercisePolicy do
|
describe ExercisePolicy do
|
||||||
subject { ExercisePolicy }
|
subject { ExercisePolicy }
|
||||||
|
|
||||||
let(:exercise) { FactoryGirl.build(:fibonacci, team: FactoryGirl.create(:team)) }
|
before(:all) do
|
||||||
|
@exercise = FactoryGirl.build(:fibonacci, team: FactoryGirl.create(:team))
|
||||||
|
end
|
||||||
|
|
||||||
[:create?, :index?, :new?].each do |action|
|
[:create?, :index?, :new?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(subject).to permit(FactoryGirl.build(:admin), exercise)
|
expect(subject).to permit(FactoryGirl.build(:admin), @exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to teachers' do
|
it 'grants access to teachers' do
|
||||||
expect(subject).to permit(FactoryGirl.build(:teacher), exercise)
|
expect(subject).to permit(FactoryGirl.build(:teacher), @exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to external users' do
|
it 'does not grant access to external users' do
|
||||||
expect(subject).not_to permit(FactoryGirl.build(:external_user), exercise)
|
expect(subject).not_to permit(FactoryGirl.build(:external_user), @exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -24,20 +26,20 @@ describe ExercisePolicy do
|
|||||||
[:clone?, :destroy?, :edit?, :show?, :statistics?, :update?].each do |action|
|
[:clone?, :destroy?, :edit?, :show?, :statistics?, :update?].each do |action|
|
||||||
permissions(action) do
|
permissions(action) do
|
||||||
it 'grants access to admins' do
|
it 'grants access to admins' do
|
||||||
expect(subject).to permit(FactoryGirl.build(:admin), exercise)
|
expect(subject).to permit(FactoryGirl.build(:admin), @exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to authors' do
|
it 'grants access to authors' do
|
||||||
expect(subject).to permit(exercise.author, exercise)
|
expect(subject).to permit(@exercise.author, @exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'grants access to team members' do
|
it 'grants access to team members' do
|
||||||
expect(subject).to permit(exercise.team.members.first, exercise)
|
expect(subject).to permit(@exercise.team.members.first, @exercise)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not grant access to all other users' do
|
it 'does not grant access to all other users' do
|
||||||
[:external_user, :teacher].each do |factory_name|
|
[:external_user, :teacher].each do |factory_name|
|
||||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), exercise)
|
expect(subject).not_to permit(FactoryGirl.build(factory_name), @exercise)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -55,16 +57,16 @@ describe ExercisePolicy do
|
|||||||
|
|
||||||
describe ExercisePolicy::Scope do
|
describe ExercisePolicy::Scope do
|
||||||
describe '#resolve' do
|
describe '#resolve' do
|
||||||
let(:admin) { FactoryGirl.create(:admin) }
|
before(:all) do
|
||||||
let(:external_user) { FactoryGirl.create(:external_user) }
|
@admin = FactoryGirl.create(:admin)
|
||||||
let(:teacher) { FactoryGirl.create(:teacher) }
|
@external_user = FactoryGirl.create(:external_user)
|
||||||
let(:team) { FactoryGirl.create(:team) }
|
@teacher = FactoryGirl.create(:teacher)
|
||||||
|
@team = FactoryGirl.create(:team)
|
||||||
|
@team.members << @teacher
|
||||||
|
|
||||||
before(:each) do
|
[@admin, @teacher].each do |user|
|
||||||
[admin, teacher].each do |user|
|
|
||||||
[true, false].each do |public|
|
[true, false].each do |public|
|
||||||
team.members << teacher
|
[@team, nil].each do |team|
|
||||||
[team, nil].each do |team|
|
|
||||||
FactoryGirl.create(:fibonacci, public: public, team: team, user_id: user.id, user_type: InternalUser.class.name)
|
FactoryGirl.create(:fibonacci, public: public, team: team, user_id: user.id, user_type: InternalUser.class.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,7 +74,7 @@ describe ExercisePolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'for admins' do
|
context 'for admins' do
|
||||||
let(:scope) { Pundit.policy_scope!(admin, Exercise) }
|
let(:scope) { Pundit.policy_scope!(@admin, Exercise) }
|
||||||
|
|
||||||
it 'returns all exercises' do
|
it 'returns all exercises' do
|
||||||
expect(scope.map(&:id)).to include(*Exercise.all.map(&:id))
|
expect(scope.map(&:id)).to include(*Exercise.all.map(&:id))
|
||||||
@ -80,7 +82,7 @@ describe ExercisePolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'for external users' do
|
context 'for external users' do
|
||||||
let(:scope) { Pundit.policy_scope!(external_user, Exercise) }
|
let(:scope) { Pundit.policy_scope!(@external_user, Exercise) }
|
||||||
|
|
||||||
it 'returns nothing' do
|
it 'returns nothing' do
|
||||||
expect(scope.count).to be 0
|
expect(scope.count).to be 0
|
||||||
@ -88,22 +90,22 @@ describe ExercisePolicy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'for teachers' do
|
context 'for teachers' do
|
||||||
let(:scope) { Pundit.policy_scope!(teacher, Exercise) }
|
let(:scope) { Pundit.policy_scope!(@teacher, Exercise) }
|
||||||
|
|
||||||
it 'includes all public exercises' do
|
it 'includes all public exercises' do
|
||||||
expect(scope.map(&:id)).to include(*Exercise.where(public: true).map(&:id))
|
expect(scope.map(&:id)).to include(*Exercise.where(public: true).map(&:id))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'includes all authored non-public exercises' do
|
it 'includes all authored non-public exercises' do
|
||||||
expect(scope.map(&:id)).to include(*Exercise.where(public: false, user_id: teacher.id).map(&:id))
|
expect(scope.map(&:id)).to include(*Exercise.where(public: false, user_id: @teacher.id).map(&:id))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes all of team members' non-public exercises" do
|
it "includes all of team members' non-public exercises" do
|
||||||
expect(scope.map(&:id)).to include(*Exercise.where(public: false, team_id: teacher.teams.first.id).map(&:id))
|
expect(scope.map(&:id)).to include(*Exercise.where(public: false, team_id: @teacher.teams.first.id).map(&:id))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not include other authors' non-public exercises" do
|
it "does not include other authors' non-public exercises" do
|
||||||
expect(scope.map(&:id)).not_to include(*Exercise.where(public: false).where("team_id <> #{teacher.teams.first.id} AND user_id <> #{teacher.id}").map(&:id))
|
expect(scope.map(&:id)).not_to include(*Exercise.where(public: false).where("team_id <> #{@team.id} AND user_id <> #{@teacher.id}").map(&:id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ RSpec.configure do |config|
|
|||||||
unless example.metadata[:docker]
|
unless example.metadata[:docker]
|
||||||
allow(DockerClient).to receive(:check_availability!).and_return(true)
|
allow(DockerClient).to receive(:check_availability!).and_return(true)
|
||||||
allow(DockerClient).to receive(:image_tags).and_return([IMAGE])
|
allow(DockerClient).to receive(:image_tags).and_return([IMAGE])
|
||||||
|
allow_any_instance_of(DockerClient).to receive(:execute_command).and_return({})
|
||||||
allow_any_instance_of(DockerClient).to receive(:find_image_by_tag).and_return(IMAGE)
|
allow_any_instance_of(DockerClient).to receive(:find_image_by_tag).and_return(IMAGE)
|
||||||
allow_any_instance_of(ExecutionEnvironment).to receive(:working_docker_image?)
|
allow_any_instance_of(ExecutionEnvironment).to receive(:working_docker_image?)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user