aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorRobert2017-06-30 17:51:31 +0200
committerRobert2017-06-30 17:51:31 +0200
commitd0e0b5aa02098575d5ac453567439f13c5d7be91 (patch)
tree6dd236a0090c3ff2e5d6503e84d4c930ec6cc0ea /spec/support
parentd24a3689d6ba1a575e8cc3e506f04b471cc4c977 (diff)
downloadchouette-core-check_policy_specs.tar.bz2
Spec fix and optimizationcheck_policy_specs
- Fixed bugs in Policy Specs (Shared methods were not using records) - Using build_stubbed instead of create for all Policy Methods (5.43s -> 3.75s)
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/pundit/policies.rb4
-rw-r--r--spec/support/pundit/shared_examples.rb26
2 files changed, 15 insertions, 15 deletions
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index 56433b2ee..02fea2944 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -24,8 +24,8 @@ module Support
into.module_eval do
subject { described_class }
let( :user_context ) { create_user_context(user: user, referential: referential) }
- let( :referentail ) { create :referential }
- let( :user ) { create :user }
+ let( :referential ) { build_stubbed :referential }
+ let( :user ) { build_stubbed :user }
end
end
def with_user_permission(permission, &blk)
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 4d14c46da..33ed1ffae 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -3,11 +3,11 @@ RSpec.shared_examples 'permitted policy and same organisation' do
context 'permission absent → ' do
it "denies a user with a different organisation" do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
it 'and also a user with the same organisation' do
- user.update_attribute :organisation, referential.organisation
- expect_it.not_to permit(user_context, referential)
+ user.organisation = referential.organisation
+ expect_it.not_to permit(user_context, record)
end
end
@@ -17,19 +17,19 @@ RSpec.shared_examples 'permitted policy and same organisation' do
end
it 'denies a user with a different organisation' do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
it 'but allows it for a user with the same organisation' do
- user.update_attribute :organisation, referential.organisation
- expect_it.to permit(user_context, referential)
+ user.organisation = referential.organisation
+ expect_it.to permit(user_context, record)
end
if archived
it 'removes the permission for archived referentials' do
- user.update_attribute :organisation, referential.organisation
- referential.update_attribute :archived_at, 42.seconds.ago
- expect_it.not_to permit(user_context, referential)
+ user.organisation = referential.organisation
+ referential.archived_at = 42.seconds.ago
+ expect_it.not_to permit(user_context, record)
end
end
end
@@ -39,7 +39,7 @@ RSpec.shared_examples 'permitted policy' do
| permission, archived: false|
context 'permission absent → ' do
it "denies a user with a different organisation" do
- expect_it.not_to permit(user_context, referential)
+ expect_it.not_to permit(user_context, record)
end
end
context 'permission present → ' do
@@ -47,13 +47,13 @@ RSpec.shared_examples 'permitted policy' do
add_permissions(permission, for_user: user)
end
it 'allows a user with a different organisation' do
- expect_it.to permit(user_context, referential)
+ expect_it.to permit(user_context, record)
end
if archived
it 'removes the permission for archived referentials' do
- referential.update_attribute :archived_at, 42.seconds.ago
- expect_it.not_to permit(user_context, referential)
+ referential.archived_at = 42.seconds.ago
+ expect_it.not_to permit(user_context, record)
end
end
end