Rewrite ability

This commit is contained in:
benji 2015-10-29 15:42:23 +01:00
parent 41d67556f4
commit 512a3aeede
2 changed files with 2 additions and 3 deletions

View file

@ -25,9 +25,7 @@ class Ability
def initialize_user(user)
can :read, :all
can :manage, User, id: user.id
can :create, Order do |order|
order.try(:user) == user
end
can :create, Order, user: user
can :destroy, Order do |order|
order.try(:user) == user && order.deletable
end

View file

@ -24,6 +24,7 @@ describe User do
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)) }
it{ should_not be_able_to(:create, Order.new) }
it{ should_not be_able_to(:create, Order.new(user: create(:user))) }
it{ should_not be_able_to(:update, Order.new) }
it{ should be_able_to(:read, Product.new) }