Starting to fix the tests(about damn time)

This commit is contained in:
Wedge 2016-07-11 09:35:58 +03:00
parent 73dbed3962
commit 69fd5d9742
46 changed files with 5 additions and 3361 deletions

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Admin::BuildScriptsController, type: :controller do
it_should_behave_like 'an admin controller'
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Admin::NodeInstructionsController, type: :controller do
it_should_behave_like 'an admin controller'
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Admin::RegisterRequestsController, type: :controller do
it_should_behave_like 'an admin controller'
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Admin::ResqueController, type: :controller do
it_should_behave_like 'an admin controller'
end

View File

@ -1,15 +0,0 @@
require 'spec_helper'
describe AdvisoriesController, type: :controller do
context 'for all' do
it "should be able to perform search action" do
get :search
expect(response).to_not redirect_to(forbidden_path)
end
it "should be able to perform index action" do
get :index
expect(response).to be_success
end
end
end

View File

@ -1,138 +0,0 @@
require 'spec_helper'
shared_examples_for 'api advisories user with show rights' do
it 'should be able to perform show action' do
get :show, id: @advisory.advisory_id, format: :json
expect(response).to be_success
end
it 'should be able to perform index action' do
get :index, format: :json
expect(response).to be_success
end
end
shared_examples_for 'api advisories user with admin rights' do
context 'api advisories user with create rights' do
let(:params) {{ build_list_id: @build_list.id, advisory: { description: 'test' }, format: :json }}
it 'should be able to perform create action' do
post :create, params
expect(response).to be_success
end
it 'ensures that advisory has been created' do
expect { post :create, params }.to change(Advisory, :count).by(1)
end
it 'ensures that build_list has been associated with advisory' do
post :create, params
expect(@build_list.reload.advisory).to_not be_nil
end
end
context 'api advisories user with update rights' do
let(:params) {{ id: @advisory.advisory_id, build_list_id: @build_list.id, format: :json }}
it 'should be able to perform update action' do
put :update, params
expect(response).to be_success
end
it 'ensures that advisory has not been created' do
expect { put :update, params }.to_not change(Advisory, :count)
end
it 'ensures that build_list has been associated with advisory' do
put :update, params
expect(@build_list.reload.advisory).to_not be_nil
end
end
end
shared_examples_for 'api advisories user without admin rights' do
context 'api advisories user without create rights' do
let(:params) {{ build_list_id: @build_list.id, advisory: { description: 'test' }, format: :json }}
it 'should not be able to perform create action' do
post :create, params
expect(response).to_not be_success
end
it 'ensures that advisory has not been created' do
expect { post :create, params }.to_not change(Advisory, :count)
end
it 'ensures that build_list has not been associated with advisory' do
post :create, params
expect(@build_list.reload.advisory).to be_nil
end
end
context 'api advisories user without update rights' do
let(:params) {{ id: @advisory.advisory_id, build_list_id: @build_list.id, format: :json }}
it 'should not be able to perform update action' do
put :update, params
expect(response).to_not be_success
end
it 'ensures that advisory has not been created' do
expect { put :update, params }.to_not change(Advisory, :count)
end
it 'ensures that build_list has not been associated with advisory' do
put :update, params
expect(@build_list.reload.advisory).to be_nil
end
end
end
describe Api::V1::AdvisoriesController, type: :controller do
before do
stub_symlink_methods
@advisory = FactoryGirl.create(:advisory)
@build_list = FactoryGirl.create(:build_list, status: BuildList::BUILD_PUBLISHED)
@build_list.save_to_platform.update_column(:released, true)
@build_list.save_to_repository.update_column(:publish_without_qa, false)
end
context 'for guest' do
if APP_CONFIG['anonymous_access']
it_should_behave_like 'api advisories user with show rights'
end
it 'should not be able to perform show action', :anonymous_access => false do
get :show, id: @advisory.advisory_id, format: :json
expect(response).to_not be_success
end
it 'should not be able to perform index action', :anonymous_access => false do
get :index, format: :json
expect(response).to_not be_success
end
it_should_behave_like 'api advisories user without admin rights'
end
context 'for simple user' do
before do
@user = FactoryGirl.create(:user)
http_login(@user)
end
it_should_behave_like 'api advisories user with show rights'
it_should_behave_like 'api advisories user without admin rights'
end
context 'for admin' do
before do
@admin = FactoryGirl.create(:admin)
http_login(@admin)
end
it_should_behave_like 'api advisories user with show rights'
it_should_behave_like 'api advisories user with admin rights'
end
context 'for user who has access to update build_list' do
before do
@user = FactoryGirl.create(:user)
create_relation @build_list.save_to_platform, @user, 'admin'
http_login(@user)
end
it_should_behave_like 'api advisories user with show rights'
it_should_behave_like 'api advisories user with admin rights'
end
end

View File

@ -1,222 +0,0 @@
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))
end
context 'read and accessible abilities' do
context 'for user' do
before do
http_login(user)
end
it 'can show issue in own project' do
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
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
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
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
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)
end
it 'should render right template for all index action' do
get :all_index, format: :json
expect(response).to render_template('api/v1/issues/index')
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].count).to eq 1
end
it 'should render right template for user index action' do
get :user_index, format: :json
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
expect(response.code).to eq '404'
end
it 'should redirect to pull request page' do
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
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
expect(response.code).to eq '403'
end
it 'should not return any issues' do
get :all_index, filter: 'all', format: :json
expect(response.code).to eq '401'
end
end
end
context 'create accessibility' do
context 'for user' do
before do
http_login(user)
end
it 'can create issue in own project' do
expect do
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)
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)
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)
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: 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: 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
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)
end.to change(Issue, :count).by(0)
end
end
end
context 'update accessibility' do
context 'for user' do
before(:each) do
http_login(user)
end
it 'can update issue in own project' do
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'
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'
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'
end
it "can't assignee issue in open project" do
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
end
end
context 'for anonymous user' do
it "can't update issue in project", anonymous_access: true do
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)
expect(response.code).to eq '401'
end
end
end
end

View File

@ -1,330 +0,0 @@
require 'spec_helper'
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
pull.save; pull.check
pull.reload
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
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(user)
end
it 'can show pull request in own project' do
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
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
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
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
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)
end
it 'should render right template for all index action' do
get :all_index, format: :json
expect(response).to render_template('api/v1/pull_requests/index')
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].count).to eq 1
end
it 'should render right template for user index action' do
get :user_index, format: :json
expect(response).to render_template('api/v1/pull_requests/index')
end
%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
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
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
expect(response).to_not be_success
end
end
it 'should return 404' do
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))
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
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: hidden_project.id, id: hidden_pull.serial_id, format: :json
expect(response.status).to eq 403
end
it 'should not return any pull requests' do
get :all_index, filter: 'all', format: :json
expect(response.status).to eq 401
end
%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
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
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
expect(response).to_not be_success
end
end
end
end
context 'create accessibility' do
context 'for user' do
before(:each) do
http_login(user)
end
it 'can create pull request in own project' do
expect do
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)
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)
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)
end.to_not change(PullRequest, :count)
end
end
context 'for anonymous user' do
it 'cant create pull request in project', anonymous_access: true do
expect do
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)
end.to_not change(PullRequest, :count)
end
end
end
context 'update accessibility' do
context 'for user' do
before(:each) do
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'
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'
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'
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'
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'
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'
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'
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'
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
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)
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'
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'
expect(response.status).to eq 401
end
end
end
context 'send email messages' do
let(:project_reader) { FactoryGirl.create :user }
let(:project_writer) { FactoryGirl.create :user }
let(:project_admin) { FactoryGirl.create :user }
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
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})
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})
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})
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
end
end

View File

