protector 0.6.3 → 0.6.4

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: a094c41767f9fee30c80858e19061dd0468c877a
4
- data.tar.gz: b202613a388beb22fcf6209b56d36fbf22bfe2b8
3
+ metadata.gz: 06ef70fc6fb353ebf794e6386d1f071f5561bf01
4
+ data.tar.gz: e566043d18cb952d1eff71144afaa1f50d7b2657
5
5
  SHA512:
6
- metadata.gz: 371868628bfce74285256e22c178c015f69bc93754747a9c15cadb7092b04b2cd2d2f25e17e1d6b22f19b9311a257fcd4b0bcb01bded148c7bc153835eb70858
7
- data.tar.gz: 275e55334c99481a7f3eae8f3576aa18c26e3275d271f5d8563425b1abfbadf8f72f7fa100464f4bf7f3ab9490d784794d216acd4450b50bac23b55126327068
6
+ metadata.gz: 89d14e47526fbbe0b59f63467188db88ac0d7a02729370da0ff07a4938cd43c47d7fee7639cbd429f09a9020f5a93af5ac50d700414c178feb80f93197918fe8
7
+ data.tar.gz: 2e82a2ce1327e8f5573d7321ac481a2054850ddce6d5fde687362cda6525da3b31317cf23423ffea86d5116c1dff981e15c335d371086eedff033857276af679
@@ -37,6 +37,10 @@ module Protector
37
37
  @klass.protector_meta.evaluate(subject)
38
38
  end
39
39
 
40
+ def protector_relation
41
+ protector_meta.relation ? merge(protector_meta.relation) : clone
42
+ end
43
+
40
44
  # @note Unscoped relation drops properties and therefore should be re-restricted
41
45
  def unscoped
42
46
  return super unless protector_subject?
@@ -66,13 +70,13 @@ module Protector
66
70
  # Merges current relation with restriction and calls real `calculate`
67
71
  def calculate(*args)
68
72
  return super unless protector_subject?
69
- merge(protector_meta.relation).unrestrict!.calculate *args
73
+ protector_relation.unrestrict!.calculate *args
70
74
  end
71
75
 
72
76
  # Merges current relation with restriction and calls real `exists?`
73
77
  def exists?(*args)
74
78
  return super unless protector_subject?
75
- merge(protector_meta.relation).unrestrict!.exists? *args
79
+ protector_relation.unrestrict!.exists? *args
76
80
  end
77
81
 
78
82
  # Forwards protection subject to the new instance
@@ -117,7 +121,7 @@ module Protector
117
121
  return exec_queries_without_protector unless protector_subject?
118
122
 
119
123
  subject = protector_subject
120
- relation = merge(protector_meta.relation).unrestrict!
124
+ relation = protector_relation.unrestrict!
121
125
  relation = protector_substitute_includes(subject, relation)
122
126
 
123
127
  # Preserve associations from internal loading. We are going to handle that
@@ -1,4 +1,4 @@
1
1
  module Protector
2
2
  # Gem version
3
- VERSION = "0.6.3"
3
+ VERSION = "0.6.4"
4
4
  end
@@ -16,8 +16,6 @@ if defined?(ActiveRecord)
16
16
  scope{ where('1=0') }
17
17
  elsif x == '+'
18
18
  scope{ where(klass.table_name => {number: 999}) }
19
- elsif !Protector.config.paranoid && Protector::Adapters::ActiveRecord.modern?
20
- scope { all }
21
19
  end
22
20
 
23
21
  can :view, :dummy_id unless x == '-'
@@ -123,6 +121,7 @@ if defined?(ActiveRecord)
123
121
 
124
122
  context "with open relation" do
125
123
  context "adequate", paranoid: false do
124
+
126
125
  it "checks existence" do
127
126
  Dummy.any?.should == true
128
127
  Dummy.restrict!('!').any?.should == true
@@ -130,7 +129,9 @@ if defined?(ActiveRecord)
130
129
 
131
130
  it "counts" do
132
131
  Dummy.count.should == 4
133
- Dummy.restrict!('!').count.should == 4
132
+ dummy = Dummy.restrict!('!')
133
+ dummy.count.should == 4
134
+ dummy.protector_subject?.should == true
134
135
  end
135
136
 
136
137
  it "fetches" do
@@ -149,7 +150,9 @@ if defined?(ActiveRecord)
149
150
 
150
151
  it "counts" do
151
152
  Dummy.count.should == 4
152
- Dummy.restrict!('!').count.should == 0
153
+ dummy = Dummy.restrict!('!')
154
+ dummy.count.should == 0
155
+ dummy.protector_subject?.should == true
153
156
  end
154
157
 
155
158
  it "fetches" do
@@ -169,7 +172,9 @@ if defined?(ActiveRecord)
169
172
 
170
173
  it "counts" do
171
174
  Dummy.count.should == 4
172
- Dummy.restrict!('-').count.should == 0
175
+ dummy = Dummy.restrict!('-')
176
+ dummy.count.should == 0
177
+ dummy.protector_subject?.should == true
173
178
  end
174
179
 
175
180
  it "fetches" do
@@ -193,7 +198,9 @@ if defined?(ActiveRecord)
193
198
 
194
199
  it "counts" do
195
200
  Dummy.count.should == 4
196
- Dummy.restrict!('+').count.should == 2
201
+ dummy = Dummy.restrict!('+')
202
+ dummy.count.should == 2
203
+ dummy.protector_subject?.should == true
197
204
  end
198
205
 
199
206
  it "fetches" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal