[refs #2249] Add products specs. Fix some things in other specs

This commit is contained in:
konstantin.grabar 2011-12-06 19:24:04 +04:00
parent fc4643ce9b
commit fcc17da1ad
8 changed files with 131 additions and 30 deletions

View File

@ -30,7 +30,7 @@ class CollaboratorsController < ApplicationController
def update
all_user_ids = []
all_groups_ids = []
puts params.inspect
Relation::ROLES.each { |r|
all_user_ids = all_user_ids | params['user'][r.to_sym].keys if params['user'][r.to_sym]
all_groups_ids = all_groups_ids | params['group'][r.to_sym].keys if params['group'][r.to_sym]

View File

@ -36,8 +36,7 @@ describe CollaboratorsController do
@user = Factory(:user)
@user.relations
set_session_for(@user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_index#collaborators'
@ -50,8 +49,7 @@ describe CollaboratorsController do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_index#collaborators'
@ -64,8 +62,7 @@ describe CollaboratorsController do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'not_be_able_to_perform_index#collaborators'
@ -78,8 +75,7 @@ describe CollaboratorsController do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'writer')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
end
it_should_behave_like 'not_be_able_to_perform_index#collaborators'

View File

@ -50,12 +50,10 @@ describe PersonalRepositoriesController do
set_session_for(@user)
@repository.update_attribute(:owner, @user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
@repository.platform.update_attribute(:owner, @user)
p = @repository.platform.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
p.save!
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_settings#personal_repositories'
@ -73,8 +71,7 @@ describe PersonalRepositoriesController do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_show#personal_repositories'

View File

@ -67,8 +67,7 @@ describe PlatformsController do
@user = Factory(:user)
set_session_for(@user)
@platform.update_attribute(:owner, @user)
r = @platform.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'able_to_perform_index#platforms'
@ -93,8 +92,7 @@ describe PlatformsController do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @platform.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'able_to_perform_index#platforms'

View File

@ -1,5 +1,120 @@
require 'spec_helper'
describe ProductsController do
before(:each) do
@another_user = Factory(:user)
@platform = Factory(:platform)
@product = Factory(:product, :platform => @platform)
@create_params = {:product => {:name => 'pro'}, :platform_id => @platform.id}
@update_params = {:product => {:name => 'pro2'}, :platform_id => @platform.id}
end
context 'for guest' do
[:create].each do |action|
it "should not be able to perform #{ action } action" do
get action, :platform_id => @platform.id
response.should redirect_to(new_user_session_path)
end
end
[:show, :new, :edit, :update, :destroy].each do |action|
it "should not be able to perform #{ action } action" do
get action, :id => @product.id, :platform_id => @platform.id
response.should redirect_to(new_user_session_path)
end
end
end
context 'for global admin' do
before(:each) do
@admin = Factory(:admin)
set_session_for(@admin)
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_path( Product.last.platform.id ))
end
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
end
it 'should be able to perform update action' do
put :update, {:id => @product.id}.merge(@update_params)
response.should redirect_to(platform_path(@platform))
end
it 'should change objects count on destroy success' do
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
end
it 'should be able to perform destroy action' do
delete :destroy, :platform_id => @platform.id, :id => @product.id
response.should redirect_to(platform_path(@platform))
end
end
context 'for admin relation user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @product.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r = @platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(platform_path( Product.last.platform.id ))
end
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
end
it 'should be able to perform update action' do
put :update, {:id => @product.id}.merge(@update_params)
response.should redirect_to(platform_path(@platform))
end
it 'should change objects count on destroy success' do
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
end
it 'should be able to perform destroy action' do
delete :destroy, :platform_id => @platform.id, :id => @product.id
response.should redirect_to(platform_path(@platform))
end
end
context 'for no relation user' do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
end
it 'should not be able to perform create action' do
post :create, @create_params
response.should redirect_to(forbidden_path)
end
it 'should not change objects count on create' do
lambda { post :create, @create_params }.should change{ Product.count }.by(0)
end
it 'should not be able to perform update action' do
put :update, {:id => @product.id}.merge(@update_params)
response.should redirect_to(forbidden_path)
end
it 'should not change objects count on destroy success' do
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(0)
end
it 'should not be able to perform destroy action' do
delete :destroy, :platform_id => @platform.id, :id => @product.id
response.should redirect_to(forbidden_path)
end
end
end

View File

@ -58,8 +58,7 @@ describe ProjectsController do
@user = Factory(:user)
set_session_for(@user)
@project.update_attribute(:owner, @user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_update#projects'
@ -86,8 +85,7 @@ describe ProjectsController do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_index#projects'
@ -104,8 +102,7 @@ describe ProjectsController do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'writer')
r.save!
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
end
it_should_behave_like 'be_able_to_perform_update#projects'

View File

@ -88,8 +88,7 @@ describe RepositoriesController do
@user = Factory(:user)
set_session_for(@user)
@repository.update_attribute(:owner, @user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'admin')
r.save!
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
end
it_should_behave_like 'be_able_to_perform_index#repositories'
@ -107,8 +106,7 @@ describe RepositoriesController do
before(:each) do
@user = Factory(:user)
set_session_for(@user)
r = @repository.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader')
r.save!
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'be_able_to_perform_index#repositories'