Update specs
This commit is contained in:
parent
d6234ae758
commit
0ca2f9e383
|
@ -35,127 +35,139 @@ describe Api::V1::IssuesController, type: :controller do
|
|||
|
||||
context 'read and accessible abilities' do
|
||||
context 'for user' do
|
||||
before(:each) do
|
||||
before do
|
||||
http_login(@issue.user)
|
||||
end
|
||||
|
||||
it 'can show issue in own project' do
|
||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should render right template for show action' do
|
||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
||||
response.should render_template('api/v1/issues/show')
|
||||
expect(response).to render_template('api/v1/issues/show')
|
||||
end
|
||||
|
||||
it 'can show issue in open project' do
|
||||
get :show, project_id: @open_project.id, id: @open_issue.serial_id, format: :json
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'can show issue in own hidden project' do
|
||||
get :show, project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id, format: :json
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "can't show issue in hidden project" do
|
||||
get :show, project_id: @hidden_project.id, id: @hidden_issue.serial_id, format: :json
|
||||
response.status.should == 403
|
||||
expect(response.code).to eq '403'
|
||||
end
|
||||
|
||||
it 'should return three issues' do
|
||||
get :all_index, filter: 'all', format: :json
|
||||
assigns[:issues].should include(@issue)
|
||||
assigns[:issues].should include(@own_hidden_issue)
|
||||
assigns[:issues].should include(@membered_issue)
|
||||
expect(assigns[:issues]).to include(@issue)
|
||||
expect(assigns[:issues]).to include(@own_hidden_issue)
|
||||
expect(assigns[:issues]).to include(@membered_issue)
|
||||
end
|
||||
|
||||
it 'should render right template for all index action' do
|
||||
get :all_index, format: :json
|
||||
response.should render_template('api/v1/issues/index')
|
||||
expect(response).to render_template('api/v1/issues/index')
|
||||
end
|
||||
|
||||
it 'should return only assigned issue' do
|
||||
get :user_index, format: :json
|
||||
assigns[:issues].should include(@own_hidden_issue)
|
||||
expect(assigns[:issues]).to include(@own_hidden_issue)
|
||||
expect(assigns[:issues].count).to eq 1
|
||||
end
|
||||
|
||||
it 'should render right template for user index action' do
|
||||
get :user_index, format: :json
|
||||
response.should render_template('api/v1/issues/index')
|
||||
expect(response).to render_template('api/v1/issues/index')
|
||||
end
|
||||
|
||||
it 'should return 404' do
|
||||
get :show, project_id: @project.id, id: 999999, format: :json
|
||||
response.status.should == 404
|
||||
expect(response.code).to eq '404'
|
||||
end
|
||||
|
||||
it 'should redirect to pull request page' do
|
||||
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
||||
response.should redirect_to(api_v1_project_pull_request_path(@project.id, @pull.serial_id))
|
||||
get :show, project_id: @project.id, id: @pull.reload.serial_id, format: :json
|
||||
expect(response).to redirect_to(api_v1_project_pull_request_path(@project.id, @pull.serial_id))
|
||||
end
|
||||
end
|
||||
|
||||
context 'for anonymous user' do
|
||||
it 'can show issue in open project', anonymous_access: true do
|
||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "can't show issue in hidden project", anonymous_access: true do
|
||||
get :show, project_id: @hidden_project.id, id: @hidden_issue.serial_id, format: :json
|
||||
response.status.should == 403
|
||||
expect(response.code).to eq '403'
|
||||
end
|
||||
|
||||
it 'should not return any issues' do
|
||||
get :all_index, filter: 'all', format: :json
|
||||
response.status.should == 401
|
||||
expect(response.code).to eq '401'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'create accessibility' do
|
||||
context 'for user' do
|
||||
before(:each) do
|
||||
before do
|
||||
http_login(@issue.user)
|
||||
end
|
||||
|
||||
it 'can create issue in own project' do
|
||||
lambda { post :create, @create_params}.should change{ Issue.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Issue, :count).by(1)
|
||||
end
|
||||
|
||||
it 'can create issue in own hidden project' do
|
||||
lambda { post :create, @create_params.merge(project_id: @own_hidden_project.id)}.should change{ Issue.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params.merge(project_id: @own_hidden_project.id)
|
||||
end.to change(Issue, :count).by(1)
|
||||
end
|
||||
|
||||
it 'can create issue in open project' do
|
||||
lambda { post :create, @create_params.merge(project_id: @open_project.id)}.should change{ Issue.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params.merge(project_id: @open_project.id)
|
||||
end.to change(Issue, :count).by(1)
|
||||
end
|
||||
|
||||
it "can't create issue in hidden project" do
|
||||
lambda { post :create, @create_params.merge(project_id: @hidden_project.id)}.should change{ Issue.count }.by(0)
|
||||
expect do
|
||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
||||
end.to change(Issue, :count).by(0)
|
||||
end
|
||||
|
||||
it 'can assignee issue in own project' do
|
||||
post :create, @create_params.deep_merge(project_id: @own_hidden_project.id, issue: {assignee_id: @issue.user.id})
|
||||
@own_hidden_project.issues.order(:id).last.assignee.id.should == @issue.user.id
|
||||
expect(@own_hidden_project.issues.order(:id).last.assignee.id).to eq @issue.user.id
|
||||
end
|
||||
|
||||
it "can't assignee issue in open project" do
|
||||
post :create, @create_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
||||
@open_project.issues.order(:id).last.assignee.should be_nil
|
||||
expect(@open_project.issues.order(:id).last.assignee).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'for anonymous user' do
|
||||
it "can't create issue in project", anonymous_access: true do
|
||||
lambda { post :create, @create_params}.should change{ Issue.count }.by(0)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Issue, :count).by(0)
|
||||
end
|
||||
|
||||
it "can't create issue in hidden project", anonymous_access: true do
|
||||
lambda { post :create, @create_params.merge(project_id: @hidden_project.id)}.should change{ Issue.count }.by(0)
|
||||
expect do
|
||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
||||
end.to change(Issue, :count).by(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -168,47 +180,44 @@ describe Api::V1::IssuesController, type: :controller do
|
|||
|
||||
it 'can update issue in own project' do
|
||||
put :update, @update_params
|
||||
@issue.reload.title.should == 'new title'
|
||||
expect(@issue.reload.title).to eq 'new title'
|
||||
end
|
||||
|
||||
it 'can update issue in own hidden project' do
|
||||
put :update, @update_params.merge(project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id)
|
||||
@own_hidden_issue.reload.title.should == 'new title'
|
||||
expect(@own_hidden_issue.reload.title).to eq 'new title'
|
||||
end
|
||||
|
||||
it "can't update issue in open project" do
|
||||
put :update, @update_params.merge(project_id: @open_project.id, id: @open_issue.serial_id)
|
||||
@open_issue.reload.title.should_not == 'new title'
|
||||
expect(@open_issue.reload.title).to_not eq 'new title'
|
||||
end
|
||||
|
||||
it "can't update issue in hidden project" do
|
||||
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_issue.serial_id)
|
||||
@hidden_issue.reload.title.should_not == 'title'
|
||||
expect(@hidden_issue.reload.title).to_not eq 'title'
|
||||
end
|
||||
|
||||
it "can't assignee issue in open project" do
|
||||
post :create, @update_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
||||
@open_issue.reload.assignee.id.should_not == @issue.user.id
|
||||
expect(@open_issue.reload.assignee.id).to_not eq @issue.user.id
|
||||
end
|
||||
|
||||
it 'can assignee issue in own project' do
|
||||
post :create, @update_params.deep_merge(issue: {assignee_id: @issue.user.id})
|
||||
@issue.reload.assignee.id.should_not == @issue.user.id
|
||||
expect(@issue.reload.assignee.id).to_not eq @issue.user.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'for anonymous user' do
|
||||
before(:each) do
|
||||
@count = Issue.count
|
||||
end
|
||||
it "can't update issue in project", anonymous_access: true do
|
||||
put :update, @update_params
|
||||
response.status.should == 401
|
||||
expect(response.code).to eq '401'
|
||||
end
|
||||
|
||||
it "can't update issue in hidden project", anonymous_access: true do
|
||||
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_issue.serial_id)
|
||||
response.status.should == 401
|
||||
expect(response.code).to eq '401'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,12 +40,12 @@ end
|
|||
shared_examples_for 'issue 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)
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'should be able to perform show action' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: @issue.serial_id
|
||||
response.should render_template(:show)
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,16 +54,18 @@ shared_examples_for 'issue 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)
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'should be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(project_issues_path(@project))
|
||||
expect(response).to redirect_to(project_issues_path(@project))
|
||||
end
|
||||
|
||||
it 'should create issue object into db' do
|
||||
lambda{ post :create, @create_params }.should change{ Issue.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Issue, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,18 +73,20 @@ shared_examples_for 'issue user with project writer 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)
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'should create issue object into db' do
|
||||
lambda{ post :create, @create_params }.should change{ Issue.count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Issue, :count).by(1)
|
||||
end
|
||||
|
||||
context 'perform create action' do
|
||||
before { post :create, @create_params }
|
||||
|
||||
it 'user should be assigned to issue' do
|
||||
@project.issues.last.assignee_id.should_not be_nil
|
||||
expect(@project.issues.last.assignee_id).to_not be_nil
|
||||
end
|
||||
|
||||
it 'label should be attached to issue' do
|
||||
|
@ -94,47 +98,49 @@ end
|
|||
shared_examples_for 'user with issue update rights' do
|
||||
it 'should be able to perform update action' do
|
||||
put :update, {id: @issue.serial_id}.merge(@update_params)
|
||||
response.code.should eq('200')
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should update issue title' do
|
||||
put :update, {id: @issue.serial_id}.merge(@update_params)
|
||||
@issue.reload.title.should == 'issue2'
|
||||
expect(@issue.reload.title).to eq 'issue2'
|
||||
end
|
||||
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(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not update issue title' do
|
||||
put :update, {id: @issue.serial_id}.merge(@update_params)
|
||||
@issue.reload.title.should_not == 'issue2'
|
||||
expect(@issue.reload.title).to_not eq 'issue2'
|
||||
end
|
||||
end
|
||||
|
||||
# shared_examples_for 'user without issue destroy rights' do
|
||||
# it 'should not be able to perform destroy action' do
|
||||
# delete :destroy, id: @issue.serial_id, name_with_owner: @project.name_with_owner
|
||||
# response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
||||
# expect(response).to redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
||||
# end
|
||||
|
||||
# it 'should not reduce issues count' do
|
||||
# lambda{ delete :destroy, id: @issue.serial_id, name_with_owner: @project.name_with_owner }.should_not change{ Issue.count }
|
||||
# expect
|
||||
# delete :destroy, id: @issue.serial_id, name_with_owner: @project.name_with_owner
|
||||
# end.to change(Issue, :count).by(0)
|
||||
# end
|
||||
# end
|
||||
|
||||
shared_examples_for 'project with issues turned off' do
|
||||
it 'should not be able to perform index action' do
|
||||
get :index, name_with_owner: @project_with_turned_off_issues.name_with_owner
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
it 'should not be able to perform show action' do
|
||||
get :show, name_with_owner: @project_with_turned_off_issues.name_with_owner, id: @turned_of_issue.serial_id
|
||||
response.should redirect_to(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -142,7 +148,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
include_context "issues controller"
|
||||
|
||||
context 'for global admin user' do
|
||||
before(:each) do
|
||||
before do
|
||||
@user.role = "admin"
|
||||
@user.save
|
||||
end
|
||||
|
@ -156,7 +162,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'for project admin user' do
|
||||
before(:each) do
|
||||
before do
|
||||
create_relation(@project, @user, 'admin')
|
||||
end
|
||||
|
||||
|
@ -169,7 +175,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'for project owner user' do
|
||||
before(:each) do
|
||||
before do
|
||||
@user = @project.owner
|
||||
set_session_for(@user)
|
||||
end
|
||||
|
@ -183,7 +189,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'for project reader user' do
|
||||
before(:each) do
|
||||
before do
|
||||
create_relation(@project, @user, 'reader')
|
||||
end
|
||||
|
||||
|
@ -197,7 +203,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
before { post :create, @create_params }
|
||||
|
||||
it 'user should not be assigned to issue' do
|
||||
@project.issues.last.assignee_id.should be_nil
|
||||
expect(@project.issues.last.assignee_id).to be_nil
|
||||
end
|
||||
|
||||
it 'label should not be attached to issue' do
|
||||
|
@ -207,26 +213,28 @@ describe Projects::IssuesController, type: :controller do
|
|||
|
||||
# it 'should not be able to perform create action on project' do
|
||||
# post :create, @create_params
|
||||
# response.should redirect_to(forbidden_path)
|
||||
# expect(response).to 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)
|
||||
# expect
|
||||
# post :create, @create_params
|
||||
# end.to change(Issue, :count).by(0)
|
||||
# end
|
||||
|
||||
it 'should return 404' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: 999999
|
||||
render_template(file: "#{Rails.root}/public/404.html")
|
||||
expect(response).to render_template(file: "#{Rails.root}/public/404.html")
|
||||
end
|
||||
|
||||
it 'should redirect to pull request page' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: @pull.serial_id
|
||||
response.should redirect_to(project_pull_request_path(@project, @pull))
|
||||
get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id
|
||||
expect(response).to redirect_to(project_pull_request_path(@project, @pull))
|
||||
end
|
||||
end
|
||||
|
||||
context 'for project writer user' do
|
||||
before(:each) do
|
||||
before do
|
||||
create_relation(@project, @user, 'writer')
|
||||
end
|
||||
|
||||
|
@ -239,7 +247,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'for issue assign user' do
|
||||
before(:each) do
|
||||
before do
|
||||
set_session_for(@issue_user)
|
||||
end
|
||||
|
||||
|
@ -250,7 +258,7 @@ describe Projects::IssuesController, type: :controller do
|
|||
|
||||
context 'for guest' do
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
set_session_for(User.new)
|
||||
end
|
||||
|
||||
|
@ -261,45 +269,47 @@ describe Projects::IssuesController, type: :controller do
|
|||
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(forbidden_path)
|
||||
expect(response).to redirect_to(forbidden_path)
|
||||
end
|
||||
|
||||
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)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not be able to perform show action' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: @issue.serial_id
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to 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)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not create issue object into db' do
|
||||
lambda{ post :create, @create_params }.should_not change{ Issue.count }
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(Issue, :count).by(0)
|
||||
end
|
||||
|
||||
#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
|
||||
expect(response.code).to eq '401'
|
||||
end
|
||||
|
||||
it 'should not update issue title' do
|
||||
put :update, {id: @issue.serial_id}.merge(@update_params)
|
||||
@issue.reload.title.should_not == 'issue2'
|
||||
expect(@issue.reload.title).to_not eq 'issue2'
|
||||
end
|
||||
|
||||
# it_should_behave_like 'user without issue destroy rights'
|
||||
|
|
|
@ -21,7 +21,7 @@ shared_context "pull request controller" do
|
|||
to_project: @project.name_with_owner,
|
||||
name_with_owner: @project.name_with_owner
|
||||
}
|
||||
@update_params = @create_params.merge(pull_request_action: 'close', id: @pull.serial_id)
|
||||
@update_params = @create_params.merge(pull_request_action: 'close', id: @pull.reload.serial_id)
|
||||
@wrong_update_params = @create_params.merge(
|
||||
pull_request: { issue_attributes: { title: 'update', body: 'updating', id: @pull.issue.id }},
|
||||
id: @pull.serial_id
|
||||
|
@ -38,114 +38,124 @@ shared_examples_for 'pull request user with project guest rights' do
|
|||
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
|
||||
response.should render_template(:show)
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'pull request user with project reader 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))
|
||||
expect(response).to redirect_to(project_pull_request_path(@project, @project.pull_requests.last))
|
||||
end
|
||||
|
||||
it 'should create pull request object into db' do
|
||||
lambda{ post :create, @create_params }.should change{ PullRequest.joins(:issue).
|
||||
where(issues: {title: 'create', body: 'creating'}).count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change {
|
||||
PullRequest.joins(:issue).where(issues: {title: 'create', body: 'creating'}).count
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
it "should not create same pull" do
|
||||
post :create, @create_params.merge({pull_request: {issue_attributes: {title: 'same', body: 'creating'}, from_ref: 'non_conflicts', to_ref: 'master'}, to_project_id: @project.id})
|
||||
PullRequest.joins(:issue).where(issues: {title: 'same', body: 'creating'}).count.should == 0
|
||||
expect do
|
||||
post :create, @create_params.merge({pull_request: {issue_attributes: {title: 'same', body: 'creating'}, from_ref: 'non_conflicts', to_ref: 'master'}, to_project_id: @project.id})
|
||||
end.to change(PullRequest, :count).by(0)
|
||||
end
|
||||
|
||||
it "should not create already up-to-date pull" do
|
||||
lambda{
|
||||
expect do
|
||||
post :create, @create_params.merge({pull_request: {issue_attributes: {title: 'already', body: 'creating'},
|
||||
to_ref: 'master', from_ref: 'master'}, to_project_id: @project.id}) }.should
|
||||
change{ PullRequest.count }.by(0)
|
||||
to_ref: 'master', from_ref: 'master'}, to_project_id: @project.id})
|
||||
end.to change(PullRequest, :count).by(0)
|
||||
end
|
||||
|
||||
it "should create pull request to the same project" do
|
||||
@parent = FactoryGirl.create(:project)
|
||||
@project.update_attributes({parent_id: @parent}, without_protection: true)
|
||||
|
||||
lambda{ post :create, @create_params }.should change{ PullRequest.joins(:issue).
|
||||
where(issues: {user_id: @user}, to_project_id: @project, from_project_id: @project).count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change {
|
||||
PullRequest.joins(:issue).where(issues: {user_id: @user}, to_project_id: @project, from_project_id: @project).count
|
||||
}.by(1)
|
||||
end
|
||||
|
||||
it "should create pull request to the parent project" do
|
||||
@parent = FactoryGirl.create(:project_with_commit)
|
||||
@project.update_attributes({parent_id: @parent}, without_protection: true)
|
||||
|
||||
lambda{ post :create, @create_params.merge({to_project: @parent.name_with_owner}) }.should change{ PullRequest.joins(:issue).
|
||||
where(issues: {user_id: @user}, to_project_id: @parent, from_project_id: @project).count }.by(1)
|
||||
expect do
|
||||
post :create, @create_params.merge({to_project: @parent.name_with_owner})
|
||||
end.to change {
|
||||
PullRequest.joins(:issue).where(issues: {user_id: @user}, to_project_id: @parent, from_project_id: @project).count
|
||||
}.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user with pull request update rights' do
|
||||
it 'should be able to perform update action' do
|
||||
put :update, @update_params
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'should be able to perform merge action' do
|
||||
@pull.check
|
||||
put :merge, @update_params
|
||||
response.should be_success
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
let(:pull) { @project.pull_requests.find(@pull) }
|
||||
it 'should update pull request status' do
|
||||
put :update, @update_params
|
||||
pull.status.should =='closed'
|
||||
expect(pull.status).to eq 'closed'
|
||||
end
|
||||
|
||||
it 'should not update pull request title' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.title.should =='test'
|
||||
expect(pull.issue.title).to eq 'test'
|
||||
end
|
||||
|
||||
it 'should not update pull request body' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.body.should =='testing'
|
||||
expect(pull.issue.body).to eq 'testing'
|
||||
end
|
||||
|
||||
it 'should not update pull request title direct' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.title.should_not =='update'
|
||||
expect(pull.issue.title).to_not eq 'update'
|
||||
end
|
||||
|
||||
it 'should not update pull request body direct' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.body.should_not =='updating'
|
||||
expect(pull.issue.body).to_not eq 'updating'
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'user without pull request update rights' do
|
||||
it 'should not be able to perform update action' do
|
||||
put :update, @update_params
|
||||
response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
||||
expect(response).to redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
||||
end
|
||||
|
||||
let(:pull) { @project.pull_requests.find(@pull) }
|
||||
it 'should not update pull request status' do
|
||||
put :update, @update_params
|
||||
pull.status.should_not =='closed'
|
||||
expect(pull.status).to_not eq 'closed'
|
||||
end
|
||||
it 'should not update pull request title' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.title.should_not =='update'
|
||||
expect(pull.issue.title).to_not eq 'update'
|
||||
end
|
||||
|
||||
it 'should not update pull request body' do
|
||||
put :update, @wrong_update_params
|
||||
pull.issue.body.should_not =='updating'
|
||||
expect(pull.issue.body).to_not eq 'updating'
|
||||
end
|
||||
|
||||
it 'should not be able to perform merge action' do
|
||||
@pull.check
|
||||
put :merge, @update_params
|
||||
response.should_not be_success
|
||||
expect(response).to_not be_success
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -156,7 +166,7 @@ shared_examples_for 'pull request when project with issues turned off' do
|
|||
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
|
||||
response.should render_template(:show)
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -210,12 +220,12 @@ describe Projects::PullRequestsController, type: :controller do
|
|||
|
||||
it 'should return 404' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: 999999
|
||||
render_template(file: "#{Rails.root}/public/404.html")
|
||||
expect(response).to render_template(file: "#{Rails.root}/public/404.html")
|
||||
end
|
||||
|
||||
it 'should redirect to issue page' do
|
||||
get :show, name_with_owner: @project.name_with_owner, id: @issue.serial_id
|
||||
response.should redirect_to(project_issue_path(@project, @issue))
|
||||
expect(response).to redirect_to(project_issue_path(@project, @issue))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -256,24 +266,26 @@ describe Projects::PullRequestsController, type: :controller do
|
|||
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)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not be able to perform create action' do
|
||||
post :create, @create_params
|
||||
response.should redirect_to(new_user_session_path)
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not create pull request object into db' do
|
||||
lambda{ post :create, @create_params }.should_not change{ PullRequest.count }
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(PullRequest, :count).by(0)
|
||||
end
|
||||
|
||||
it_should_behave_like 'user without pull request update rights'
|
||||
end
|
||||
|
||||
context 'send email messages' do
|
||||
before(:each) do
|
||||
before do
|
||||
@project_reader = FactoryGirl.create :user
|
||||
create_relation(@project, @project_reader, 'reader')
|
||||
@project_admin = FactoryGirl.create :user
|
||||
|
@ -286,19 +298,22 @@ describe Projects::PullRequestsController, type: :controller do
|
|||
end
|
||||
|
||||
it 'should send two email messages to project admins' do
|
||||
post :create, @create_params
|
||||
ActionMailer::Base.deliveries.count.should == 2
|
||||
expect do
|
||||
post :create, @create_params
|
||||
end.to change(ActionMailer::Base.deliveries, :count).by(2)
|
||||
end
|
||||
|
||||
it 'should send two email messages to admins and one to assignee' do
|
||||
post :create, @create_params.deep_merge(issue: {assignee_id: @project_reader.id})
|
||||
ActionMailer::Base.deliveries.count.should == 3
|
||||
expect do
|
||||
post :create, @create_params.deep_merge(issue: {assignee_id: @project_reader.id})
|
||||
end.to change(ActionMailer::Base.deliveries, :count).by(3)
|
||||
end
|
||||
|
||||
it 'should not duplicate email message' do
|
||||
post :create, @create_params.deep_merge(issue: {assignee_id: @project_admin.id})
|
||||
ActionMailer::Base.deliveries.count.should == 2 # send only to admins
|
||||
ActionMailer::Base.deliveries.first.to != ActionMailer::Base.deliveries.last.to
|
||||
expect do
|
||||
post :create, @create_params.deep_merge(issue: {assignee_id: @project_admin.id})
|
||||
end.to change(ActionMailer::Base.deliveries, :count).by(2) # send only to admins
|
||||
expect(ActionMailer::Base.deliveries.first.to).to_not eq ActionMailer::Base.deliveries.last.to
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue