From ec4503e2d41c0b6c3789243552855efce5e22723 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 9 Jun 2015 22:34:39 +0300 Subject: [PATCH] Cleanup of specs --- .../api/v1/issues_controller_spec.rb | 133 ++++++------ .../api/v1/pull_requests_controller_spec.rb | 196 +++++++++--------- 2 files changed, 168 insertions(+), 161 deletions(-) diff --git a/spec/controllers/api/v1/issues_controller_spec.rb b/spec/controllers/api/v1/issues_controller_spec.rb index 84f9c915f..84ef4f7f9 100644 --- a/spec/controllers/api/v1/issues_controller_spec.rb +++ b/spec/controllers/api/v1/issues_controller_spec.rb @@ -1,74 +1,64 @@ require 'spec_helper' describe Api::V1::IssuesController, type: :controller do + let(:user) { FactoryGirl.create(:user) } + let(:project) { FactoryGirl.create(:project_with_commit) } + let(:issue) { FactoryGirl.create(:issue, project: project, user: user) } + let(:open_project) { FactoryGirl.create(:project) } + let(:open_issue) { FactoryGirl.create(:issue, project: open_project) } + let(:own_hidden_project) { FactoryGirl.create(:project, owner: user, visibility: 'hidden') } + let(:own_hidden_issue) { FactoryGirl.create(:issue, project: own_hidden_project, assignee: user) } + let(:hidden_project) { FactoryGirl.create(:project, visibility: 'hidden') } + let(:hidden_issue) { FactoryGirl.create(:issue, project: hidden_project) } + let(:create_params) { {issue: {title: 'title', body: 'body'}, project_id: project.id, format: :json} } + let(:update_params) { {issue: {title: 'new title'}, project_id: project.id, id: issue.serial_id, format: :json} } + before do stub_symlink_methods allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0)) - - @project = FactoryGirl.create(:project_with_commit) - @issue = FactoryGirl.create(:issue, project: @project) - - @membered_issue = FactoryGirl.create(:issue) - @membered_project = @membered_issue.project - create_relation(@membered_project, @issue.user, 'reader') - - @open_issue = FactoryGirl.create(:issue) - @open_project = @open_issue.project - - @own_hidden_project = FactoryGirl.create(:project, owner: @issue.user) - @own_hidden_project.update_column :visibility, 'hidden' - @own_hidden_issue = FactoryGirl.create(:issue, project: @own_hidden_project, assignee: @issue.user) - - @hidden_issue = FactoryGirl.create(:issue) - @hidden_project = @hidden_issue.project - @hidden_project.update_column :visibility, 'hidden' - - @create_params = {issue: {title: 'title', body: 'body'}, project_id: @project.id, format: :json} - @update_params = {issue: {title: 'new title'}, project_id: @project.id, id: @issue.serial_id, format: :json} - - @pull = @project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'} - @pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project - @pull.to_ref = 'master' - @pull.from_project, @pull.from_ref = @project, 'non_conflicts' - @pull.save end context 'read and accessible abilities' do context 'for user' do before do - http_login(@issue.user) + http_login(user) end it 'can show issue in own project' do - get :show, project_id: @project.id, id: @issue.serial_id, format: :json + get :show, project_id: project.id, id: issue.serial_id, format: :json 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 + get :show, project_id: project.id, id: issue.serial_id, format: :json 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 + get :show, project_id: open_project.id, id: open_issue.serial_id, format: :json 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 + get :show, project_id: own_hidden_project.id, id: own_hidden_issue.serial_id, format: :json 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 + get :show, project_id: hidden_project.id, id: hidden_issue.serial_id, format: :json expect(response.code).to eq '403' end it 'should return three issues' do + membered_issue = FactoryGirl.create(:issue) + membered_project = membered_issue.project + create_relation(membered_project, issue.user, 'reader') + + issue && own_hidden_issue # init get :all_index, filter: 'all', format: :json - expect(assigns[:issues]).to include(@issue) - expect(assigns[:issues]).to include(@own_hidden_issue) - expect(assigns[:issues]).to 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 @@ -77,8 +67,9 @@ describe Api::V1::IssuesController, type: :controller do end it 'should return only assigned issue' do + own_hidden_issue # init get :user_index, format: :json - expect(assigns[:issues]).to include(@own_hidden_issue) + expect(assigns[:issues]).to include(own_hidden_issue) expect(assigns[:issues].count).to eq 1 end @@ -88,24 +79,30 @@ describe Api::V1::IssuesController, type: :controller do end it 'should return 404' do - get :show, project_id: @project.id, id: 999999, format: :json + get :show, project_id: project.id, id: 999999, format: :json expect(response.code).to eq '404' end it 'should redirect to pull request page' do - 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)) + pull = project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'} + pull.issue.user, pull.issue.project = project.owner, pull.to_project + pull.to_ref = 'master' + pull.from_project, pull.from_ref = project, 'non_conflicts' + pull.save + + 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 + get :show, project_id: project.id, id: issue.serial_id, format: :json 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 + get :show, project_id: hidden_project.id, id: hidden_issue.serial_id, format: :json expect(response.code).to eq '403' end @@ -119,54 +116,54 @@ describe Api::V1::IssuesController, type: :controller do context 'create accessibility' do context 'for user' do before do - http_login(@issue.user) + http_login(user) end it 'can create issue in own project' do expect do - post :create, @create_params + post :create, create_params end.to change(Issue, :count).by(1) end it 'can create issue in own hidden project' do expect do - post :create, @create_params.merge(project_id: @own_hidden_project.id) + 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 expect do - post :create, @create_params.merge(project_id: @open_project.id) + 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 expect do - post :create, @create_params.merge(project_id: @hidden_project.id) + 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}) - expect(@own_hidden_project.issues.order(:id).last.assignee.id).to eq @issue.user.id + post :create, create_params.deep_merge(project_id: own_hidden_project.id, issue: {assignee_id: user.id}) + expect(own_hidden_project.issues.order(:id).last.assignee.id).to eq 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}) - expect(@open_project.issues.order(:id).last.assignee).to be_nil + post :create, create_params.deep_merge(project_id: open_project.id, issue: {assignee_id: user.id}) + 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 expect do - post :create, @create_params + post :create, create_params end.to change(Issue, :count).by(0) end it "can't create issue in hidden project", anonymous_access: true do expect do - post :create, @create_params.merge(project_id: @hidden_project.id) + post :create, create_params.merge(project_id: hidden_project.id) end.to change(Issue, :count).by(0) end end @@ -175,48 +172,48 @@ describe Api::V1::IssuesController, type: :controller do context 'update accessibility' do context 'for user' do before(:each) do - http_login(@issue.user) + http_login(user) end it 'can update issue in own project' do - put :update, @update_params - expect(@issue.reload.title).to eq 'new title' + put :update, update_params + 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) - expect(@own_hidden_issue.reload.title).to eq 'new title' + put :update, update_params.merge(project_id: own_hidden_project.id, id: own_hidden_issue.serial_id) + 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) - expect(@open_issue.reload.title).to_not eq 'new title' + put :update, update_params.merge(project_id: open_project.id, id: open_issue.serial_id) + 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) - expect(@hidden_issue.reload.title).to_not eq 'title' + put :update, update_params.merge(project_id: hidden_project.id, id: hidden_issue.serial_id) + 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}) - expect(@open_issue.reload.assignee.id).to_not eq @issue.user.id + post :create, update_params.deep_merge(project_id: open_project.id, issue: {assignee_id: 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}) - expect(@issue.reload.assignee.id).to_not eq @issue.user.id + post :create, update_params.deep_merge(issue: {assignee_id: issue.user.id}) + expect(issue.reload.assignee.id).to_not eq issue.user.id end end context 'for anonymous user' do it "can't update issue in project", anonymous_access: true do - put :update, @update_params + put :update, update_params 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) + put :update, update_params.merge(project_id: hidden_project.id, id: hidden_issue.serial_id) expect(response.code).to eq '401' end end diff --git a/spec/controllers/api/v1/pull_requests_controller_spec.rb b/spec/controllers/api/v1/pull_requests_controller_spec.rb index 46df0d5f7..c72470243 100644 --- a/spec/controllers/api/v1/pull_requests_controller_spec.rb +++ b/spec/controllers/api/v1/pull_requests_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -def create_pull to_ref, from_ref, owner, project = @project +def create_pull to_ref, from_ref, owner, project pull = project.pull_requests.build issue_attributes: {title: 'test', body: 'testing'} pull.issue.user, pull.issue.project = owner, pull.to_project pull.to_ref, pull.from_ref, pull.from_project = to_ref, from_ref, project @@ -9,74 +9,81 @@ def create_pull to_ref, from_ref, owner, project = @project end describe Api::V1::PullRequestsController, type: :controller do + let(:user) { FactoryGirl.create(:user) } + let(:project) { FactoryGirl.create(:project_with_commit, owner: user) } + let(:issue) { FactoryGirl.create(:issue, project: project) } + let(:pull) { create_pull 'master', 'non_conflicts', user, project } + let(:another_project) { FactoryGirl.create(:project_with_commit) } + let(:another_pull) { create_pull 'master', 'non_conflicts', another_project.owner, another_project } + let(:hidden_project) { FactoryGirl.create(:project_with_commit, visibility: 'hidden') } + let(:hidden_pull) { create_pull 'master', 'non_conflicts', hidden_project.owner, hidden_project } + let(:own_hidden_project) { FactoryGirl.create(:project_with_commit, owner: user, visibility: 'hidden') } + let(:own_hidden_pull) { create_pull 'master', 'non_conflicts', user, own_hidden_project } + let(:membered_project) { FactoryGirl.create(:project_with_commit) } + let(:membered_pull) { create_pull 'master', 'non_conflicts', membered_project.owner, membered_project } + let(:create_params) { { + pull_request: { + title: 'title', + body: 'body', + from_ref: 'conflicts', + to_ref: 'master' + }, + project_id: project.id, + format: :json + } } + let(:update_params) { { + pull_request: { + title: 'new title' + }, + project_id: project.id, + id: pull.serial_id, + format: :json + } } + before do stub_symlink_methods - @project = FactoryGirl.create(:project_with_commit) - @pull = create_pull 'master', 'non_conflicts', @project.owner - - @another_project = FactoryGirl.create(:project_with_commit) - @another_pull = create_pull 'master', 'non_conflicts', @another_project.owner, @another_project - - @hidden_project = FactoryGirl.create(:project_with_commit) - @hidden_project.update_column :visibility, 'hidden' - @hidden_pull = create_pull 'master', 'non_conflicts', @hidden_project.owner, @hidden_project - - @own_hidden_project = FactoryGirl.create(:project_with_commit, owner: @project.owner) - @own_hidden_project.update_column :visibility, 'hidden' - @own_hidden_pull = create_pull 'master', 'non_conflicts', @own_hidden_project.owner, @own_hidden_project - @own_hidden_pull.issue.update_column :assignee_id, @project.owner.id - - @membered_project = FactoryGirl.create(:project_with_commit) - @membered_pull = create_pull 'master', 'non_conflicts', @membered_project.owner, @membered_project - create_relation(@membered_project, @pull.user, 'reader') - - @create_params = {pull_request: {title: 'title', body: 'body', - from_ref: 'conflicts', to_ref: 'master'}, - project_id: @project.id, format: :json} - - @update_params = {pull_request: {title: 'new title'}, - project_id: @project.id, id: @pull.serial_id, format: :json} - - @issue = FactoryGirl.create(:issue, project: @project) + own_hidden_pull.issue.update_column :assignee_id, user.id + create_relation(membered_project, user, 'reader') end context 'read and accessible abilities' do context 'for user' do before do - http_login(@project.owner) + http_login(user) end it 'can show pull request in own project' do - get :show, project_id: @project.id, id: @pull.serial_id, format: :json + get :show, project_id: project.id, id: pull.serial_id, format: :json expect(response).to be_success end it 'should render right template for show action' do - get :show, project_id: @project.id, id: @pull.serial_id, format: :json + get :show, project_id: project.id, id: pull.serial_id, format: :json expect(response).to render_template('api/v1/pull_requests/show') end it 'can show pull request in open project' do - get :show, project_id: @another_project.id, id: @another_pull.serial_id, format: :json + get :show, project_id: another_project.id, id: another_pull.serial_id, format: :json expect(response).to be_success end it 'can show pull request in own hidden project' do - get :show, project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id, format: :json + get :show, project_id: own_hidden_project.id, id: own_hidden_pull.serial_id, format: :json expect(response).to be_success end it 'cant show pull request in hidden project' do - get :show, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json + get :show, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json expect(response.status).to eq 403 end it 'should return three pull requests' do + pull && own_hidden_pull && membered_pull # init get :all_index, filter: 'all', format: :json - expect(assigns[:pulls]).to include(@pull) - expect(assigns[:pulls]).to include(@own_hidden_pull) - expect(assigns[:pulls]).to include(@membered_pull) + expect(assigns[:pulls]).to include(pull) + expect(assigns[:pulls]).to include(own_hidden_pull) + expect(assigns[:pulls]).to include(membered_pull) end it 'should render right template for all index action' do @@ -85,8 +92,9 @@ describe Api::V1::PullRequestsController, type: :controller do end it 'should return only assigned pull request' do + own_hidden_pull # init get :user_index, format: :json - expect(assigns[:pulls]).to include(@own_hidden_pull) + expect(assigns[:pulls]).to include(own_hidden_pull) expect(assigns[:pulls].count).to eq 1 end @@ -97,41 +105,41 @@ describe Api::V1::PullRequestsController, type: :controller do %w(commits files).each do |action| it "can show pull request #{action} in own project" do - get action, project_id: @project.id, id: @pull.serial_id, format: :json + get action, project_id: project.id, id: pull.serial_id, format: :json expect(response).to be_success end it "should render right template for commits action" do - get action, project_id: @project.id, id: @pull.serial_id, format: :json + get action, project_id: project.id, id: pull.serial_id, format: :json expect(response).to render_template("api/v1/pull_requests/#{action}") end it "can't show pull request #{action} in hidden project" do - get action, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json + get action, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json expect(response).to_not be_success end end it 'should return 404' do - get :show, project_id: @project.id, id: 999999, format: :json + get :show, project_id: project.id, id: 999999, format: :json expect(response.status).to eq 404 end it 'should redirect to issue page' do - get :show, project_id: @project.id, id: @issue.serial_id, format: :json - expect(response).to redirect_to(api_v1_project_issue_path(@project.id, @issue.serial_id)) + get :show, project_id: project.id, id: issue.serial_id, format: :json + expect(response).to redirect_to(api_v1_project_issue_path(project.id, issue.serial_id)) end end context 'for anonymous user' do it 'can show pull request in open project', anonymous_access: true do - get :show, project_id: @project.id, id: @pull.serial_id, format: :json + get :show, project_id: project.id, id: pull.serial_id, format: :json expect(response).to be_success end it 'cant show pull request in hidden project', anonymous_access: true do - @project.update_column :visibility, 'hidden' - get :show, project_id: @project.id, id: @pull.serial_id, format: :json + # project.update_column :visibility, 'hidden' + get :show, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json expect(response.status).to eq 403 end @@ -142,17 +150,17 @@ describe Api::V1::PullRequestsController, type: :controller do %w(commits files).each do |action| it "can show pull request #{action} in project", anonymous_access: true do - get action, project_id: @project.id, id: @pull.serial_id, format: :json + get action, project_id: project.id, id: pull.serial_id, format: :json expect(response).to be_success end it "should render right template for commits action", anonymous_access: true do - get action, project_id: @project.id, id: @pull.serial_id, format: :json + get action, project_id: project.id, id: pull.serial_id, format: :json expect(response).to render_template("api/v1/pull_requests/#{action}") end it "can't show pull request #{action} in hidden project", anonymous_access: true do - get action, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json + get action, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json expect(response).to_not be_success end end @@ -162,30 +170,30 @@ describe Api::V1::PullRequestsController, type: :controller do context 'create accessibility' do context 'for user' do before(:each) do - http_login(@pull.user) + http_login(user) end it 'can create pull request in own project' do expect do - post :create, @create_params + post :create, create_params end.to change(PullRequest, :count).by(1) end it 'can create pull request in own hidden project' do expect do - post :create, @create_params.merge(project_id: @own_hidden_project.id) + post :create, create_params.merge(project_id: own_hidden_project.id) end.to change(PullRequest, :count).by(1) end it 'can create pull request in open project' do expect do - post :create, @create_params.merge(project_id: @another_project.id) + post :create, create_params.merge(project_id: another_project.id) end.to change(PullRequest, :count).by(1) end it 'cant create pull request in hidden project' do expect do - post :create, @create_params.merge(project_id: @hidden_project.id) + post :create, create_params.merge(project_id: hidden_project.id) end.to_not change(PullRequest, :count) end end @@ -193,13 +201,13 @@ describe Api::V1::PullRequestsController, type: :controller do context 'for anonymous user' do it 'cant create pull request in project', anonymous_access: true do expect do - post :create, @create_params + post :create, create_params end.to_not change(PullRequest, :count) end it 'cant create pull request in hidden project', anonymous_access: true do expect do - post :create, @create_params.merge(project_id: @hidden_project.id) + post :create, create_params.merge(project_id: hidden_project.id) end.to_not change(PullRequest, :count) end end @@ -208,110 +216,112 @@ describe Api::V1::PullRequestsController, type: :controller do context 'update accessibility' do context 'for user' do before(:each) do - http_login(@project.owner) + http_login(project.owner) end it 'can update pull request in own project' do - put :update, @update_params - expect(@pull.reload.title).to eq 'new title' + put :update, update_params + expect(pull.reload.title).to eq 'new title' end it 'can update pull request in own hidden project' do - put :update, @update_params.merge(project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id) - expect(@own_hidden_pull.reload.title).to eq 'new title' + put :update, update_params.merge(project_id: own_hidden_project.id, id: own_hidden_pull.serial_id) + expect(own_hidden_pull.reload.title).to eq 'new title' end it 'cant update pull request in open project' do - put :update, @update_params.merge(project_id: @another_project.id, id: @another_pull.serial_id) - expect(@another_pull.reload.title).to_not eq 'new title' + put :update, update_params.merge(project_id: another_project.id, id: another_pull.serial_id) + expect(another_pull.reload.title).to_not eq 'new title' end it 'cant update pull request in hidden project' do - put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_pull.serial_id) - expect(@hidden_pull.reload.title).to_not eq 'title' + put :update, update_params.merge(project_id: hidden_project.id, id: hidden_pull.serial_id) + expect(hidden_pull.reload.title).to_not eq 'title' end it 'can merge pull request in own project' do - put :merge, project_id: @project.id, id: @pull.serial_id, format: :json - expect(@pull.reload.status).to eq 'merged' + put :merge, project_id: project.id, id: pull.serial_id, format: :json + expect(pull.reload.status).to eq 'merged' expect(response).to be_success end it 'can merge pull request in own hidden project' do - put :merge, project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id, format: :json - expect(@own_hidden_pull.reload.status).to eq 'merged' + put :merge, project_id: own_hidden_project.id, id: own_hidden_pull.serial_id, format: :json + expect(own_hidden_pull.reload.status).to eq 'merged' expect(response).to be_success end it 'cant merge pull request in open project' do - put :merge, project_id: @another_project.id, id: @another_pull.serial_id, format: :json - expect(@another_pull.reload.status).to eq 'ready' + put :merge, project_id: another_project.id, id: another_pull.serial_id, format: :json + expect(another_pull.reload.status).to eq 'ready' expect(response.status).to eq 403 end it 'cant merge pull request in hidden project' do - put :merge, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json - expect(@hidden_pull.reload.status).to eq 'ready' + put :merge, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json + expect(hidden_pull.reload.status).to eq 'ready' expect(response.status).to eq 403 end end context 'for anonymous user' do it 'cant update pull request in project', anonymous_access: true do - put :update, @update_params + put :update, update_params expect(response.status).to eq 401 end it 'cant update pull request in hidden project', anonymous_access: true do - put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_pull.serial_id) + put :update, update_params.merge(project_id: hidden_project.id, id: hidden_pull.serial_id) expect(response.status).to eq 401 end it 'cant merge pull request in open project' do - put :merge, project_id: @another_project.id, id: @another_pull.serial_id, format: :json - expect(@another_pull.reload.status).to eq 'ready' + put :merge, project_id: another_project.id, id: another_pull.serial_id, format: :json + expect(another_pull.reload.status).to eq 'ready' expect(response.status).to eq 401 end it 'cant merge pull request in hidden project' do - put :merge, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json - expect(@hidden_pull.reload.status).to eq 'ready' + put :merge, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json + expect(hidden_pull.reload.status).to eq 'ready' expect(response.status).to eq 401 end end end context 'send email messages' do - before do - @project_reader = FactoryGirl.create :user - create_relation(@project, @project_reader, 'reader') - @project_admin = FactoryGirl.create :user - create_relation(@project, @project_admin, 'admin') - @project_writer = FactoryGirl.create :user - create_relation(@project, @project_writer, 'writer') + let(:project_reader) { FactoryGirl.create :user } + let(:project_writer) { FactoryGirl.create :user } + let(:project_admin) { FactoryGirl.create :user } - http_login(@project_writer) + before do + create_relation(project, project_reader, 'reader') + create_relation(project, project_admin, 'admin') + create_relation(project, project_writer, 'writer') + + http_login(project_writer) + pull # init ActionMailer::Base.deliveries = [] end it 'should send two email messages to all project members' do - post :create, @create_params + post :create, create_params expect(ActionMailer::Base.deliveries.count).to eq 3 # project owner + reader + admin end it 'should send two email messages to admins and one to assignee' do - post :create, @create_params.deep_merge(pull_request: {assignee_id: @project_reader.id}) + post :create, create_params.deep_merge(pull_request: {assignee_id: project_reader.id}) expect(ActionMailer::Base.deliveries.count).to eq 3 end it 'should send email message to new assignee' do - http_login(@project_admin) - put :update, @update_params.deep_merge(pull_request: {assignee_id: @project_reader.id}) + http_login(project_admin) + put :update, update_params.deep_merge(pull_request: {assignee_id: project_reader.id}) expect(ActionMailer::Base.deliveries.count).to eq 1 end it 'should not duplicate email message' do - post :create, @create_params.deep_merge(pull_request: {assignee_id: @project_admin.id}) + post :create, create_params.deep_merge(pull_request: {assignee_id: project_admin.id}) expect(ActionMailer::Base.deliveries.count).to eq 3 # send to all project members expect(ActionMailer::Base.deliveries.map(&:to).uniq).to match_array(ActionMailer::Base.deliveries.map(&:to)) end