Show More
Commit Description:
updated db/schema.rb: removed unused tables
Commit Description:
updated db/schema.rb: removed unused tables
References:
File last commit:
Show/Diff file:
Action:
spec/controllers/main_controller_spec.rb
| 56 lines
| 2.1 KiB
| text/x-ruby
| RubyLexer
|
|
r71 | |||
require File.dirname(__FILE__) + '/../spec_helper' | ||||
describe MainController do | ||||
before(:each) do | ||||
|
r158 | @problem = mock(Problem, :name => 'test', :output_only => false) | ||
|
r71 | @language = mock(Language, :name => 'cpp', :ext => 'cpp') | ||
@submission = mock(Submission, | ||||
:id => 1, | ||||
:user_id => 1, | ||||
:problem => @problem, | ||||
:language => @language, | ||||
:source => 'sample source', | ||||
:compiler_message => 'none') | ||||
@user = mock(User, :id => 1, :login => 'john') | ||||
|
r158 | @another_user = mock(User, :id => 2, :login => 'mary') | ||
|
r79 | end | ||
it "should redirect user to login page when unlogged-in user try to access main/list" do | ||||
get 'list' | ||||
response.should redirect_to(:action => 'login') | ||||
|
r71 | end | ||
it "should let user sees her own source" do | ||||
|
r79 | Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
r158 | User.should_receive(:find).with(1).and_return(@user) | ||
|
r275 | @user.should_receive(:update_start_time) | ||
|
r76 | get 'source', {:id => @submission.id}, {:user_id => 1} | ||
|
r71 | response.should be_success | ||
end | ||||
it "should let user sees her own compiler message" do | ||||
|
r79 | Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
r158 | User.should_receive(:find).with(1).and_return(@user) | ||
|
r76 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 1} | ||
|
r71 | response.should be_success | ||
end | ||||
it "should not let user sees other user's source" do | ||||
|
r79 | Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
r158 | User.should_receive(:find).with(2).and_return(@another_user) | ||
|
r76 | get 'source', {:id => @submission.id}, {:user_id => 2} | ||
|
r71 | flash[:notice].should =~ /[Ee]rror/ | ||
response.should redirect_to(:action => 'list') | ||||
end | ||||
it "should not let user sees other user's compiler message" do | ||||
|
r79 | Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) | ||
|
r158 | User.should_receive(:find).with(2).and_return(@another_user) | ||
|
r76 | get 'compiler_msg', {:id => @submission.id}, {:user_id => 2} | ||
|
r71 | flash[:notice].should =~ /[Ee]rror/ | ||
response.should redirect_to(:action => 'list') | ||||
end | ||||
end | ||||