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.
213 lines
6.0 KiB
213 lines
6.0 KiB
8 years ago
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
|
# Copyright (C) 2012-2015 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 'spec_helper'
|
||
|
|
||
|
describe CustomStylesController, type: :controller do
|
||
|
let(:a_token) { EnterpriseToken.new }
|
||
|
|
||
|
before do
|
||
|
login_as user
|
||
|
end
|
||
|
|
||
|
context 'with admin' do
|
||
|
let(:user) { FactoryGirl.build(:admin) }
|
||
|
|
||
|
describe '#show' do
|
||
|
subject { get :show }
|
||
|
render_views
|
||
|
|
||
|
context 'when active token exists' do
|
||
|
before do
|
||
|
allow(a_token).to receive(:allows_to?).with(:define_custom_style).and_return(true)
|
||
|
allow(EnterpriseToken).to receive(:current).and_return(a_token)
|
||
|
end
|
||
|
|
||
|
it 'renders show' do
|
||
|
expect(subject).to be_success
|
||
|
expect(response).to render_template 'show'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'when no active token exists' do
|
||
|
before do
|
||
|
allow(EnterpriseToken).to receive(:current).and_return(nil)
|
||
|
end
|
||
|
|
||
|
it 'redirects to #upsale' do
|
||
|
expect(subject).to redirect_to action: :upsale
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#upsale" do
|
||
|
subject { get :upsale }
|
||
|
render_views
|
||
|
|
||
|
it 'renders upsale' do
|
||
|
expect(subject).to be_success
|
||
|
expect(subject).to render_template 'upsale'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#create" do
|
||
|
let(:custom_style) { CustomStyle.new }
|
||
|
let(:params) do
|
||
|
{
|
||
|
custom_style: { logo: 'foo' }
|
||
|
}
|
||
|
end
|
||
|
|
||
|
before do
|
||
|
allow(a_token).to receive(:allows_to?).with(:define_custom_style).and_return(true)
|
||
|
allow(EnterpriseToken).to receive(:current).and_return(a_token)
|
||
|
|
||
|
expect(CustomStyle).to receive(:create).and_return(custom_style)
|
||
|
expect(custom_style).to receive(:valid?).and_return(valid)
|
||
|
|
||
|
post :create, params: params
|
||
|
end
|
||
|
|
||
|
context 'valid custom_style input' do
|
||
|
# let(:valid) { true }
|
||
|
let(:valid) { true }
|
||
|
|
||
|
it 'redirects to show' do
|
||
|
# expect(custom_style).to receive(:logo=)
|
||
|
expect(response).to redirect_to action: :show
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'invalid custom_style input' do
|
||
|
let(:valid) { false }
|
||
|
|
||
|
it 'renders with error' do
|
||
|
expect(response).not_to be_redirect
|
||
|
expect(response).to render_template 'custom_styles/show'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#update" do
|
||
|
let(:custom_style) { FactoryGirl.build(:custom_style_with_logo) }
|
||
|
let(:params) do
|
||
|
{
|
||
|
custom_style: { logo: 'foo' }
|
||
|
}
|
||
|
end
|
||
|
|
||
|
before do
|
||
|
allow(a_token).to receive(:allows_to?).with(:define_custom_style).and_return(true)
|
||
|
allow(EnterpriseToken).to receive(:current).and_return(a_token)
|
||
|
|
||
|
expect(CustomStyle).to receive(:current).and_return(custom_style)
|
||
|
expect(custom_style).to receive(:update_attributes).and_return(valid)
|
||
|
|
||
|
post :update, params: params
|
||
|
end
|
||
|
|
||
|
context 'valid custom_style input' do
|
||
|
# let(:valid) { true }
|
||
|
let(:valid) { true }
|
||
|
|
||
|
it 'redirects to show' do
|
||
|
# expect(custom_style).to receive(:logo=)
|
||
|
expect(response).to redirect_to action: :show
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'invalid custom_style input' do
|
||
|
let(:valid) { false }
|
||
|
|
||
|
it 'renders with error' do
|
||
|
expect(response).not_to be_redirect
|
||
|
expect(response).to render_template 'custom_styles/show'
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
describe "#logo_download" do
|
||
|
|
||
|
subject { get :logo_download, params: { digest: "1234", filename: "logo_image.png" }}
|
||
|
render_views
|
||
|
|
||
|
before do
|
||
|
expect(CustomStyle).to receive(:current).and_return(custom_style)
|
||
|
end
|
||
|
|
||
|
context "when logo is present" do
|
||
|
let(:custom_style) { FactoryGirl.build(:custom_style_with_logo) }
|
||
|
|
||
|
it 'will send a file' do
|
||
|
expect(controller).to receive(:send_file) {controller.render nothing: true}
|
||
|
expect(subject.status).to eq(200)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when no logo is present" do
|
||
|
let(:custom_style){ nil }
|
||
|
|
||
|
it 'renders with error' do
|
||
|
expect(controller).to_not receive(:send_file)
|
||
|
expect(subject.status).to eq(404)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#logo_delete" do
|
||
|
let(:custom_style) { FactoryGirl.build(:custom_style_with_logo) }
|
||
|
subject { delete :logo_delete }
|
||
|
|
||
|
before do
|
||
|
allow(a_token).to receive(:allows_to?).with(:define_custom_style).and_return(true)
|
||
|
allow(EnterpriseToken).to receive(:current).and_return(a_token)
|
||
|
end
|
||
|
|
||
|
it 'removes the logo from custom_style' do
|
||
|
expect(CustomStyle).to receive(:current).and_return(custom_style)
|
||
|
expect(custom_style).to receive(:remove_logo!).and_return(custom_style)
|
||
|
expect(subject).to redirect_to action: :show
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
|
context 'regular user' do
|
||
|
let(:user) { FactoryGirl.build(:user) }
|
||
|
|
||
|
before do
|
||
|
get :show
|
||
|
end
|
||
|
|
||
|
it 'is forbidden' do
|
||
|
expect(response.status).to eq 403
|
||
|
end
|
||
|
end
|
||
|
end
|