@ -1,141 +0,0 @@
require 'spec_helper'
shared_context "collaborators controller" do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@group = FactoryGirl.create(:group)
@member_user = FactoryGirl.create(:user)
# Create relation with 'writer' rights
@collaborator = Collaborator.create(actor: @member_user, project: @project, role: 'writer')
@user = FactoryGirl.create(:user)
set_session_for(@user)
@user_params = {
actor_id: @another_user.id.to_s,
actor_type: 'user',
role: 'reader'
}
@group_params = {
actor_id: @group.id.to_s,
actor_type: 'group',
role: 'reader'
} if @group
@create_params = {
name_with_owner: @project.name_with_owner,
format: :json
}
@update_params = @create_params.merge(collaborator: { role: 'reader' })
end
end
shared_examples_for 'project admin user' do
it 'should be able to view collaborators list' do
get :index, name_with_owner: @project.name_with_owner
expect(response).to be_success
end
it 'should be able to perform update action' do
put :update, {id: @collaborator.id}.merge(@update_params)
expect(response).to be_success
end
it 'should add new collaborator with reader role' do
post :create, @create_params.merge(collaborator: @user_params)
expect(@project.relations.exists?(actor_type: 'User', actor_id: @another_user.id, role: 'reader')).to be true
end
it 'should add new group with reader role' do
post :create, @create_params.merge(collaborator: @group_params)
expect(@project.relations.exists?(actor_type: 'Group', actor_id: @group.id, role: 'reader')).to be true
end
it 'should be able to set reader role for any user' do
put :update, {id: @collaborator.id}.merge(@update_params)
expect(@collaborator.actor.relations.exists? target_id: @project.id, target_type: 'Project', role: 'reader').to be true
end
end
shared_examples_for 'user with no rights for this project' do
it 'should not be able to view collaborators list' do
get :index, name_with_owner: @project.name_with_owner
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform update action' do
put :update, {id: @collaborator.id}.merge(@update_params)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to set reader role for any user' do
put :update, {id: @collaborator.id}.merge(@update_params)
expect(@another_user.relations.exists? target_id: @project.id, target_type: 'Project', role: 'reader').to be false
end
end
describe Projects::CollaboratorsController, type: :controller do
include_context "collaborators controller"
context 'for guest' do
before(:each) do
set_session_for(User.new)
end
it 'should not be able to perform index action' do
get :index, name_with_owner: @project.name_with_owner
expect(response).to redirect_to(new_user_session_path)
end
it 'should not be able to perform update action' do
put :update, {id: @collaborator.id}.merge(@update_params)
expect(response.code).to eq '401'
end
end
context 'for global admin' do
before(:each) do
@user.role = "admin"
@user.save
end
it_should_behave_like 'project admin user'
end
context 'for admin user' do
before(:each) do
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'project admin user'
end
context 'for owner user' do
before(:each) do
@user = @project.owner # owner should be user
set_session_for(@user)
end
it_should_behave_like 'project admin user'
end
context 'for reader user' do
before(:each) do
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with no rights for this project'
end
context 'for writer user' do
before(:each) do
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with no rights for this project'
end
context 'for another user' do
it_should_behave_like 'user with no rights for this project'
end
end

View File

@ -1,67 +0,0 @@
require 'spec_helper'
describe Projects::CommentsController, type: :controller do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project_with_commit)
@commit = @project.repo.commits.first
@create_params = { comment: { body: 'I am a comment!' }, name_with_owner: @project.name_with_owner,
commit_id: @commit.id, format: :json }
@update_params = { comment: { body: 'updated' }, name_with_owner: @project.name_with_owner, commit_id: @commit.id, format: :json }
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
@comment = FactoryGirl.create(:comment, commentable: @commit, project: @project)
@user = FactoryGirl.create(:user)
@own_comment = FactoryGirl.create(:comment, commentable: @commit, user: @user, project: @project)
set_session_for(@user)
@path = { name_with_owner: @project.name_with_owner, commit_id: @commit.id }
@return_path = commit_path(@project, @commit.id)
end
context 'for project admin user' do
before(:each) do
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
#it_should_behave_like 'user with destroy ability'
end
context 'for project owner user' do
before(:each) do
set_session_for(@project.owner)
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
context 'for project reader user' do
before(:each) do
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
context 'for project writer user' do
before(:each) do
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
end

View File

@ -1,82 +0,0 @@
require 'spec_helper'
shared_context "comments controller" do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, project_id: @project.id)
@comment = FactoryGirl.create(:comment, commentable: @issue, project_id: @project.id)
@user = FactoryGirl.create(:user)
@own_comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project_id: @project.id)
set_session_for(@user)
@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)
end
end
describe Projects::CommentsController, type: :controller do
include_context "comments controller"
context 'for global admin user' do
before(:each) do
@user.role = "admin"
@user.save
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
context 'for project admin user' do
before(:each) do
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
context 'for project owner user' do
before(:each) do
set_session_for(@project.owner) # owner should be user
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user with update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user with destroy comment ability'
end
context 'for project reader user' do
before(:each) do
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
context 'for project writer user' do
before(:each) do
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with create comment ability'
it_should_behave_like 'user without update stranger comment ability'
it_should_behave_like 'user with update own comment ability'
it_should_behave_like 'user without destroy comment ability'
end
end

View File

@ -1,117 +0,0 @@
require 'spec_helper'
def subscribe_to_commit
Subscribe.subscribe_to_commit(project_id: @project.id,
subscribeable_id: @commit.id.hex,
subscribeable_type: @commit.class.name,
user_id: @user.id)
end
shared_examples_for 'can subscribe' do
it 'should be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(commit_path(@project, @commit))
end
it 'should create subscribe object into db' do
expect { post :create, @create_params }.to change(Subscribe, :count).by(1)
end
end
shared_examples_for 'can not subscribe' do
it 'should not be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(commit_path(@project, @commit))
end
it 'should not create subscribe object into db' do
expect { post :create, @create_params }.to_not change(Subscribe, :count)
end
end
shared_examples_for 'can unsubscribe' do
it 'should be able to perform destroy action' do
delete :destroy, @destroy_params
expect(response).to redirect_to(commit_path(@project, @commit))
end
it 'should reduce subscribes count' do
delete :destroy, @destroy_params
expect(Subscribe.subscribed_to_commit?(@project, @user, @commit)).to be_falsy
end
end
shared_examples_for 'can not unsubscribe' do
it 'should not be able to perform destroy action' do
delete :destroy, @destroy_params
expect(response).to redirect_to(commit_path(@project, @commit))
end
it 'should not reduce subscribes count' do
expect { delete :destroy, @destroy_params }.to_not change(Subscribe, :count)
end
end
describe Projects::CommitSubscribesController, type: :controller do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project_with_commit)
@commit = @project.repo.commits.first
@create_params = { commit_id: @commit.sha, name_with_owner: @project.name_with_owner }
@destroy_params = { commit_id: @commit.sha, name_with_owner: @project.name_with_owner }
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
context 'for global admin user' do
before(:each) do
@user = FactoryGirl.create(:admin)
set_session_for(@user)
end
context 'subscribed' do
before(:each) { subscribe_to_commit }
it_should_behave_like 'can unsubscribe'
it_should_behave_like 'can not subscribe'
end
context 'not subscribed' do
it_should_behave_like 'can subscribe'
end
end
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
context 'subscribed' do
before(:each) { subscribe_to_commit }
it_should_behave_like 'can unsubscribe'
it_should_behave_like 'can not subscribe'
end
context 'not subscribed' do
it_should_behave_like 'can subscribe'
end
end
context 'for guest' do
before(:each) { set_session_for(User.new) }
it 'should not be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(new_user_session_path)
end
it 'should not be able to perform destroy action' do
delete :destroy, @destroy_params
expect(response).to redirect_to(new_user_session_path)
end
end
end

View File

