mongoid_ability 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9a82de3d605e183be4312f39a57f7bbd9766166
4
- data.tar.gz: 533cc7a7f76e8aa3b0867e60f9363253397a5202
3
+ metadata.gz: 4350f8ee2aa6783ba0bd4790264aae87341062fa
4
+ data.tar.gz: 7f58c17ff7e7e441fb761d0ed33f48ab298c3ec3
5
5
  SHA512:
6
- metadata.gz: 02231a5fd23515b5842104d16a0a9b8a83548c6ab47e68d7c150fc2a13373e6898125be0c8381c2e4740ea1ab71ccd991539706273298ebe37f8986b351e87e3
7
- data.tar.gz: 4f3c0714a5dfe7f17b9adeddb0e42f79086f50e8af1ebbdb86b4a750be0be607988c7f03a89df88a72ba2548b3b5205096339d2707676a663e2e17889958de22
6
+ metadata.gz: 701fa1fee1c99245b7c6dada06da608352bfe4e153ac728334d54d1394516ea1ac0707f24550ff7ab88b7e7aa96eb18db396aeeaa814e29933af2217b2e6a2ee
7
+ data.tar.gz: ac018c43208f7089fe308504fec8188c5fece9cdccccc6ec76447a2ce9917740c6ef4aa5984183625ff9f3b4d3db23c04e5e5472c842ee025c83e7581017690e
@@ -27,7 +27,7 @@ module MongoidAbility
27
27
  # override if needed
28
28
  # return for example 'MyLock'
29
29
  def lock_class_name
30
- Object.descendants.detect{ |cls| cls < MongoidAbility::Lock }.name
30
+ @lock_class_name ||= Object.descendants.detect{ |cls| cls < MongoidAbility::Lock }.name
31
31
  end
32
32
 
33
33
  # ---------------------------------------------------------------------
@@ -73,7 +73,11 @@ module MongoidAbility
73
73
 
74
74
  excluded_ids << id_locks.map(&:subject_id)
75
75
 
76
- cr = cr.or(_type: cls.to_s, :_id.nin => excluded_ids.flatten)
76
+ if subject_classes.count == 1
77
+ cr = cr.or(:_id.nin => excluded_ids.flatten)
78
+ else
79
+ cr = cr.or(_type: cls.to_s, :_id.nin => excluded_ids.flatten)
80
+ end
77
81
  else
78
82
  included_ids = []
79
83
 
@@ -82,7 +86,11 @@ module MongoidAbility
82
86
 
83
87
  included_ids << id_locks.map(&:subject_id)
84
88
 
85
- cr = cr.or(_type: cls.to_s, :_id.in => included_ids.flatten)
89
+ if subject_classes.count == 1
90
+ cr = cr.or(:_id.in => included_ids.flatten)
91
+ else
92
+ cr = cr.or(_type: cls.to_s, :_id.in => included_ids.flatten)
93
+ end
86
94
  end
87
95
  end
88
96
 
@@ -1,3 +1,3 @@
1
1
  module MongoidAbility
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -15,13 +15,11 @@ module MongoidAbility
15
15
 
16
16
  subject { SubjectTest.new }
17
17
 
18
+ let(:subject_single_test) { SubjectSingleTest.create! }
19
+
18
20
  let(:subject_test_1) { SubjectTestOne.create! }
19
21
  let(:subject_test_2) { SubjectTestTwo.create! }
20
22
 
21
- # let(:embedded_test_subject_1) { EmbeddedTestSubject.new }
22
- # let(:embedded_test_subject_2) { EmbeddedTestSubjectTwo.new }
23
- # let(:embedded_test_subject_owner) { EmbeddedTestSubjectOwner.new(embedded_test_subjects: [ embedded_test_subject_1, embedded_test_subject_2 ]) }
24
-
25
23
  let(:role_1) { TestRole.new }
26
24
  let(:role_2) { TestRole.new }
27
25
 
@@ -70,33 +68,41 @@ module MongoidAbility
70
68
  before do
71
69
  subject_test_1
72
70
  subject_test_2
71
+ subject_single_test
73
72
  end
74
73
 
75
74
  it 'returns Mongoid::Criteria' do
76
75
  subject.class.accessible_by(ability).must_be_kind_of Mongoid::Criteria
77
- # embedded_test_subject_1.class.accessible_by(ability).must_be_kind_of Mongoid::Criteria
78
76
  end
79
77
 
80
- # describe 'embedded relations' do
81
- # it 'returns correct criteria type' do
82
- # embedded_test_subject_owner.embedded_test_subjects.accessible_by(ability).embedded?.must_equal true
83
- # end
84
- # end
85
-
86
78
  # ---------------------------------------------------------------------
87
79
 
88
80
  describe 'default locks' do
89
- describe 'referenced relations' do
81
+ it 'returns everything when open' do
82
+ subject.class.stub(:default_locks, [ subject_type_lock(subject.class, true) ]) do
83
+ subject.class.accessible_by(ability).must_include subject_test_1
84
+ subject.class.accessible_by(ability).must_include subject_test_2
85
+ end
86
+ end
87
+
88
+ describe 'single class' do
90
89
  it 'returns everything when open' do
91
- subject.class.stub(:default_locks, [ subject_type_lock(subject.class, true) ]) do
92
- subject.class.accessible_by(ability).must_include subject_test_1
93
- subject.class.accessible_by(ability).must_include subject_test_2
90
+ subject_single_test.class.stub(:default_locks, [ subject_type_lock(subject_single_test.class, true) ]) do
91
+ subject_single_test.class.accessible_by(ability).must_include subject_single_test
94
92
  end
95
93
  end
94
+ end
95
+
96
+ it 'returns nothing when closed' do
97
+ subject.class.stub(:default_locks, [ subject_type_lock(subject.class, false) ]) do
98
+ subject.class.accessible_by(ability).must_be :empty?
99
+ end
100
+ end
96
101
 
102
+ describe 'single class' do
97
103
  it 'returns nothing when closed' do
98
- subject.class.stub(:default_locks, [ subject_type_lock(subject.class, false) ]) do
99
- subject.class.accessible_by(ability).must_be :empty?
104
+ subject_single_test.class.stub(:default_locks, [ subject_type_lock(subject_single_test.class, false) ]) do
105
+ subject_single_test.class.accessible_by(ability).wont_include subject_single_test
100
106
  end
101
107
  end
102
108
  end
data/test/test_helper.rb CHANGED
@@ -84,22 +84,12 @@ end
84
84
  class SubjectTestTwo < SubjectTest
85
85
  end
86
86
 
87
+ class SubjectSingleTest
88
+ include Mongoid::Document
89
+ include MongoidAbility::Subject
87
90
 
88
-
89
- # class EmbeddedTestSubjectOwner
90
- # include Mongoid::Document
91
- # include MongoidAbility::Subject
92
-
93
- # embeds_many :embedded_test_subjects
94
- # end
95
-
96
- # class EmbeddedTestSubject < TestSubject
97
- # embedded_in :embedded_test_subject_owner
98
- # end
99
-
100
- # class EmbeddedTestSubjectTwo < TestSubject
101
- # embedded_in :embedded_test_subject_owner
102
- # end
91
+ default_lock :read, true
92
+ end
103
93
 
104
94
  # ---------------------------------------------------------------------
105
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_ability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna