Description:
- refactor into submission controller
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r596:2446ae98481f - - 24 files changed: 588 inserted, 58 deleted
@@ -0,0 +1,112 | |||||
|
|
1 | + class SubmissionsController < ApplicationController | ||
|
|
2 | + before_filter :authenticate | ||
|
|
3 | + | ||
|
|
4 | + before_filter(only: [:show]) { | ||
|
|
5 | + #check if authenticated | ||
|
|
6 | + return false unless authenticate | ||
|
|
7 | + | ||
|
|
8 | + #admin always has privileged | ||
|
|
9 | + if @current_user.admin? | ||
|
|
10 | + return true | ||
|
|
11 | + end | ||
|
|
12 | + | ||
|
|
13 | + sub = Submission.find(params[:id]) | ||
|
|
14 | + if sub.problem.available? | ||
|
|
15 | + return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user | ||
|
|
16 | + end | ||
|
|
17 | + | ||
|
|
18 | + #default to NO | ||
|
|
19 | + unauthorized_redirect | ||
|
|
20 | + return false | ||
|
|
21 | + } | ||
|
|
22 | + | ||
|
|
23 | + # GET /submissions | ||
|
|
24 | + # GET /submissions.json | ||
|
|
25 | + def index | ||
|
|
26 | + @user = @current_user | ||
|
|
27 | + @problems = @user.available_problems | ||
|
|
28 | + | ||
|
|
29 | + if params[:problem_id]==nil | ||
|
|
30 | + @problem = nil | ||
|
|
31 | + @submissions = nil | ||
|
|
32 | + else | ||
|
|
33 | + @problem = Problem.find_by_id(params[:problem_id]) | ||
|
|
34 | + if (@problem == nil) or (not @problem.available) | ||
|
|
35 | + redirect_to :action => 'list' | ||
|
|
36 | + flash[:notice] = 'Error: submissions for that problem are not viewable.' | ||
|
|
37 | + return | ||
|
|
38 | + end | ||
|
|
39 | + @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) | ||
|
|
40 | + end | ||
|
|
41 | + end | ||
|
|
42 | + | ||
|
|
43 | + # GET /submissions/1 | ||
|
|
44 | + # GET /submissions/1.json | ||
|
|
45 | + def show | ||
|
|
46 | + @submission = Submission.find(params[:id]) | ||
|
|
47 | + | ||
|
|
48 | + #log the viewing | ||
|
|
49 | + user = User.find(session[:user_id]) | ||
|
|
50 | + SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? | ||
|
|
51 | + end | ||
|
|
52 | + | ||
|
|
53 | + # GET /submissions/new | ||
|
|
54 | + # GET /submissions/new.json | ||
|
|
55 | + def new | ||
|
|
56 | + @submission = Submission.new | ||
|
|
57 | + | ||
|
|
58 | + respond_to do |format| | ||
|
|
59 | + format.html # new.html.erb | ||
|
|
60 | + format.json { render json: @submission } | ||
|
|
61 | + end | ||
|
|
62 | + end | ||
|
|
63 | + | ||
|
|
64 | + # GET /submissions/1/edit | ||
|
|
65 | + def edit | ||
|
|
66 | + @submission = Submission.find(params[:id]) | ||
|
|
67 | + end | ||
|
|
68 | + | ||
|
|
69 | + # POST /submissions | ||
|
|
70 | + # POST /submissions.json | ||
|
|
71 | + def create | ||
|
|
72 | + @submission = Submission.new(params[:submission]) | ||
|
|
73 | + | ||
|
|
74 | + respond_to do |format| | ||
|
|
75 | + if @submission.save | ||
|
|
76 | + format.html { redirect_to @submission, notice: 'Submission was successfully created.' } | ||
|
|
77 | + format.json { render json: @submission, status: :created, location: @submission } | ||
|
|
78 | + else | ||
|
|
79 | + format.html { render action: "new" } | ||
|
|
80 | + format.json { render json: @submission.errors, status: :unprocessable_entity } | ||
|
|
81 | + end | ||
|
|
82 | + end | ||
|
|
83 | + end | ||
|
|
84 | + | ||
|
|
85 | + # PUT /submissions/1 | ||
|
|
86 | + # PUT /submissions/1.json | ||
|
|
87 | + def update | ||
|
|
88 | + @submission = Submission.find(params[:id]) | ||
|
|
89 | + | ||
|
|
90 | + respond_to do |format| | ||
|
|
91 | + if @submission.update_attributes(params[:submission]) | ||
|
|
92 | + format.html { redirect_to @submission, notice: 'Submission was successfully updated.' } | ||
|
|
93 | + format.json { head :no_content } | ||
|
|
94 | + else | ||
|
|
95 | + format.html { render action: "edit" } | ||
|
|
96 | + format.json { render json: @submission.errors, status: :unprocessable_entity } | ||
|
|
97 | + end | ||
|
|
98 | + end | ||
|
|
99 | + end | ||
|
|
100 | + | ||
|
|
101 | + # DELETE /submissions/1 | ||
|
|
102 | + # DELETE /submissions/1.json | ||
|
|
103 | + def destroy | ||
|
|
104 | + @submission = Submission.find(params[:id]) | ||
|
|
105 | + @submission.destroy | ||
|
|
106 | + | ||
|
|
107 | + respond_to do |format| | ||
|
|
108 | + format.html { redirect_to submissions_url } | ||
|
|
109 | + format.json { head :no_content } | ||
|
|
110 | + end | ||
|
|
111 | + end | ||
|
|
112 | + end |
@@ -0,0 +1,15 | |||||
|
|
1 | + | ||
|
|
2 | + <% if compiler_message == nil or compiler_message.chomp == '' %> | ||
|
|
3 | + No message | ||
|
|
4 | + <% else %> | ||
|
|
5 | + <div><div><a href="#" onClick="n = this.parentNode.parentNode.lastChild; | ||
|
|
6 | + if(n.style.display == 'none') { n.style.display = 'block'; } | ||
|
|
7 | + else {n.style.display ='none'; } return false;"> | ||
|
|
8 | + (click to see)</a> | ||
|
|
9 | + </div> | ||
|
|
10 | + <div style="display: none"> | ||
|
|
11 | + <div class="compilermsgbody" style="border: thin solid grey; margin: 2px"> | ||
|
|
12 | + <%=simple_format(compiler_message) %> | ||
|
|
13 | + </div> | ||
|
|
14 | + </div></div> | ||
|
|
15 | + <% end %> |
@@ -0,0 +1,26 | |||||
|
|
1 | + | ||
|
|
2 | + %tr | ||
|
|
3 | + %td{:align => "center"} | ||
|
|
4 | + = submission_counter+1 | ||
|
|
5 | + %td{:align => "center"} | ||
|
|
6 | + = link_to "##{submission.id}", submission_path(submission.id) | ||
|
|
7 | + %td | ||
|
|
8 | + = l submission.submitted_at, format: :long | ||
|
|
9 | + = "( #{time_ago_in_words(submission.submitted_at)} ago)" | ||
|
|
10 | + %td | ||
|
|
11 | + = submission.source_filename | ||
|
|
12 | + = " (#{submission.language.pretty_name}) " | ||
|
|
13 | + = link_to('[load]',{:action => 'source', :id => submission.id}) | ||
|
|
14 | + %td | ||
|
|
15 | + - if submission.graded_at | ||
|
|
16 | + = "Graded at #{format_short_time(submission.graded_at)}." | ||
|
|
17 | + %br/ | ||
|
|
18 | + = "Score: #{(submission.points*100/submission.problem.full_score).to_i} " if GraderConfiguration['ui.show_score'] | ||
|
|
19 | + = " [" | ||
|
|
20 | + %tt | ||
|
|
21 | + = submission.grader_comment | ||
|
|
22 | + = "]" | ||
|
|
23 | + %td | ||
|
|
24 | + = render :partial => 'compiler_message', :locals => {:compiler_message => submission.compiler_message } | ||
|
|
25 | + %td | ||
|
|
26 | + = link_to 'Edit', direct_edit_submission_path(submission.id), class: 'btn btn-success' |
@@ -0,0 +1,10 | |||||
|
|
1 | + = form_for @submission do |f| | ||
|
|
2 | + - if @submission.errors.any? | ||
|
|
3 | + #error_explanation | ||
|
|
4 | + %h2= "#{pluralize(@submission.errors.count, "error")} prohibited this submission from being saved:" | ||
|
|
5 | + %ul | ||
|
|
6 | + - @submission.errors.full_messages.each do |msg| | ||
|
|
7 | + %li= msg | ||
|
|
8 | + | ||
|
|
9 | + .actions | ||
|
|
10 | + = f.submit 'Save' |
@@ -0,0 +1,7 | |||||
|
|
1 | + %h1 Editing submission | ||
|
|
2 | + | ||
|
|
3 | + = render 'form' | ||
|
|
4 | + | ||
|
|
5 | + = link_to 'Show', @submission | ||
|
|
6 | + \| | ||
|
|
7 | + = link_to 'Back', submissions_path |
@@ -0,0 +1,29 | |||||
|
|
1 | + .panel.panel-info | ||
|
|
2 | + .panel-heading | ||
|
|
3 | + Select Problems | ||
|
|
4 | + .panel-body | ||
|
|
5 | + .form-inline | ||
|
|
6 | + = select 'submission', | ||
|
|
7 | + 'problem_id', | ||
|
|
8 | + @problems.collect {|p| ["[#{p.name}] #{p.full_name}", problem_submissions_url(p.id)]}, | ||
|
|
9 | + { selected: (@problem ? problem_submissions_url(@problem) : -1) }, | ||
|
|
10 | + { class: 'select2 form-control'} | ||
|
|
11 | + %button.btn.btn-primary.btn-sm.go-button#problem_go{data: {source: '#submission_problem_id'}} Go | ||
|
|
12 | + | ||
|
|
13 | + - if @problem!=nil | ||
|
|
14 | + %h2= "Task: #{@problem.full_name} (#{@problem.name})" | ||
|
|
15 | + | ||
|
|
16 | + - if @submissions!=nil | ||
|
|
17 | + - if @submissions.length>0 | ||
|
|
18 | + %table.table | ||
|
|
19 | + %thead | ||
|
|
20 | + %th No. | ||
|
|
21 | + %th # | ||
|
|
22 | + %th At | ||
|
|
23 | + %th Source | ||
|
|
24 | + %th Result | ||
|
|
25 | + %th{:width => "300px"} Compiler message | ||
|
|
26 | + %th | ||
|
|
27 | + = render :partial => 'submission', :collection => @submissions | ||
|
|
28 | + - else | ||
|
|
29 | + No submission |
@@ -0,0 +1,5 | |||||
|
|
1 | + %h1 New submission | ||
|
|
2 | + | ||
|
|
3 | + = render 'form' | ||
|
|
4 | + | ||
|
|
5 | + = link_to 'Back', submissions_path |
@@ -0,0 +1,84 | |||||
|
|
1 | + %h1= "Submission: #{@submission.id}" | ||
|
|
2 | + | ||
|
|
3 | + %textarea#data{style: "display:none;"} | ||
|
|
4 | + :preserve | ||
|
|
5 | + #{@submission.source} | ||
|
|
6 | + | ||
|
|
7 | + //%div.highlight{:style => "border: 1px solid black;"} | ||
|
|
8 | + //=@formatted_code.html_safe | ||
|
|
9 | + .containter | ||
|
|
10 | + .row | ||
|
|
11 | + .col-md-7 | ||
|
|
12 | + %h2 Source Code | ||
|
|
13 | + .col-md-5 | ||
|
|
14 | + %h2 Stat | ||
|
|
15 | + .row | ||
|
|
16 | + .col-md-7 | ||
|
|
17 | + %div#editor{ style: "font-size: 14px; height: 400px; border-radius:5px;" } | ||
|
|
18 | + :javascript | ||
|
|
19 | + e = ace.edit("editor") | ||
|
|
20 | + e.setOptions({ maxLines: Infinity }) | ||
|
|
21 | + e.setValue($("#data").text()) | ||
|
|
22 | + e.gotoLine(1) | ||
|
|
23 | + e.getSession().setMode("#{get_ace_mode(@submission.language)}") | ||
|
|
24 | + e.setReadOnly(true) | ||
|
|
25 | + .col-md-5 | ||
|
|
26 | + %table.table.table-striped | ||
|
|
27 | + %tr | ||
|
|
28 | + %td.text-right | ||
|
|
29 | + %strong User | ||
|
|
30 | + %td | ||
|
|
31 | + - if @submission.user | ||
|
|
32 | + = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user | ||
|
|
33 | + = @submission.user.full_name | ||
|
|
34 | + - else | ||
|
|
35 | + = "(n/a)" | ||
|
|
36 | + %tr | ||
|
|
37 | + %td.text-right | ||
|
|
38 | + %strong Task | ||
|
|
39 | + %td | ||
|
|
40 | + - if @submission.problem!=nil | ||
|
|
41 | + = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem | ||
|
|
42 | + = @submission.problem.full_name | ||
|
|
43 | + - else | ||
|
|
44 | + = "(n/a)" | ||
|
|
45 | + %tr | ||
|
|
46 | + %td.text-right | ||
|
|
47 | + %strong Tries | ||
|
|
48 | + %td= @submission.number | ||
|
|
49 | + %tr | ||
|
|
50 | + %td.text-right | ||
|
|
51 | + %strong Language | ||
|
|
52 | + %td= @submission.language.pretty_name | ||
|
|
53 | + %tr | ||
|
|
54 | + %td.text-right | ||
|
|
55 | + %strong Submitted | ||
|
|
56 | + %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)}) | ||
|
|
57 | + %tr | ||
|
|
58 | + %td.text-right | ||
|
|
59 | + %strong Graded | ||
|
|
60 | + - if @submission.graded_at | ||
|
|
61 | + %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)}) | ||
|
|
62 | + - else | ||
|
|
63 | + %td - | ||
|
|
64 | + %tr | ||
|
|
65 | + %td.text-right | ||
|
|
66 | + %strong Points | ||
|
|
67 | + %td #{@submission.points}/#{@submission.problem.full_score} | ||
|
|
68 | + %tr | ||
|
|
69 | + %td.text-right | ||
|
|
70 | + %strong Comment | ||
|
|
71 | + %td #{@submission.grader_comment} | ||
|
|
72 | + %tr | ||
|
|
73 | + %td.text-right | ||
|
|
74 | + %strong Runtime (s) | ||
|
|
75 | + %td #{@submission.max_runtime} | ||
|
|
76 | + %tr | ||
|
|
77 | + %td.text-right | ||
|
|
78 | + %strong Memory (kb) | ||
|
|
79 | + %td #{@submission.peak_memory} | ||
|
|
80 | + - if session[:admin] | ||
|
|
81 | + %tr | ||
|
|
82 | + %td.text-right | ||
|
|
83 | + %strong IP | ||
|
|
84 | + %td #{@submission.ip_address} |
@@ -0,0 +1,160 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + # This spec was generated by rspec-rails when you ran the scaffold generator. | ||
|
|
4 | + # It demonstrates how one might use RSpec to specify the controller code that | ||
|
|
5 | + # was generated by Rails when you ran the scaffold generator. | ||
|
|
6 | + # | ||
|
|
7 | + # It assumes that the implementation code is generated by the rails scaffold | ||
|
|
8 | + # generator. If you are using any extension libraries to generate different | ||
|
|
9 | + # controller code, this generated spec may or may not pass. | ||
|
|
10 | + # | ||
|
|
11 | + # It only uses APIs available in rails and/or rspec-rails. There are a number | ||
|
|
12 | + # of tools you can use to make these specs even more expressive, but we're | ||
|
|
13 | + # sticking to rails and rspec-rails APIs to keep things simple and stable. | ||
|
|
14 | + # | ||
|
|
15 | + # Compared to earlier versions of this generator, there is very limited use of | ||
|
|
16 | + # stubs and message expectations in this spec. Stubs are only used when there | ||
|
|
17 | + # is no simpler way to get a handle on the object needed for the example. | ||
|
|
18 | + # Message expectations are only used when there is no simpler way to specify | ||
|
|
19 | + # that an instance is receiving a specific message. | ||
|
|
20 | + | ||
|
|
21 | + describe SubmissionsController do | ||
|
|
22 | + | ||
|
|
23 | + # This should return the minimal set of attributes required to create a valid | ||
|
|
24 | + # Submission. As you add validations to Submission, be sure to | ||
|
|
25 | + # adjust the attributes here as well. | ||
|
|
26 | + let(:valid_attributes) { { } } | ||
|
|
27 | + | ||
|
|
28 | + # This should return the minimal set of values that should be in the session | ||
|
|
29 | + # in order to pass any filters (e.g. authentication) defined in | ||
|
|
30 | + # SubmissionsController. Be sure to keep this updated too. | ||
|
|
31 | + let(:valid_session) { {} } | ||
|
|
32 | + | ||
|
|
33 | + describe "GET index" do | ||
|
|
34 | + it "assigns all submissions as @submissions" do | ||
|
|
35 | + submission = Submission.create! valid_attributes | ||
|
|
36 | + get :index, {}, valid_session | ||
|
|
37 | + assigns(:submissions).should eq([submission]) | ||
|
|
38 | + end | ||
|
|
39 | + end | ||
|
|
40 | + | ||
|
|
41 | + describe "GET show" do | ||
|
|
42 | + it "assigns the requested submission as @submission" do | ||
|
|
43 | + submission = Submission.create! valid_attributes | ||
|
|
44 | + get :show, {:id => submission.to_param}, valid_session | ||
|
|
45 | + assigns(:submission).should eq(submission) | ||
|
|
46 | + end | ||
|
|
47 | + end | ||
|
|
48 | + | ||
|
|
49 | + describe "GET new" do | ||
|
|
50 | + it "assigns a new submission as @submission" do | ||
|
|
51 | + get :new, {}, valid_session | ||
|
|
52 | + assigns(:submission).should be_a_new(Submission) | ||
|
|
53 | + end | ||
|
|
54 | + end | ||
|
|
55 | + | ||
|
|
56 | + describe "GET edit" do | ||
|
|
57 | + it "assigns the requested submission as @submission" do | ||
|
|
58 | + submission = Submission.create! valid_attributes | ||
|
|
59 | + get :edit, {:id => submission.to_param}, valid_session | ||
|
|
60 | + assigns(:submission).should eq(submission) | ||
|
|
61 | + end | ||
|
|
62 | + end | ||
|
|
63 | + | ||
|
|
64 | + describe "POST create" do | ||
|
|
65 | + describe "with valid params" do | ||
|
|
66 | + it "creates a new Submission" do | ||
|
|
67 | + expect { | ||
|
|
68 | + post :create, {:submission => valid_attributes}, valid_session | ||
|
|
69 | + }.to change(Submission, :count).by(1) | ||
|
|
70 | + end | ||
|
|
71 | + | ||
|
|
72 | + it "assigns a newly created submission as @submission" do | ||
|
|
73 | + post :create, {:submission => valid_attributes}, valid_session | ||
|
|
74 | + assigns(:submission).should be_a(Submission) | ||
|
|
75 | + assigns(:submission).should be_persisted | ||
|
|
76 | + end | ||
|
|
77 | + | ||
|
|
78 | + it "redirects to the created submission" do | ||
|
|
79 | + post :create, {:submission => valid_attributes}, valid_session | ||
|
|
80 | + response.should redirect_to(Submission.last) | ||
|
|
81 | + end | ||
|
|
82 | + end | ||
|
|
83 | + | ||
|
|
84 | + describe "with invalid params" do | ||
|
|
85 | + it "assigns a newly created but unsaved submission as @submission" do | ||
|
|
86 | + # Trigger the behavior that occurs when invalid params are submitted | ||
|
|
87 | + Submission.any_instance.stub(:save).and_return(false) | ||
|
|
88 | + post :create, {:submission => { }}, valid_session | ||
|
|
89 | + assigns(:submission).should be_a_new(Submission) | ||
|
|
90 | + end | ||
|
|
91 | + | ||
|
|
92 | + it "re-renders the 'new' template" do | ||
|
|
93 | + # Trigger the behavior that occurs when invalid params are submitted | ||
|
|
94 | + Submission.any_instance.stub(:save).and_return(false) | ||
|
|
95 | + post :create, {:submission => { }}, valid_session | ||
|
|
96 | + response.should render_template("new") | ||
|
|
97 | + end | ||
|
|
98 | + end | ||
|
|
99 | + end | ||
|
|
100 | + | ||
|
|
101 | + describe "PUT update" do | ||
|
|
102 | + describe "with valid params" do | ||
|
|
103 | + it "updates the requested submission" do | ||
|
|
104 | + submission = Submission.create! valid_attributes | ||
|
|
105 | + # Assuming there are no other submissions in the database, this | ||
|
|
106 | + # specifies that the Submission created on the previous line | ||
|
|
107 | + # receives the :update_attributes message with whatever params are | ||
|
|
108 | + # submitted in the request. | ||
|
|
109 | + Submission.any_instance.should_receive(:update_attributes).with({ "these" => "params" }) | ||
|
|
110 | + put :update, {:id => submission.to_param, :submission => { "these" => "params" }}, valid_session | ||
|
|
111 | + end | ||
|
|
112 | + | ||
|
|
113 | + it "assigns the requested submission as @submission" do | ||
|
|
114 | + submission = Submission.create! valid_attributes | ||
|
|
115 | + put :update, {:id => submission.to_param, :submission => valid_attributes}, valid_session | ||
|
|
116 | + assigns(:submission).should eq(submission) | ||
|
|
117 | + end | ||
|
|
118 | + | ||
|
|
119 | + it "redirects to the submission" do | ||
|
|
120 | + submission = Submission.create! valid_attributes | ||
|
|
121 | + put :update, {:id => submission.to_param, :submission => valid_attributes}, valid_session | ||
|
|
122 | + response.should redirect_to(submission) | ||
|
|
123 | + end | ||
|
|
124 | + end | ||
|
|
125 | + | ||
|
|
126 | + describe "with invalid params" do | ||
|
|
127 | + it "assigns the submission as @submission" do | ||
|
|
128 | + submission = Submission.create! valid_attributes | ||
|
|
129 | + # Trigger the behavior that occurs when invalid params are submitted | ||
|
|
130 | + Submission.any_instance.stub(:save).and_return(false) | ||
|
|
131 | + put :update, {:id => submission.to_param, :submission => { }}, valid_session | ||
|
|
132 | + assigns(:submission).should eq(submission) | ||
|
|
133 | + end | ||
|
|
134 | + | ||
|
|
135 | + it "re-renders the 'edit' template" do | ||
|
|
136 | + submission = Submission.create! valid_attributes | ||
|
|
137 | + # Trigger the behavior that occurs when invalid params are submitted | ||
|
|
138 | + Submission.any_instance.stub(:save).and_return(false) | ||
|
|
139 | + put :update, {:id => submission.to_param, :submission => { }}, valid_session | ||
|
|
140 | + response.should render_template("edit") | ||
|
|
141 | + end | ||
|
|
142 | + end | ||
|
|
143 | + end | ||
|
|
144 | + | ||
|
|
145 | + describe "DELETE destroy" do | ||
|
|
146 | + it "destroys the requested submission" do | ||
|
|
147 | + submission = Submission.create! valid_attributes | ||
|
|
148 | + expect { | ||
|
|
149 | + delete :destroy, {:id => submission.to_param}, valid_session | ||
|
|
150 | + }.to change(Submission, :count).by(-1) | ||
|
|
151 | + end | ||
|
|
152 | + | ||
|
|
153 | + it "redirects to the submissions list" do | ||
|
|
154 | + submission = Submission.create! valid_attributes | ||
|
|
155 | + delete :destroy, {:id => submission.to_param}, valid_session | ||
|
|
156 | + response.should redirect_to(submissions_url) | ||
|
|
157 | + end | ||
|
|
158 | + end | ||
|
|
159 | + | ||
|
|
160 | + end |
@@ -0,0 +1,15 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + # Specs in this file have access to a helper object that includes | ||
|
|
4 | + # the SubmissionsHelper. For example: | ||
|
|
5 | + # | ||
|
|
6 | + # describe SubmissionsHelper do | ||
|
|
7 | + # describe "string concat" do | ||
|
|
8 | + # it "concats two strings with spaces" do | ||
|
|
9 | + # expect(helper.concat_strings("this","that")).to eq("this that") | ||
|
|
10 | + # end | ||
|
|
11 | + # end | ||
|
|
12 | + # end | ||
|
|
13 | + describe SubmissionsHelper do | ||
|
|
14 | + pending "add some examples to (or delete) #{__FILE__}" | ||
|
|
15 | + end |
@@ -0,0 +1,11 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + describe "Submissions" do | ||
|
|
4 | + describe "GET /submissions" do | ||
|
|
5 | + it "works! (now write some real specs)" do | ||
|
|
6 | + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers | ||
|
|
7 | + get submissions_path | ||
|
|
8 | + response.status.should be(200) | ||
|
|
9 | + end | ||
|
|
10 | + end | ||
|
|
11 | + end |
@@ -0,0 +1,35 | |||||
|
|
1 | + require "spec_helper" | ||
|
|
2 | + | ||
|
|
3 | + describe SubmissionsController do | ||
|
|
4 | + describe "routing" do | ||
|
|
5 | + | ||
|
|
6 | + it "routes to #index" do | ||
|
|
7 | + get("/submissions").should route_to("submissions#index") | ||
|
|
8 | + end | ||
|
|
9 | + | ||
|
|
10 | + it "routes to #new" do | ||
|
|
11 | + get("/submissions/new").should route_to("submissions#new") | ||
|
|
12 | + end | ||
|
|
13 | + | ||
|
|
14 | + it "routes to #show" do | ||
|
|
15 | + get("/submissions/1").should route_to("submissions#show", :id => "1") | ||
|
|
16 | + end | ||
|
|
17 | + | ||
|
|
18 | + it "routes to #edit" do | ||
|
|
19 | + get("/submissions/1/edit").should route_to("submissions#edit", :id => "1") | ||
|
|
20 | + end | ||
|
|
21 | + | ||
|
|
22 | + it "routes to #create" do | ||
|
|
23 | + post("/submissions").should route_to("submissions#create") | ||
|
|
24 | + end | ||
|
|
25 | + | ||
|
|
26 | + it "routes to #update" do | ||
|
|
27 | + put("/submissions/1").should route_to("submissions#update", :id => "1") | ||
|
|
28 | + end | ||
|
|
29 | + | ||
|
|
30 | + it "routes to #destroy" do | ||
|
|
31 | + delete("/submissions/1").should route_to("submissions#destroy", :id => "1") | ||
|
|
32 | + end | ||
|
|
33 | + | ||
|
|
34 | + end | ||
|
|
35 | + end |
@@ -0,0 +1,15 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + describe "submissions/edit" do | ||
|
|
4 | + before(:each) do | ||
|
|
5 | + @submission = assign(:submission, stub_model(Submission)) | ||
|
|
6 | + end | ||
|
|
7 | + | ||
|
|
8 | + it "renders the edit submission form" do | ||
|
|
9 | + render | ||
|
|
10 | + | ||
|
|
11 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | ||
|
|
12 | + assert_select "form[action=?][method=?]", submission_path(@submission), "post" do | ||
|
|
13 | + end | ||
|
|
14 | + end | ||
|
|
15 | + end |
@@ -0,0 +1,15 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + describe "submissions/index" do | ||
|
|
4 | + before(:each) do | ||
|
|
5 | + assign(:submissions, [ | ||
|
|
6 | + stub_model(Submission), | ||
|
|
7 | + stub_model(Submission) | ||
|
|
8 | + ]) | ||
|
|
9 | + end | ||
|
|
10 | + | ||
|
|
11 | + it "renders a list of submissions" do | ||
|
|
12 | + render | ||
|
|
13 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | ||
|
|
14 | + end | ||
|
|
15 | + end |
@@ -0,0 +1,15 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + describe "submissions/new" do | ||
|
|
4 | + before(:each) do | ||
|
|
5 | + assign(:submission, stub_model(Submission).as_new_record) | ||
|
|
6 | + end | ||
|
|
7 | + | ||
|
|
8 | + it "renders new submission form" do | ||
|
|
9 | + render | ||
|
|
10 | + | ||
|
|
11 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | ||
|
|
12 | + assert_select "form[action=?][method=?]", submissions_path, "post" do | ||
|
|
13 | + end | ||
|
|
14 | + end | ||
|
|
15 | + end |
@@ -0,0 +1,12 | |||||
|
|
1 | + require 'spec_helper' | ||
|
|
2 | + | ||
|
|
3 | + describe "submissions/show" do | ||
|
|
4 | + before(:each) do | ||
|
|
5 | + @submission = assign(:submission, stub_model(Submission)) | ||
|
|
6 | + end | ||
|
|
7 | + | ||
|
|
8 | + it "renders attributes in <p>" do | ||
|
|
9 | + render | ||
|
|
10 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | ||
|
|
11 | + end | ||
|
|
12 | + end |
@@ -1,15 +1,12 | |||||
|
1 | - //%style{type: "text/css"} |
|
||
|
2 | - // = @css_style |
|
||
|
3 | - |
|
||
|
4 |
|
|
1 | %h1= "Submission: #{@submission.id}" |
|
5 |
|
2 | ||
|
6 | %textarea#data{style: "display:none;"} |
|
3 | %textarea#data{style: "display:none;"} |
|
7 | :preserve |
|
4 | :preserve |
|
8 | #{@submission.source} |
|
5 | #{@submission.source} |
|
9 |
|
6 | ||
|
10 | //%div.highlight{:style => "border: 1px solid black;"} |
|
7 | //%div.highlight{:style => "border: 1px solid black;"} |
|
11 | //=@formatted_code.html_safe |
|
8 | //=@formatted_code.html_safe |
|
12 | .containter |
|
9 | .containter |
|
13 | .row |
|
10 | .row |
|
14 | .col-md-7 |
|
11 | .col-md-7 |
|
15 | %h2 Source Code |
|
12 | %h2 Source Code |
@@ -1,18 +1,18 | |||||
|
1 | %tr |
|
1 | %tr |
|
2 | %td |
|
2 | %td |
|
3 | = "#{problem.name}" |
|
3 | = "#{problem.name}" |
|
4 | %td |
|
4 | %td |
|
5 | = "#{problem.full_name}" |
|
5 | = "#{problem.full_name}" |
|
6 | %br |
|
6 | %br |
|
7 | = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem |
|
7 | = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem |
|
8 | %td |
|
8 | %td |
|
9 | = @prob_submissions[problem.id][:count] |
|
9 | = @prob_submissions[problem.id][:count] |
|
10 | = link_to "[subs]", main_submission_path(problem.id) |
|
10 | = link_to "[subs]", main_submission_path(problem.id) |
|
11 | %td |
|
11 | %td |
|
12 | = render :partial => 'submission_short', |
|
12 | = render :partial => 'submission_short', |
|
13 | - :locals => {:submission => @prob_submissions[problem.id][:submission], :problem_name => problem.name } |
|
13 | + :locals => {:submission => @prob_submissions[problem.id][:submission], :problem_name => problem.name, :problem_id => problem.id } |
|
14 | %td |
|
14 | %td |
|
15 | - if @prob_submissions[problem.id][:submission] |
|
15 | - if @prob_submissions[problem.id][:submission] |
|
16 | = link_to 'Edit', direct_edit_submission_path(@prob_submissions[problem.id][:submission]), class: 'btn btn-success' |
|
16 | = link_to 'Edit', direct_edit_submission_path(@prob_submissions[problem.id][:submission]), class: 'btn btn-success' |
|
17 | - else |
|
17 | - else |
|
18 | = link_to 'New', direct_edit_path(problem.id), class: 'btn btn-success' |
|
18 | = link_to 'New', direct_edit_path(problem.id), class: 'btn btn-success' |
@@ -15,13 +15,13 | |||||
|
15 | = " [" |
|
15 | = " [" |
|
16 | %tt |
|
16 | %tt |
|
17 | = submission.grader_comment |
|
17 | = submission.grader_comment |
|
18 | = "]" |
|
18 | = "]" |
|
19 | %br |
|
19 | %br |
|
20 | %strong View: |
|
20 | %strong View: |
|
21 | - if GraderConfiguration.show_grading_result |
|
21 | - if GraderConfiguration.show_grading_result |
|
22 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
22 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
23 | = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true}) |
|
23 | = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true}) |
|
24 | = " | " |
|
24 | = " | " |
|
25 | = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) |
|
25 | = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id}) |
|
26 | = " | " |
|
26 | = " | " |
|
27 |
- = link_to "[#{t 'main.submissions_link'}]", |
|
27 | + = link_to "[#{t 'main.submissions_link'}]", problem_submissions_path(problem_id) |
@@ -42,95 +42,95 | |||||
|
42 | %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) |
|
42 | %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) |
|
43 | - if @best |
|
43 | - if @best |
|
44 | %tr |
|
44 | %tr |
|
45 | %td.info_param Best Runtime |
|
45 | %td.info_param Best Runtime |
|
46 | %td |
|
46 | %td |
|
47 | by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
47 | by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
48 | %br |
|
48 | %br |
|
49 | using <span class="text-success">#{@best[:runtime][:lang]}</span> |
|
49 | using <span class="text-success">#{@best[:runtime][:lang]}</span> |
|
50 | %br |
|
50 | %br |
|
51 | with <span class="text-success">#{@best[:runtime][:value] * 1000} milliseconds</span> |
|
51 | with <span class="text-success">#{@best[:runtime][:value] * 1000} milliseconds</span> |
|
52 | %br |
|
52 | %br |
|
53 | at submission |
|
53 | at submission |
|
54 |
- = link_to |
|
54 | + = link_to "#" + @best[:runtime][:sub_id].to_s, submission_path(@best[:runtime][:sub_id]) |
|
55 |
|
55 | ||
|
56 | %tr |
|
56 | %tr |
|
57 | %td.info_param |
|
57 | %td.info_param |
|
58 | Best Memory Usage |
|
58 | Best Memory Usage |
|
59 | %sup{ id: "xmem_remark", |
|
59 | %sup{ id: "xmem_remark", |
|
60 | style: "position:relative; color: blue;", |
|
60 | style: "position:relative; color: blue;", |
|
61 | data: {toggle: 'tooltip', placement: 'top', animation: 'false', delay: 20}, |
|
61 | data: {toggle: 'tooltip', placement: 'top', animation: 'false', delay: 20}, |
|
62 | title: "This counts only for submission with 100% score. Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...)"} |
|
62 | title: "This counts only for submission with 100% score. Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...)"} |
|
63 | [?] |
|
63 | [?] |
|
64 | %td |
|
64 | %td |
|
65 | by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
65 | by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} |
|
66 | %br |
|
66 | %br |
|
67 | using <span class="text-success">#{@best[:memory][:lang]}</span> |
|
67 | using <span class="text-success">#{@best[:memory][:lang]}</span> |
|
68 | %br |
|
68 | %br |
|
69 | with <span class="text-success">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> |
|
69 | with <span class="text-success">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> |
|
70 | %br |
|
70 | %br |
|
71 | at submission |
|
71 | at submission |
|
72 |
- = link_to |
|
72 | + = link_to "#" + @best[:memory][:sub_id].to_s, submission_path(@best[:memory][:sub_id]) |
|
73 |
|
73 | ||
|
74 | %tr |
|
74 | %tr |
|
75 | %td.info_param Shortest Code |
|
75 | %td.info_param Shortest Code |
|
76 | %td |
|
76 | %td |
|
77 | by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} |
|
77 | by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} |
|
78 | %br |
|
78 | %br |
|
79 | using <span class="text-success">#{@best[:length][:lang]}</span> |
|
79 | using <span class="text-success">#{@best[:length][:lang]}</span> |
|
80 | %br |
|
80 | %br |
|
81 | with <span class="text-success">#{@best[:length][:value]} bytes</span> |
|
81 | with <span class="text-success">#{@best[:length][:value]} bytes</span> |
|
82 | %br |
|
82 | %br |
|
83 | at submission |
|
83 | at submission |
|
84 |
- = link_to |
|
84 | + = link_to "#" + @best[:length][:sub_id].to_s, submission_path(@best[:length][:sub_id]) |
|
85 |
|
85 | ||
|
86 | %tr |
|
86 | %tr |
|
87 | %td.info_param First solver |
|
87 | %td.info_param First solver |
|
88 | %td |
|
88 | %td |
|
89 | - if @best[:first][:user] != '(NULL)' |
|
89 | - if @best[:first][:user] != '(NULL)' |
|
90 | #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver |
|
90 | #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver |
|
91 | %br |
|
91 | %br |
|
92 | using <span class="text-success">#{@best[:first][:lang]}</span> |
|
92 | using <span class="text-success">#{@best[:first][:lang]}</span> |
|
93 | %br |
|
93 | %br |
|
94 | on <span class="text-success">#{@best[:first][:value]}</span> |
|
94 | on <span class="text-success">#{@best[:first][:value]}</span> |
|
95 | %br |
|
95 | %br |
|
96 | at submission |
|
96 | at submission |
|
97 |
- = link_to |
|
97 | + = link_to "#" + @best[:first][:sub_id].to_s, submission_path( @best[:first][:sub_id]) |
|
98 | - else |
|
98 | - else |
|
99 | no first solver |
|
99 | no first solver |
|
100 | .col-md-8 |
|
100 | .col-md-8 |
|
101 | - if @best |
|
101 | - if @best |
|
102 | %h2 By Language |
|
102 | %h2 By Language |
|
103 | %table.table.table-hover |
|
103 | %table.table.table-hover |
|
104 | %thead |
|
104 | %thead |
|
105 | %tr |
|
105 | %tr |
|
106 | %th Language |
|
106 | %th Language |
|
107 | %th Best runtime (ms) |
|
107 | %th Best runtime (ms) |
|
108 | %th Best memory (kbytes) |
|
108 | %th Best memory (kbytes) |
|
109 | %th Shortest Code (bytes) |
|
109 | %th Shortest Code (bytes) |
|
110 | %th First solver |
|
110 | %th First solver |
|
111 | %tbody |
|
111 | %tbody |
|
112 | - @by_lang.each do |lang,value| |
|
112 | - @by_lang.each do |lang,value| |
|
113 | %tr |
|
113 | %tr |
|
114 | %td= lang |
|
114 | %td= lang |
|
115 | %td |
|
115 | %td |
|
116 | = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] |
|
116 | = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] |
|
117 | %br |
|
117 | %br |
|
118 |
- = " |
|
118 | + = "#{(value[:runtime][:value] * 1000).to_i} @" |
|
119 |
- = |
|
119 | + = link_to "#" + value[:runtime][:sub_id].to_s, submission_path( value[:runtime][:sub_id]) |
|
120 | %td |
|
120 | %td |
|
121 | = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] |
|
121 | = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] |
|
122 | %br |
|
122 | %br |
|
123 |
- = " |
|
123 | + = "#{number_with_delimiter(value[:memory][:value])} @" |
|
124 |
- = |
|
124 | + = link_to "#" + value[:memory][:sub_id].to_s, submission_path(value[:memory][:sub_id]) |
|
125 | %td |
|
125 | %td |
|
126 | = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] |
|
126 | = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] |
|
127 | %br |
|
127 | %br |
|
128 |
- = " |
|
128 | + = "#{value[:length][:value]} @" |
|
129 |
- = |
|
129 | + = link_to "#" + value[:length][:sub_id].to_s, submission_path(value[:length][:sub_id]) |
|
130 | %td |
|
130 | %td |
|
131 | - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... |
|
131 | - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... |
|
132 | = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] |
|
132 | = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] |
|
133 | %br |
|
133 | %br |
|
134 |
- = " |
|
134 | + = "#{value[:first][:value]} @" |
|
135 |
- = |
|
135 | + = link_to "#" + value[:first][:sub_id].to_s, submission_path( value[:first][:sub_id]) |
|
136 |
|
136 |
@@ -25,24 +25,30 | |||||
|
25 | get 'manage' |
|
25 | get 'manage' |
|
26 | end |
|
26 | end |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | resources :grader_configuration, controller: 'configurations' |
|
29 | resources :grader_configuration, controller: 'configurations' |
|
30 |
|
30 | ||
|
31 | resources :users do |
|
31 | resources :users do |
|
32 | member do |
|
32 | member do |
|
33 | get 'toggle_activate', 'toggle_enable' |
|
33 | get 'toggle_activate', 'toggle_enable' |
|
34 | end |
|
34 | end |
|
35 | end |
|
35 | end |
|
36 |
|
36 | ||
|
|
37 | + resources :submissions do | ||
|
|
38 | + collection do | ||
|
|
39 | + get 'prob/:problem_id', to: 'submissions#index', as: 'problem' | ||
|
|
40 | + end | ||
|
|
41 | + end | ||
|
|
42 | + | ||
|
37 | #source code edit |
|
43 | #source code edit |
|
38 | get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit' |
|
44 | get 'sources/direct_edit/:pid', to: 'sources#direct_edit', as: 'direct_edit' |
|
39 | get 'sources/direct_edit_submission/:sid', to: 'sources#direct_edit_submission', as: 'direct_edit_submission' |
|
45 | get 'sources/direct_edit_submission/:sid', to: 'sources#direct_edit_submission', as: 'direct_edit_submission' |
|
40 | get 'sources/get_latest_submission_status/:uid/:pid', to: 'sources#get_latest_submission_status', as: 'get_latest_submission_status' |
|
46 | get 'sources/get_latest_submission_status/:uid/:pid', to: 'sources#get_latest_submission_status', as: 'get_latest_submission_status' |
|
41 |
|
47 | ||
|
42 |
|
48 | ||
|
43 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
49 | match 'tasks/view/:file.:ext' => 'tasks#view' |
|
44 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
50 | match 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
45 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
51 | match 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
46 |
|
52 | ||
|
47 | #main |
|
53 | #main |
|
48 | get "main/list" |
|
54 | get "main/list" |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now