README.md in consul-0.3.0 vs README.md in consul-0.4.0

- old
+ new

@@ -257,20 +257,67 @@ end class Power ... - def assignable_story_projects(story) + power :assignable_story_projects do |story| user.account.projects end end The `authorize_values_for` macro comes with many useful options and details best explained in the [assignable_values README](https://github.com/makandra/assignable_values), so head over there for more. The macro is basically a shortcut for this: assignable_values_for :field, :through => lambda { Power.current } +Testing +------- + +This section Some hints for testing authorization with Consul. + +### Test that a controller checks against a power + +You can say this in any controller spec: + + describe CakesController do + + it { should check_power(:cakes) } + + end + +You can test against all options of the `power` macro: + + describe CakesController do + + it { should check_power(:cakes, :map => { [:edit, :update] => :updatable_cakes }) } + + end + +### Temporarily change the current power + +When you set `Power.current` to a power in an RSpec example, you must remember to nilify it afterwards. Otherwise other examples will see your global changes. + +A better way is to use the `.with_power` method to change the current power for the duration of a block: + + admin = User.new(:role => 'admin') + admin_power = Power.new(admin) + + Power.with_power(admin_power) do + # run code that uses Power.current + end + +`Power.current` will be `nil` (or its former value) after the block has ended. + +A nice shortcut is that when you call `with_power` with an argument that is not already a `Power`, Consul will instantiate a `Power` for you: + + admin = User.new(:role => 'admin') + + Power.with_power(admin) do + # run code that uses Power.current + end + + Installation ------------ Add the following to your `Gemfile`: @@ -290,10 +337,10 @@ - Fork the repository. - Push your changes **with specs**. - Send me a pull request. -I'm very eager to keep this gem leightweight and on topic. If you're unsure whether a change would make it into the gem, [talk to me beforehand](henning.koch@makandra.de). +I'm very eager to keep this gem leightweight and on topic. If you're unsure whether a change would make it into the gem, [talk to me beforehand](mailto:henning.koch@makandra.de). Credits -------