diff --git a/spec/controllers/main_controller_spec.rb b/spec/controllers/main_controller_spec.rb --- a/spec/controllers/main_controller_spec.rb +++ b/spec/controllers/main_controller_spec.rb @@ -4,7 +4,7 @@ describe MainController do before(:each) do - @problem = mock(Problem, :name => 'test') + @problem = mock(Problem, :name => 'test', :output_only => false) @language = mock(Language, :name => 'cpp', :ext => 'cpp') @submission = mock(Submission, :id => 1, @@ -14,6 +14,7 @@ :source => 'sample source', :compiler_message => 'none') @user = mock(User, :id => 1, :login => 'john') + @another_user = mock(User, :id => 2, :login => 'mary') end it "should redirect user to login page when unlogged-in user try to access main/list" do @@ -23,18 +24,21 @@ it "should let user sees her own source" do Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) + User.should_receive(:find).with(1).and_return(@user) get 'source', {:id => @submission.id}, {:user_id => 1} response.should be_success end it "should let user sees her own compiler message" do Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) + User.should_receive(:find).with(1).and_return(@user) get 'compiler_msg', {:id => @submission.id}, {:user_id => 1} response.should be_success end it "should not let user sees other user's source" do Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) + User.should_receive(:find).with(2).and_return(@another_user) get 'source', {:id => @submission.id}, {:user_id => 2} flash[:notice].should =~ /[Ee]rror/ response.should redirect_to(:action => 'list') @@ -42,6 +46,7 @@ it "should not let user sees other user's compiler message" do Submission.should_receive(:find).with(@submission.id.to_s).and_return(@submission) + User.should_receive(:find).with(2).and_return(@another_user) get 'compiler_msg', {:id => @submission.id}, {:user_id => 2} flash[:notice].should =~ /[Ee]rror/ response.should redirect_to(:action => 'list')