From 88b8e30a415f300108be4a19a53ca9768671d21e Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 09:11:04 +0100 Subject: Refs #5287; Add specs for the view. Refactor to come --- spec/support/integration_spec_helper.rb | 17 +++++++++++++++++ spec/support/pundit/pundit_view_policy.rb | 16 +++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 spec/support/integration_spec_helper.rb (limited to 'spec/support') 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 -- cgit v1.2.3 From cd92a6e07393b1b6ee57a8d980f072aa8a034874 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 11:27:14 +0100 Subject: - Fix specs on connections_links/index - Fix specs on connections_links/show - Update pundit view specs helper to use the current referential when it has already been defined --- spec/support/pundit/pundit_view_policy.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spec/support') diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 02a78a4e0..6a663a471 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -5,8 +5,9 @@ module Pundit included do let(:permissions){ nil } - let(:current_referential){ build_stubbed :referential } - let(:current_user){ build_stubbed :user, permissions: permissions } + let(:organisation){ referential.try(:organisation) } + let(:current_referential){ referential || build_stubbed(:referential) } + let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } before do allow(view).to receive(:pundit_user) { pundit_user } -- cgit v1.2.3 From 1b2c50949d827d8f82a40d591489394f5dc2f993 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:25:10 +0100 Subject: Refs #5287; CR 1 - Get rid of ActiveSupport::Concern in the spec helpers - Rename misnamed spec files --- spec/support/integration_spec_helper.rb | 15 +++++---------- spec/support/pundit/pundit_view_policy.rb | 17 +++++++---------- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'spec/support') diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 958aab9d5..182cadf24 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -1,17 +1,12 @@ 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 + def with_permission permission, &block + context "with permission #{permission}" do + let(:permissions){ [permission] } + context('', &block) if block_given? end end end - RSpec.configure do |config| - config.include IntegrationSpecHelper, type: :view + config.extend IntegrationSpecHelper, type: :view end diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 6a663a471..91be0624c 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -1,15 +1,12 @@ module Pundit module PunditViewPolicy - extend ActiveSupport::Concern - - included do - - let(:permissions){ nil } - let(:organisation){ referential.try(:organisation) } - let(:current_referential){ referential || build_stubbed(:referential) } - let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } - let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } - before do + def self.included into + into.let(:permissions){ nil } + into.let(:organisation){ referential.try(:organisation) } + into.let(:current_referential){ referential || build_stubbed(:referential) } + into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } + into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } + into.before do allow(view).to receive(:pundit_user) { pundit_user } allow(view).to receive(:policy) do |instance| -- cgit v1.2.3