@ -1,123 +0,0 @@
require 'spec_helper'
describe Projects::Git::TreesController, type: :controller do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@params = { name_with_owner: @project.name_with_owner, treeish: "#{@project.name}-master" }
fill_project @project
end
context 'for guest' do
[:tags, :branches].each do |action|
it "should be able to perform #{action} action with anonymous acccess", anonymous_access: true do
get action, @params.merge(treeish: 'master')
expect(response).to be_success
end
it "should not be able to perform #{action} action without anonymous acccess", anonymous_access: false do
get action, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
end
it "should be able to perform archive action with anonymous acccess", anonymous_access: true do
get :archive, @params.merge(format: 'tar.gz')
expect(response).to be_success
end
it "should not be able to perform archive action without anonymous acccess", anonymous_access: false do
get :archive, @params.merge(format: 'tar.gz')
expect(response.code).to eq '401'
end
it 'should not be able to perform destroy action' do
delete :destroy, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
it 'should not be able to perform restore_branch action' do
put :restore_branch, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
it 'should not be able to perform create action' do
post :create, @params.merge(treeish: '', from_ref: 'master', new_ref: 'master-1')
expect(response).to_not be_success
end
end
context 'for other user' do
before { set_session_for FactoryGirl.create(:user) }
it 'should not be able to archive empty project' do
%x(rm -rf #{@project.path})
expect { get :archive, @params.merge(format: 'tar.gz') }.to raise_error(ActionController::RoutingError)
end
it 'should not be able to injection code with treeish' do
expect do
get :archive, @params.merge(format: 'tar.gz', treeish: "master > /dev/null; echo 'I am hacker!';\#")
end.to raise_error(ActionController::RoutingError)
end
it 'should be able to perform archive action' do
get :archive, @params.merge(format: 'tar.gz')
expect(response).to be_success
end
it 'should not be able to perform destroy action' do
delete :destroy, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
it 'should not be able to perform restore_branch action' do
put :restore_branch, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
it 'should not be able to perform create action' do
post :create, @params.merge(treeish: '', from_ref: 'master', new_ref: 'master-1')
expect(response).to_not be_success
end
[:tags, :branches].each do |action|
it "should be able to perform #{action} action" do
get action, @params.merge(treeish: 'master')
expect(response).to be_success
end
end
end
context 'for writer user' do
before(:each) do
user = FactoryGirl.create(:user)
create_relation(@project, user, 'writer')
set_session_for user
end
it 'should be able to perform destroy action' do
delete :destroy, @params.merge(treeish: 'conflicts')
expect(response).to be_success
end
it 'should not be able to perform destroy action for master branch' do
delete :destroy, @params.merge(treeish: 'master')
expect(response).to_not be_success
end
it 'should be able to perform restore_branch action' do
put :restore_branch, @params.merge(treeish: 'master-1', sha: 'master')
expect(response).to be_success
end
it 'should be able to perform create action' do
post :create, @params.merge(treeish: '', from_ref: 'master', new_ref: 'master-1')
expect(response).to be_success
end
end
after(:all) {clean_projects_dir}
end

View File

@ -1,181 +0,0 @@
require 'spec_helper'
shared_examples_for 'hooks user with project admin rights' do
it 'should be able to perform index action' do
get :index, {name_with_owner: "#{@project.owner.uname}/#{@project.name}"}
expect(response).to be_success
end
it 'should be able to perform new action' do
get :new, { name_with_owner: @project.name_with_owner, hook: { name: 'web' }}
expect(response).to be_success
end
it 'should be able to perform edit action' do
get :new, { name_with_owner: @project.name_with_owner, id: @hook.id }
expect(response).to be_success
end
it 'should be able to perform update action' do
put :update, { name_with_owner: @project.name_with_owner, id: @hook.id }.merge(@update_params)
expect(response).to redirect_to(project_hooks_path(@project, name: 'web'))
end
it 'should be able to perform create action' do
post :create, { name_with_owner: @project.name_with_owner }.merge(@create_params)
expect(response).to redirect_to(project_hooks_path(@project, name: 'web'))
end
end
shared_examples_for 'hooks user without project admin rights' do
it 'should not be able to perform index action' do
get :index, { name_with_owner: @project.name_with_owner }
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform new action' do
get :new, { name_with_owner: @project.name_with_owner, hook: { name: 'web' }}
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform edit action' do
get :new, { name_with_owner: @project.name_with_owner, id: @hook.id }
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform update action' do
put :update, { name_with_owner: @project.name_with_owner, id: @hook.id }.merge(@update_params)
expect(response).to redirect_to(forbidden_path)
end
it 'should not be able to perform create action' do
post :create, { name_with_owner: @project.name_with_owner }.merge(@create_params)
expect(response).to redirect_to(forbidden_path)
end
end
describe Projects::HooksController, type: :controller do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@hook = FactoryGirl.create(:hook, project: @project)
@create_params = {hook: {name: 'web', data: {url: 'create'}}}
@update_params = {hook: {data: {url: 'update'}}}
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
context 'registered user' do
it_should_behave_like 'hooks user without project admin rights'
end # context 'registered user'
context 'for project members' do
context 'for global admin' do
before do
@user.role = "admin"
@user.save
end
it_should_behave_like 'hooks user with project admin rights'
end
context 'for owner user' do
before do
@user = @project.owner
set_session_for(@user) # owner should be user
end
it_should_behave_like 'hooks user with project admin rights'
end
context 'for reader user' do
before do
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'hooks user without project admin rights'
end
context 'for writer user' do
before do
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'hooks user without project admin rights'
end
end # context 'for project members'
context 'for group' do
before do
@group = FactoryGirl.create(:group)
end
context 'group is owner of the project' do
before do
@project = FactoryGirl.create(:project, owner: @group)
@hook = FactoryGirl.create(:hook, project: @project)
end
context 'group member user with reader role' do
before { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'hooks user without project admin rights'
context 'user should has best role' do
before { create_relation(@project, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group is member of the project' do
context 'with admin rights' do
before { create_relation(@project, @group, 'admin') }
context 'group member user with reader role' do
before { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'hooks user with project admin rights'
context 'user should has best role' do
before { create_relation(@project, @user, 'reader') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'with reader rights' do
before { create_relation(@project, @group, 'reader') }
context 'group member user with reader role' do
before { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'hooks user without project admin rights'
context 'user should has best role' do
before { create_relation(@project, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user without project admin rights'
end
end
end
end
end

View File

@ -1,309 +0,0 @@
require 'spec_helper'
shared_context "issues controller" do
before do
stub_symlink_methods
@project = FactoryGirl.create(:project_with_commit)
@issue_user = FactoryGirl.create(:user)
@issue = FactoryGirl.create(:issue, project_id: @project.id, assignee_id: @issue_user.id)
@label = FactoryGirl.create(:label, project_id: @project.id)
@project_with_turned_off_issues = FactoryGirl.create(:project, has_issues: false)
@turned_of_issue = FactoryGirl.create(:issue, project_id: @project_with_turned_off_issues.id, assignee_id: @issue_user.id)
@user = FactoryGirl.create(:user)
set_session_for(@user)
@create_params = {
name_with_owner: @project.name_with_owner,
issue: {
title: "issue1",
body: "issue body",
labelings_attributes: { @label.id.to_s => { label_id: @label.id }},
assignee_id: @issue_user.id
}
}
@update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }, format: :json }
@pull = create_pull_request(@project)
end
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
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
expect(response).to render_template(:show)
end
end
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
expect(response).to render_template(:index)
end
it 'should be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(project_issues_path(@project))
end
it 'should create issue object into db' do
expect do
post :create, @create_params
end.to change(Issue, :count).by(1)
end
end
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
expect(response).to render_template(:index)
end
it 'should create issue object into db' do
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
expect(@project.issues.last.assignee_id).to_not be_nil
end
it 'label should be attached to issue' do
expect(@project.issues.last.labels.count).to eq 1
end
end
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)
expect(response).to be_success
end
it 'should update issue title' do
put :update, {id: @issue.serial_id}.merge(@update_params)
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)
expect(response).to redirect_to(forbidden_path)
end
it 'should not update issue title' do
put :update, {id: @issue.serial_id}.merge(@update_params)
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
# expect(response).to redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
# end
# it 'should not reduce issues count' do
# 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
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
expect(response).to redirect_to(forbidden_path)
end
end
describe Projects::IssuesController, type: :controller do
include_context "issues controller"
context 'for global admin user' do
before do
@user.role = "admin"
@user.save
end
it_should_behave_like 'issue user with project guest rights'
it_should_behave_like 'issue user with project reader rights'
it_should_behave_like 'issue user with project writer rights'
it_should_behave_like 'user with issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
end
context 'for project admin user' do
before do
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'issue user with project guest rights'
it_should_behave_like 'issue user with project reader rights'
it_should_behave_like 'issue user with project writer rights'
it_should_behave_like 'user with issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
end
context 'for project owner user' do
before do
@user = @project.owner
set_session_for(@user)
end
it_should_behave_like 'issue user with project guest rights'
it_should_behave_like 'issue user with project reader rights'
it_should_behave_like 'issue user with project writer rights'
it_should_behave_like 'user with issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
end
context 'for project reader user' do
before do
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'issue user with project guest rights'
it_should_behave_like 'issue user with project reader rights'
it_should_behave_like 'user without issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
context 'perform create action' do
before { post :create, @create_params }
it 'user should not be assigned to issue' do
expect(@project.issues.last.assignee_id).to be_nil
end
it 'label should not be attached to issue' do
expect(@project.issues.last.labels.count).to eq 0
end
end
it 'should return 404' do
get :show, name_with_owner: @project.name_with_owner, id: 999999
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.reload.serial_id
expect(response).to redirect_to(project_pull_request_path(@project, @pull))
end
it 'should redirect to pull request in project with turned off issues' do
@project.update_attribute :has_issues, false
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 do
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'issue user with project guest rights'
it_should_behave_like 'issue user with project reader rights'
it_should_behave_like 'issue user with project writer rights'
it_should_behave_like 'user without issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
end
context 'for issue assign user' do
before do
set_session_for(@issue_user)
end
it_should_behave_like 'user without issue update rights'
it_should_behave_like 'project with issues turned off'
# it_should_behave_like 'user without issue destroy rights'
end
context 'for guest' do
before do
set_session_for(User.new)
end
if APP_CONFIG['anonymous_access']
it_should_behave_like 'issue user with project guest rights'
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
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
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
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
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
expect(response).to redirect_to(new_user_session_path)
end
it 'should not create issue object into db' do
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)
expect(response.code).to eq '401'
end
it 'should not update issue title' do
put :update, {id: @issue.serial_id}.merge(@update_params)
expect(@issue.reload.title).to_not eq 'issue2'
end
# it_should_behave_like 'user without issue destroy rights'
end
end

View File

@ -1,312 +0,0 @@
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_with_commit)
@pull = create_pull_request(@project)
@create_params = {
pull_request: { issue_attributes: { title: 'create', body: 'creating' },
to_ref: 'non_conflicts',
from_ref: 'master' },
to_project: @project.name_with_owner,
name_with_owner: @project.name_with_owner
}
@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
)
@user = FactoryGirl.create(:user)
set_session_for(@user)
@issue = FactoryGirl.create(:issue, project: @project)
end
end
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
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
expect(response).to redirect_to(project_pull_request_path(@project, @project.pull_requests.last))
end
it 'should create pull request object into db' do
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
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
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})
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)
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)
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
expect(response).to be_success
end
it 'should be able to perform merge action' do
@pull.check
put :merge, @update_params
expect(response).to be_success
end
let(:pull) { @project.pull_requests.find(@pull) }
it 'should update pull request status' do
put :update, @update_params
expect(pull.status).to eq 'closed'
end
it 'should not update pull request title' do
put :update, @wrong_update_params
expect(pull.issue.title).to eq 'test'
end
it 'should not update pull request body' do
put :update, @wrong_update_params
expect(pull.issue.body).to eq 'testing'
end
it 'should not update pull request title direct' do
put :update, @wrong_update_params
expect(pull.issue.title).to_not eq 'update'
end
it 'should not update pull request body direct' do
put :update, @wrong_update_params
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
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
expect(pull.status).to_not eq 'closed'
end
it 'should not update pull request title' do
put :update, @wrong_update_params
expect(pull.issue.title).to_not eq 'update'
end
it 'should not update pull request body' do
put :update, @wrong_update_params
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
expect(response).to_not be_success
end
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 show action when pull request has been created' do
@pull.check
get :show, name_with_owner: @project.name_with_owner, id: @pull.serial_id
expect(response).to render_template(:show)
end
end
describe Projects::PullRequestsController, type: :controller do
include_context "pull request controller"
context 'for global admin user' do
before do
@user.role = "admin"
@user.save
end
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 'user with pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
end
context 'for project admin user' do
before do
create_relation(@project, @user, 'admin')
end
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 'user with pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
end
context 'for project owner user' do
before do
@user = @project.owner
set_session_for(@user)
end
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 'user with pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
end
context 'for project reader user' do
before do
create_relation(@project, @user, 'reader')
end
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 'user without pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
it 'should return 404' do
get :show, name_with_owner: @project.name_with_owner, id: 999999
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
expect(response).to redirect_to(project_issue_path(@project, @issue))
end
end
context 'for project writer user' do
before do
create_relation(@project, @user, 'writer')
end
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 'user with pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
end
=begin
context 'for pull request assign user' do
before do
set_session_for(@pull request_user)
end
it_should_behave_like 'user without pull request update rights'
it_should_behave_like 'pull request when project with issues turned off'
end
=end
context 'for guest' do
let(:guest) { User.new }
before do
set_session_for(guest)
end
if APP_CONFIG['anonymous_access']
it_should_behave_like 'pull request user with project guest rights'
it_should_behave_like 'pull request when project with issues turned off'
else
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
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
expect(response).to redirect_to(new_user_session_path)
end
it 'should not create pull request object into db' do
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 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')
set_session_for(@project_writer)
ActionMailer::Base.deliveries = []
end
it 'should send three email messages to project members' do
# project owner + project reader + project admin (project writer is a pull creator)
expect { post :create, @create_params }.to change(ActionMailer::Base.deliveries, :count).by(3)
end
it 'should send two email messages to admins and one to assignee' do
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
expect {
post :create, @create_params.deep_merge(issue: {assignee_id: @project_admin.id})
}.to change(ActionMailer::Base.deliveries, :count).by(3) # send all project members
end
end
end

