aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorZog2017-12-15 09:11:04 +0100
committerZog2017-12-19 14:40:38 +0100
commit676f45e8fd85c1422345d4d27ba2385e4bd536fe (patch)
treee09fcebd3f7970b0043bf8adbfd5e0f54a8c73e1 /spec/support
parent8e55e7036aafb485058bf9122bf47cde73a54c33 (diff)
downloadchouette-core-676f45e8fd85c1422345d4d27ba2385e4bd536fe.tar.bz2
Refs #5287;
Add specs for the view. Refactor to come
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