2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-04-11 09:35:08 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
shared_examples_for 'admin user' do
|
|
|
|
|
|
|
|
it 'should be able to create product' do
|
|
|
|
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
|
|
|
|
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to update product' do
|
|
|
|
put :update, {:id => @product.id}.merge(@update_params)
|
|
|
|
response.should redirect_to platform_product_path(@platform, @product)
|
|
|
|
@product.reload
|
|
|
|
@product.name.should eql('pro2')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to destroy product' do
|
|
|
|
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
|
|
|
|
response.should redirect_to(platform_products_path(@platform))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-04-11 09:35:08 +01:00
|
|
|
describe ProductsController do
|
2011-12-06 15:24:04 +00:00
|
|
|
before(:each) do
|
2011-12-12 07:51:39 +00:00
|
|
|
stub_rsync_methods
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@another_user = FactoryGirl.create(:user)
|
|
|
|
@platform = FactoryGirl.create(:platform)
|
|
|
|
@product = FactoryGirl.create(:product, :platform => @platform)
|
2011-12-06 15:24:04 +00:00
|
|
|
@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
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2011-12-06 15:24:04 +00:00
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
it_should_behave_like 'admin user'
|
2011-12-06 15:24:04 +00:00
|
|
|
end
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
|
|
|
|
|
2011-12-06 15:24:04 +00:00
|
|
|
context 'for admin relation user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-06 15:24:04 +00:00
|
|
|
set_session_for(@user)
|
2011-12-28 02:57:42 +00:00
|
|
|
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-12-06 15:24:04 +00:00
|
|
|
end
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
it_should_behave_like 'admin user'
|
2011-12-06 15:24:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for no relation user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-06 15:24:04 +00:00
|
|
|
set_session_for(@user)
|
|
|
|
end
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
it 'should not be able to create product' do
|
2011-12-06 15:24:04 +00:00
|
|
|
lambda { post :create, @create_params }.should change{ Product.count }.by(0)
|
2012-04-03 13:21:39 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
2011-12-06 15:24:04 +00:00
|
|
|
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
|
|
|
|
|
2012-04-03 13:21:39 +01:00
|
|
|
it 'should not be able to destroy product' do
|
2011-12-06 15:24:04 +00:00
|
|
|
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(0)
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
2012-04-03 13:21:39 +01:00
|
|
|
|
2011-12-06 15:24:04 +00:00
|
|
|
end
|
2011-04-11 09:35:08 +01:00
|
|
|
|
|
|
|
end
|