View File

@ -1,109 +0,0 @@
require 'spec_helper'
shared_examples_for 'can subscribe' do
it 'should be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(project_issue_path(@project, @issue))
end
it 'should create subscribe object into db' do
expect { post :create, @create_params }.to change(Subscribe, :count).by(1)
end
end
shared_examples_for 'can not subscribe' do
it 'should not be able to perform create action' do
post :create, @create_params
expect(response).to redirect_to(forbidden_path)
end
it 'should not create subscribe object into db' do
expect { post :create, @create_params }.to_not change(Subscribe, :count)
end
end
shared_examples_for 'can unsubscribe' do
it 'should be able to perform destroy action' do
delete :destroy, @destroy_params
expect(response).to redirect_to([@project, @issue])
end
it 'should reduce subscribes count' do
expect { delete :destroy, @destroy_params }.to change(Subscribe, :count).by(-1)
end
end
shared_examples_for 'can not unsubscribe' do
it 'should not be able to perform destroy action' do
delete :destroy, @destroy_params
expect(response).to redirect_to(forbidden_path)
end
it 'should not reduce subscribes count' do
expect { delete :destroy, @destroy_params }.to_not change(Subscribe, :count)
end
end
describe Projects::SubscribesController, type: :controller do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, project_id: @project.id)
@create_params = { issue_id: @issue.serial_id, name_with_owner: @project.name_with_owner }
@destroy_params = { issue_id: @issue.serial_id, name_with_owner: @project.name_with_owner }
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
@request.env['HTTP_REFERER'] = project_issue_path(@project, @issue)
end
context 'for global admin user' do
before(:each) do
@user = FactoryGirl.create(:admin)
set_session_for(@user)
create_relation(@project, @user, 'admin')
end
context 'subscribed' do
before(:each) do
ss = @issue.subscribes.build
ss.user = @user
ss.save!
end
it_should_behave_like 'can unsubscribe'
it_should_behave_like 'can not subscribe'
end
context 'not subscribed' do
it_should_behave_like 'can subscribe'
end
end
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@destroy_params = @destroy_params.merge({id: @user.id})
end
context 'subscribed' do
before(:each) do
ss = @issue.subscribes.build
ss.user = @user
ss.save!
end
it_should_behave_like 'can unsubscribe'
it_should_behave_like 'can not subscribe'
end
context 'not subscribed' do
it_should_behave_like 'can subscribe'
end
end
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Projects::WikiController, type: :controller do
end

