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

@ -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) }