From 4420895da1f758fc329713db67230ce19d640ce6 Mon Sep 17 00:00:00 2001 From: Martin Czuchra Date: Fri, 14 Jun 2013 17:12:26 +0200 Subject: [PATCH] Fixes most of the controller specs. This includes moving API tests out to api/v2, as well as fixing some view expectations. In addition, the redirect path of destroys was altered. --- app/controllers/timelines_controller.rb | 2 +- ...anning_element_statuses_controller_spec.rb | 4 +- .../planning_element_types_controller_spec.rb | 231 +++++++++ .../v2/planning_elements_controller_spec.rb | 450 ++++++++++++++++++ .../project_associations_controller_spec.rb | 152 ++++++ .../api/v2/scenarios_controller_spec.rb | 171 +++++++ .../api/v2/timelines_controller_spec.rb | 203 ++++++++ .../planning_element_types_controller_spec.rb | 206 +------- .../planning_elements_controller_spec.rb | 374 +-------------- .../project_associations_controller_spec.rb | 132 ----- spec/controllers/scenarios_controller_spec.rb | 152 ------ spec/controllers/timelines_controller_spec.rb | 14 +- 12 files changed, 1223 insertions(+), 868 deletions(-) rename spec/controllers/{ => api/v2}/planning_element_statuses_controller_spec.rb (96%) create mode 100644 spec/controllers/api/v2/planning_element_types_controller_spec.rb create mode 100644 spec/controllers/api/v2/planning_elements_controller_spec.rb create mode 100644 spec/controllers/api/v2/project_associations_controller_spec.rb create mode 100644 spec/controllers/api/v2/scenarios_controller_spec.rb create mode 100644 spec/controllers/api/v2/timelines_controller_spec.rb diff --git a/app/controllers/timelines_controller.rb b/app/controllers/timelines_controller.rb index 20caf71f01..e4e2a40990 100644 --- a/app/controllers/timelines_controller.rb +++ b/app/controllers/timelines_controller.rb @@ -73,7 +73,7 @@ class TimelinesController < ApplicationController @timeline.destroy flash[:notice] = l(:notice_successful_delete) - redirect_to project_path @project + redirect_to project_timelines_path @project end protected diff --git a/spec/controllers/planning_element_statuses_controller_spec.rb b/spec/controllers/api/v2/planning_element_statuses_controller_spec.rb similarity index 96% rename from spec/controllers/planning_element_statuses_controller_spec.rb rename to spec/controllers/api/v2/planning_element_statuses_controller_spec.rb index eb18ab0059..734f4929e8 100644 --- a/spec/controllers/planning_element_statuses_controller_spec.rb +++ b/spec/controllers/api/v2/planning_element_statuses_controller_spec.rb @@ -9,9 +9,9 @@ # See doc/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../../../../spec_helper', __FILE__) -describe PlanningElementStatusesController do +describe Api::V2::PlanningElementStatusesController do let(:current_user) { FactoryGirl.create(:admin) } before do diff --git a/spec/controllers/api/v2/planning_element_types_controller_spec.rb b/spec/controllers/api/v2/planning_element_types_controller_spec.rb new file mode 100644 index 0000000000..c40f25c74f --- /dev/null +++ b/spec/controllers/api/v2/planning_element_types_controller_spec.rb @@ -0,0 +1,231 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require File.expand_path('../../../../spec_helper', __FILE__) + +describe Api::V2::PlanningElementTypesController do + let (:current_user) { FactoryGirl.create(:admin) } + + before do + User.stub(:current).and_return current_user + end + + def enable_type(project, type) + FactoryGirl.create(:enabled_planning_element_type, + :project_id => project.id, + :planning_element_type_id => type.id) + end + + + describe 'with project scope' do + let(:project) { FactoryGirl.create(:project, :is_public => false) } + + describe 'index.xml' do + def fetch + get 'index', :project_id => project.identifier, :format => 'xml' + end + it_should_behave_like "a controller action which needs project permissions" + + describe 'with unknown project' do + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'index', :project_id => 'blah', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + + describe 'with no planning element types available' do + it 'assigns an empty planning_element_types array' do + get 'index', :project_id => project.identifier, :format => 'xml' + assigns(:planning_element_types).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => project.identifier, :format => 'xml' + response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) + end + end + + describe 'with 3 planning element types available' do + before do + @created_planning_element_types = [ + FactoryGirl.create(:planning_element_type), + FactoryGirl.create(:planning_element_type), + FactoryGirl.create(:planning_element_type) + ] + + @created_planning_element_types.each do |type| + enable_type(project, type) + end + + # Creating one PlanningElemenType which is not assigned to any + # Project and should therefore not show up in projects with a project + # type + FactoryGirl.create(:planning_element_type) + end + + it 'assigns an array with all planning element types' do + get 'index', :project_id => project.identifier, :format => 'xml' + assigns(:planning_element_types).should == @created_planning_element_types + end + + it 'renders the index template' do + get 'index', :project_id => project.identifier, :format => 'xml' + response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) + end + end + end + + describe 'show.xml' do + def fetch + @available_type = FactoryGirl.create(:planning_element_type, :id => '1337') + enable_type(project, @available_type) + + get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' + end + it_should_behave_like "a controller action which needs project permissions" + + describe 'with unknown project' do + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => 'blah', :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + + describe 'with unknown planning element type' do + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + + describe 'with an planning element type, which is not enabled in the project' do + before do + FactoryGirl.create(:planning_element_type, :id => '1337') + end + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + + describe 'with an available planning element type' do + before do + @available_planning_element_type = FactoryGirl.create(:planning_element_type, + :id => '1337') + + enable_type(project, @available_planning_element_type) + end + + it 'assigns the available planning element type' do + get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' + assigns(:planning_element_type).should == @available_planning_element_type + end + + it 'renders the show template' do + get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' + response.should render_template('timelines/planning_element_types/show', :formats => ["api"]) + end + end + end + end + + describe 'without project scope' do + describe 'index.xml' do + def fetch + get 'index', :format => 'xml' + end + it_should_behave_like "a controller action with unrestricted access" + + describe 'with no planning element types available' do + it 'assigns an empty planning_element_types array' do + get 'index', :format => 'xml' + assigns(:planning_element_types).should == [] + end + + it 'renders the index builder template' do + get 'index', :format => 'xml' + response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) + end + end + + describe 'with 3 planning element types available' do + before do + @created_planning_element_types = [ + FactoryGirl.create(:planning_element_type), + FactoryGirl.create(:planning_element_type), + FactoryGirl.create(:planning_element_type) + ] + end + + it 'assigns an array with all planning element types' do + get 'index', :format => 'xml' + assigns(:planning_element_types).should == @created_planning_element_types + end + + it 'renders the index template' do + get 'index', :format => 'xml' + response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) + end + end + end + + describe 'show.xml' do + describe 'with unknown planning element type' do + if false # would like to write it this way + it 'returns status code 404' do + get 'show', :id => '1337', :format => 'xml' + + response.status.should == '404 Not Found' + end + + it 'returns an empty body' do + get 'show', :id => '1337', :format => 'xml' + + response.body.should be_empty + end + + else # but have to write it that way + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + + describe 'with an available planning element type' do + before do + @available_planning_element_type = FactoryGirl.create(:planning_element_type, :id => '1337') + end + + def fetch + get 'show', :id => '1337', :format => 'xml' + end + it_should_behave_like "a controller action with unrestricted access" + + it 'assigns the available planning element type' do + get 'show', :id => '1337', :format => 'xml' + assigns(:planning_element_type).should == @available_planning_element_type + end + + it 'renders the show template' do + get 'show', :id => '1337', :format => 'xml' + response.should render_template('timelines/planning_element_types/show', :formats => ["api"]) + end + end + end + end +end diff --git a/spec/controllers/api/v2/planning_elements_controller_spec.rb b/spec/controllers/api/v2/planning_elements_controller_spec.rb new file mode 100644 index 0000000000..5225a49b52 --- /dev/null +++ b/spec/controllers/api/v2/planning_elements_controller_spec.rb @@ -0,0 +1,450 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require File.expand_path('../../../../spec_helper', __FILE__) + +describe Api::V2::PlanningElementsController do + # =========================================================== + # Helpers + def self.become_admin + let(:current_user) { FactoryGirl.create(:admin) } + end + + def self.become_non_member(&block) + let(:current_user) { FactoryGirl.create(:user) } + + before do + projects = block ? instance_eval(&block) : [project] + + projects.each do |p| + current_user.memberships.select {|m| m.project_id == p.id}.each(&:destroy) + end + end + end + + def self.become_member_with_view_planning_element_permissions(&block) + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:view_planning_elements]) + + projects = block ? instance_eval(&block) : [project] + + projects.each do |p| + member = FactoryGirl.build(:member, :user => current_user, :project => p) + member.roles = [role] + member.save! + end + end + end + + def self.become_member_with_edit_planning_element_permissions(&block) + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:edit_planning_elements]) + + projects = block ? instance_eval(&block) : [project] + + projects.each do |p| + member = FactoryGirl.build(:member, :user => current_user, :project => p) + member.roles = [role] + member.save! + end + end + end + + def self.become_member_with_delete_planning_element_permissions(&block) + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:delete_planning_elements]) + + projects = block ? instance_eval(&block) : [project] + + projects.each do |p| + member = FactoryGirl.build(:member, :user => current_user, :project => project) + member.roles = [role] + member.save! + end + end + end + + + before do + User.stub(:current).and_return current_user + end + + # =========================================================== + # API tests + + describe 'index.xml' do + become_admin + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'index', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'index', :project_id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + get 'index', :project_id => project.identifier, :format => 'xml' + + response.response_code.should == 403 + end + end + + describe 'w/ the current user being a member with view_planning_elements permissions' do + become_member_with_view_planning_element_permissions + + describe 'w/o any planning elements within the project' do + it 'assigns an empty planning_elements array' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:planning_elements).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/planning_elements/index', :formats => ["api"]) + end + end + + describe 'w/ 3 planning elements within the project' do + before do + @created_planning_elements = [ + FactoryGirl.create(:planning_element, :project_id => project.id), + FactoryGirl.create(:planning_element, :project_id => project.id), + FactoryGirl.create(:planning_element, :project_id => project.id) + ] + end + + it 'assigns a planning_elements array containing all three elements' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:planning_elements).should =~ @created_planning_elements + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/planning_elements/index', :formats => ["api"]) + end + end + end + end + + describe 'w/ multiple known projects' do + let(:project_a) { FactoryGirl.create(:project, :identifier => 'project_a') } + let(:project_b) { FactoryGirl.create(:project, :identifier => 'project_b') } + let(:project_c) { FactoryGirl.create(:project, :identifier => 'project_c') } + + describe 'w/ an unknown project in the list' do + become_admin { [project_a, project_b] } + + it 'renders a 404 Not Found page' do + get 'index', :project_id => 'project_x,project_b', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a project in the list, the current user may not access' do + before { project_a; project_b } + become_non_member { [project_b] } + + it 'assigns an empty planning_elements array' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + assigns(:planning_elements).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + response.should render_template('timelines/planning_elements/index', :formats => ["api"]) + end + end + + describe 'w/ the current user being a member with view_planning_elements permissions' do + become_member_with_view_planning_element_permissions { [project_a, project_b] } + + describe 'w/o any planning elements within the project' do + it 'assigns an empty planning_elements array' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + assigns(:planning_elements).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + response.should render_template('timelines/planning_elements/index', :formats => ["api"]) + end + end + + describe 'w/ 1 planning element in project_a and 2 in project_b' do + before do + @created_planning_elements = [ + FactoryGirl.create(:planning_element, :project_id => project_a.id), + FactoryGirl.create(:planning_element, :project_id => project_b.id), + FactoryGirl.create(:planning_element, :project_id => project_b.id) + ] + # adding another planning element, just to make sure, that the + # result set is properly filtered + FactoryGirl.create(:planning_element, :project_id => project_c.id) + end + + it 'assigns a planning_elements array containing all three elements' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + assigns(:planning_elements).should =~ @created_planning_elements + end + + it 'renders the index builder template' do + get 'index', :project_id => 'project_a,project_b', :format => 'xml' + response.should render_template('timelines/planning_elements/index', :formats => ["api"]) + end + end + end + end + end + + describe 'create.xml' do + become_admin + + it 'needs to be tested' + + let(:project) { FactoryGirl.create(:project, :is_public => false) } + def fetch + post 'create', :project_id => project.identifier, + :planning_element => FactoryGirl.build(:planning_element, + :project_id => project.id).attributes + end + def expect_redirect_to + Regexp.new(project_planning_elements_path(project)) + end + let(:permission) { :edit_planning_elements } + + it_should_behave_like "a controller action which needs project permissions" + end + + describe 'show.xml' do + become_admin + + describe 'w/o a valid planning element id' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'show', :project_id => '4711', :id => '1337', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + get 'show', :project_id => project.id, :id => '1337', :format => 'xml' + + response.response_code.should === 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_view_planning_element_permissions + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => project.id, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + + describe 'w/ a valid planning element id' do + become_admin + + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) } + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => planning_element.id, :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' + + response.response_code.should == 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_view_planning_element_permissions + + it 'assigns the planning_element' do + get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' + assigns(:planning_element).should == planning_element + end + + it 'renders the show builder template' do + get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' + response.should render_template('timelines/planning_elements/show', :formats => ["api"]) + end + end + end + end + end + + describe 'update.xml' do + become_admin + + it 'needs to be tested' + + let(:project) { FactoryGirl.create(:project, :is_public => false) } + let(:planning_element) { FactoryGirl.create(:planning_element, + :project_id => project.id) } + + def fetch + post 'update', :project_id => project.identifier, + :id => planning_element.id, + :planning_element => { name: "blubs" } + end + def expect_redirect_to + project_planning_element_path(project, planning_element) + end + let(:permission) { :edit_planning_elements } + + it_should_behave_like "a controller action which needs project permissions" + end + + describe 'destroy.xml' do + become_admin + + describe 'w/o a valid planning element id' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'destroy', :id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'destroy', :project_id => '4711', :id => '1337', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + get 'destroy', :project_id => project.id, :id => '1337', :format => 'xml' + + response.response_code.should == 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_delete_planning_element_permissions + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'destroy', :project_id => project.id, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + + describe 'w/ a valid planning element id' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) } + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'destroy', :id => planning_element.id, :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' + + response.response_code.should == 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_delete_planning_element_permissions + + it 'assigns the planning_element' do + get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' + + assigns(:planning_element).should == planning_element + end + + it 'renders the destroy builder template' do + get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' + + response.should render_template('timelines/planning_elements/destroy', :formats => ["api"]) + end + + it 'deletes the record' do + get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' + lambda do + planning_element.reload + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + end +end diff --git a/spec/controllers/api/v2/project_associations_controller_spec.rb b/spec/controllers/api/v2/project_associations_controller_spec.rb new file mode 100644 index 0000000000..bb209c9b44 --- /dev/null +++ b/spec/controllers/api/v2/project_associations_controller_spec.rb @@ -0,0 +1,152 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require File.expand_path('../../../../spec_helper', __FILE__) + +describe Api::V2::ProjectAssociationsController do + let(:current_user) { FactoryGirl.create(:admin) } + + before do + User.stub(:current).and_return current_user + end + + describe 'index.xml' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'index', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'index', :project_id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + def fetch + get 'index', :project_id => project.id, :format => 'xml' + end + let(:permission) { :view_project_associations } + + it_should_behave_like "a controller action which needs project permissions" + + describe 'w/ the current user being a member' do + describe 'w/o any project_associations within the project' do + it 'assigns an empty project_associations array' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:project_associations).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/project_associations/index', :formats => ["api"]) + end + end + + describe 'w/ 3 project_associations within the project' do + before do + @created_project_associations = [ + FactoryGirl.create(:project_association, :project_a_id => project.id, + :project_b_id => FactoryGirl.create(:public_project).id), + FactoryGirl.create(:project_association, :project_a_id => project.id, + :project_b_id => FactoryGirl.create(:public_project).id), + FactoryGirl.create(:project_association, :project_b_id => project.id, + :project_a_id => FactoryGirl.create(:public_project).id) + ] + end + + it 'assigns a project_associations array containing all three elements' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:project_associations).should == @created_project_associations + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/project_associations/index', :formats => ["api"]) + end + end + end + end + end + + describe 'show.xml' do + describe 'w/o a valid project_association id' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'index', :project_id => '4711', :id => '1337', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/ the current user being a member' do + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => project.id, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + + describe 'w/ a valid project_association id' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + let(:project_association) { FactoryGirl.create(:project_association, :project_a_id => project.id) } + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => project_association.id, :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + def fetch + get 'show', :project_id => project.id, :id => project_association.id, :format => 'xml' + end + let(:permission) { :view_project_associations } + + it_should_behave_like "a controller action which needs project permissions" + + describe 'w/ the current user being a member' do + it 'assigns the project_association' do + get 'show', :project_id => project.id, :id => project_association.id, :format => 'xml' + assigns(:project_association).should == project_association + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :id => project_association.id, :format => 'xml' + response.should render_template('timelines/project_associations/index', :formats => ["api"]) + end + end + end + end + end +end diff --git a/spec/controllers/api/v2/scenarios_controller_spec.rb b/spec/controllers/api/v2/scenarios_controller_spec.rb new file mode 100644 index 0000000000..e80603d411 --- /dev/null +++ b/spec/controllers/api/v2/scenarios_controller_spec.rb @@ -0,0 +1,171 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require File.expand_path('../../../../spec_helper', __FILE__) + +describe Api::V2::ScenariosController do + describe 'index.xml' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'index', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'index', :project_id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o any scenarios within the project' do + it 'assigns an empty scenarios array' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:scenarios).should == [] + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/scenarios/index', :formats => ["api"]) + end + end + + describe 'w/ 3 scenarios within the project' do + before do + @created_scenarios = [ + FactoryGirl.create(:scenario, :project_id => project.id), + FactoryGirl.create(:scenario, :project_id => project.id), + FactoryGirl.create(:scenario, :project_id => project.id) + ] + end + + it 'assigns a scenarios array containing all three elements' do + get 'index', :project_id => project.id, :format => 'xml' + assigns(:scenarios).should =~ @created_scenarios + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :format => 'xml' + response.should render_template('timelines/scenarios/index', :formats => ["api"]) + end + end + end + + describe 'access control' do + describe 'with a private project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', + :is_public => false) } + + def fetch + get 'index', :project_id => project.id, :format => 'xml' + end + it_should_behave_like "a controller action which needs project permissions" + end + + describe 'with a public project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', + :is_public => true) } + + def fetch + get 'index', :project_id => project.id, :format => 'xml' + end + it_should_behave_like "a controller action with unrestricted access" + end + end + end + + describe 'show.xml' do + describe 'w/o a valid scenario id' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => '4711', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + get 'index', :project_id => '4711', :id => '1337', :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + get 'show', :project_id => project.id, :id => '1337', :format => 'xml' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + + describe 'w/ a valid scenario id' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + let(:scenario) { FactoryGirl.create(:scenario, :project_id => project.id) } + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + get 'show', :id => scenario.id, :format => 'xml' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + it 'assigns the scenario' do + get 'show', :project_id => project.id, :id => scenario.id, :format => 'xml' + assigns(:scenario).should == scenario + end + + it 'renders the index builder template' do + get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' + response.should render_template('timelines/scenarios/index', :formats => ["api"]) + end + end + + describe 'access control' do + describe 'with a private project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', + :is_public => false) } + + def fetch + get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' + end + it_should_behave_like "a controller action which needs project permissions" + end + + describe 'with a public project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', + :is_public => true) } + + def fetch + get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' + end + it_should_behave_like "a controller action with unrestricted access" + end + end + end + end + + def project_settings_path(project) + {:controller => 'projects', :action => 'settings', :tab => 'timelines', :id => project} + end +end diff --git a/spec/controllers/api/v2/timelines_controller_spec.rb b/spec/controllers/api/v2/timelines_controller_spec.rb new file mode 100644 index 0000000000..c06e7c5fa8 --- /dev/null +++ b/spec/controllers/api/v2/timelines_controller_spec.rb @@ -0,0 +1,203 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +require File.expand_path('../../../../spec_helper', __FILE__) + +describe Api::V2::TimelinesController do + # =========================================================== + # Helpers + def self.become_admin + let(:current_user) { FactoryGirl.create(:admin) } + end + + def self.become_non_member + let(:current_user) { FactoryGirl.create(:user) } + + before do + current_user.memberships.select {|m| m.project_id == project.id}.each(&:destroy) + end + end + + def self.become_member_with_all_permissions + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:view_timelines, :edit_timelines, :delete_timelines]) + member = FactoryGirl.build(:member, :user => current_user, :project => project) + member.roles = [role] + member.save! + end + end + + def self.become_member_with_view_permissions + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:view_timelines]) + member = FactoryGirl.build(:member, :user => current_user, :project => project) + member.roles = [role] + member.save! + end + end + + def self.become_member_with_edit_permissions + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:edit_timelines]) + member = FactoryGirl.build(:member, :user => current_user, :project => project) + member.roles = [role] + member.save! + end + end + + def self.become_member_with_delete_permissions + let(:current_user) { FactoryGirl.create(:user) } + + before do + role = FactoryGirl.create(:role, :permissions => [:delete_timelines]) + member = FactoryGirl.build(:member, :user => current_user, :project => project) + member.roles = [role] + member.save! + end + end + + + before do + User.stub(:current).and_return current_user + end + + shared_examples_for 'all actions related to all timelines within a project' do + describe 'w/o a given project' do + become_admin + + it 'renders a 404 Not Found page' do + fetch + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + become_admin + + it 'renders a 404 Not Found page' do + fetch :project_id => '4711' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + fetch :project_id => project.identifier + + response.response_code.should == 403 + end + end + end + end + + shared_examples_for 'all actions related to an existing timeline' do + become_admin + + describe 'w/o a valid timelines id' do + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + fetch :id => '4711' + + response.response_code.should == 404 + end + end + + describe 'w/ an unknown project' do + it 'renders a 404 Not Found page' do + fetch :project_id => '4711', :id => '1337' + + response.response_code.should == 404 + end + end + + describe 'w/ a known project' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + fetch :project_id => project.id, :id => '1337' + + response.response_code.should === 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_all_permissions + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + fetch :project_id => project.id, :id => '1337' + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + + describe 'w/ a valid timelines id' do + let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } + let(:timeline) { FactoryGirl.create(:timelines, :project_id => project.id, :name => 'b') } + + describe 'w/o a given project' do + it 'renders a 404 Not Found page' do + fetch :id => timeline.id + + response.response_code.should == 404 + end + end + + describe 'w/ a different project' do + let(:other_project) { FactoryGirl.create(:project, :identifier => 'other') } + + it 'raises ActiveRecord::RecordNotFound errors' do + lambda do + fetch :project_id => other_project.identifier,:id => timeline.id + end.should raise_error(ActiveRecord::RecordNotFound) + end + end + + describe 'w/ a proper project' do + describe 'w/o being a member or administrator' do + become_non_member + + it 'renders a 403 Forbidden page' do + fetch :project_id => project.id, :id => timeline.id + + response.response_code.should == 403 + end + end + + describe 'w/ the current user being a member' do + become_member_with_all_permissions + + it 'assigns the timeline' do + fetch :project_id => project.id, :id => timeline.id + assigns(:timeline).should == timeline + end + end + end + end + end +end diff --git a/spec/controllers/planning_element_types_controller_spec.rb b/spec/controllers/planning_element_types_controller_spec.rb index 99d78ea10d..771fc7c50e 100644 --- a/spec/controllers/planning_element_types_controller_spec.rb +++ b/spec/controllers/planning_element_types_controller_spec.rb @@ -20,167 +20,11 @@ describe PlanningElementTypesController do def enable_type(project, type) FactoryGirl.create(:enabled_planning_element_type, - :project_id => project.id, - :planning_element_type_id => type.id) - end - - - describe 'with project scope' do - let(:project) { FactoryGirl.create(:project, :is_public => false) } - - describe 'index.xml' do - def fetch - get 'index', :project_id => project.identifier, :format => 'xml' - end - it_should_behave_like "a controller action which needs project permissions" - - describe 'with unknown project' do - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'index', :project_id => 'blah', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - - describe 'with no planning element types available' do - it 'assigns an empty planning_element_types array' do - get 'index', :project_id => project.identifier, :format => 'xml' - assigns(:planning_element_types).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => project.identifier, :format => 'xml' - response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) - end - end - - describe 'with 3 planning element types available' do - before do - @created_planning_element_types = [ - FactoryGirl.create(:planning_element_type), - FactoryGirl.create(:planning_element_type), - FactoryGirl.create(:planning_element_type) - ] - - @created_planning_element_types.each do |type| - enable_type(project, type) - end - - # Creating one PlanningElemenType which is not assigned to any - # Project and should therefore not show up in projects with a project - # type - FactoryGirl.create(:planning_element_type) - end - - it 'assigns an array with all planning element types' do - get 'index', :project_id => project.identifier, :format => 'xml' - assigns(:planning_element_types).should == @created_planning_element_types - end - - it 'renders the index template' do - get 'index', :project_id => project.identifier, :format => 'xml' - response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) - end - end - end - - describe 'show.xml' do - def fetch - @available_type = FactoryGirl.create(:planning_element_type, :id => '1337') - enable_type(project, @available_type) - - get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' - end - it_should_behave_like "a controller action which needs project permissions" - - describe 'with unknown project' do - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => 'blah', :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - - describe 'with unknown planning element type' do - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - - describe 'with an planning element type, which is not enabled in the project' do - before do - FactoryGirl.create(:planning_element_type, :id => '1337') - end - - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - - describe 'with an available planning element type' do - before do - @available_planning_element_type = FactoryGirl.create(:planning_element_type, - :id => '1337') - - enable_type(project, @available_planning_element_type) - end - - it 'assigns the available planning element type' do - get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' - assigns(:planning_element_type).should == @available_planning_element_type - end - - it 'renders the show template' do - get 'show', :project_id => project.identifier, :id => '1337', :format => 'xml' - response.should render_template('timelines/planning_element_types/show', :formats => ["api"]) - end - end - end + :project_id => project.id, + :planning_element_type_id => type.id) end describe 'without project scope' do - describe 'index.xml' do - def fetch - get 'index', :format => 'xml' - end - it_should_behave_like "a controller action with unrestricted access" - - describe 'with no planning element types available' do - it 'assigns an empty planning_element_types array' do - get 'index', :format => 'xml' - assigns(:planning_element_types).should == [] - end - - it 'renders the index builder template' do - get 'index', :format => 'xml' - response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) - end - end - - describe 'with 3 planning element types available' do - before do - @created_planning_element_types = [ - FactoryGirl.create(:planning_element_type), - FactoryGirl.create(:planning_element_type), - FactoryGirl.create(:planning_element_type) - ] - end - - it 'assigns an array with all planning element types' do - get 'index', :format => 'xml' - assigns(:planning_element_types).should == @created_planning_element_types - end - - it 'renders the index template' do - get 'index', :format => 'xml' - response.should render_template('timelines/planning_element_types/index', :formats => ["api"]) - end - end - end describe 'index.html' do def fetch @@ -189,52 +33,6 @@ describe PlanningElementTypesController do it_should_behave_like "a controller action with require_admin" end - describe 'show.xml' do - describe 'with unknown planning element type' do - if false # would like to write it this way - it 'returns status code 404' do - get 'show', :id => '1337', :format => 'xml' - - response.status.should == '404 Not Found' - end - - it 'returns an empty body' do - get 'show', :id => '1337', :format => 'xml' - - response.body.should be_empty - end - - else # but have to write it that way - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - - describe 'with an available planning element type' do - before do - @available_planning_element_type = FactoryGirl.create(:planning_element_type, :id => '1337') - end - - def fetch - get 'show', :id => '1337', :format => 'xml' - end - it_should_behave_like "a controller action with unrestricted access" - - it 'assigns the available planning element type' do - get 'show', :id => '1337', :format => 'xml' - assigns(:planning_element_type).should == @available_planning_element_type - end - - it 'renders the show template' do - get 'show', :id => '1337', :format => 'xml' - response.should render_template('timelines/planning_element_types/show', :formats => ["api"]) - end - end - end - describe 'new.html' do def fetch get 'new' diff --git a/spec/controllers/planning_elements_controller_spec.rb b/spec/controllers/planning_elements_controller_spec.rb index 11f8c862f5..9f4eaef3e4 100644 --- a/spec/controllers/planning_elements_controller_spec.rb +++ b/spec/controllers/planning_elements_controller_spec.rb @@ -131,7 +131,7 @@ describe PlanningElementsController do it 'renders the index builder template' do get 'index', :project_id => project.identifier - response.should render_template('timelines/planning_elements/index', :formats => ["html"], :layout => :base) + response.should render_template('planning_elements/index', :formats => ["html"], :layout => :base) end end @@ -157,7 +157,7 @@ describe PlanningElementsController do it 'renders the index builder template' do get 'index', :project_id => project.identifier - response.should render_template('timelines/planning_elements/index', :formats => ["html"], :layout => :base) + response.should render_template('planning_elements/index', :formats => ["html"], :layout => :base) end end end @@ -244,7 +244,7 @@ describe PlanningElementsController do it 'renders the show builder template' do get 'show', :project_id => project.id, :id => planning_element.id - response.should render_template('timelines/planning_elements/show', :formats => ["html"], :layout => :base) + response.should render_template('planning_elements/show', :formats => ["html"], :layout => :base) end end end @@ -331,7 +331,7 @@ describe PlanningElementsController do it 'renders the confirm_destroy view' do get 'confirm_destroy', :project_id => project.id, :id => planning_element.id - response.should render_template('timelines/planning_elements/confirm_destroy', :formats => ["html"], :layout => :base) + response.should render_template('planning_elements/confirm_destroy', :formats => ["html"], :layout => :base) end end end @@ -432,370 +432,4 @@ describe PlanningElementsController do end end end - - - # =========================================================== - # API tests - - describe 'index.xml' do - become_admin - - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'index', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'index', :project_id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - describe 'w/o being a member or administrator' do - become_non_member - - it 'renders a 403 Forbidden page' do - get 'index', :project_id => project.identifier, :format => 'xml' - - response.response_code.should == 403 - end - end - - describe 'w/ the current user being a member with view_planning_elements permissions' do - become_member_with_view_planning_element_permissions - - describe 'w/o any planning elements within the project' do - it 'assigns an empty planning_elements array' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:planning_elements).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/planning_elements/index', :formats => ["api"]) - end - end - - describe 'w/ 3 planning elements within the project' do - before do - @created_planning_elements = [ - FactoryGirl.create(:planning_element, :project_id => project.id), - FactoryGirl.create(:planning_element, :project_id => project.id), - FactoryGirl.create(:planning_element, :project_id => project.id) - ] - end - - it 'assigns a planning_elements array containing all three elements' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:planning_elements).should =~ @created_planning_elements - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/planning_elements/index', :formats => ["api"]) - end - end - end - end - - describe 'w/ multiple known projects' do - let(:project_a) { FactoryGirl.create(:project, :identifier => 'project_a') } - let(:project_b) { FactoryGirl.create(:project, :identifier => 'project_b') } - let(:project_c) { FactoryGirl.create(:project, :identifier => 'project_c') } - - describe 'w/ an unknown project in the list' do - become_admin { [project_a, project_b] } - - it 'renders a 404 Not Found page' do - get 'index', :project_id => 'project_x,project_b', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a project in the list, the current user may not access' do - before { project_a; project_b } - become_non_member { [project_b] } - - it 'assigns an empty planning_elements array' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - assigns(:planning_elements).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - response.should render_template('timelines/planning_elements/index', :formats => ["api"]) - end - end - - describe 'w/ the current user being a member with view_planning_elements permissions' do - become_member_with_view_planning_element_permissions { [project_a, project_b] } - - describe 'w/o any planning elements within the project' do - it 'assigns an empty planning_elements array' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - assigns(:planning_elements).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - response.should render_template('timelines/planning_elements/index', :formats => ["api"]) - end - end - - describe 'w/ 1 planning element in project_a and 2 in project_b' do - before do - @created_planning_elements = [ - FactoryGirl.create(:planning_element, :project_id => project_a.id), - FactoryGirl.create(:planning_element, :project_id => project_b.id), - FactoryGirl.create(:planning_element, :project_id => project_b.id) - ] - # adding another planning element, just to make sure, that the - # result set is properly filtered - FactoryGirl.create(:planning_element, :project_id => project_c.id) - end - - it 'assigns a planning_elements array containing all three elements' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - assigns(:planning_elements).should =~ @created_planning_elements - end - - it 'renders the index builder template' do - get 'index', :project_id => 'project_a,project_b', :format => 'xml' - response.should render_template('timelines/planning_elements/index', :formats => ["api"]) - end - end - end - end - end - - describe 'create.xml' do - become_admin - - it 'needs to be tested' - - let(:project) { FactoryGirl.create(:project, :is_public => false) } - def fetch - post 'create', :project_id => project.identifier, - :planning_element => FactoryGirl.build(:planning_element, - :project_id => project.id).attributes - end - def expect_redirect_to - Regexp.new(project_planning_elements_path(project)) - end - let(:permission) { :edit_planning_elements } - - it_should_behave_like "a controller action which needs project permissions" - end - - describe 'show.xml' do - become_admin - - describe 'w/o a valid planning element id' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'show', :project_id => '4711', :id => '1337', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - describe 'w/o being a member or administrator' do - become_non_member - - it 'renders a 403 Forbidden page' do - get 'show', :project_id => project.id, :id => '1337', :format => 'xml' - - response.response_code.should === 403 - end - end - - describe 'w/ the current user being a member' do - become_member_with_view_planning_element_permissions - - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => project.id, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - end - - describe 'w/ a valid planning element id' do - become_admin - - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) } - - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => planning_element.id, :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - describe 'w/o being a member or administrator' do - become_non_member - - it 'renders a 403 Forbidden page' do - get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' - - response.response_code.should == 403 - end - end - - describe 'w/ the current user being a member' do - become_member_with_view_planning_element_permissions - - it 'assigns the planning_element' do - get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' - assigns(:planning_element).should == planning_element - end - - it 'renders the show builder template' do - get 'show', :project_id => project.id, :id => planning_element.id, :format => 'xml' - response.should render_template('timelines/planning_elements/show', :formats => ["api"]) - end - end - end - end - end - - describe 'update.xml' do - become_admin - - it 'needs to be tested' - - let(:project) { FactoryGirl.create(:project, :is_public => false) } - let(:planning_element) { FactoryGirl.create(:planning_element, - :project_id => project.id) } - - def fetch - post 'update', :project_id => project.identifier, - :id => planning_element.id, - :planning_element => { name: "blubs" } - end - def expect_redirect_to - project_planning_element_path(project, planning_element) - end - let(:permission) { :edit_planning_elements } - - it_should_behave_like "a controller action which needs project permissions" - end - - describe 'destroy.xml' do - become_admin - - describe 'w/o a valid planning element id' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'destroy', :id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'destroy', :project_id => '4711', :id => '1337', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - describe 'w/o being a member or administrator' do - become_non_member - - it 'renders a 403 Forbidden page' do - get 'destroy', :project_id => project.id, :id => '1337', :format => 'xml' - - response.response_code.should == 403 - end - end - - describe 'w/ the current user being a member' do - become_member_with_delete_planning_element_permissions - - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'destroy', :project_id => project.id, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - end - - describe 'w/ a valid planning element id' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - let(:planning_element) { FactoryGirl.create(:planning_element, :project_id => project.id) } - - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'destroy', :id => planning_element.id, :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - describe 'w/o being a member or administrator' do - become_non_member - - it 'renders a 403 Forbidden page' do - get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' - - response.response_code.should == 403 - end - end - - describe 'w/ the current user being a member' do - become_member_with_delete_planning_element_permissions - - it 'assigns the planning_element' do - get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' - - assigns(:planning_element).should == planning_element - end - - it 'renders the destroy builder template' do - get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' - - response.should render_template('timelines/planning_elements/destroy', :formats => ["api"]) - end - - it 'deletes the record' do - get 'destroy', :project_id => project.id, :id => planning_element.id, :format => 'xml' - lambda do - planning_element.reload - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - end - end end diff --git a/spec/controllers/project_associations_controller_spec.rb b/spec/controllers/project_associations_controller_spec.rb index 6991c69825..2ca2b2d4e9 100644 --- a/spec/controllers/project_associations_controller_spec.rb +++ b/spec/controllers/project_associations_controller_spec.rb @@ -18,72 +18,6 @@ describe ProjectAssociationsController do User.stub(:current).and_return current_user end - describe 'index.xml' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'index', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'index', :project_id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - def fetch - get 'index', :project_id => project.id, :format => 'xml' - end - let(:permission) { :view_project_associations } - - it_should_behave_like "a controller action which needs project permissions" - - describe 'w/ the current user being a member' do - describe 'w/o any project_associations within the project' do - it 'assigns an empty project_associations array' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:project_associations).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/project_associations/index', :formats => ["api"]) - end - end - - describe 'w/ 3 project_associations within the project' do - before do - @created_project_associations = [ - FactoryGirl.create(:project_association, :project_a_id => project.id, - :project_b_id => FactoryGirl.create(:public_project).id), - FactoryGirl.create(:project_association, :project_a_id => project.id, - :project_b_id => FactoryGirl.create(:public_project).id), - FactoryGirl.create(:project_association, :project_b_id => project.id, - :project_a_id => FactoryGirl.create(:public_project).id) - ] - end - - it 'assigns a project_associations array containing all three elements' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:project_associations).should == @created_project_associations - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/project_associations/index', :formats => ["api"]) - end - end - end - end - end - describe 'index.html' do let(:project) { FactoryGirl.create(:project, :is_public => false) } def fetch @@ -120,72 +54,6 @@ describe ProjectAssociationsController do it_should_behave_like "a controller action which needs project permissions" end - describe 'show.xml' do - describe 'w/o a valid project_association id' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'index', :project_id => '4711', :id => '1337', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - describe 'w/ the current user being a member' do - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => project.id, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - end - - describe 'w/ a valid project_association id' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - let(:project_association) { FactoryGirl.create(:project_association, :project_a_id => project.id) } - - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => project_association.id, :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - def fetch - get 'show', :project_id => project.id, :id => project_association.id, :format => 'xml' - end - let(:permission) { :view_project_associations } - - it_should_behave_like "a controller action which needs project permissions" - - describe 'w/ the current user being a member' do - it 'assigns the project_association' do - get 'show', :project_id => project.id, :id => project_association.id, :format => 'xml' - assigns(:project_association).should == project_association - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :id => project_association.id, :format => 'xml' - response.should render_template('timelines/project_associations/index', :formats => ["api"]) - end - end - end - end - end - describe 'edit.html' do let(:project) { FactoryGirl.create(:project, :is_public => false) } let(:project_b) { FactoryGirl.create(:project, :is_public => true) } diff --git a/spec/controllers/scenarios_controller_spec.rb b/spec/controllers/scenarios_controller_spec.rb index 4fd4be64bd..4d1b1930f4 100644 --- a/spec/controllers/scenarios_controller_spec.rb +++ b/spec/controllers/scenarios_controller_spec.rb @@ -12,158 +12,6 @@ require File.expand_path('../../spec_helper', __FILE__) describe ScenariosController do - describe 'index.xml' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'index', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'index', :project_id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - describe 'w/o any scenarios within the project' do - it 'assigns an empty scenarios array' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:scenarios).should == [] - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/scenarios/index', :formats => ["api"]) - end - end - - describe 'w/ 3 scenarios within the project' do - before do - @created_scenarios = [ - FactoryGirl.create(:scenario, :project_id => project.id), - FactoryGirl.create(:scenario, :project_id => project.id), - FactoryGirl.create(:scenario, :project_id => project.id) - ] - end - - it 'assigns a scenarios array containing all three elements' do - get 'index', :project_id => project.id, :format => 'xml' - assigns(:scenarios).should =~ @created_scenarios - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :format => 'xml' - response.should render_template('timelines/scenarios/index', :formats => ["api"]) - end - end - end - - describe 'access control' do - describe 'with a private project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', - :is_public => false) } - - def fetch - get 'index', :project_id => project.id, :format => 'xml' - end - it_should_behave_like "a controller action which needs project permissions" - end - - describe 'with a public project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', - :is_public => true) } - - def fetch - get 'index', :project_id => project.id, :format => 'xml' - end - it_should_behave_like "a controller action with unrestricted access" - end - end - end - - describe 'show.xml' do - describe 'w/o a valid scenario id' do - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => '4711', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ an unknown project' do - it 'renders a 404 Not Found page' do - get 'index', :project_id => '4711', :id => '1337', :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - - it 'raises ActiveRecord::RecordNotFound errors' do - lambda do - get 'show', :project_id => project.id, :id => '1337', :format => 'xml' - end.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - - describe 'w/ a valid scenario id' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project') } - let(:scenario) { FactoryGirl.create(:scenario, :project_id => project.id) } - - describe 'w/o a given project' do - it 'renders a 404 Not Found page' do - get 'show', :id => scenario.id, :format => 'xml' - - response.response_code.should == 404 - end - end - - describe 'w/ a known project' do - it 'assigns the scenario' do - get 'show', :project_id => project.id, :id => scenario.id, :format => 'xml' - assigns(:scenario).should == scenario - end - - it 'renders the index builder template' do - get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' - response.should render_template('timelines/scenarios/index', :formats => ["api"]) - end - end - - describe 'access control' do - describe 'with a private project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', - :is_public => false) } - - def fetch - get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' - end - it_should_behave_like "a controller action which needs project permissions" - end - - describe 'with a public project' do - let(:project) { FactoryGirl.create(:project, :identifier => 'test_project', - :is_public => true) } - - def fetch - get 'index', :project_id => project.id, :id => scenario.id, :format => 'xml' - end - it_should_behave_like "a controller action with unrestricted access" - end - end - end - end describe 'new.html' do let(:project) { FactoryGirl.create(:project, :is_public => false) } diff --git a/spec/controllers/timelines_controller_spec.rb b/spec/controllers/timelines_controller_spec.rb index 473b068dba..7922b2af4d 100644 --- a/spec/controllers/timelines_controller_spec.rb +++ b/spec/controllers/timelines_controller_spec.rb @@ -257,7 +257,7 @@ describe TimelinesController do it 'renders the new template' do fetch :project_id => project.id - response.should render_template('timelines/timelines/new', :formats => ["html"], :layout => :base) + response.should render_template('timelines/new', :formats => ["html"], :layout => :base) end it 'assigns a new timeline instance for the current project' do @@ -313,7 +313,7 @@ describe TimelinesController do it 'renders the create action' do fetch :project_id => project.id, :timeline => {:name => ''} - response.should render_template('timelines/timelines/new', :formats => ["html"], :layout => :base) + response.should render_template('timelines/new', :formats => ["html"], :layout => :base) end it 'assigns the unsaved timeline instance for the view to access it' do @@ -362,7 +362,7 @@ describe TimelinesController do it 'renders the show template' do fetch :project_id => project.id, :id => timeline.id - response.should render_template('timelines/timelines/show', :formats => ["html"], :layout => :base) + response.should render_template('timelines/show', :formats => ["html"], :layout => :base) end end end @@ -382,7 +382,7 @@ describe TimelinesController do it 'renders the edit template' do fetch :project_id => project.id, :id => timeline.id - response.should render_template('timelines/timelines/edit', :formats => ["html"], :layout => :base) + response.should render_template('timelines/edit', :formats => ["html"], :layout => :base) end end end @@ -432,7 +432,7 @@ describe TimelinesController do it 'renders the edit action' do fetch :project_id => project.id, :id => timeline.id, :timeline => {:name => ''} - response.should render_template('timelines/timelines/edit', :formats => ["html"], :layout => :base) + response.should render_template('timelines/edit', :formats => ["html"], :layout => :base) end it 'assigns the unsaved timeline instance for the view to access it' do @@ -461,7 +461,7 @@ describe TimelinesController do it 'renders the confirm_destroy action' do fetch :project_id => project.id, :id => timeline.id - response.should render_template('timelines/timelines/confirm_destroy', :formats => ["html"], :layout => :base) + response.should render_template('timelines/confirm_destroy', :formats => ["html"], :layout => :base) end end end @@ -488,7 +488,7 @@ describe TimelinesController do it 'redirects to index' do fetch :project_id => project.id, :id => timeline.id - response.should redirect_to :action => 'index', :project_id => project.identifier + response.should redirect_to project_timelines_path project end it 'notifies the user about the successful deletion' do