View File

@ -6,7 +6,7 @@ FactoryGirl.define do
password '123456'
password_confirmation {|u| u.password}
confirmed_at { Time.now.utc }
after(:create) { |u| u.send(:new_user_notification) }
#after(:create) { |u| u.send(:new_user_notification) }
end
factory :admin, parent: :user do

View File

@ -1,40 +0,0 @@
require 'spec_helper'
describe RestartNodesJob do
it 'ensures that not raises error' do
lambda do
RestartNodesJob.perform
end.should_not raise_exception
end
it 'ensures that do nothing when all instructions disabled' do
NodeInstruction.lock_all
expect(RpmBuildNode).to_not receive(:all)
RestartNodesJob.perform
end
it 'ensures that creates tasks' do
allow_any_instance_of(NodeInstruction).to receive(:perform_restart)
# ABF active node
ni1 = FactoryGirl.create(:node_instruction)
FactoryGirl.create(:rpm_build_node, user_id: ni1.user_id)
# User node
FactoryGirl.create(:rpm_build_node)
FactoryGirl.create(:node_instruction, status: NodeInstruction::DISABLED)
ni2 = FactoryGirl.create(:node_instruction, status: NodeInstruction::RESTARTING)
FactoryGirl.create(:node_instruction, status: NodeInstruction::FAILED)
ni3 = FactoryGirl.create(:node_instruction)
RestartNodesJob.perform
expect(NodeInstruction.where(status: NodeInstruction::RESTARTING).count).to eq 2
NodeInstruction.where(status: NodeInstruction::RESTARTING).should include(ni2, ni3)
NodeInstruction.where(status: NodeInstruction::RESTARTING).should_not include(ni1)
end
end

View File

@ -1,47 +0,0 @@
require 'spec_helper'
shared_examples_for 'attach advisory to build_list' do
it 'ensure that advisory has been attached to build_list' do
build_list.reload.advisory.should == advisory
end
it 'ensure that save_to_platform of build_list has been attached to advisory' do
build_list.save_to_platform.advisories.should include(advisory)
end
it 'ensure that projects of build_list has been attached to advisory' do
build_list.project.advisories.should include(advisory)
end
end
describe Advisory do
before { stub_symlink_methods }
context 'attach_build_list' do
let(:build_list) { FactoryGirl.create(:build_list) }
context 'attach new advisory to build_list' do
let(:advisory) { FactoryGirl.build(:advisory) }
before do
advisory.attach_build_list(build_list)
end
it_should_behave_like 'attach advisory to build_list'
it 'ensure that advisory has been created' do
expect(Advisory.count).to eq 1
end
end
context 'attach old advisory to build_list' do
let(:advisory) { FactoryGirl.create(:advisory) }
before do
advisory.attach_build_list(build_list)
end
it_should_behave_like 'attach advisory to build_list'
end
end
end

View File

@ -1,24 +0,0 @@
require 'spec_helper'
describe BuildScript do
before { stub_symlink_methods }
let(:build_script) { FactoryGirl.build(:build_script) }
it 'is valid given valid attributes' do
build_script.should be_valid
end
context 'ensures that validations and associations exist' do
it { should belong_to(:project) }
it { should validate_presence_of(:project) }
it { should validate_presence_of(:treeish) }
context 'uniqueness' do
before { build_script.save }
it { should validate_uniqueness_of(:project_id).scoped_to(:treeish) }
end
end
end

View File

@ -1,307 +0,0 @@
require 'spec_helper'
def create_comment user
FactoryGirl.create(:comment, user: user, commentable: @commit, project: @project)
end
def create_comment_in_commit commit, project, body
FactoryGirl.create(:comment, user: @user, commentable: commit, project: project, body: body)
end
def set_comments_data_for_commit
@project = FactoryGirl.create(:project_with_commit, owner: @user)
@commit = @project.repo.commits.first
@comment = create_comment(@user)
@stranger_comment = create_comment(@stranger)
@subscribe_params = {project_id: @project.id, subscribeable_id: @commit.id.hex, subscribeable_type: @commit.class.name}
Subscribe.destroy_all
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
def should_send_email(args={})
user_mailer = double(:user_mailer)
expect(UserMailer).to receive(:new_comment_notification).with(kind_of(Comment), args[:receiver].id).and_return(user_mailer)
expect(user_mailer).to receive(:deliver)
create_comment args[:commentor]
end
def should_not_send_email(args={})
create_comment args[:commentor]
expect(UserMailer).to_not receive(:new_comment_notification)
end
def should_send_emails(commentor:, receivers:)
reset_email
create_comment commentor
expect(ActionMailer::Base.deliveries.count).to eq(receivers.count)
expect(ActionMailer::Base.deliveries.map &:to).to match_array(receivers.map {|u| [u.email]})
end
describe Comment do
before { stub_symlink_methods }
context 'for project admin user' do
before do
@user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
set_comments_data_for_commit
@admin = FactoryGirl.create(:user)
create_relation(@project, @admin, 'admin')
end
it 'should send two emails by default settings' do
should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end
context 'for disabled notify setting new_comment_commit_repo_owner' do
it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_repo_owner, false
should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end
end
context 'for disabled notify setting new_comment_commit_owner' do
it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_owner, false
should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end
end
context 'for disabled notify setting new_comment_commit_commentor' do
it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_commentor, false
should_send_emails(commentor: @stranger, receivers: [@user, @admin])
end
end
context 'for disabled all notify setting expect global' do
it 'should not send an e-mail' do
@user.notifier.update_column :new_comment_commit_repo_owner, false
@user.notifier.update_column :new_comment_commit_owner, false
@user.notifier.update_column :new_comment_commit_commentor, false
should_not_send_email(commentor: @stranger)
end
end
context 'for unsubscribe commit' do
it 'should not send an e-mail' do
Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id)
should_not_send_email(commentor: @stranger)
end
end
context 'for disabled global notify setting' do
it 'should not send an e-mail' do
@user.notifier.update_column :can_notify, false
should_not_send_email(commentor: @stranger)
end
end
end
context 'for project owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
set_comments_data_for_commit
@project.owner = @user
@project.save
end
context 'for default enabled settings' do
it 'should send an e-mail by default settings' do
should_send_email(commentor: @stranger, receiver: @project.owner)
end
end
context 'for disabled notify setting new_comment_commit_repo_owner' do
it 'should not send an e-mail' do
@user.notifier.update_column :new_comment_commit_repo_owner, false
Comment.destroy_all
should_not_send_email(commentor: @stranger)
end
end
context 'for disabled notify setting new_comment_commit_owner' do
it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_owner, false
should_send_email(commentor: @stranger, receiver: @user)
end
end
context 'for disabled notify setting new_comment_commit_commentor' do
it 'should send an e-mail' do
@user.notifier.update_column :new_comment_commit_commentor, false
should_send_email(commentor: @stranger, receiver: @user)
end
end
context 'for disabled all notify setting expect global' do
it 'should not send an e-mail' do
@user.notifier.update_column :new_comment_commit_repo_owner, false
@user.notifier.update_column :new_comment_commit_owner, false
@user.notifier.update_column :new_comment_commit_commentor, false
should_not_send_email(commentor: @stranger)
end
end
context 'for unsubscribe project' do
it 'should not send an e-mail' do
Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: @user.id)
should_not_send_email(commentor: @stranger)
end
end
context 'for disabled global notify setting' do
it 'should not send an e-mail' do
@user.notifier.update_column :can_notify, false
should_not_send_email(commentor: @stranger)
end
end
context 'for own commit' do
it 'should send a one e-mail' do
@project.owner.update_column :email, 'code@tpope.net'
should_send_email(commentor: @stranger, receiver: @project.owner)
end
end
end
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
@simple = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
set_comments_data_for_commit
@comment = create_comment(@simple)
Subscribe.unsubscribe_from_commit @subscribe_params.merge(user_id: [@stranger.id, @project.owner.id])
end
context 'for default enabled settings' do
it 'should send an e-mail' do
should_send_email(commentor: @stranger, receiver: @simple)
end
it 'should send an e-mail for comments after his comment' do
comment = create_comment(@simple)
should_send_email(commentor: @stranger, receiver: @simple)
end
it 'should send an e-mail when subscribed to project' do
Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id)
should_send_email(commentor: @project.owner, receiver: @simple)
end
it 'should not send an e-mail for own comment' do
should_not_send_email(commentor: @simple)
end
end
context 'for committer' do
it 'should send an e-mail' do
@simple.update_column :email, 'test@test.test'
should_send_email commentor: @stranger, receiver: @simple
end
it 'should send a one e-mail when subscribed to commit' do
Subscribe.subscribe_to_commit @subscribe_params.merge(user_id: @simple.id)
@simple.update_column :email, 'test@test.test'
should_send_email(commentor: @stranger, receiver: @simple)
end
it 'should not send an e-mail for own comment' do
@simple.update_column :email, 'test@test.test'
should_not_send_email(commentor: @simple)
end
it 'should not send an e-mail if global notify off' do
@project.owner.notifier.update_column :can_notify, false
@simple.update_column :email, 'test@test.test'
@simple.notifier.update_column :can_notify, false
should_not_send_email(commentor: @user)
end
it 'should not send an e-mail if notify for my commits off' do
Comment.destroy_all
@simple.notifier.update_column :new_comment_commit_owner, false
@simple.update_column :email, 'test@test.test'
should_not_send_email(commentor: @user)
end
end
context 'automatic issue linking' do
before(:each) do
@same_name_project = FactoryGirl.create(:project, name: @project.name)
@issue_in_same_name_project = FactoryGirl.create(:issue, project: @same_name_project, user: @same_name_project.owner)
@another_project = FactoryGirl.create(:project, owner: @user)
@other_user_project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, project: @project, user: @user)
@second_issue = FactoryGirl.create(:issue, project: @project, user: @user)
@issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user)
@issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner)
end
it 'should create automatic comment' do
create_comment_in_commit(@commit, @project, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_commit_hash: @commit.id.hex).count
).to eq(1)
end
it 'should create automatic comment in the another project issue' do
body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
create_comment_in_commit(@commit, @project, body)
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @issue_in_another_project.id,
created_from_commit_hash: @commit.id.hex).count
).to eq(1)
end
it 'should create automatic comment in the same name project issue' do
body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
create_comment_in_commit(@commit, @project, body)
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @issue_in_same_name_project.id,
created_from_commit_hash: @commit.id.hex).count
).to eq(1)
end
it 'should not create duplicate automatic comment' do
create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]")
create_comment_in_commit(@commit, @project, "test duplicate link to [##{@second_issue.serial_id}]")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_commit_hash: @commit.id.hex).count
).to eq(1)
end
it 'should not create duplicate automatic comment from one' do
create_comment_in_commit(@commit, @project, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_commit_hash: @commit.id.hex).count
).to eq(1)
end
it 'should create two automatic comment' do
body = "test ##{@second_issue.serial_id}" +
" && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
create_comment_in_commit(@commit, @project, body)
expect(
Comment.where(automatic: true,
created_from_commit_hash: @commit.id.hex).count
).to eq(2)
end
end
end
end

