Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow adjusting the points for a solution

  • Loading branch information...
commit f86b5c5182ceaef21d05bca82dd26b078bdae2a4 1 parent ddf44d6
@skanev authored
View
3  app/assets/stylesheets/_tasks.scss
@@ -28,7 +28,8 @@ table.solutions {
.results ul li { background: { position: 0 0; repeat: no-repeat; } list-style: none; padding-left: 25px; }
.results ul li.points { background-image: image-url('icons/emoticon_grin.png'); }
- .results ul li.bonus-points { background-image: image-url('icons/star.png'); }
+ .results ul li.bonus { background-image: image-url('icons/star.png'); }
+ .results ul li.penalty { background-image: image-url('icons/stop.png'); }
.results ul li.passed-tests { background-image: image-url('icons/flag_green.png'); }
.results ul li.failed-tests { background-image: image-url('icons/flag_red.png'); }
View
8 app/controllers/solutions_controller.rb
@@ -1,4 +1,6 @@
class SolutionsController < ApplicationController
+ before_filter :require_admin, only: :update
+
def index
@task = Task.find params[:task_id]
@@ -16,4 +18,10 @@ def show
deny_access unless @task.closed? or @solution.commentable_by?(current_user)
end
+
+ def update
+ solution = Solution.find params[:id]
+ solution.update_attributes! params[:solution]
+ redirect_to solution
+ end
end
View
4 app/views/solutions/_adjustment.html.haml
@@ -0,0 +1,4 @@
+%h2 Корекция на точки
+= simple_form_for [solution.task, solution] do |form|
+ = form.input :adjustment, as: :radio, collection: -6.upto(3).map { |n| ["%+d" % n, n] }
+ = form.button :submit, 'Промени'
View
11 app/views/solutions/show.html.haml
@@ -8,8 +8,12 @@
%h2 Резултати
%ul
- %li.points #{@solution.points} точки
- %li.bonus-points 0 бонус точки
+ %li.points= pluralize @solution.points, 'точка', 'точки'
+
+ - if @solution.adjustment >= 0
+ %li.bonus= pluralize @solution.adjustment, 'бонус точка', 'бонус точки'
+ - else
+ %li.penalty= pluralize @solution.adjustment.abs, 'отнета точка', 'отнети точки'
%ul
%li.passed-tests #{@solution.passed_tests} успешни тест(а)
@@ -22,6 +26,9 @@
%h2 Лог от изпълнението
%pre.test-log(data-test-log)= @solution.log
+ - if admin?
+ = render 'solutions/adjustment', solution: @solution
+
%h2 Коментари
- if @solution.comments.present?
View
2  config/locales/en.yml
@@ -80,6 +80,8 @@ en:
description: Условие
test_case: Тест
closes_at: Краен срок
+ solution:
+ adjustment: Корекция
comment:
body: Коментар
datetime:
View
5 db/migrate/20111101184754_add_adjustment_to_solution.rb
@@ -0,0 +1,5 @@
+class AddAdjustmentToSolution < ActiveRecord::Migration
+ def change
+ add_column :solutions, :adjustment, :integer, null: false, default: 0
+ end
+end
View
6 features/solutions.feature
@@ -45,3 +45,9 @@
И трябва да виждам "6 неуспешни тест(а)"
И трябва да виждам "print('larodi')"
И трябва да виждам "OK"
+
+ Сценарий: Даване на бонус точки на решение
+ Дадено че съм влязъл като администратор
+ И че студент "Петър Петров" е предал решение на задача "Класика и джаз"
+ Когато дам 2 бонус точку да решението на "Петър Петров"
+ То решението на "Петър Петров" трябва да има 2 допълнителни точки
View
17 features/step_definitions/solutions_steps.rb
@@ -39,6 +39,15 @@
click_on 'Изпрати'
end
+When /^дам (\d+) бонус точку да решението на "([^"]*)"$/ do |points, student_name|
+ user = User.find_by_full_name! student_name
+ solution = Solution.find_by_user_id! user.id
+
+ visit solution_path(solution)
+ choose "+#{points}"
+ click_on 'Промени'
+end
+
То 'трябва да виждам следните решения:' do |table|
header = all('table th').map(&:text)
rows = all('table tbody tr').map do |table_row|
@@ -56,3 +65,11 @@
page.should have_content('Number of lines per method')
page.should have_content(method_name)
end
+
+Then /^решението на "([^"]*)" трябва да има (\d+) допълнителни точки$/ do |student_name, points|
+ user = User.find_by_full_name! student_name
+ solution = Solution.find_by_user_id! user.id
+
+ visit solution_path(solution)
+ page.should have_content "#{points} бонус точки"
+end
View
32 spec/controllers/solutions_controller_spec.rb
@@ -75,4 +75,36 @@
assigns(:solution).should == 'solution'
end
end
+
+ describe "PUT update" do
+ log_in_as :admin
+
+ let(:solution) { build_stubbed :solution }
+
+ before do
+ Solution.stub find: solution
+ solution.stub :update_attributes!
+ end
+
+ it "denies access to non-admins" do
+ current_user.stub admin?: false
+ put :update, task_id: '1', id: '2'
+ response.should deny_access
+ end
+
+ it "looks up the solution by id" do
+ Solution.should_receive(:find).with('42')
+ put :update, task_id: '1', id: '42'
+ end
+
+ it "updates the solution with params[:solution]" do
+ solution.should_receive(:update_attributes!).with('attributes')
+ put :update, task_id: '1', id: '2', solution: 'attributes'
+ end
+
+ it "redirects to the solution" do
+ put :update, task_id: '1', id: '42'
+ response.should redirect_to solution
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.