fixed multiple style guide violations

This commit is contained in:
Hauke Klement
2015-02-17 10:23:01 +01:00
parent cb87870a46
commit a13d1738e2
32 changed files with 56 additions and 64 deletions

View File

@ -1,5 +1,5 @@
module CommonBehavior
def create_and_respond(options = {}, &block)
def create_and_respond(options = {})
@object = options[:object]
respond_to do |format|
if @object.save

View File

@ -2,8 +2,8 @@ module SubmissionParameters
include FileParameters
def reject_illegal_file_attributes!(submission_params)
if exercise = Exercise.find_by(id: submission_params[:exercise_id])
submission_params[:files_attributes].try(:reject!) do |index, file_attributes|
if Exercise.exists?(id: submission_params[:exercise_id])
submission_params[:files_attributes].try(:reject!) do |_, file_attributes|
file = CodeOcean::File.find_by(id: file_attributes[:file_id])
file.nil? || file.hidden || file.read_only
end

View File

@ -24,7 +24,7 @@ class ExecutionEnvironmentsController < ApplicationController
end
def execute_command
@docker_client = DockerClient.new(execution_environment: @execution_environment, user: current_user)
@docker_client = DockerClient.new(execution_environment: @execution_environment)
render(json: @docker_client.execute_arbitrary_command(params[:command]))
end

View File

@ -9,7 +9,7 @@ class SessionsController < ApplicationController
skip_before_action :verify_authenticity_token, only: :create_through_lti
def create
if user = login(params[:email], params[:password], params[:remember_me])
if login(params[:email], params[:password], params[:remember_me])
redirect_back_or_to(:root, notice: t('.success'))
else
flash.now[:danger] = t('.failure')

View File

@ -72,7 +72,7 @@ class SubmissionsController < ApplicationController
end
def set_docker_client
@docker_client = DockerClient.new(execution_environment: @submission.execution_environment, user: current_user)
@docker_client = DockerClient.new(execution_environment: @submission.execution_environment)
end
private :set_docker_client

View File

@ -42,7 +42,7 @@ module ApplicationHelper
Kramdown::Document.new(markdown).to_html.html_safe
end
def row(options={}, &block)
def row(options = {}, &block)
content_tag(:div, class: 'attribute-row row') do
label_column(options[:label]) + value_column(options[:value], &block)
end
@ -65,7 +65,7 @@ module ApplicationHelper
end
private :translation_present?
def value_column(value, &block)
def value_column(value)
content_tag(:div, class: 'col-sm-9') do
block_given? ? yield : symbol_for(value)
end

View File

@ -4,7 +4,7 @@ class UserMailer < ActionMailer::Base
mail(subject: t('mailers.user_mailer.activation_needed.subject'), to: user.email)
end
def activation_success_email(user)
def activation_success_email(*)
end
def reset_password_email(user)

View File

@ -13,7 +13,7 @@ module User
end
ROLES.each do |role|
define_method("#{role}?") { self.try(:role) == role }
define_method("#{role}?") { try(:role) == role }
end
def external?

View File

@ -7,6 +7,8 @@ class Submission < ActiveRecord::Base
belongs_to :exercise
delegate :execution_environment, to: :exercise
scope :final, -> { where(cause: 'submit') }
scope :intermediate, -> { where.not(cause: 'submit') }
@ -24,10 +26,6 @@ class Submission < ActiveRecord::Base
ancestors.merge(descendants).values
end
def execution_environment
exercise.execution_environment
end
[:download, :render, :run, :test].each do |action|
filename = FILENAME_URL_PLACEHOLDER.gsub(/\W/, '')
define_method("#{action}_url") do

View File

@ -1 +1 @@
Docker::Container::send(:include, DockerContainerMixin)
Docker::Container.send(:include, DockerContainerMixin)

View File

@ -4,7 +4,8 @@ def find_factories_by_class(klass)
end
end
class ActiveRecord::Base
module ActiveRecord
class Base
[:build, :create].each do |strategy|
define_singleton_method("#{strategy}_factories") do |attributes = {}|
find_factories_by_class(self).map(&:name).map do |factory_name|
@ -12,6 +13,7 @@ class ActiveRecord::Base
end
end
end
end
end
# delete all present records

View File

@ -4,7 +4,7 @@ class Assessor
def assess(output)
test_outcome = @testing_framework_adapter.test_outcome(output)
test_outcome.merge(score: calculate_score(test_outcome))
rescue Exception
rescue
{score: 0}
end
@ -20,7 +20,6 @@ class Assessor
fail(Error, 'No testing framework adapter set!')
end
end
end
class Assessor::Error < RuntimeError
class Error < RuntimeError; end
end