View File

@ -1,126 +0,0 @@
require 'spec_helper'
def set_commentable_data
@project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, project_id: @project.id, user: @user)
@comment = FactoryGirl.create(:comment, commentable: @issue, user: @user, project: @project)
@stranger_comment = FactoryGirl.create(:comment, commentable: @issue, user: @stranger, project: @project)
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
def create_comment_in_issue issue, body
FactoryGirl.create(:comment, user: issue.user, commentable: issue, project: issue.project, body: body)
end
describe Comment do
before { stub_symlink_methods }
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
set_commentable_data
end
context 'automatic issue linking' do
before(:each) do
@same_name_project = FactoryGirl.create(:project, name: @project.name)
@issue_in_same_name_project = FactoryGirl.create(:issue, project: @same_name_project, user: @same_name_project.owner)
@another_project = FactoryGirl.create(:project, owner: @user)
@other_user_project = FactoryGirl.create(:project)
@issue = FactoryGirl.create(:issue, project: @project, user: @user)
@second_issue = FactoryGirl.create(:issue, project: @project, user: @user)
@issue_in_another_project = FactoryGirl.create(:issue, project: @another_project, user: @user)
@issue_in_other_user_project = FactoryGirl.create(:issue, project: @other_user_project, user: @other_user_project.owner)
end
it 'should create automatic comment' do
create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should not create automatic comment to the same issue' do
create_comment_in_issue(@issue, "test link to ##{@issue.serial_id}; [##{@second_issue.serial_id}]")
expect(
Comment.where(automatic: true,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should create automatic comment in the another project issue' do
body = "[#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
create_comment_in_issue(@issue, body)
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @issue_in_another_project.id,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should create automatic comment in the same name project issue' do
body = "[#{@same_name_project.owner.uname}##{@issue_in_same_name_project.serial_id}]"
create_comment_in_issue(@issue, body)
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @issue_in_same_name_project.id,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should not create duplicate automatic comment' do
create_comment_in_issue(@issue, "test link to [##{@second_issue.serial_id}]")
create_comment_in_issue(@issue, "test duplicate link to [##{@second_issue.serial_id}]")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should not create duplicate automatic comment from one' do
create_comment_in_issue(@issue, "test link to [##{@second_issue.serial_id}]; ##{@second_issue.serial_id}")
expect(
Comment.where(automatic: true, commentable_type: 'Issue',
commentable_id: @second_issue.id,
created_from_issue_id: @issue.id).count
).to eq(1)
end
it 'should create two automatic comment' do
body = "test ##{@second_issue.serial_id}" +
" && [#{@another_project.name_with_owner}##{@issue_in_another_project.serial_id}]"
create_comment_in_issue(@issue, body)
expect(Comment.where(automatic: true,
created_from_issue_id: @issue.id).count).to eq(2)
end
it 'should create automatic comment by issue title' do
issue = FactoryGirl.create(:issue, project: @project, user: @user,
title: "link to ##{@issue.serial_id}")
expect(Comment.where(automatic: true,
created_from_issue_id: issue.id).count).to eq(1)
end
it 'should create automatic comment from issue body' do
issue = FactoryGirl.create(:issue, project: @project, user: @user,
body: "link to ##{@issue.serial_id}")
expect(Comment.where(automatic: true,
created_from_issue_id: issue.id).count).to eq(1)
end
it 'should create only one automatic comment from issue title and body' do
issue = FactoryGirl.create(:issue, project: @project, user: @user,
title: "link to ##{@issue.serial_id} in title",
:body => "link to ##{@issue.serial_id} in body")
expect(Comment.where(automatic: true,
created_from_issue_id: issue.id).count).to eq(1)
end
end
end
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Hook do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,157 +0,0 @@
require 'spec_helper'
def set_data
@user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
end
def create_issue issue_owner
ActionMailer::Base.deliveries = []
@issue = FactoryGirl.create(:issue, project_id: @project.id,
user: issue_owner, assignee: nil)
end
describe Issue do
before do
stub_symlink_methods
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
context '#update_statistic' do
it 'updates styatistics' do
expect { FactoryGirl.create(:issue) }.to change(Statistic, :count).by(1)
end
end
context 'for project admin user' do
before(:each) do
set_data
@project = FactoryGirl.create(:project, owner: @user)
end
it 'should send an e-mail' do
create_issue(@stranger)
expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.last.to).to include(@user.email)
end
it 'should not send an e-mail to creator' do
create_issue(@user)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it 'should create automatic comment from another issue' do
create_issue(@user)
another_issue = FactoryGirl.create(:issue, project: @project, title: "[##{@issue.serial_id}]")
expect(Comment.where(automatic: true, commentable_type: 'Issue',
created_from_issue_id: another_issue.id).count).to eq(1)
end
it 'should create automatic comment after updating another issue body' do
create_issue(@user)
another_issue = FactoryGirl.create(:issue, project: @project)
another_issue = Issue.find another_issue.id
another_issue.update_attribute(:title, "[##{@issue.serial_id}]")
expect(Comment.where(automatic: true, commentable_type: 'Issue',
created_from_issue_id: another_issue.id).count).to eq(1)
end
it 'should send email message to new assignee' do
create_issue(@user)
ActionMailer::Base.deliveries = []
@issue = Issue.find @issue.id
@issue.update_attribute :assignee_id, @user.id
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
end
context 'for member-group' do
before(:each) do
set_data
@project = FactoryGirl.create(:project, owner: @user)
@group = FactoryGirl.create(:group)
@reader = FactoryGirl.create :user
create_actor_relation(@group, @reader, 'reader')
end
it 'should send an e-mail to all members of the admin group' do
create_relation(@project, @group, 'admin')
create_issue(@stranger)
expect(ActionMailer::Base.deliveries.count).to eq(3) # 1 owner + 2 group member. enough?
end
it 'should send an e-mail to all members of the admin group except creator' do
create_relation(@project, @group, 'admin')
create_issue(@group.owner)
expect(ActionMailer::Base.deliveries.count).to eq(2) # 1 owner + 1 group member. enough?
end
it 'should send emails to members of the reader group' do
create_relation(@project, @group, 'reader')
create_issue(@stranger)
expect(ActionMailer::Base.deliveries.count).to eq(3) # project owner + group owner + group member
end
it 'should reset issue assignee after remove him from group' do
create_relation(@project, @group, 'reader')
create_issue(@group.owner)
@issue.update_column :assignee_id, @reader.id
@group.remove_member @reader
expect(@issue.reload.assignee_id).to be_nil
end
it 'should not reset issue assignee' do
create_relation(@project, @group, 'reader')
create_relation(@project, @reader, 'reader')
create_issue(@group.owner)
@issue.update_column :assignee_id, @reader.id
@group.remove_member @reader
expect(@issue.reload.assignee_id).to eq(@reader.id)
end
it 'should reset issue assignee after remove him from project' do
create_relation(@project, @reader, 'reader')
create_issue(@reader)
@issue.update_column :assignee_id, @reader.id
@project.remove_member @reader # via api
expect(@issue.reload.assignee_id).to be_nil
end
end
context 'Group project' do
before(:each) do
set_data
@group = FactoryGirl.create(:group, owner: @user)
@project = FactoryGirl.create(:project, owner: @group)
end
context 'for admin of the group' do
it 'should send an e-mail' do
create_issue(@stranger)
expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.last.to).to include(@user.email)
end
it 'should not send an e-mail to creator' do
create_issue(@user)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end
context 'for reader of the group' do
it 'should send an email' do
reader = FactoryGirl.create :user
create_actor_relation(@group, reader, 'reader')
create_issue(@stranger)
expect(ActionMailer::Base.deliveries.count).to eq(2) # group owner + group reader
end
end
end
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Label do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,9 +0,0 @@
require 'spec_helper'
describe NodeInstruction do
it 'is valid given valid attributes' do
FactoryGirl.build(:node_instruction).should be_valid
end
end

