diff --git a/app/views/submissions/edit.html.haml b/app/views/submissions/edit.html.haml --- a/app/views/submissions/edit.html.haml +++ b/app/views/submissions/edit.html.haml @@ -1,10 +1,11 @@ -%h2 Live submit -%br - %textarea#text_sourcecode{style: "display:none"}~ @source .container .row .col-md-12 + %h2 Live submit + + .row + .col-md-12 .alert.alert-info Write your code in the following box, choose language, and click submit button when finished .row diff --git a/test/fixtures/problems.yml b/test/fixtures/problems.yml --- a/test/fixtures/problems.yml +++ b/test/fixtures/problems.yml @@ -1,24 +1,26 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html prob_add: - id: 1 name: add full_name: add_full_name + full_score: 100 available: true prob_sub: - id: 2 name: subtract full_name: subtract_full_name + full_score: 100 available: false easy: name: easy_problem full_name: Easy Problem available: true + full_score: 10 contests: contest_a, contest_b hard: name: hard_problem full_name: Hard Problem available: true + full_score: 20 contests: contest_b diff --git a/test/fixtures/submissions.yml b/test/fixtures/submissions.yml --- a/test/fixtures/submissions.yml +++ b/test/fixtures/submissions.yml @@ -1,10 +1,11 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html add1_by_admin: - id: 1 user: admin problem: prob_add language: Language_c + submitted_at: "2019-10-22 08:34" source: + xxx \#include \#include int main() { @@ -12,10 +13,10 @@ } sub1_by_admin: - id: 2 user: admin problem: prob_sub language: Language_c + submitted_at: "2019-10-22 08:34" source: \#include \#include @@ -24,10 +25,22 @@ } add1_by_john: - id: 3 user: john problem: prob_add language: Language_c + submitted_at: "2019-10-22 08:34" + source: + \#include + \#include + int main() { + cout << 33 << endl; + } + +add1_by_james: + user: james + problem: prob_add + language: Language_c + submitted_at: "2019-10-22 08:34" source: \#include \#include @@ -36,10 +49,10 @@ } sub1_by_james: - id: 4 user: james problem: prob_sub language: Language_c + submitted_at: "2019-10-22 08:34" source: \#include \#include diff --git a/test/system/submissions_test.rb b/test/system/submissions_test.rb --- a/test/system/submissions_test.rb +++ b/test/system/submissions_test.rb @@ -34,6 +34,89 @@ assert_text 'You are not authorized' end + test "admin view submissions" do + login('admin','admin') + + #view own submission + within 'header' do + click_on 'Submission' + click_on 'View' + end + click_on 'Go' + + #click the first item in the table + first('table a').click + assert_text "Source Code" + assert_text "Task" + + #view other submission of available problem + within 'header' do + click_on 'Manage' + click_on 'Problem' + end + + row = find('tr', text: 'add_full_name') + within row do + click_on 'Stat' + end + + assert_text "Submissions" + within find('tr', text: 'john') do + first('a').click + end + assert_text "Source Code" + assert_text "Task" + + #view other submission of unavailable problem + visit submission_path( submissions(:sub1_by_james) ) + assert_text "Source Code" + assert_text "Task" + end + + test "user view submissions" do + login('john','hello') + + #view own submission + within 'header' do + click_on 'Submission' + click_on 'View' + end + click_on 'Go' + + #click the first item in the table + first('table a').click + assert_text "Source Code" + assert_text "Task" + + #view other submission of available problem + GraderConfiguration.where(key: 'right.user_view_submission').update(value: 'true') + + #using direct link + visit submission_path( submissions(:add1_by_james) ) + assert_text "Source Code" + assert_text "Task" + + #view admin's submission of available problem + #using direct link + visit submission_path( submissions(:add1_by_admin) ) + assert_text "Source Code" + assert_text "Task" + + #view other submission of unavailable problem + visit submission_path( submissions(:sub1_by_james) ) + assert_text "You are not authorized" + + #view admin's submission of unavailable problem + login('john','hello') + visit submission_path( submissions(:sub1_by_admin) ) + assert_text "You are not authorized" + + #view other submission of available problem, right not allow + GraderConfiguration.where(key: 'right.user_view_submission').update(value: 'false') + login('john','hello') + visit submission_path( submissions(:add1_by_james) ) + assert_text "You are not authorized" + end def login(username,password) visit root_path