View File

@ -6,15 +6,14 @@ module CodeOcean
def read(options = {})
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
if ::File.exists?(path)
if ::File.exist?(path)
content = options[:erb] ? YAML.load(ERB.new(::File.new(path, 'r').read).result) : YAML.load_file(path)
content[Rails.env].with_indifferent_access
else
fail(Error, "Configuration file not found: #{path}")
end
end
end
class Config::Error < RuntimeError
class Error < RuntimeError; end
end
end

View File

@ -8,7 +8,7 @@ class DockerClient
attr_reader :container_id
def self.check_availability!
Timeout::timeout(config[:connection_timeout]) { Docker.version }
Timeout.timeout(config[:connection_timeout]) { Docker.version }
rescue Excon::Errors::SocketError, Timeout::Error
raise(Error, "The Docker host at #{Docker.url} is not reachable!")
end
@ -94,7 +94,6 @@ class DockerClient
def initialize(options = {})
@execution_environment = options[:execution_environment]
@user = options[:user]
@image = self.class.find_image_by_tag(@execution_environment.docker_image)
fail(Error, "Cannot find image #{@execution_environment.docker_image}!") unless @image
end
@ -133,7 +132,7 @@ class DockerClient
end
def send_command(command, container, &block)
Timeout::timeout(@execution_environment.permitted_execution_time) do
Timeout.timeout(@execution_environment.permitted_execution_time) do
stderr = []
stdout = []
container.attach(stdin: StringIO.new(command)) do |stream, chunk|
@ -152,7 +151,6 @@ class DockerClient
Concurrent::Future.execute { self.class.destroy_container(container) }
end
private :send_command
end
class DockerClient::Error < RuntimeError
class Error < RuntimeError; end
end

View File

@ -6,12 +6,12 @@ namespace :docker do
end
desc 'List all installed Docker images'
task :images => :environment do
task images: :environment do
puts DockerClient.image_tags
end
desc 'Pull all Docker images referenced by execution environments'
task :pull => :environment do
task pull: :environment do
ExecutionEnvironment.all.map(&:docker_image).each do |docker_image|
puts "Pulling #{docker_image}..."
DockerClient.pull(docker_image)

View File

@ -11,10 +11,10 @@ class TestingFrameworkAdapter
private :augment_output
def self.framework_name
self.name
name
end
def parse_output(output)
def parse_output(*)
fail(NotImplementedError, "#{self.class} should implement #parse_output!")
end
private :parse_output

View File

@ -67,7 +67,7 @@ describe Lti do
describe '#return_to_consumer' do
context 'with a return URL' do
let(:consumer_return_url) { 'http://example.org' }
before(:each) { expect(controller).to receive(:params).and_return({launch_presentation_return_url: consumer_return_url}) }
before(:each) { expect(controller).to receive(:params).and_return(launch_presentation_return_url: consumer_return_url) }
it 'redirects to the tool consumer' do
expect(controller).to receive(:redirect_to).with(consumer_return_url)

View File

@ -38,7 +38,7 @@ describe CodeOcean::FilesController do
expect_assigns(file: CodeOcean::File)
it 'destroys the file' do
exercise = FactoryGirl.create(:fibonacci)
FactoryGirl.create(:fibonacci)
expect { request.call }.to change(CodeOcean::File, :count).by(-1)
end

View File

@ -60,7 +60,7 @@ describe ExecutionEnvironmentsController do
let(:command) { 'which ruby' }
before(:each) do
expect(DockerClient).to receive(:new).with(execution_environment: execution_environment, user: user).and_call_original
expect(DockerClient).to receive(:new).with(execution_environment: execution_environment).and_call_original
expect_any_instance_of(DockerClient).to receive(:execute_arbitrary_command).with(command)
post :execute_command, command: command, id: execution_environment.id
end

View File

@ -30,7 +30,7 @@ describe ExercisesController do
end
end
context "with a file upload" do
context 'with a file upload' do
let(:files_attributes) { {'0' => FactoryGirl.build(:file, content: fixture_file_upload('upload.rb', 'text/x-ruby')).attributes} }
let(:request) { proc { post :create, exercise: exercise_attributes.merge(files_attributes: files_attributes) } }
@ -144,7 +144,7 @@ describe ExercisesController do
context 'when the score transmission succeeds' do
before(:each) do
expect(controller).to receive(:send_score).and_return({status: 'success'})
expect(controller).to receive(:send_score).and_return(status: 'success')
request
end
@ -160,7 +160,7 @@ describe ExercisesController do
context 'when the score transmission fails' do
before(:each) do
expect(controller).to receive(:send_score).and_return({status: 'unsupported'})
expect(controller).to receive(:send_score).and_return(status: 'unsupported')
request
end

