aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/integration_spec_helper.rb17
-rw-r--r--spec/support/pundit/pundit_view_policy.rb16
2 files changed, 26 insertions, 7 deletions
diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb
new file mode 100644
index 000000000..958aab9d5
--- /dev/null
+++ b/spec/support/integration_spec_helper.rb
@@ -0,0 +1,17 @@
+module IntegrationSpecHelper
+ extend ActiveSupport::Concern
+
+ included do
+ def self.with_permission permission, &block
+ context "with permission #{permission}" do
+ let(:permissions){ [permission] }
+ context('', &block) if block_given?
+ end
+ end
+ end
+end
+
+
+RSpec.configure do |config|
+ config.include IntegrationSpecHelper, type: :view
+end
diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb
index b8434cac0..02a78a4e0 100644
--- a/spec/support/pundit/pundit_view_policy.rb
+++ b/spec/support/pundit/pundit_view_policy.rb
@@ -3,14 +3,16 @@ module Pundit
extend ActiveSupport::Concern
included do
+
+ let(:permissions){ nil }
+ let(:current_referential){ build_stubbed :referential }
+ let(:current_user){ build_stubbed :user, permissions: permissions }
+ let(:pundit_user){ UserContext.new(current_user, referential: current_referential) }
before do
- controller.singleton_class.class_eval do
- def policy(instance)
- Class.new do
- def method_missing(*args, &block); true; end
- end.new
- end
- helper_method :policy
+ allow(view).to receive(:pundit_user) { pundit_user }
+
+ allow(view).to receive(:policy) do |instance|
+ ::Pundit.policy pundit_user, instance
end
end
end