View File

@ -1,155 +0,0 @@
require 'spec_helper'
def set_data_for_pull
@project = FactoryGirl.create(:project_with_commit, owner: @user)
@clone_path = File.join(APP_CONFIG['root_path'], 'repo_clone', @project.id.to_s)
FileUtils.mkdir_p(@clone_path)
@other_project = FactoryGirl.create(:project_with_commit, owner: @user)
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
end
describe PullRequest do
before { stub_symlink_methods }
context 'for owner user' do
before do
@user = FactoryGirl.create(:user)
set_data_for_pull
@pull = @project.pull_requests.new(issue_attributes: {title: 'test', body: 'testing'})
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
@pull.to_ref = 'master'
@pull.from_project, @pull.from_ref = @project, 'non_conflicts'
@pull.save
@other_pull = @project.pull_requests.new(issue_attributes: {title: 'test_other', body: 'testing_other'})
@other_pull.issue.user, @other_pull.issue.project = @user, @other_pull.to_project
@other_pull.to_ref = 'master'
@other_pull.from_project, @other_pull.from_ref = @other_project, 'non_conflicts'
@other_pull.save
end
it 'ensures that path to pull_request repository has been changed after rename of project' do
@pull.check
@project.update_attributes(name: "#{@project.name}-new")
@pull.reload
expect(Dir.exists? @pull.path).to be_truthy
end
it 'master should merge with non_conflicts branch' do
@pull.check
expect(@pull.status).to eq('ready')
end
it 'master should not merge with conflicts branch' do
@pull.from_ref = 'conflicts'
@pull.check
expect(@pull.status).to eq('blocked')
end
it 'should already merged when already up-to-date branches' do
@pull.from_ref = 'master'
@pull.check
expect(@pull.status).to eq('merged')
end
context 'for other head project' do
it 'master should merge with non_conflicts branch' do
@other_pull.check
expect(@other_pull.status).to eq('ready')
end
it 'master should not merge with conflicts branch' do
@other_pull.from_ref = 'conflicts'
@other_pull.check
expect(@other_pull.status).to eq('blocked')
end
it 'should already merged when already up-to-date branches' do
@other_pull.from_ref = 'master'
@other_pull.check
expect(@other_pull.status).to eq('merged')
end
end
it "should not create same pull" do
expect {
@same_pull = @project.pull_requests.new(issue_attributes: {title: 'same', body: 'testing'})
@same_pull.issue.user, @same_pull.issue.project = @user, @same_pull.to_project
@same_pull.to_ref = 'master'
@same_pull.from_project, @same_pull.from_ref = @project, 'non_conflicts'
@same_pull.save
}.to change { PullRequest.count }.by(0)
#expect(@project.pull_requests.joins(:issue).where(issues: {title: @same_pull.title}).count).to == 0
end
it "should not create pull with wrong base ref" do
expect {
@wrong_pull = @project.pull_requests.new(issue_attributes: {title: 'wrong base', body: 'testing'})
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.to_project
@wrong_pull.to_ref = 'wrong'
@wrong_pull.from_project, @wrong_pull.from_ref = @project, 'non_conflicts'
@wrong_pull.save
}.to change { PullRequest.count }.by(0)
end
it "should not create pull with wrong head ref" do
expect {
@wrong_pull = @project.pull_requests.new(issue_attributes: {title: 'wrong head', body: 'testing'})
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.to_project
@wrong_pull.to_ref = 'master'
@wrong_pull.from_project, @wrong_pull.from_ref = @project, 'wrong'
@wrong_pull.save
}.to change { PullRequest.count }.by(0)
end
it "should create pull with tag" do
expect {
system("cd #{@project.path} && git tag 4.7.5.3 $(git rev-parse #{@pull.from_ref})") # TODO REDO through grit
@pull = @project.pull_requests.new(issue_attributes: {title: 'tag', body: 'testing'})
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
@pull.to_ref = 'master'
@pull.from_project, @pull.from_ref = @project, '4.7.5.3'
@pull.save
}.to change { @project.pull_requests.count }.by(1)
end
it "should close pull when deleting from branch" do
expect {
system("cd #{@project.path} && git branch -D #{@pull.from_branch}")
@pull.check
}.to change {
@project.pull_requests.joins(:issue).where(issues: {title: @pull.title, status: 'closed'}).count
}.by(1)
end
end
before do
FileUtils.rm_rf(APP_CONFIG['root_path'])
end
it { should belong_to(:issue).validate(true) }
it { should belong_to(:to_project) }
it { should belong_to(:from_project) }
context '#update_statistic' do
let(:issue) { FactoryGirl.build(:issue) }
let(:pull_request) { FactoryGirl.build(:pull_request, issue: issue) }
it 'updates styatistics' do
allow(PullRequest).to receive(:check_ref).and_return(true)
issue.new_pull_request = true
expect do
pull_request.save
end.to change(Statistic, :count).by(1)
expect(Statistic.last.key).to eq "#{Statistic::KEY_PULL_REQUEST}.#{Issue::STATUS_OPEN}"
end
end
after do
FileUtils.rm_rf(APP_CONFIG['root_path'])
FileUtils.rm_rf File.join(Rails.root, "tmp", Rails.env, "pull_requests")
end
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe RegisterRequest do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe SshKey do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,19 +0,0 @@
require 'spec_helper'
describe Subscribe do
before(:each) { stub_symlink_methods }
context 'validates that subscribe contains user' do
it 'when subscribe contains user' do
s = FactoryGirl.build(:subscribe)
expect(s.valid?).to be_truthy
end
it 'when subscribe does not contains user' do
s = FactoryGirl.build(:subscribe)
s.user = nil
expect(s.valid?).to be_falsy
end
end
end

