Fix and redo specs after great build_lists refactoring and improvement. Fix minor bugs. Code cleanup. Refs #65

This commit is contained in:
Pavel Chipiga 2011-12-23 04:14:28 +02:00
parent 96d458875e
commit 8c3291d237
8 changed files with 90 additions and 35 deletions

View File

@ -36,7 +36,7 @@ class BuildListsController < ApplicationController
def create def create
notices, errors = [], [] 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| Platform.main.where(:id => params[:bpls]).each do |bpl|
@build_list = @project.build_lists.build(params[:build_list]) @build_list = @project.build_lists.build(params[:build_list])
@build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user @build_list.bpl = bpl; @build_list.arch = arch; @build_list.user = current_user

View File

@ -38,8 +38,8 @@
.group .group
= f.label :arches, t("activerecord.attributes.build_list.arch"), :class => :label = f.label :arches, t("activerecord.attributes.build_list.arch"), :class => :label
- Arch.recent.each do |arch| - Arch.recent.each do |arch|
= check_box_tag "archs[]", arch.id, (params[:archs]||[]).include?(arch.id.to_s), :id => "archs_#{arch.id}" = check_box_tag "arches[]", arch.id, (params[:arches]||[]).include?(arch.id.to_s), :id => "arches_#{arch.id}"
= label_tag "archs_#{arch.id}", arch.name = label_tag "arches_#{arch.id}", arch.name
%br %br
.group .group

View File

@ -25,8 +25,49 @@ describe BuildListsController do
response.should redirect_to(forbidden_url) response.should redirect_to(forbidden_url)
end end
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 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 context 'for guest' do
it 'should not be able to perform index action' do it 'should not be able to perform index action' do
get :index get :index
@ -36,7 +77,6 @@ describe BuildListsController do
context 'for user' do context 'for user' do
before(:each) do before(:each) do
stub_rsync_methods
@build_list = Factory(:build_list_core) @build_list = Factory(:build_list_core)
@project = @build_list.project @project = @build_list.project
@owner_user = @project.owner @owner_user = @project.owner
@ -47,7 +87,6 @@ describe BuildListsController do
@user = Factory(:user) @user = Factory(:user)
set_session_for(@user) set_session_for(@user)
@show_params = {:project_id => @project.id, :id => @build_list.id} @show_params = {:project_id => @project.id, :id => @build_list.id}
end end
context 'for all build lists' do context 'for all build lists' do
@ -76,15 +115,18 @@ describe BuildListsController do
context 'for open project' do context 'for open project' do
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {set_session_for(@owner_user)} before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list'
end end
context 'if user is project member' do context 'if user is project member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
end end
end end
@ -95,23 +137,24 @@ describe BuildListsController do
end end
it_should_behave_like 'not show build list' it_should_behave_like 'not show build list'
it_should_behave_like 'not create build list'
context 'if user is project owner' do context 'if user is project owner' do
before(:each) {set_session_for(@owner_user)} before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list'
end end
context 'if user is project member' do context 'if user is project member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
end end
end end
end end
context 'for group' do context 'for group' do
before(:each) do before(:each) do
stub_rsync_methods
@owner_group = Factory(:group) @owner_group = Factory(:group)
@owner_user = Factory(:user) @owner_user = Factory(:user)
@owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => '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 context 'for open project' do
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)} before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list'
end end
context 'if user is group member' do context 'if user is group member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
end end
end end
@ -177,15 +223,18 @@ describe BuildListsController do
end end
it_should_behave_like 'not show build list' it_should_behave_like 'not show build list'
it_should_behave_like 'not create build list'
context 'if user is group owner' do context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)} before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'create build list'
end end
context 'if user is group member' do context 'if user is group member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
it_should_behave_like 'not create build list'
end end
end end

View File

@ -8,17 +8,6 @@ describe ProjectsController do
@another_user = Factory(:user) @another_user = Factory(:user)
@create_params = {:project => {:name => 'pro'}} @create_params = {:project => {:name => 'pro'}}
@update_params = {:project => {:name => 'pro2'}} @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 end
context 'for guest' do context 'for guest' do

View File

@ -1,11 +1,13 @@
Factory.define(:build_list) do |p| Factory.define(:build_list) do |p|
p.association :project, :factory => :project p.association :user
p.association :pl, :factory => :platform p.association :project
p.association :arch, :factory => :arch p.association :pl, :factory => :platform_with_repos
p.bpl { |bl| bl.pl } p.association :arch
p.bpl {|bl| bl.pl}
p.project_version "1.0" p.project_version "1.0"
p.build_requires true p.build_requires true
p.update_type 'security' p.update_type 'security'
p.include_repos {|bl| bl.pl.repositories.map(&:id)}
end end
Factory.define(:build_list_core, :parent => :build_list) do |p| Factory.define(:build_list_core, :parent => :build_list) do |p|

View File

@ -5,3 +5,7 @@ Factory.define(:platform) do |p|
p.distrib_type APP_CONFIG['distr_types'].first p.distrib_type APP_CONFIG['distr_types'].first
p.association :owner, :factory => :user p.association :owner, :factory => :user
end end
Factory.define(:platform_with_repos, :parent => :platform) do |p|
p.repositories {|r| [r.association(:repository)]}
end

View File

@ -139,11 +139,18 @@ describe CanCan do
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer') @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'writer')
end end
[:read, :update, :process_build, :build].each do |action| [:read, :update].each do |action|
it "should be able to #{ action } project" do it "should be able to #{ action } project" do
@ability.should be_able_to(action, @project) @ability.should be_able_to(action, @project)
end end
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
context 'with admin rights' do context 'with admin rights' do
@ -151,12 +158,19 @@ describe CanCan do
@project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'admin') @project.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'admin')
end end
[:read, :update, :process_build, :build].each do |action| [:read, :update].each do |action|
it "should be able to #{ action } project" do it "should be able to #{ action } project" do
@ability.should be_able_to(action, @project) @ability.should be_able_to(action, @project)
end end
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 it "should be able to manage collaborators of project" do
@ability.should be_able_to(:manage_collaborators, @project) @ability.should be_able_to(:manage_collaborators, @project)
end end
@ -167,11 +181,18 @@ describe CanCan do
@project.update_attribute(:owner, @user) @project.update_attribute(:owner, @user)
end end
[:read, :update, :process_build, :build, :destroy].each do |action| [:read, :update, :destroy].each do |action|
it "should be able to #{ action } project" do it "should be able to #{ action } project" do
@ability.should be_able_to(action, @project) @ability.should be_able_to(action, @project)
end end
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
end end

View File

@ -12,16 +12,6 @@ shared_examples_for 'projects user with writer rights' do
put :update, {:id => @project.id}.merge(@update_params) put :update, {:id => @project.id}.merge(@update_params)
response.should redirect_to(project_path(@project)) response.should redirect_to(project_path(@project))
end 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 end
shared_examples_for 'user with rights to view projects' do shared_examples_for 'user with rights to view projects' do