mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
moved class definitions from pundit_spec.rb to spec_helper.rb
This commit is contained in:
parent
c028f722e6
commit
30b7861431
2 changed files with 57 additions and 56 deletions
|
@ -1,59 +1,4 @@
|
||||||
require "pundit"
|
require "spec_helper"
|
||||||
require "pry"
|
|
||||||
require "active_support/core_ext"
|
|
||||||
require "active_model/naming"
|
|
||||||
|
|
||||||
class PostPolicy < Struct.new(:user, :post)
|
|
||||||
def update?
|
|
||||||
post.user == user
|
|
||||||
end
|
|
||||||
def destroy?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
def show?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class PostPolicy::Scope < Struct.new(:user, :scope)
|
|
||||||
def resolve
|
|
||||||
scope.published
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class Post < Struct.new(:user)
|
|
||||||
def self.published
|
|
||||||
:published
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class CommentPolicy < Struct.new(:user, :comment); end
|
|
||||||
class CommentPolicy::Scope < Struct.new(:user, :scope)
|
|
||||||
def resolve
|
|
||||||
scope
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class Comment; extend ActiveModel::Naming; end
|
|
||||||
|
|
||||||
class Article; end
|
|
||||||
|
|
||||||
class BlogPolicy < Struct.new(:user, :blog); end
|
|
||||||
class Blog; end
|
|
||||||
class ArtificialBlog < Blog
|
|
||||||
def self.policy_class
|
|
||||||
BlogPolicy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class ArticleTag
|
|
||||||
def self.policy_class
|
|
||||||
Struct.new(:user, :tag) do
|
|
||||||
def show?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
def destroy?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe Pundit do
|
describe Pundit do
|
||||||
let(:user) { double }
|
let(:user) { double }
|
||||||
|
|
56
spec/spec_helper.rb
Normal file
56
spec/spec_helper.rb
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
require "pundit"
|
||||||
|
require "pry"
|
||||||
|
require "active_support/core_ext"
|
||||||
|
require "active_model/naming"
|
||||||
|
|
||||||
|
class PostPolicy < Struct.new(:user, :post)
|
||||||
|
def update?
|
||||||
|
post.user == user
|
||||||
|
end
|
||||||
|
def destroy?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
def show?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class PostPolicy::Scope < Struct.new(:user, :scope)
|
||||||
|
def resolve
|
||||||
|
scope.published
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class Post < Struct.new(:user)
|
||||||
|
def self.published
|
||||||
|
:published
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class CommentPolicy < Struct.new(:user, :comment); end
|
||||||
|
class CommentPolicy::Scope < Struct.new(:user, :scope)
|
||||||
|
def resolve
|
||||||
|
scope
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class Comment; extend ActiveModel::Naming; end
|
||||||
|
|
||||||
|
class Article; end
|
||||||
|
|
||||||
|
class BlogPolicy < Struct.new(:user, :blog); end
|
||||||
|
class Blog; end
|
||||||
|
class ArtificialBlog < Blog
|
||||||
|
def self.policy_class
|
||||||
|
BlogPolicy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class ArticleTag
|
||||||
|
def self.policy_class
|
||||||
|
Struct.new(:user, :tag) do
|
||||||
|
def show?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
def destroy?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue