From bfeb3c218b9ec7b6069ee3158a1bdda7d508c8c2 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 2 Feb 2015 23:21:43 +0500 Subject: [PATCH] [#369] fix specs --- .../projects/comments_controller_spec.rb | 2 +- .../projects/issues_controller_spec.rb | 16 +++++++++--- .../projects/pull_requests_controller_spec.rb | 26 ------------------- spec/support/shared_examples/comments.rb | 4 +-- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/spec/controllers/projects/comments_controller_spec.rb b/spec/controllers/projects/comments_controller_spec.rb index 8bd00dc83..3ea583a2f 100644 --- a/spec/controllers/projects/comments_controller_spec.rb +++ b/spec/controllers/projects/comments_controller_spec.rb @@ -13,7 +13,7 @@ shared_context "comments controller" do set_session_for(@user) - @path = { name_with_owner: @project.name_with_owner, issue_id: @issue.serial_id } + @path = { name_with_owner: @project.name_with_owner, issue_id: @issue.serial_id, format: :json } @return_path = project_issue_path(@project, @issue) @create_params = { comment: { body: 'I am a comment!' }}.merge(@path) @update_params = { comment: { body: 'updated' }}.merge(@path) diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 0777b3384..09ec1297d 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -26,7 +26,7 @@ shared_context "issues controller" do } } - @update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }} + @update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }, format: :json } @pull = @project.pull_requests.new issue_attributes: { title: 'test', body: 'testing' } @pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project @@ -106,7 +106,7 @@ end shared_examples_for 'user without issue update rights' do it 'should not be able to perform update action' do put :update, {id: @issue.serial_id}.merge(@update_params) - response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path) + response.should redirect_to(forbidden_path) end it 'should not update issue title' do @@ -291,7 +291,17 @@ describe Projects::IssuesController do lambda{ post :create, @create_params }.should_not change{ Issue.count } end - it_should_behave_like 'user without issue update rights' + #it_should_behave_like 'user without issue update rights' + it 'should not be able to perform update action' do + put :update, {id: @issue.serial_id}.merge(@update_params) + response.status.should == 401 + end + + it 'should not update issue title' do + put :update, {id: @issue.serial_id}.merge(@update_params) + @issue.reload.title.should_not == 'issue2' + end + # it_should_behave_like 'user without issue destroy rights' end end diff --git a/spec/controllers/projects/pull_requests_controller_spec.rb b/spec/controllers/projects/pull_requests_controller_spec.rb index 4a78dc106..5649ee466 100644 --- a/spec/controllers/projects/pull_requests_controller_spec.rb +++ b/spec/controllers/projects/pull_requests_controller_spec.rb @@ -35,11 +35,6 @@ shared_context "pull request controller" do end shared_examples_for 'pull request user with project guest rights' do - it 'should be able to perform index action' do - get :index, name_with_owner: @project.name_with_owner - response.should render_template(:index) - end - it 'should be able to perform show action when pull request has been created' do @pull.check get :show, name_with_owner: @project.name_with_owner, id: @pull.serial_id @@ -48,12 +43,6 @@ shared_examples_for 'pull request user with project guest rights' do end shared_examples_for 'pull request user with project reader rights' do - it 'should be able to perform index action on hidden project' do - @project.update_attributes(visibility: 'hidden') - get :index, name_with_owner: @project.name_with_owner - response.should render_template(:index) - end - it 'should be able to perform create action' do post :create, @create_params response.should redirect_to(project_pull_request_path(@project, @project.pull_requests.last)) @@ -163,10 +152,6 @@ end shared_examples_for 'pull request when project with issues turned off' do before { @project.update_attributes(has_issues: false) } - it 'should be able to perform index action' do - get :index, name_with_owner: @project.name_with_owner - response.should render_template(:index) - end it 'should be able to perform show action when pull request has been created' do @pull.check @@ -268,22 +253,11 @@ describe Projects::PullRequestsController do it_should_behave_like 'pull request when project with issues turned off' else - it 'should not be able to perform index action' do - get :index, name_with_owner: @project.name_with_owner - response.should redirect_to(new_user_session_path) - end - it 'should not be able to perform show action' do @pull.check get :show, name_with_owner: @project.name_with_owner, id: @pull.serial_id response.should redirect_to(new_user_session_path) end - - it 'should not be able to perform index action on hidden project' do - @project.update_attributes(visibility: 'hidden') - get :index, name_with_owner: @project.name_with_owner - response.should redirect_to(new_user_session_path) - end end it 'should not be able to perform create action' do diff --git a/spec/support/shared_examples/comments.rb b/spec/support/shared_examples/comments.rb index 903c8a34b..455a6d24e 100644 --- a/spec/support/shared_examples/comments.rb +++ b/spec/support/shared_examples/comments.rb @@ -38,7 +38,7 @@ end shared_examples_for 'user with create comment ability' do it 'should be able to perform create action' do post :create, @create_params - response.should redirect_to(@return_path+"#comment#{Comment.last.id}") + response.should be_success #redirect_to(@return_path+"#comment#{Comment.last.id}") end it 'should create comment in the database' do @@ -81,7 +81,7 @@ end shared_examples_for 'user with destroy comment ability' do it 'should be able to perform destroy action' do delete :destroy, {id: @comment.id}.merge(@path) - response.should redirect_to(@return_path) + response.should be_success #redirect_to(@return_path) end it 'should delete comment from database' do