RSpec::Authorization
RSpec matcher for declarative_authorization. A neat way of asserting declarative_authorization's rules inside controller using RSpec matcher.
Installation
Add this line to your application's Gemfile:
gem 'rspec-authorization', group: :test
And then execute:
bundle
Or install it yourself as:
gem install rspec-
Requirement
Current development focus is as follows, future development may support other dependencies, following are requirements for this gem:
- declarative_authorization 1.0.0.pre
- rails 4.x
- rspec-rails 3.x
Usage
In your controller spec:
describe ArticlesController do
it { is_expected.to (:a_role).to(:restful_action_name) }
it { is_expected.to (:writer).to(:index) }
it { is_expected.to (:writer).to(:show) }
it { is_expected.to (:writer).to(:new) }
it { is_expected.to (:writer).to(:create) }
it { is_expected.not_to (:writer).to(:edit) }
it { is_expected.not_to (:writer).to(:update) }
it { is_expected.not_to (:writer).to(:destroy) }
end
You can also use convenience RESTful methods matcher:
describe ArticlesController do
it { is_expected.to (:user).to_read }
it { is_expected.not_to (:user).to_create }
it { is_expected.not_to (:user).to_update }
it { is_expected.not_to (:user).to_delete }
it { is_expected.to (:writer).to_read }
it { is_expected.to (:writer).to_create }
it { is_expected.to (:writer).to_update }
it { is_expected.not_to (:writer).to_delete }
it { is_expected.to (:editor).to_manage }
end
Contributing
- Fork it ( https://github.com/hendrauzia/rspec-authorization/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Setup rails test app (
bundle exec rake setup
) - Test your changes (
bundle exec rake spec
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request