2015-09-07 14:26:07 +02:00
|
|
|
require 'cancan/matchers'
|
2015-09-04 18:13:58 +02:00
|
|
|
|
|
|
|
describe User do
|
2015-09-07 14:26:07 +02:00
|
|
|
describe 'abilities' do
|
2015-09-04 18:13:58 +02:00
|
|
|
subject(:ability){ Ability.new(user) }
|
|
|
|
let(:user) { nil}
|
|
|
|
|
2015-09-21 08:23:43 +02:00
|
|
|
# Admin
|
2015-09-07 14:26:07 +02:00
|
|
|
describe 'as admin' do
|
2015-09-04 18:13:58 +02:00
|
|
|
let(:user) { create :admin }
|
|
|
|
|
|
|
|
it{ should be_able_to(:manage, Order.new) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should be_able_to(:manage, OrderItem.new) }
|
|
|
|
it{ should be_able_to(:manage, Product.new) }
|
2015-09-04 18:13:58 +02:00
|
|
|
it{ should be_able_to(:manage, Stock.new) }
|
|
|
|
it{ should be_able_to(:manage, User.new) }
|
|
|
|
end
|
|
|
|
|
2015-09-21 08:23:43 +02:00
|
|
|
# Normal User
|
2015-09-07 14:26:07 +02:00
|
|
|
describe 'as normal user' do
|
2015-09-04 18:13:58 +02:00
|
|
|
let(:user) { create :user }
|
|
|
|
|
2016-03-01 16:05:46 +01:00
|
|
|
# it{ should be_able_to(:create, Order.new(user: user)) }
|
2015-10-29 14:27:06 +01:00
|
|
|
it{ should be_able_to(:destroy, Order.new(user: user, created_at: (Rails.application.config.call_api_after - 1.minutes).ago)) }
|
|
|
|
it{ should_not be_able_to(:destroy, Order.new(user: user, created_at: 10.minutes.ago)) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should_not be_able_to(:create, Order.new) }
|
2015-10-29 15:42:23 +01:00
|
|
|
it{ should_not be_able_to(:create, Order.new(user: create(:user))) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should_not be_able_to(:update, Order.new) }
|
2015-09-04 18:13:58 +02:00
|
|
|
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should be_able_to(:read, Product.new) }
|
2015-10-29 14:27:06 +01:00
|
|
|
it{ should_not be_able_to(:destroy, Product.new) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should_not be_able_to(:update, Product.new) }
|
|
|
|
|
|
|
|
it{ should_not be_able_to(:create, Stock.new) }
|
2015-09-04 18:13:58 +02:00
|
|
|
|
|
|
|
it{ should be_able_to(:manage, user) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should_not be_able_to(:create, User.new) }
|
|
|
|
it{ should_not be_able_to(:update, User.new) }
|
2015-09-04 18:13:58 +02:00
|
|
|
end
|
|
|
|
|
2015-09-07 14:26:07 +02:00
|
|
|
describe 'as koelkast' do
|
2015-09-04 18:13:58 +02:00
|
|
|
let(:user) { create :koelkast }
|
|
|
|
|
|
|
|
it{ should_not be_able_to(:manage, Product.new) }
|
2016-03-01 16:05:46 +01:00
|
|
|
# it{ should be_able_to(:manage, Order.new, user: create(:user)) }
|
2015-09-21 08:23:43 +02:00
|
|
|
it{ should_not be_able_to(:create, build(:order, user: create(:user, private: true))) }
|
2015-09-04 18:13:58 +02:00
|
|
|
it{ should_not be_able_to(:manage, Stock.new) }
|
|
|
|
it{ should_not be_able_to(:manage, User.new) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|