View File

@ -10,7 +10,7 @@ def create_seed_file(exercise, path, file_attributes = {})
else
file_attributes.merge!(content: SeedsHelper.read_seed_file(path))
end
file = exercise.add_file!(file_attributes)
exercise.add_file!(file_attributes)
end
FactoryGirl.define do
@ -18,7 +18,7 @@ FactoryGirl.define do
created_by_teacher
description "Try HTML's audio and video capabilities."
association :execution_environment, factory: :html
instructions "Build a simple website including an HTML <audio> and <video> element. Link the following media files: chai.ogg, devstories.mp4."
instructions 'Build a simple website including an HTML <audio> and <video> element. Link the following media files: chai.ogg, devstories.mp4.'
title 'Audio & Video'
after(:create) do |exercise|

View File

@ -182,9 +182,7 @@ FactoryGirl.define do
end
%w(binary executable renderable).each do |attribute|
trait(attribute) do
self.send(attribute, true)
end
trait(attribute) { send(attribute, true) }
end
trait :singleton_file_type do

View File

@ -27,13 +27,11 @@ describe DockerContainerPool do
end
it 'destroys all containers' do
described_class.instance_variable_get(:@containers).each do |key, value|
value.each do |container|
described_class.instance_variable_get(:@containers).values.flatten.each do |container|
expect(DockerClient).to receive(:destroy_container).with(container)
end
end
end
end
describe '.get_container' do
context 'when active' do

View File

@ -10,7 +10,7 @@ describe JunitAdapter do
let(:stdout) { "FAILURES!!!\nTests run: #{count}, Failures: #{failed}" }
it 'returns the correct numbers' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: count, failed: failed})
expect(adapter.parse_output(stdout: stdout)).to eq(count: count, failed: failed)
end
end
@ -19,7 +19,7 @@ describe JunitAdapter do
let(:stdout) { "OK (#{count} tests)" }
it 'returns the correct numbers' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: count, passed: count})
expect(adapter.parse_output(stdout: stdout)).to eq(count: count, passed: count)
end
end
end

View File

@ -8,7 +8,7 @@ describe PyUnitAdapter do
describe '#parse_output' do
it 'returns the correct numbers' do
expect(adapter.parse_output(stderr: stderr)).to eq({count: count, failed: failed})
expect(adapter.parse_output(stderr: stderr)).to eq(count: count, failed: failed)
end
end
end

View File

@ -8,7 +8,7 @@ describe RspecAdapter do
describe '#parse_output' do
it 'returns the correct numbers' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: count, failed: failed})
expect(adapter.parse_output(stdout: stdout)).to eq(count: count, failed: failed)
end
end
end

View File

@ -8,7 +8,7 @@ describe SqlResultSetComparatorAdapter do
let(:stdout) { "Missing tuples: [1]\nUnexpected tuples: []" }
it 'considers the test as failed' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: 1, failed: 1})
expect(adapter.parse_output(stdout: stdout)).to eq(count: 1, failed: 1)
end
end
@ -16,7 +16,7 @@ describe SqlResultSetComparatorAdapter do
let(:stdout) { "Missing tuples: []\nUnexpected tuples: [1]" }
it 'considers the test as failed' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: 1, failed: 1})
expect(adapter.parse_output(stdout: stdout)).to eq(count: 1, failed: 1)
end
end
@ -24,7 +24,7 @@ describe SqlResultSetComparatorAdapter do
let(:stdout) { "Missing tuples: []\nUnexpected tuples: []" }
it 'considers the test as passed' do
expect(adapter.parse_output(stdout: stdout)).to eq({count: 1, passed: 1})
expect(adapter.parse_output(stdout: stdout)).to eq(count: 1, passed: 1)
end
end
end

View File

@ -81,7 +81,7 @@ describe ExecutionEnvironment do
context 'when the command produces an error' do
it 'adds an error' do
expect_any_instance_of(DockerClient).to receive(:execute_arbitrary_command).and_return({stderr: 'command not found'})
expect_any_instance_of(DockerClient).to receive(:execute_arbitrary_command).and_return(stderr: 'command not found')
working_docker_image?
expect(execution_environment.errors[:docker_image]).to be_present
end

View File

@ -1,7 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'pundit/rspec'
@ -12,7 +12,7 @@ require 'pundit/rspec'
# 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
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.

View File

@ -3,7 +3,7 @@ class AnonymousController < ApplicationController
@flash ||= {}
end
def redirect_to(*options)
def redirect_to(*)
end
def session