diff --git a/app/views/test/result.html.haml b/app/views/test/result.html.haml new file mode 100644 --- /dev/null +++ b/app/views/test/result.html.haml @@ -0,0 +1,27 @@ += user_title_bar(@user) + +%div{:style => "text-align: center"} + = "Problem: #{@test_request.problem.full_name}" + %br/ + = "Submission: #{@test_request.submission.number}" + %br/ + = "Test submitted at: #{format_short_time(@test_request.submitted_at)}" + %br/ + = simple_format((@test_request.running_stat or '')) + +- if @test_request.compiler_message!=nil and @test_request.compiler_message!='' + %b Compiler Message + %div{:style => "border: 1px solid black; background: lightgrey"} + = simple_format((@test_request.compiler_message or '')) + +%b Input +%div{:style => "border: 1px solid black; background: lightgrey"} + - if @test_request.input_file_name!=nil + = simple_format(read_textfile(@test_request.input_file_name,2048)) + +%b Output +%div{:style => "border: 1px solid black; background: lightgrey"} + - if @test_request.output_file_name!=nil + = simple_format(read_textfile(@test_request.output_file_name,2048)) + - else + (no output) diff --git a/spec/controllers/test_controller_spec.rb b/spec/controllers/test_controller_spec.rb new file mode 100644 --- /dev/null +++ b/spec/controllers/test_controller_spec.rb @@ -0,0 +1,28 @@ + +require File.dirname(__FILE__) + '/../spec_helper' + +describe TestController do + + before(:each) do + @john = mock(User, :id => "1", :login => 'john') + @john_result = mock(TestRequest, :id => "1", :user_id => @john.id) + @mary_result = mock(TestRequest, :id => "2", :user_id => @john.id + '1') + User.should_receive(:find).with(@john.id).and_return(@john) + end + + it "should let user see her testing result" do + TestRequest.should_receive(:find).with(@john_result.id). + and_return(@john_result) + get 'result', {:id => @john_result.id}, {:user_id => @john.id} + response.should be_success + end + + it "should not let user see other's testing result" do + TestRequest.should_receive(:find).with(@mary_result.id). + and_return(@mary_result) + get 'result', {:id => @mary_result.id}, {:user_id => @john.id} + response.should redirect_to(:action => 'index') + end + +end +