#-- copyright # OpenProject is a project management system. # Copyright (C) 2012-2013 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 StatusesController do let(:user) { FactoryGirl.create(:admin) } let(:status) { FactoryGirl.create(:status) } before { User.stub(:current).and_return user } shared_examples_for :response do subject { response } it { should be_success } it { should render_template(template) } end shared_examples_for :redirect do subject { response } it { should be_redirect } it { should redirect_to({ action: :index }) } end shared_examples_for :statuses do subject { Status.find_by_name(name) } it { should_not be_nil } end describe :index do let(:template) { 'index' } before { get :index } it_behaves_like :response end describe :new do let(:template) { 'new' } before { get :new } it_behaves_like :response end describe :create do let(:name) { 'New Status' } before { post :create, status: { name: name } } it_behaves_like :statuses it_behaves_like :redirect end describe :edit do let(:template) { 'edit' } context :default do let!(:status_default) { FactoryGirl.create(:status, is_default: true) } before { get :edit, id: status_default.id } it_behaves_like :response describe :view do render_views it do assert_no_tag tag: 'p', content: Status.human_attribute_name(:is_default) end end end context 'no_default' do before do status get :edit, id: status.id end it_behaves_like :response describe :view do render_views it do assert_tag tag: 'p', content: Status.human_attribute_name(:is_default) end end end end describe :update do let(:name) { 'Renamed Status' } before do status put :update, id: status.id, status: { name: name } end it_behaves_like :statuses it_behaves_like :redirect end describe :destroy do let(:name) { status.name } shared_examples_for :destroyed do subject { Status.find_by_name(name) } it { should be_nil } end context "unused" do before do status delete :destroy, id: status.id end it_behaves_like :destroyed it_behaves_like :redirect end context "used" do let(:work_package) { FactoryGirl.create(:work_package, status: status) } before do work_package delete :destroy, id: status.id end it_behaves_like :statuses it_behaves_like :redirect end end describe :update_work_package_done_ratio do shared_examples_for :flash do it { should set_the_flash.to(message) } end context "with 'work_package_done_ratio' using 'field'" do let(:message) { /not updated/ } before do Setting.stub(:work_package_done_ratio).and_return 'field' post :update_work_package_done_ratio end it_behaves_like :flash it_behaves_like :redirect end context "with 'work_package_done_ratio' using 'status'" do let(:message) { /Work package done ratios updated/ } before do Setting.stub(:work_package_done_ratio).and_return 'status' post :update_work_package_done_ratio end it_behaves_like :flash it_behaves_like :redirect end end end