View File

@ -1,31 +0,0 @@
require 'spec_helper'
RSpec.describe AdvisoryPolicy, type: :policy do
let(:advisory) { FactoryGirl.build(:advisory) }
subject { described_class }
%i(index? search? show?).each do |perm|
permissions perm do
it "grants access to anonymous user" do
expect(subject).to permit(User.new, advisory)
end
it "grants access to user" do
expect(subject).to permit(FactoryGirl.create(:user), advisory)
end
end
end
%i(create? update?).each do |perm|
permissions perm do
it "denies access to anonymous user" do
expect(subject).not_to permit(User.new, advisory)
end
it "grants access to user" do
expect(subject).to permit(FactoryGirl.create(:user), advisory)
end
end
end
end

View File

@ -1,47 +0,0 @@
require 'spec_helper'
RSpec.describe CommentPolicy, type: :policy do
let(:comment) { FactoryGirl.build(:comment) }
subject { described_class }
%i(create? new_line?).each do |perm|
permissions perm do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, comment)
end
it "denies access if user can not read a project" do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(false)
expect(subject).to_not permit(FactoryGirl.create(:user), comment)
end
it "grants access if user can read a project" do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(true)
expect(subject).to permit(FactoryGirl.create(:user), comment)
end
end
end
%i(update? destroy?).each do |perm|
permissions perm do
it "denies access to user" do
expect(subject).to_not permit(User.new, comment)
end
it "grants access for creator" do
expect(subject).to permit(comment.user, comment)
end
it "grants access for admin of project" do
allow_any_instance_of(CommentPolicy).to receive(:local_admin?).
with(comment.project).and_return(true)
expect(subject).to permit(User.new, comment)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.build(:admin), comment)
end
end
end
end

View File

@ -1,25 +0,0 @@
require 'spec_helper'
RSpec.describe HookPolicy, type: :policy do
let(:hook) { FactoryGirl.build(:hook) }
subject { described_class }
%i(show? read? create? destroy? update?).each do |perm|
permissions perm do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, hook)
end
it "denies access if user can not update a project" do
allow_any_instance_of(ProjectPolicy).to receive(:update?).and_return(false)
expect(subject).to_not permit(User.new, hook)
end
it "grants access if user can update a project" do
allow_any_instance_of(ProjectPolicy).to receive(:update?).and_return(true)
expect(subject).to permit(User.new, hook)
end
end
end
end

View File

@ -1,63 +0,0 @@
require 'spec_helper'
RSpec.describe IssuePolicy, type: :policy do
let(:issue) { FactoryGirl.build(:issue) }
let(:user) { FactoryGirl.create(:user) }
subject { described_class }
permissions :index? do
it "grants access to anonymous user" do
expect(subject).to permit(User.new, issue)
end
end
%i(show? create? read?).each do |perm|
permissions perm do
it "denies access if user can not read a project" do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(false)
expect(subject).to_not permit(User.new, issue)
end
context "user can read a project" do
before do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(true)
end
it "grants access" do
expect(subject).to permit(User.new, issue)
end
it "denies access if project issues are disabled" do
issue.project.has_issues = false
expect(subject).to_not permit(User.new, issue)
end
end
end
end
permissions :update? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, issue)
end
it "denies access to user" do
expect(subject).to_not permit(user, issue)
end
it "grants access to project admin" do
allow_any_instance_of(IssuePolicy).to receive(:local_admin?).with(issue.project).and_return(true)
expect(subject).to permit(user, issue)
end
it "grants access to issue owner" do
issue.save!
expect(subject).to permit(issue.user, issue)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.create(:admin), issue)
end
end
end

View File

@ -1,80 +0,0 @@
require 'spec_helper'
RSpec.describe PullRequestPolicy, type: :policy do
let(:pull_request) { FactoryGirl.build(:pull_request) }
let(:user) { FactoryGirl.create(:user) }
subject { described_class }
permissions :index? do
it "grants access to anonymous user" do
expect(subject).to permit(User.new, pull_request)
end
end
%i(show? read? commits? files? create?).each do |perm|
permissions perm do
it "denies access if user can not read a project" do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(false)
expect(subject).to_not permit(User.new, pull_request)
end
context "user can read a project" do
before do
allow_any_instance_of(ProjectPolicy).to receive(:show?).and_return(true)
end
it "grants access" do
expect(subject).to permit(User.new, pull_request)
end
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.create(:admin), pull_request)
end
end
end
permissions :update? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, pull_request)
end
it "denies access to user" do
expect(subject).to_not permit(user, pull_request)
end
it "grants access for writer of project" do
allow_any_instance_of(PullRequestPolicy).to receive(:local_writer?).and_return(true)
expect(subject).to permit(user, pull_request)
end
it "grants access to issue owner" do
pull_request.user.save!
expect(subject).to permit(pull_request.user, pull_request)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.create(:admin), pull_request)
end
end
permissions :merge? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, pull_request)
end
it "denies access to user" do
expect(subject).to_not permit(user, pull_request)
end
it "grants access for writer of project" do
allow_any_instance_of(PullRequestPolicy).to receive(:local_writer?).and_return(true)
expect(subject).to permit(user, pull_request)
end
it "grants access for to global admin" do
expect(subject).to permit(FactoryGirl.create(:admin), pull_request)
end
end
end

View File

@ -1,35 +0,0 @@
require 'spec_helper'
RSpec.describe SubscribePolicy, type: :policy do
let(:subscribe) { FactoryGirl.create(:subscribe) }
subject { described_class }
permissions :create? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, subscribe)
end
it "grants access to user" do
expect(subject).to permit(FactoryGirl.create(:user), subscribe)
end
it "denies access if user already subscribed" do
expect(subject).to_not permit(subscribe.user, subscribe)
end
end
permissions :destroy? do
it "denies access to anonymous user" do
expect(subject).to_not permit(User.new, subscribe)
end
it "denies access to user" do
expect(subject).to_not permit(FactoryGirl.create(:user), subscribe)
end
it "grants access if user already subscribed" do
expect(subject).to permit(subscribe.user, subscribe)
end
end
end

View File

@ -57,14 +57,14 @@ def http_login(user=nil, password = '123456')
end
def stub_symlink_methods
allow_any_instance_of(Platform).to receive(:symlink_directory).and_return(true)
allow_any_instance_of(Platform).to receive(:remove_symlink_directory).and_return(true)
#allow_any_instance_of(Platform).to receive(:symlink_directory).and_return(true)
#allow_any_instance_of(Platform).to receive(:remove_symlink_directory).and_return(true)
allow_any_instance_of(Platform).to receive(:create_empty_metadata).and_return(true)
allow_any_instance_of(Repository).to receive(:create_empty_metadata).and_return(true)
end
Resque.inline = true
#Resque.inline = true
APP_CONFIG['root_path'] = "#{Rails.root}/tmp/test_root"
APP_CONFIG['git_path'] = "#{Rails.root}/tmp/test_root"
APP_CONFIG['tmpfs_path'] = "#{Rails.root}/tmp/test_root"
@ -83,7 +83,7 @@ def stub_redis
allow(Redis).to receive(:new).and_return(@redis_instance)
allow(Redis).to receive(:current).and_return(@redis_instance)
allow(Redis::Store).to receive(:new).and_return(@redis_instance)
Resque.redis = @redis_instance
#Resque.redis = @redis_instance
end
def fill_project project