Is there a way to test the declarative_authorization permissions with respect?
In the documentation it has some instructions to use test unit, but I can't seem to find a way to use rspec.
Is there a way to test the declarative_authorization permissions with respect?
In the documentation it has some instructions to use test unit, but I can't seem to find a way to use rspec.
You can use all assertion in rspec, so you can use it or convert it in rpsec style.
I've manage to use cucumber to test the roles.
Like this:
require 'machinist/active_record'
require 'spec/blueprints.rb'
def user
@user ||= User.make
end
Given /^I am an Administrator$/ do
user
@user.assignments.delete_all
@user.roles.delete_all
@user.assignments << Assignment.create(:user_id => @user.id,
:role_id => Role.find_by_name("admin").id)
@user.roles.count.should == 1
@user.roles << Role.find_by_name("admin")
Authorization.current_user = @user
end
Yes, you can test permissions. See here under Authorization::TestHelper -- require the helpers in your spec_helper file, and include Authorization::TestHelper. This pulls in methods that allow you to specify the current user and its privileges in rspec's before
method.
Another tip: to make it easier to create factory objects, declarative_authorization has a without_access_control
method that allows you to bypass authorization in your before
sections.