Align project files with CodeHarbor

Since both projects are developed together and by the same team, we also want to have the same code structure and utility methods available in both projects. Therefore, this commit changes many files, but without a functional change.
This commit is contained in:
Sebastian Serth
2023-10-10 23:25:02 +02:00
parent fb3e8972d9
commit 99bd46af1a
112 changed files with 433 additions and 320 deletions

View File

@ -6,7 +6,7 @@ class Controller < AnonymousController
include FileParameters
end
describe FileParameters do
RSpec.describe FileParameters do
let(:controller) { Controller.new }
let(:hello_world) { create(:hello_world) }

View File

@ -6,7 +6,7 @@ class Controller < AnonymousController
include Lti
end
describe Lti do
RSpec.describe Lti do
let(:controller) { Controller.new }
let(:session) { double }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Admin::DashboardController do
RSpec.describe Admin::DashboardController do
render_views
let(:codeocean_config) { instance_double(CodeOcean::Config) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ApplicationController do
RSpec.describe ApplicationController do
render_views
describe '#current_user' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeOcean::FilesController do
RSpec.describe CodeOcean::FilesController do
render_views
let(:contributor) { create(:admin) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeharborLinksController do
RSpec.describe CodeharborLinksController do
render_views
let(:user) { create(:teacher) }
@ -44,14 +44,13 @@ describe CodeharborLinksController do
context 'with invalid params' do
let(:params) { {push_url: '', check_uuid_url: '', api_key: ''} }
before { post_request }
it 'does not create a codeharbor_link' do
expect { post_request }.not_to change(CodeharborLink, :count)
end
it 'redirects to user show' do
post_request
expect(response).to render_template(:new)
end
expect_template(:new)
end
end
@ -79,14 +78,13 @@ describe CodeharborLinksController do
context 'with invalid params' do
let(:params) { {push_url: '', check_uuid_url: '', api_key: ''} }
before { put_request }
it 'does not change codeharbor_link' do
expect { put_request }.not_to(change { codeharbor_link.reload.attributes })
end
it 'redirects to user show' do
put_request
expect(response).to render_template(:edit)
end
expect_template(:edit)
end
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CommentsController do
RSpec.describe CommentsController do
render_views
let(:user) { create(:learner) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ConsumersController do
RSpec.describe ConsumersController do
render_views
let(:consumer) { create(:consumer) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ErrorTemplateAttributesController do
RSpec.describe ErrorTemplateAttributesController do
render_views
let!(:error_template_attribute) { create(:error_template_attribute) }
@ -10,39 +10,67 @@ describe ErrorTemplateAttributesController do
before { allow(controller).to receive(:current_user).and_return(user) }
it 'gets index' do
get :index
expect(response).to have_http_status(:ok)
expect(assigns(:error_template_attributes)).not_to be_nil
describe 'GET #index' do
before { get :index }
expect_assigns(error_template_attributes: ErrorTemplateAttribute.all)
expect_http_status(:ok)
expect_template(:index)
end
it 'gets new' do
get :new
expect(response).to have_http_status(:ok)
describe 'GET #new' do
before { get :new }
expect_http_status(:ok)
expect_template(:new)
end
it 'creates error_template_attribute' do
expect { post :create, params: {error_template_attribute: {}} }.to change(ErrorTemplateAttribute, :count).by(1)
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
describe 'POST #create' do
before { post :create, params: {error_template_attribute: {}} }
expect_assigns(error_template_attribute: ErrorTemplateAttribute)
it 'creates the error template attribute' do
expect { post :create, params: {error_template_attribute: {}} }.to change(ErrorTemplateAttribute, :count).by(1)
end
expect_redirect { error_template_attribute_path(assigns(:error_template_attribute)) }
end
it 'shows error_template_attribute' do
get :show, params: {id: error_template_attribute}
expect(response).to have_http_status(:ok)
describe 'GET #show' do
before { get :show, params: {id: error_template_attribute} }
expect_assigns(error_template_attribute: ErrorTemplateAttribute)
expect_http_status(:ok)
expect_template(:show)
end
it 'gets edit' do
get :edit, params: {id: error_template_attribute}
expect(response).to have_http_status(:ok)
describe 'GET #edit' do
before { get :edit, params: {id: error_template_attribute} }
expect_assigns(error_template_attribute: ErrorTemplateAttribute)
expect_http_status(:ok)
expect_template(:edit)
end
it 'updates error_template_attribute' do
patch :update, params: {id: error_template_attribute, error_template_attribute: attributes_for(:error_template_attribute)}
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
describe 'PATCH #update' do
before { patch :update, params: {id: error_template_attribute, error_template_attribute: attributes_for(:error_template_attribute)} }
expect_assigns(error_template_attribute: ErrorTemplateAttribute)
expect_redirect { error_template_attribute }
end
it 'destroys error_template_attribute' do
expect { delete :destroy, params: {id: error_template_attribute} }.to change(ErrorTemplateAttribute, :count).by(-1)
expect(response).to redirect_to(error_template_attributes_path)
describe 'DELETE #destroy' do
before { delete :destroy, params: {id: error_template_attribute} }
expect_assigns(error_template_attribute: ErrorTemplateAttribute)
it 'destroys the error template attribute' do
error_template_attribute = create(:error_template_attribute)
expect { delete :destroy, params: {id: error_template_attribute} }.to change(ErrorTemplateAttribute, :count).by(-1)
end
expect_redirect { error_template_attribute }
end
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ErrorTemplatesController do
RSpec.describe ErrorTemplatesController do
render_views
let!(:error_template) { create(:error_template) }
@ -10,39 +10,67 @@ describe ErrorTemplatesController do
before { allow(controller).to receive(:current_user).and_return(user) }
it 'gets index' do
get :index
expect(response).to have_http_status(:ok)
expect(assigns(:error_templates)).not_to be_nil
describe 'GET #index' do
before { get :index }
expect_assigns(error_templates: ErrorTemplate.all)
expect_http_status(:ok)
expect_template(:index)
end
it 'gets new' do
get :new
expect(response).to have_http_status(:ok)
describe 'GET #new' do
before { get :new }
expect_http_status(:ok)
expect_template(:new)
end
it 'creates error_template' do
expect { post :create, params: {error_template: {execution_environment_id: error_template.execution_environment.id}} }.to change(ErrorTemplate, :count).by(1)
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
describe 'POST #create' do
before { post :create, params: {error_template: {execution_environment_id: error_template.execution_environment.id}} }
expect_assigns(error_template: ErrorTemplate)
it 'creates the error template' do
expect { post :create, params: {error_template: {execution_environment_id: error_template.execution_environment.id}} }.to change(ErrorTemplate, :count).by(1)
end
expect_redirect { error_template_path(assigns(:error_template)) }
end
it 'shows error_template' do
get :show, params: {id: error_template}
expect(response).to have_http_status(:ok)
describe 'GET #show' do
before { get :show, params: {id: error_template} }
expect_assigns(error_template: ErrorTemplate)
expect_http_status(:ok)
expect_template(:show)
end
it 'gets edit' do
get :edit, params: {id: error_template}
expect(response).to have_http_status(:ok)
describe 'GET #edit' do
before { get :edit, params: {id: error_template} }
expect_assigns(error_template: ErrorTemplate)
expect_http_status(:ok)
expect_template(:edit)
end
it 'updates error_template' do
patch :update, params: {id: error_template, error_template: attributes_for(:error_template)}
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
describe 'PATCH #update' do
before { patch :update, params: {id: error_template, error_template: attributes_for(:error_template)} }
expect_assigns(error_template: ErrorTemplate)
expect_redirect { error_template }
end
it 'destroys error_template' do
expect { delete :destroy, params: {id: error_template} }.to change(ErrorTemplate, :count).by(-1)
expect(response).to redirect_to(error_templates_path)
describe 'DELETE #destroy' do
before { delete :destroy, params: {id: error_template} }
expect_assigns(error_template: ErrorTemplate)
it 'destroys the error template' do
error_template = create(:error_template)
expect { delete :destroy, params: {id: error_template} }.to change(ErrorTemplate, :count).by(-1)
end
expect_redirect { error_template }
end
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe EventsController do
RSpec.describe EventsController do
render_views
let(:user) { create(:admin) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExecutionEnvironmentsController do
RSpec.describe ExecutionEnvironmentsController do
render_views
let(:execution_environment) { create(:ruby) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExercisesController do
RSpec.describe ExercisesController do
render_views
let(:exercise) { create(:dummy) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExternalUsersController do
RSpec.describe ExternalUsersController do
render_views
let(:user) { build(:admin) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe FileTypesController do
RSpec.describe FileTypesController do
render_views
let(:file_type) { create(:dot_rb) }

View File

@ -2,13 +2,14 @@
require 'rails_helper'
describe InternalUsersController do
RSpec.describe InternalUsersController do
render_views
let(:user) { create(:admin) }
let(:consumer) { create(:consumer) }
let(:user) { create(:admin, consumer:) }
describe 'GET #activate' do
let(:user) { InternalUser.create(attributes_for(:teacher)) }
let(:user) { InternalUser.create(attributes_for(:teacher).merge(consumer:)) }
before do
user.send(:setup_activation)
@ -40,7 +41,7 @@ describe InternalUsersController do
end
describe 'PUT #activate' do
let(:user) { InternalUser.create(build(:teacher).attributes) }
let(:user) { InternalUser.create(build(:teacher, consumer:).attributes) }
let(:password) { SecureRandom.hex }
before do
@ -145,8 +146,8 @@ describe InternalUsersController do
end
describe 'DELETE #destroy' do
let(:second_user) { create(:teacher) }
let(:third_user) { create(:teacher) }
let(:second_user) { create(:teacher, consumer:) }
let(:third_user) { create(:teacher, consumer:) }
before do
allow(controller).to receive(:current_user).and_return(user)

View File

@ -5,13 +5,13 @@ require 'rails_helper'
RSpec.describe PingController do
render_views
describe 'index' do
before { allow(Runner.strategy_class).to receive(:health).and_return(true) }
it 'returns the wanted page and answer with HTTP Status 200' do
describe 'GET #index' do
before do
allow(Runner.strategy_class).to receive(:health).and_return(true)
get :index
expect(response).to have_http_status :ok
end
expect_json
expect_http_status(:ok)
end
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe RequestForCommentsController do
RSpec.describe RequestForCommentsController do
render_views
let(:user) { create(:admin) }
@ -61,12 +61,10 @@ describe RequestForCommentsController do
end
describe 'GET #index' do
it 'renders the index template' do
get :index
before { get :index }
expect(response).to have_http_status :ok
expect(response).to render_template :index
end
expect_template(:index)
expect_http_status(:ok)
it 'shows only rfc`s belonging to selected study group' do
my_study_group = create(:study_group)

View File

@ -2,14 +2,14 @@
require 'rails_helper'
describe SessionsController do
RSpec.describe SessionsController do
render_views
let(:consumer) { create(:consumer) }
describe 'POST #create' do
let(:password) { attributes_for(:teacher)[:password] }
let(:user) { InternalUser.create(user_attributes.merge(password:)) }
let(:user) { InternalUser.create(user_attributes.merge(password:, consumer:)) }
let(:user_attributes) { build(:teacher).attributes }
context 'with valid credentials' do
@ -76,7 +76,7 @@ describe SessionsController do
context 'with valid launch parameters' do
let(:locale) { :de }
let(:perform_request) { post :create_through_lti, params: {custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id} }
let(:user) { create(:external_user, consumer_id: consumer.id) }
let(:user) { create(:external_user, consumer:) }
before { allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe StatisticsController do
RSpec.describe StatisticsController do
render_views
let(:user) { create(:admin) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe SubmissionsController do
RSpec.describe SubmissionsController do
render_views
let(:exercise) { create(:math) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'seeds' do
RSpec.describe 'seeds' do
subject(:seed) { Rake::Task['db:seed'].invoke }
before do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Authentication' do
RSpec.describe 'Authentication' do
let(:user) { create(:admin) }
let(:password) { attributes_for(:admin)[:password] }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Authorization' do
RSpec.describe 'Authorization' do
before { allow(Runner.strategy_class).to receive(:available_images).and_return([]) }
context 'when being an admin' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Editor', :js do
RSpec.describe 'Editor', :js do
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
let(:scoring_response) do
[{

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'ExternalUserStatistics', :js do
RSpec.describe 'ExternalUserStatistics', :js do
let(:learner) { create(:external_user) }
let(:exercise) { create(:dummy, user:) }
let(:study_group) { create(:study_group) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Factories' do
RSpec.describe 'Factories' do
it 'are all valid', permitted_execution_time: 30 do
expect { FactoryBot.lint }.not_to raise_error
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Prometheus::Controller do
RSpec.describe Prometheus::Controller do
let(:codeocean_config) { instance_double(CodeOcean::Config) }
let(:prometheus_config) { {prometheus_exporter: {enabled: true}} }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Request_for_Comments' do
RSpec.describe 'Request_for_Comments' do
let(:user) { create(:teacher) }
before do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Admin::DashboardHelper do
RSpec.describe Admin::DashboardHelper do
before do
create(:ruby)
dcp = class_double Runner::Strategy::DockerContainerPool

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ApplicationHelper do
RSpec.describe ApplicationHelper do
describe '#code_tag' do
context 'with code' do
let(:code) { 'puts 42' }
@ -80,7 +80,7 @@ describe ApplicationHelper do
end
describe '#row' do
let(:html) { row(label: 'foo', value: 42) }
let(:html) { row(label: 'shared.show', value: 42) }
it "builds nested 'div' tags" do
expect(html).to have_css('div.attribute-row.row div.col-md-3 + div.col-md-9')

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe AuthenticatedUrlHelper do
RSpec.describe AuthenticatedUrlHelper do
describe '#add_query_parameters' do
it 'adds the given parameters to the given url' do
expect(described_class.add_query_parameters(root_url, {foo: 'bar'})).to eq(root_url(foo: 'bar'))

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExerciseHelper do
RSpec.describe ExerciseHelper do
describe '#embedding_parameters' do
let(:exercise) { build(:dummy) }

View File

@ -4,7 +4,7 @@ require 'find'
require 'active_support'
require 'rails'
describe 'yaml config files' do
RSpec.describe 'yaml config files' do
Find.find(__dir__, 'config') do |path|
next unless /.*.\.yml/.match?(path)

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Assessor do
RSpec.describe Assessor do
let(:assessor) { described_class.new(execution_environment: build(:ruby)) }
describe '#assess' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeOcean::Config do
RSpec.describe CodeOcean::Config do
describe '#read' do
let(:content) { {'foo' => 'bar'} }
let(:filename) { :foo }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe FileTree do
RSpec.describe FileTree do
let(:file_tree) { described_class.new }
describe '#file_icon' do

View File

@ -4,7 +4,7 @@ require 'rails/generators'
require 'generators/testing_framework_adapter_generator'
require 'rails_helper'
describe TestingFrameworkAdapterGenerator do
RSpec.describe TestingFrameworkAdapterGenerator do
include Silencer
describe '#create_testing_framework_adapter' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe JunitAdapter do
RSpec.describe JunitAdapter do
let(:adapter) { described_class.new }
describe '#parse_output' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe MochaAdapter do
RSpec.describe MochaAdapter do
let(:adapter) { described_class.new }
let(:count) { 42 }
let(:failed) { 25 }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe NonceStore do
RSpec.describe NonceStore do
let(:nonce) { SecureRandom.hex }
before do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe PyUnitAdapter do
RSpec.describe PyUnitAdapter do
let(:adapter) { described_class.new }
let(:count) { 42 }
let(:failed) { 25 }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe RspecAdapter do
RSpec.describe RspecAdapter do
let(:adapter) { described_class.new }
let(:count) { 42 }
let(:failed) { 25 }

View File

@ -3,7 +3,7 @@
require 'rails_helper'
require 'pathname'
describe Runner::Strategy::DockerContainerPool do
RSpec.describe Runner::Strategy::DockerContainerPool do
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create(:ruby) }
let(:container_pool) { described_class.new(runner_id, execution_environment) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Runner::Strategy::Poseidon::Connection do
RSpec.describe Runner::Strategy::Poseidon::Connection do
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create(:ruby) }
let(:strategy) { Runner::Strategy::Poseidon.new(runner_id, execution_environment) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Runner::Strategy::Poseidon do
RSpec.describe Runner::Strategy::Poseidon do
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create(:ruby) }
let(:poseidon) { described_class.new(runner_id, execution_environment) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe SqlResultSetComparatorAdapter do
RSpec.describe SqlResultSetComparatorAdapter do
let(:adapter) { described_class.new }
describe '#parse_output' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe TestingFrameworkAdapter do
RSpec.describe TestingFrameworkAdapter do
let(:adapter) { described_class.new }
let(:count) { 42 }
let(:failed) { 25 }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe UserMailer do
RSpec.describe UserMailer do
let(:user) { InternalUser.create(attributes_for(:teacher)) }
describe '#activation_needed_email' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeOcean::File do
RSpec.describe CodeOcean::File do
let(:file) { described_class.create.tap {|file| file.update(content: nil, hidden: nil, read_only: nil) } }
it 'validates the presence of a file type' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeharborLink do
RSpec.describe CodeharborLink do
it { is_expected.to validate_presence_of(:check_uuid_url) }
it { is_expected.to validate_presence_of(:push_url) }
it { is_expected.to validate_presence_of(:api_key) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Consumer do
RSpec.describe Consumer do
let(:consumer) { described_class.create }
let(:valid_consumer) { create(:consumer) }

View File

@ -2,12 +2,13 @@
require 'rails_helper'
describe ExecutionEnvironment do
RSpec.describe ExecutionEnvironment do
let(:execution_environment) { described_class.create.tap {|execution_environment| execution_environment.update(network_enabled: nil, privileged_execution: nil) } }
it 'validates that the Docker image works' do
allow(execution_environment).to receive_messages(validate_docker_image?: true, working_docker_image?: true)
execution_environment.update(build(:ruby).attributes)
execution_environment.assign_attributes(build(:ruby).attributes)
execution_environment.save(validate: false)
expect(execution_environment).to have_received(:working_docker_image?)
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Exercise do
RSpec.describe Exercise do
let(:exercise) { described_class.create.tap {|exercise| exercise.update(public: nil, token: nil) } }
let(:users) { create_list(:external_user, 10) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExternalUser do
RSpec.describe ExternalUser do
let(:user) { described_class.create }
it 'validates the presence of a consumer' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe FileType do
RSpec.describe FileType do
let(:file_type) { described_class.create.tap {|file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } }
it 'validates the presence of the binary flag' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe InternalUser do
RSpec.describe InternalUser do
let(:password) { SecureRandom.hex }
let(:user) { described_class.create }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe RequestForComment do
RSpec.describe RequestForComment do
let!(:rfc) { create(:rfc) }
describe 'scope with_comments' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Runner do
RSpec.describe Runner do
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:strategy_class) { described_class.strategy_class }
let(:strategy) { instance_double(strategy_class) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Submission do
RSpec.describe Submission do
let(:submission) { create(:submission, exercise: create(:dummy)) }
it 'validates the presence of a cause' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe Admin::DashboardPolicy do
RSpec.describe Admin::DashboardPolicy do
subject(:policy) { described_class }
permissions :show? do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ApplicationPolicy do
RSpec.describe ApplicationPolicy do
describe '#initialize' do
context 'without a user' do
it 'raises an error' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeOcean::FilePolicy do
RSpec.describe CodeOcean::FilePolicy do
subject(:policy) { described_class }
let(:exercise) { create(:fibonacci) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe CodeharborLinkPolicy do
RSpec.describe CodeharborLinkPolicy do
subject(:policy) { described_class }
let(:codeharbor_link) { create(:codeharbor_link) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ConsumerPolicy do
RSpec.describe ConsumerPolicy do
subject(:policy) { described_class }
%i[create? destroy? edit? index? new? show? update?].each do |action|

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExecutionEnvironmentPolicy do
RSpec.describe ExecutionEnvironmentPolicy do
subject(:policy) { described_class }
let(:execution_environment) { build(:ruby) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExercisePolicy do
RSpec.describe ExercisePolicy do
subject(:policy) { described_class }
let(:exercise) { build(:dummy, public: true) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExternalUserPolicy do
RSpec.describe ExternalUserPolicy do
subject(:policy) { described_class }
%i[create? destroy? edit? new? show? update?].each do |action|

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe FileTypePolicy do
RSpec.describe FileTypePolicy do
subject(:policy) { described_class }
let(:file_type) { build(:dot_rb) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe InternalUserPolicy do
RSpec.describe InternalUserPolicy do
subject(:policy) { described_class }
%i[create? edit? new? show? update?].each do |action|

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ProgrammingGroupPolicy do
RSpec.describe ProgrammingGroupPolicy do
subject(:policy) { described_class }
let(:programming_group) { build(:programming_group) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe RequestForCommentPolicy do
RSpec.describe RequestForCommentPolicy do
subject(:policy) { described_class }
context 'when the RfC visibility is not considered' do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe SubmissionPolicy do
RSpec.describe SubmissionPolicy do
subject(:policy) { described_class }
permissions :create? do

View File

@ -5,16 +5,25 @@ ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require 'support/prometheus_client_stub'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
require 'pundit/rspec'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f }
# Checks for pending migrations before tests are run.
@ -22,10 +31,8 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.include(Authentication, type: :feature)
config.include(WaitForAjax, type: :feature)
config.include(Sorcery::TestHelpers::Rails::Controller, type: :controller)
config.include(Sorcery::TestHelpers::Rails::Integration, type: :feature)
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = Rails.root.join('spec/fixtures')
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
@ -41,6 +48,13 @@ RSpec.configure do |config|
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
config.include FactoryBot::Syntax::Methods
config.include Authentication, type: :feature
config.include WaitForAjax, type: :feature
end
Shoulda::Matchers.configure do |config|

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe PingController do
RSpec.describe PingController do
context 'with routes to #show' do
it { expect(get: '/ping').to route_to('ping#index', format: :json) }
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ExerciseService::CheckExternal do
RSpec.describe ExerciseService::CheckExternal do
describe '.new' do
subject(:export_service) { described_class.new(uuid:, codeharbor_link:) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ProformaService::ConvertTaskToExercise do
RSpec.describe ProformaService::ConvertTaskToExercise do
describe '.new' do
subject(:convert_to_exercise_service) { described_class.new(task:, user:, exercise:) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ProformaService::ExportTask do
RSpec.describe ProformaService::ExportTask do
describe '.new' do
subject(:export_task) { described_class.new(exercise:) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe ProformaService::Import do
RSpec.describe ProformaService::Import do
describe '.new' do
subject(:import_service) { described_class.new(zip:, user:) }

View File

@ -2,15 +2,17 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs
# that actually need it.
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
@ -25,6 +27,37 @@ end
require 'webmock/rspec'
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - https://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
@ -32,6 +65,18 @@ RSpec.configure do |config|
# config.filter_run :focus
# config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = 'tmp/rspec_persistence_file.txt'
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
@ -58,28 +103,4 @@ RSpec.configure do |config|
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - https://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
# Save test results to persistence file to enable usage of --next-failure flag in local testing/debugging
config.example_status_persistence_file_path = 'tmp/rspec_persistence_file.txt'
end

View File

@ -2,9 +2,6 @@
require 'factory_bot'
# Use "old" FactoryBot default to allow auto-creating associations for #build
FactoryBot.use_parent_strategy = false
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe FileUploader do
RSpec.describe FileUploader do
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
let(:uploader) { described_class.new(create(:file)) }

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'execution_environments/shell.html.slim' do
RSpec.describe 'execution_environments/shell.html.slim' do
let(:execution_environment) { create(:ruby) }
before do

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'exercises/implement.html.slim' do
RSpec.describe 'exercises/implement.html.slim' do
let(:exercise) { create(:fibonacci) }
let(:files) { exercise.files.visible }
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }