#90: updated specs for pull requests

This commit is contained in:
Vokhmin Alexey V 2012-10-01 15:32:40 +04:00
parent fb8d1ded5f
commit ea9baa4972
1 changed files with 27 additions and 37 deletions

View File

@ -2,7 +2,9 @@
require 'spec_helper'
shared_context "pull request controller" do
after { FileUtils.rm_rf File.join(Rails.root, "tmp", Rails.env, "pull_requests") }
before do
FileUtils.rm_rf(APP_CONFIG['root_path'])
stub_symlink_methods
@project = FactoryGirl.create(:project)
@ -14,14 +16,6 @@ shared_context "pull request controller" do
@pull.head_project, @pull.head_ref = @project, 'non_conflicts'
@pull.save
@project_with_turned_off_issues = FactoryGirl.create(:project, :has_issues => false)
@pull2 = @project_with_turned_off_issues.pull_requests.new :issue_attributes => {:title => 'test', :body => 'testing'}
@pull2.issue.user, @pull.issue.project = @project_with_turned_off_issues.owner, @pull.base_project
@pull2.base_ref = 'master'
@pull2.head_project, @pull.head_ref = @project_with_turned_off_issues, 'non_conflicts'
@pull2.save
@create_params = {
:pull_request => {:issue_attributes => {:title => 'create', :body => 'creating'},
:base_ref => 'non_conflicts',
@ -34,7 +28,6 @@ shared_context "pull request controller" do
:id => @pull.serial_id)
@user = FactoryGirl.create(:user)
@another_user = FactoryGirl.create(:user)
set_session_for(@user)
end
@ -46,7 +39,8 @@ shared_examples_for 'pull request user with project guest rights' do
response.should render_template(:index)
end
it 'should be able to perform show action' do
it 'should be able to perform show action when pull request has been created' do
@pull.check
get :show, :owner_name => @project.owner.uname, :project_name => @project.name, :id => @pull.serial_id
response.should render_template(:show)
end
@ -58,9 +52,7 @@ shared_examples_for 'pull request user with project reader rights' do
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
response.should render_template(:index)
end
end
shared_examples_for 'pull request user with project writer rights' do
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))
@ -80,7 +72,6 @@ shared_examples_for 'pull request user with project writer rights' do
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'already', :body => 'creating'}, :base_ref => 'master', :head_ref => 'master'}, :base_project_id => @project.id})
PullRequest.joins(:issue).where(:issues => {:title => 'already', :body => 'creating'}).count.should == 0
end
end
shared_examples_for 'user with pull request update rights' do
@ -89,9 +80,15 @@ shared_examples_for 'user with pull request update rights' do
response.code.should eq('200')
end
let(:issue) { @project.pull_requests.find(@pull).issue }
it 'should update pull request title and body' do
put :update, @update_params
@project.pull_requests.joins(:issue).where(:id => @pull.id, :issues => {:title => 'update', :body => 'updating'}).count.should have(1).item
issue.title.should =='update'
end
it 'should update pull request body' do
put :update, @update_params
issue.body.should =='updating'
end
end
@ -101,20 +98,28 @@ shared_examples_for 'user without pull request update rights' do
response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
end
let(:issue) { @project.pull_requests.find(@pull).issue }
it 'should not update pull request title and body' do
put :update, @update_params
@project.pull_requests.joins(:issue).where(:id => @pull.id, :issues => {:title => 'update', :body => 'updating'}).count.should have(:no).items
issue.title.should_not =='update'
end
it 'should not update pull request body' do
put :update, @update_params
issue.body.should_not =='updating'
end
end
shared_examples_for 'project with issues turned off' do
before { @project.update_attributes(:has_issues => false) }
it 'should be able to perform index action' do
get :index, :project_id => @project_with_turned_off_issues.id
get :index, :project_id => @project.id
response.should render_template(:index)
end
it 'should be able to perform show action' do
get :show, :project_id => @project_with_turned_off_issues.id, :id => @pull2.serial_id
it 'should be able to perform show action when pull request has been created' do
@pull.check
get :show, :owner_name => @project.owner.uname, :project_name => @project.name, :id => @pull.serial_id
response.should render_template(:show)
end
end
@ -130,7 +135,6 @@ describe Projects::PullRequestsController do
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request user with project reader rights'
it_should_behave_like 'pull request user with project writer rights'
it_should_behave_like 'user with pull request update rights'
it_should_behave_like 'project with issues turned off'
end
@ -142,7 +146,6 @@ describe Projects::PullRequestsController do
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request user with project reader rights'
it_should_behave_like 'pull request user with project writer rights'
it_should_behave_like 'user with pull request update rights'
it_should_behave_like 'project with issues turned off'
end
@ -155,7 +158,6 @@ describe Projects::PullRequestsController do
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request user with project reader rights'
it_should_behave_like 'pull request user with project writer rights'
it_should_behave_like 'user with pull request update rights'
it_should_behave_like 'project with issues turned off'
end
@ -167,18 +169,8 @@ describe Projects::PullRequestsController do
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request user with project reader rights'
it_should_behave_like 'pull request user with project writer rights'
it_should_behave_like 'user without pull request update rights'
it_should_behave_like 'project with issues turned off'
# it 'should not be able to perform create action on project' do
# post :create, @create_params
# response.should redirect_to(forbidden_path)
# end
# it 'should not create issue object into db' do
# lambda{ post :create, @create_params }.should change{ Issue.count }.by(0)
# end
end
context 'for project writer user' do
@ -188,7 +180,6 @@ describe Projects::PullRequestsController do
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request user with project reader rights'
it_should_behave_like 'pull request user with project writer rights'
it_should_behave_like 'user without pull request update rights'
it_should_behave_like 'project with issues turned off'
end
@ -203,10 +194,11 @@ describe Projects::PullRequestsController do
it_should_behave_like 'project with issues turned off'
end
=end
context 'for guest' do
context 'for guest' do
let(:guest) { User.new }
before do
set_session_for(User.new)
set_session_for(guest)
end
if APP_CONFIG['anonymous_access']
@ -221,6 +213,7 @@ describe Projects::PullRequestsController do
end
it 'should not be able to perform show action' do
@pull.check
get :show, :owner_name => @project.owner.uname, :project_name => @project.name, :id => @pull.serial_id
response.should redirect_to(new_user_session_path)
end
@ -244,6 +237,3 @@ describe Projects::PullRequestsController do
it_should_behave_like 'user without pull request update rights'
end
end