From 8c3291d237c45f44d589da9cd5dffa03772ff9ea Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 23 Dec 2011 04:14:28 +0200 Subject: [PATCH] Fix and redo specs after great build_lists refactoring and improvement. Fix minor bugs. Code cleanup. Refs #65 --- app/controllers/build_lists_controller.rb | 2 +- app/views/build_lists/new.html.haml | 4 +- .../build_lists_controller_spec.rb | 57 +++++++++++++++++-- spec/controllers/projects_controller_spec.rb | 11 ---- spec/factories/build_list_factory.rb | 10 ++-- spec/factories/platform_factory.rb | 4 ++ spec/models/cancan_spec.rb | 27 ++++++++- .../shared_examples/projects_controller.rb | 10 ---- 8 files changed, 90 insertions(+), 35 deletions(-) diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index cfb84498c..cbd847933 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -36,7 +36,7 @@ class BuildListsController < ApplicationController def create notices, errors = [], [] - Arch.where(:id => params[:archs]).each do |arch| + Arch.where(:id => params[:arches]).each do |arch| Platform.main.where(:id => params[:bpls]).each do |bpl| @build_list = @project.build_lists.build(params[:build_list]) @build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user diff --git a/app/views/build_lists/new.html.haml b/app/views/build_lists/new.html.haml index 88aa55c5d..622191b78 100644 --- a/app/views/build_lists/new.html.haml +++ b/app/views/build_lists/new.html.haml @@ -38,8 +38,8 @@ .group = f.label :arches, t("activerecord.attributes.build_list.arch"), :class => :label - Arch.recent.each do |arch| - = check_box_tag "archs[]", arch.id, (params[:archs]||[]).include?(arch.id.to_s), :id => "archs_#{arch.id}" - = label_tag "archs_#{arch.id}", arch.name + = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}" + = label_tag "arches_#{arch.id}", arch.name %br .group diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index 27b6b8174..d6d2172a7 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -25,8 +25,49 @@ describe BuildListsController do response.should redirect_to(forbidden_url) end end + + shared_examples_for 'create build list' do + it 'should be able to perform new action' do + get :new, :project_id => @project.id + response.should render_template(:new) + end + + it 'should be able to perform create action' do + post :create, {:project_id => @project.id}.merge(@create_params) + response.should redirect_to(@project) + end + end + + shared_examples_for 'not create build list' do + it 'should not be able to perform new action' do + get :new, :project_id => @project.id + response.should redirect_to(forbidden_url) + end + + it 'should not be able to perform create action' do + post :create, {:project_id => @project.id}.merge(@create_params) + response.should redirect_to(forbidden_url) + end + end context 'crud' do + before(:each) do + stub_rsync_methods + + platform = Factory(:platform_with_repos) + @create_params = { + :build_list => { + :project_version => 'v1.0', + :pl_id => platform.id, + :update_type => 'security', + :include_repos => [platform.repositories.first.id] + }, + :arches => [Factory(:arch).id], + :bpls => [platform.id] + } + any_instance_of(Project, :versions => ['v1.0', 'v2.0']) + end + context 'for guest' do it 'should not be able to perform index action' do get :index @@ -36,7 +77,6 @@ describe BuildListsController do context 'for user' do before(:each) do - stub_rsync_methods @build_list = Factory(:build_list_core) @project = @build_list.project @owner_user = @project.owner @@ -47,7 +87,6 @@ describe BuildListsController do @user = Factory(:user) set_session_for(@user) @show_params = {:project_id => @project.id, :id => @build_list.id} - end context 'for all build lists' do @@ -76,15 +115,18 @@ describe BuildListsController do context 'for open project' do it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' context 'if user is project owner' do before(:each) {set_session_for(@owner_user)} it_should_behave_like 'show build list' + it_should_behave_like 'create build list' end context 'if user is project member' do before(:each) {set_session_for(@member_user)} it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' end end @@ -95,23 +137,24 @@ describe BuildListsController do end it_should_behave_like 'not show build list' + it_should_behave_like 'not create build list' context 'if user is project owner' do before(:each) {set_session_for(@owner_user)} it_should_behave_like 'show build list' + it_should_behave_like 'create build list' end context 'if user is project member' do before(:each) {set_session_for(@member_user)} it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' end end - end context 'for group' do before(:each) do - stub_rsync_methods @owner_group = Factory(:group) @owner_user = Factory(:user) @owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User' @@ -158,15 +201,18 @@ describe BuildListsController do context 'for open project' do it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' context 'if user is group owner' do before(:each) {set_session_for(@owner_user)} it_should_behave_like 'show build list' + it_should_behave_like 'create build list' end context 'if user is group member' do before(:each) {set_session_for(@member_user)} it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' end end @@ -177,15 +223,18 @@ describe BuildListsController do end it_should_behave_like 'not show build list' + it_should_behave_like 'not create build list' context 'if user is group owner' do before(:each) {set_session_for(@owner_user)} it_should_behave_like 'show build list' + it_should_behave_like 'create build list' end context 'if user is group member' do before(:each) {set_session_for(@member_user)} it_should_behave_like 'show build list' + it_should_behave_like 'not create build list' end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index ebf0ab6ac..c17c09954 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -8,17 +8,6 @@ describe ProjectsController do @another_user = Factory(:user) @create_params = {:project => {:name => 'pro'}} @update_params = {:project => {:name => 'pro2'}} - - platform = Factory(:platform) - @process_build_params = {:build => { - :arches => {Factory(:arch).id => '1'}, - :project_version => 'v1.0', - :bpl => {platform.id => '1'}, - :pl => platform.id, - :update_type => 'security' - }} - - any_instance_of(Project, :versions => ['v1.0', 'v2.0']) end context 'for guest' do diff --git a/spec/factories/build_list_factory.rb b/spec/factories/build_list_factory.rb index a4e1aa39a..10c4fc3b5 100644 --- a/spec/factories/build_list_factory.rb +++ b/spec/factories/build_list_factory.rb @@ -1,11 +1,13 @@ Factory.define(:build_list) do |p| - p.association :project, :factory => :project - p.association :pl, :factory => :platform - p.association :arch, :factory => :arch - p.bpl { |bl| bl.pl } + p.association :user + p.association :project + p.association :pl, :factory => :platform_with_repos + p.association :arch + p.bpl {|bl| bl.pl} p.project_version "1.0" p.build_requires true p.update_type 'security' + p.include_repos {|bl| bl.pl.repositories.map(&:id)} end Factory.define(:build_list_core, :parent => :build_list) do |p| diff --git a/spec/factories/platform_factory.rb b/spec/factories/platform_factory.rb index 9fab7a443..1c1f3307a 100644 --- a/spec/factories/platform_factory.rb +++ b/spec/factories/platform_factory.rb @@ -5,3 +5,7 @@ Factory.define(:platform) do |p| p.distrib_type APP_CONFIG['distr_types'].first p.association :owner, :factory => :user end + +Factory.define(:platform_with_repos, :parent => :platform) do |p| + p.repositories {|r| [r.association(:repository)]} +end \ No newline at end of file diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 97362bb66..8875ef1f5 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -139,11 +139,18 @@ describe CanCan do @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer') end - [:read, :update, :process_build, :build].each do |action| + [:read, :update].each do |action| it "should be able to #{ action } project" do @ability.should be_able_to(action, @project) end end + + [:new, :create].each do |action| + it "should be able to #{action} build_list" do + @build_list = Factory(:build_list, :project => @project) + @ability.should be_able_to(action, @build_list) + end + end end context 'with admin rights' do @@ -151,12 +158,19 @@ describe CanCan do @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'admin') end - [:read, :update, :process_build, :build].each do |action| + [:read, :update].each do |action| it "should be able to #{ action } project" do @ability.should be_able_to(action, @project) end end + [:new, :create].each do |action| + it "should be able to #{action} build_list" do + @build_list = Factory(:build_list, :project => @project) + @ability.should be_able_to(action, @build_list) + end + end + it "should be able to manage collaborators of project" do @ability.should be_able_to(:manage_collaborators, @project) end @@ -167,11 +181,18 @@ describe CanCan do @project.update_attribute(:owner, @user) end - [:read, :update, :process_build, :build, :destroy].each do |action| + [:read, :update, :destroy].each do |action| it "should be able to #{ action } project" do @ability.should be_able_to(action, @project) end end + + [:new, :create].each do |action| + it "should be able to #{action} build_list" do + @build_list = Factory(:build_list, :project => @project) + @ability.should be_able_to(action, @build_list) + end + end end end diff --git a/spec/support/shared_examples/projects_controller.rb b/spec/support/shared_examples/projects_controller.rb index 7aa4baa01..37cd28b28 100644 --- a/spec/support/shared_examples/projects_controller.rb +++ b/spec/support/shared_examples/projects_controller.rb @@ -12,16 +12,6 @@ shared_examples_for 'projects user with writer rights' do put :update, {:id => @project.id}.merge(@update_params) response.should redirect_to(project_path(@project)) end - - it 'should be able to perform build action' do - get :build, :id => @project.id - response.should render_template(:build) - end - - it 'should be able to perform process_build action' do - post :process_build, {:id => @project.id}.merge(@process_build_params) - response.should redirect_to(project_path(@project)) - end end shared_examples_for 'user with rights to view projects' do