diff --git a/spec/pundit_spec.rb b/spec/pundit_spec.rb index 5389365..dcf87db 100644 --- a/spec/pundit_spec.rb +++ b/spec/pundit_spec.rb @@ -52,15 +52,15 @@ describe Pundit do end it "returns an instantiated policy scope given an active model class" do - expect(Pundit.policy_scope(user, Comment)).to eq Comment + expect(Pundit.policy_scope(user, Comment)).to eq CommentScope.new(Comment) end it "returns an instantiated policy scope given an active record relation" do - expect(Pundit.policy_scope(user, comments_relation)).to eq comments_relation + expect(Pundit.policy_scope(user, comments_relation)).to eq CommentScope.new(comments_relation) end it "returns an instantiated policy scope given an empty active record relation" do - expect(Pundit.policy_scope(user, empty_comments_relation)).to eq empty_comments_relation + expect(Pundit.policy_scope(user, empty_comments_relation)).to eq CommentScope.new(empty_comments_relation) end it "returns nil if the given policy scope can't be found" do @@ -84,7 +84,7 @@ describe Pundit do end it "returns an instantiated policy scope given an active model class" do - expect(Pundit.policy_scope!(user, Comment)).to eq Comment + expect(Pundit.policy_scope!(user, Comment)).to eq CommentScope.new(Comment) end it "throws an exception if the given policy scope can't be found" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 37a015e..2870ab0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -87,10 +87,21 @@ module Customer end end +class CommentScope + attr_reader :original_object + def initialize(original_object) + @original_object = original_object + end + + def ==(other) + original_object == other.original_object + end +end + class CommentPolicy < Struct.new(:user, :comment) class Scope < Struct.new(:user, :scope) def resolve - scope + CommentScope.new(scope) end end end