kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.1 KiB
135 lines
4.1 KiB
#-- copyright
|
|
# OpenProject is a project management system.
|
|
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
#
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
#++
|
|
|
|
require File.expand_path('../../spec_helper', __FILE__)
|
|
|
|
describe CopyProjectsController, :type => :controller do
|
|
let(:current_user) { FactoryGirl.create(:admin) }
|
|
let(:redirect_path) { "source_project_settings" }
|
|
let(:permission) { :copy_projects }
|
|
let(:project) { FactoryGirl.create(:project, :is_public => false) }
|
|
|
|
|
|
before do
|
|
allow(User).to receive(:current).and_return current_user
|
|
|
|
request.env['HTTP_REFERER'] = redirect_path
|
|
end
|
|
|
|
describe "copy_from_settings uses correct project to copy from" do
|
|
before do
|
|
get 'copy_project', :id => project.id, :coming_from => :settings
|
|
end
|
|
|
|
it { expect(assigns(:project)).to eq(project) }
|
|
|
|
it { expect(assigns(:copy_project).id).to be_nil }
|
|
|
|
it { expect(response).to render_template('copy_from_settings') }
|
|
end
|
|
|
|
describe "copy_from_settings without valid project" do
|
|
before { get 'copy_project' }
|
|
|
|
it { expect(response.code).to eq('404') }
|
|
end
|
|
|
|
describe 'copy_from_settings permissions' do
|
|
def fetch
|
|
get 'copy_project', :id => project.id, :coming_from => :settings
|
|
end
|
|
|
|
it_should_behave_like "a controller action which needs project permissions"
|
|
end
|
|
|
|
shared_examples_for 'successful copy' do
|
|
it { expect(flash[:notice]).to eq(I18n.t('copy_project.started', source_project_name: source_project.name, target_project_name: target_project_name)) }
|
|
end
|
|
|
|
def copy_project(project)
|
|
post 'copy',
|
|
:id => project.id,
|
|
:project => project.attributes.reject { |k,v| v.nil? }.merge({ :identifier => "copy", :name => "copy" })
|
|
end
|
|
|
|
describe 'copy creates a new project' do
|
|
before { copy_project(project) }
|
|
|
|
def expect_redirect_to
|
|
true
|
|
end
|
|
|
|
it { expect(Project.count).to eq(2) }
|
|
|
|
it_behaves_like 'successful copy' do
|
|
let(:source_project) { project }
|
|
let(:target_project_name) { "copy" }
|
|
end
|
|
|
|
it { expect(response).to redirect_to(redirect_path) }
|
|
end
|
|
|
|
describe 'copy permissions' do
|
|
def fetch
|
|
post 'copy',
|
|
:id => project.id,
|
|
:project => project.attributes.reject { |k,v| v.nil? }.merge({ :identifier => "copy", :name => "copy" })
|
|
end
|
|
|
|
def expect_redirect_to
|
|
true
|
|
end
|
|
|
|
let(:permission) { [:copy_projects, :add_project] }
|
|
let(:project) { FactoryGirl.create(:project, :is_public => false) }
|
|
|
|
it_should_behave_like "a controller action which needs project permissions"
|
|
end
|
|
|
|
describe 'copy sends eMail' do
|
|
context 'on success' do
|
|
it 'user receives success mail' do
|
|
expect(UserMailer).to receive(:copy_project_succeeded).and_return(double("mailer", deliver: true))
|
|
|
|
copy_project(project)
|
|
end
|
|
end
|
|
|
|
context 'on error' do
|
|
before do
|
|
allow(UserMailer).to receive(:with_deliveries).and_raise(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it 'user receives success mail' do
|
|
expect(UserMailer).to receive(:copy_project_failed).and_return(double("mailer", deliver: true))
|
|
|
|
copy_project(project)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|