Hi folks,

I wanted to test my method delete_if_obsolete with RSpec as a certain user 
in my app, that uses a model instance's destroy method where Hobo checks 
permission.
There is the helper method with_acting_user to simulate that behavior in a 
Hobo app. But that is not available in RSpec context. RSep messes up self 
heavily.

It took me some time to figure out the details, so I thought, I share, that 
the same effect can be stubbed in RSpec easily to be compatible with Hobo 
permissions.
Just use 

*allow(@order).to receive(:acting_user) { @admin }*

when @order is the instance you want to test and @admin is the User 
instance you want to be using in your test.
Then you can go along with

*expect{@order.delete_if_obsolete}.to change {Order.count}.by -1*

and you don't have to deal with permissions in the expect block or context.

Cheers,
Stefan

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to