This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
# This RSpec Macro is for use with the authorization plugin CanCan. It lets you test that a controller checks for a | |
# specific authorization, and if it fails, that the controller performs a certain action, such as redirecting to a | |
# different page. | |
# Example Usages in specs: | |
it_should_authorize_access_for(:new, Company) | |
it_should_authorize_access_for(:edit, Company.new) { get :edit, id: @company } | |
# For more on using it_should_authorize_access_for, see comment block above the definition of it_should_authorize_access_for | |
# in the code below. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A little function to easily merge multiple hashes. | |
# Example: Given h1, ..., h4 are hashes, | |
# hash_merge(h1, h2, h3, h4) | |
# or | |
# hash_merge *[h1, h2, h3, h4] | |
# | |
# More on this function and the Ruby syntax presented here at | |
# http://yaronwalfish.com/ruby-hash-merge-function-for-multiple-hashes-inject-and-asterisk-notation/ | |
def hash_merge *hashes | |
hashes.inject :merge |