1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00
Commit graph

21 commits

Author SHA1 Message Date
Thomas Klemm
41b3e61fba Bump version 2014-02-07 18:16:39 +01:00
Milovan Zogovic
8385fd36e6 different matchers for should and should_not 2014-01-17 14:31:53 +01:00
Thomas Klemm
f3fee8d3b9 Clarify meaning of a few variables 2013-11-05 18:58:09 +01:00
Tim Cooper
26e3706719 Allow policies and scopes to be injected into controllers.
In controller specs instead of relying on Pundit to instantiate the correct
policy object allow it to be injected into the controller. More often than not
a double is used in controller specs which means the policy cannot be
inferred. This also allows us to double the policy to ensure that on a unit
level the rights methods are being called on callaborators.

class PostsController < ApplicationController
  attr_writer :post
  helper_method :post

  def create
    authorize post

    post.save
    respond_with post
  end

  private

  def post
    @post ||= Post.new post_attributes
  end
end

describe PagesController do
  let(:policy) { double 'SomePolicy', create?: true }

  before do
    controller.policy = policy
  end

  it 'delegates authorization to policy' do
    expect(policy).to have_received(:create?)
  end
end

Add spec for injecting policy.

Use `or` instead of ternary operator.

Allow policy_scope to be injected for controller tests.
2013-09-02 11:32:30 +02:00
Philip Vieira
149a02c7b8 pundit_user should be a helper and hidden as an action 2013-07-14 00:50:39 +02:00
Philip Vieira
a847f782cd Let pundit_user raise a name error if current_user is not present. 2013-07-13 16:24:13 +02:00
Philip Vieira
d7ef22bb97 Custom pundit user 2013-07-13 05:42:34 +02:00
Jonas Nicklas and Kim Burgestrand
f88d39b34f tagged 0.2.1 2013-06-18 09:23:13 +02:00
Brendon Murphy
7be0a890a6 Add #verify_policy_scoped for controller usage.
See the readme changes for an example.  In short, this behaves
like verify_authorized but is useful for actions that find a
collection (like index) and don't authorize instances.
2013-04-17 22:05:24 -07:00
Jonas Nicklas
12292f151f Hide authorize and verify_authorized, closes #23 2013-03-28 17:26:24 +01:00
Brendon Murphy
cf8a739bb3 Change default index? policy to false
See gh-17 for initial discussion.  I think that the default provided
before this commit is confusing, because an empty result is not a
good indicator of authorization failure.  Returning false better
communicates "override this is you want it".
2013-03-09 03:01:49 -08:00
Jonas Nicklas
f71aae268d tagged 0.2.0 2013-01-08 09:48:57 +01:00
Jonas Nicklas
75683fe159 Refactor 2013-01-08 09:26:41 +01:00
Jason Daly
462362b2d4 Fixing TypeError trying to call ::Scope on nil 2012-12-13 18:25:14 -05:00
Jason Daly
e65159f26b Improvements on .policy_class support
The `BlogPolicy -> "BlogPolicy" -> "Blog" -> "BlogPolicy" -> BlogPolicy`
issue @jnicklas pointed out has been resolved. For example, given

```ruby
class BlogPolicy < Struct.new(:user, :blog); end
class Blog; end
class ArtificialBlog < Blog
  def self.policy_class
    BlogPolicy
  end
end
```

The above string manipulation/casting is prevented; the `BlogPolicy`
class will be immediately returned to `policy` and on to be evaluated.

Anonymous classes are now supported too. For example, given

```ruby
class BlogPolicy < Struct.new(:user, :blog); end
class Blog; end
class ArtificialBlog < Blog
  def self.policy_class
    Struct.new(:user, :blog) do
      def create?
        true
      end
    end
  end
end
```

The `Struct` will be returned and evaluated as any other policy.
2012-12-13 18:20:12 -05:00
Jason Daly
4fc13620ee Adds support for policy_class model instance/class for custom Policy 2012-11-30 10:21:46 -05:00
Jonas Nicklas
4c234bb3a2 start at a reasonable version 2012-11-19 13:04:28 +01:00
Jonas Nicklas
b8fd37110a Add specs and dependencies 2012-11-19 13:02:42 +01:00
Jonas Nicklas
a26b3128bd Extract the actual code 2012-11-19 10:57:17 +01:00
Jonas Nicklas
37810ccc31 Added generators 2012-11-19 10:53:14 +01:00
Jonas Nicklas
1cad0b598a initial 2012-11-04 10:20:45 +01:00