Completely remove old hints connected to the execution environment
This commit is contained in:
@@ -1,103 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe HintsController do
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
let(:hint) { FactoryBot.create(:ruby_syntax_error) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with a valid hint' do
|
||||
let(:perform_request) { proc { post :create, params: { execution_environment_id: execution_environment.id, hint: FactoryBot.attributes_for(:ruby_syntax_error) } } }
|
||||
before(:each) { perform_request.call }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
|
||||
it 'creates the hint' do
|
||||
expect { perform_request.call }.to change(Hint, :count).by(1)
|
||||
end
|
||||
|
||||
expect_redirect(Hint.last)
|
||||
end
|
||||
|
||||
context 'with an invalid hint' do
|
||||
before(:each) { post :create, params: { execution_environment_id: execution_environment.id, hint: {} } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
expect_status(200)
|
||||
expect_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, params: { execution_environment_id: execution_environment.id, id: hint.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
|
||||
it 'destroys the hint' do
|
||||
hint = FactoryBot.create(:ruby_syntax_error)
|
||||
expect { delete :destroy, params: { execution_environment_id: execution_environment.id, id: hint.id } }.to change(Hint, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect { execution_environment_hints_path(execution_environment) }
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) { get :edit, params: { execution_environment_id: execution_environment.id, id: hint.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
expect_status(200)
|
||||
expect_template(:edit)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:all) { FactoryBot.create_pair(:ruby_syntax_error) }
|
||||
before(:each) { get :index, params: { execution_environment_id: execution_environment.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hints: Hint.all)
|
||||
expect_status(200)
|
||||
expect_template(:index)
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) { get :new, params: { execution_environment_id: execution_environment.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
expect_status(200)
|
||||
expect_template(:new)
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { execution_environment_id: execution_environment.id, id: hint.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: :hint)
|
||||
expect_status(200)
|
||||
expect_template(:show)
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid hint' do
|
||||
before(:each) { put :update, params: { execution_environment_id: execution_environment.id, hint: FactoryBot.attributes_for(:ruby_syntax_error), id: hint.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
expect_redirect { hint }
|
||||
end
|
||||
|
||||
context 'with an invalid hint' do
|
||||
before(:each) { put :update, params: { execution_environment_id: execution_environment.id, hint: {name: ''}, id: hint.id } }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_assigns(hint: Hint)
|
||||
expect_status(200)
|
||||
expect_template(:edit)
|
||||
end
|
||||
end
|
||||
end
|
@@ -167,28 +167,9 @@ describe SubmissionsController do
|
||||
|
||||
after(:each) { perform_request }
|
||||
|
||||
context 'when the error is covered by a hint' do
|
||||
let(:hint) { "Your object 'main' of class 'Object' does not understand the method 'foo'." }
|
||||
|
||||
before(:each) do
|
||||
expect_any_instance_of(Whistleblower).to receive(:generate_hint).with(stderr).and_return(hint)
|
||||
end
|
||||
|
||||
it 'does not store the error' do
|
||||
pending("no server sent events used right now")
|
||||
expect(CodeOcean::Error).not_to receive(:create)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the error is not covered by a hint' do
|
||||
before(:each) do
|
||||
expect_any_instance_of(Whistleblower).to receive(:generate_hint).with(stderr)
|
||||
end
|
||||
|
||||
it 'stores the error' do
|
||||
pending("no server sent events used right now")
|
||||
expect(CodeOcean::Error).to receive(:create).with(execution_environment_id: submission.exercise.execution_environment_id, message: stderr)
|
||||
end
|
||||
it 'stores the error' do
|
||||
pending("no server sent events used right now")
|
||||
expect(CodeOcean::Error).to receive(:create).with(execution_environment_id: submission.exercise.execution_environment_id, message: stderr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,101 +0,0 @@
|
||||
FactoryBot.define do
|
||||
factory :node_js_invalid_assignment, class: Hint do
|
||||
association :execution_environment, factory: :node_js
|
||||
english
|
||||
message { 'There was an error with an assignment. Maybe you have to use the equality operator here.' }
|
||||
name { 'Invalid assignment' }
|
||||
regular_expression { 'Invalid left-hand side in assignment' }
|
||||
end
|
||||
|
||||
factory :node_js_reference_error, class: Hint do
|
||||
association :execution_environment, factory: :node_js
|
||||
english
|
||||
message { "'$1' is not defined." }
|
||||
name { 'ReferenceError' }
|
||||
regular_expression { 'ReferenceError: (\w+) is not defined' }
|
||||
end
|
||||
|
||||
factory :node_js_syntax_error, class: Hint do
|
||||
association :execution_environment, factory: :node_js
|
||||
english
|
||||
message { 'You seem to have made a typo.' }
|
||||
name { 'SyntaxError' }
|
||||
regular_expression { 'SyntaxError: Unexpected token (\w+)' }
|
||||
end
|
||||
|
||||
factory :ruby_load_error, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { "The file '$1' cannot be found." }
|
||||
name { 'LoadError' }
|
||||
regular_expression { 'cannot load such file -- (\w+) (LoadError)' }
|
||||
end
|
||||
|
||||
factory :ruby_name_error_constant, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { "The constant '$1' is not defined." }
|
||||
name { 'NameError (uninitialized constant)' }
|
||||
regular_expression { 'uninitialized constant (\w+) \(NameError\)' }
|
||||
end
|
||||
|
||||
factory :ruby_name_error_variable, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { "Your object '$2' of class '$3' does not know what '$1' is. Maybe you made a typo or still have to define '$1'." }
|
||||
name { 'NameError (undefined local variable or method)' }
|
||||
regular_expression { 'undefined local variable or method `(\w+)\' for (\w+):(\w+) \(NameError\)' }
|
||||
end
|
||||
|
||||
factory :ruby_no_method_error, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { "Your object '$2' of class '$3' does not understand the method '$1'. Maybe you made a typo or still have to implement that method." }
|
||||
name { 'NoMethodError' }
|
||||
regular_expression { 'undefined method `([\w\!\?=\[\]]+)\' for (\w+):(\w+) \(NoMethodError\)' }
|
||||
end
|
||||
|
||||
factory :ruby_syntax_error, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { 'You seem to have made a typo.' }
|
||||
name { 'SyntaxError' }
|
||||
regular_expression { 'syntax error' }
|
||||
end
|
||||
|
||||
factory :ruby_system_stack_error, class: Hint do
|
||||
association :execution_environment, factory: :ruby
|
||||
english
|
||||
message { 'You seem to have built an infinite loop or recursion.' }
|
||||
name { 'SystemStackError' }
|
||||
regular_expression { 'stack level too deep \(SystemStackError\)' }
|
||||
end
|
||||
|
||||
factory :sqlite_no_such_column, class: Hint do
|
||||
association :execution_environment, factory: :sqlite
|
||||
english
|
||||
message { "The column '$1' does not exist." }
|
||||
name { 'No Such Column' }
|
||||
regular_expression { 'no such column: (\w+)' }
|
||||
end
|
||||
|
||||
factory :sqlite_no_such_table, class: Hint do
|
||||
association :execution_environment, factory: :sqlite
|
||||
english
|
||||
message { "The table '$1' does not exist." }
|
||||
name { 'No Such Table' }
|
||||
regular_expression { 'no such table: (\w+)' }
|
||||
end
|
||||
|
||||
factory :sqlite_syntax_error, class: Hint do
|
||||
association :execution_environment, factory: :sqlite
|
||||
english
|
||||
message { "You seem to have made a typo near '$1'." }
|
||||
name { 'SyntaxError' }
|
||||
regular_expression { 'near "(\w+)": syntax error' }
|
||||
end
|
||||
|
||||
trait :english do
|
||||
locale { 'en' }
|
||||
end
|
||||
end
|
@@ -1,28 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Whistleblower do
|
||||
let(:hint) { FactoryBot.create(:ruby_no_method_error) }
|
||||
let(:stderr) { "undefined method `foo' for main:Object (NoMethodError)" }
|
||||
let(:whistleblower) { described_class.new(execution_environment: hint.execution_environment) }
|
||||
|
||||
describe '#find_hint' do
|
||||
let(:find_hint) { whistleblower.send(:find_hint, stderr) }
|
||||
|
||||
it 'finds the hint' do
|
||||
expect(find_hint).to eq(hint)
|
||||
end
|
||||
|
||||
it 'stores the matches' do
|
||||
find_hint
|
||||
expect(whistleblower.instance_variable_get(:@matches)).to be_a(MatchData)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#generate_hint' do
|
||||
it 'returns the customized hint message' do
|
||||
message = whistleblower.generate_hint(stderr)
|
||||
expect(message[0..9]).to eq(hint.message[0..9])
|
||||
expect(message[-10..-1]).to eq(hint.message[-10..-1])
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,37 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Hint do
|
||||
let(:hint) { described_class.create }
|
||||
|
||||
it 'validates the presence of an execution environment' do
|
||||
expect(hint.errors[:execution_environment_id]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a locale' do
|
||||
expect(hint.errors[:locale]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a message' do
|
||||
expect(hint.errors[:message]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a name' do
|
||||
expect(hint.errors[:name]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a regular expression' do
|
||||
expect(hint.errors[:regular_expression]).to be_present
|
||||
end
|
||||
|
||||
describe '.nested_resource?' do
|
||||
it 'is true' do
|
||||
expect(described_class.nested_resource?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it "equals the hint's name" do
|
||||
expect(hint.to_s).to eq(hint.name)
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,41 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe HintPolicy do
|
||||
subject { described_class }
|
||||
|
||||
let(:hint) { FactoryBot.build(:ruby_no_method_error) }
|
||||
|
||||
[:create?, :index?, :new?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryBot.build(:admin), hint)
|
||||
end
|
||||
|
||||
it 'grants access to teachers' do
|
||||
expect(subject).to permit(FactoryBot.build(:teacher), hint)
|
||||
end
|
||||
|
||||
it 'does not grant access to external users' do
|
||||
expect(subject).not_to permit(FactoryBot.build(:external_user), hint)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[:destroy?, :edit?, :show?, :update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryBot.build(:admin), hint)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
expect(subject).to permit(hint.execution_environment.author, hint)
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
[:external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryBot.build(factory_name), hint)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user