protector 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Appraisals +9 -0
- data/Gemfile +4 -1
- data/README.md +126 -3
- data/Rakefile +7 -2
- data/gemfiles/AR_3.2.gemfile +16 -0
- data/gemfiles/AR_3.2.gemfile.lock +104 -0
- data/gemfiles/AR_4.gemfile +16 -0
- data/gemfiles/AR_4.gemfile.lock +113 -0
- data/lib/protector/adapters/active_record/association.rb +29 -0
- data/lib/protector/adapters/active_record/base.rb +100 -0
- data/lib/protector/adapters/active_record/relation.rb +49 -0
- data/lib/protector/adapters/active_record.rb +5 -145
- data/lib/protector/dsl.rb +8 -4
- data/lib/protector/version.rb +1 -1
- data/lib/protector.rb +2 -5
- data/spec/lib/adapters/active_record_spec.rb +156 -78
- data/spec/lib/dsl_spec.rb +8 -9
- data/spec/spec_helpers/boot.rb +1 -2
- data/spec/spec_helpers/model.rb +66 -72
- metadata +11 -2
data/spec/spec_helpers/model.rb
CHANGED
@@ -1,21 +1,3 @@
|
|
1
|
-
RSpec::Matchers.define :invalidate do
|
2
|
-
match do |actual|
|
3
|
-
actual.save.should == false
|
4
|
-
actual.errors[:base].should == ["Access denied"]
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
RSpec::Matchers.define :validate do
|
9
|
-
match do |actual|
|
10
|
-
actual.class.transaction do
|
11
|
-
actual.save.should == true
|
12
|
-
raise ActiveRecord::Rollback
|
13
|
-
end
|
14
|
-
|
15
|
-
true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
1
|
shared_examples_for "a model" do
|
20
2
|
it "evaluates meta properly" do
|
21
3
|
@dummy.instance_eval do
|
@@ -31,7 +13,7 @@ shared_examples_for "a model" do
|
|
31
13
|
end
|
32
14
|
|
33
15
|
fields = Hash[*%w(id string number text created_at updated_at).map{|x| [x, nil]}.flatten]
|
34
|
-
dummy = @dummy.new.restrict('!')
|
16
|
+
dummy = @dummy.new.restrict!('!')
|
35
17
|
meta = dummy.protector_meta
|
36
18
|
|
37
19
|
meta.access[:view].should == fields
|
@@ -41,14 +23,26 @@ shared_examples_for "a model" do
|
|
41
23
|
|
42
24
|
describe "association" do
|
43
25
|
context "(has_many)" do
|
44
|
-
|
45
|
-
|
26
|
+
around(:each) do |e|
|
27
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
28
|
+
e.run
|
29
|
+
ActiveRecord::Base.logger = nil
|
30
|
+
end
|
31
|
+
it "loads" do
|
32
|
+
Dummy.first.restrict!('!').fluffies.length.should == 2
|
33
|
+
Dummy.first.restrict!('+').fluffies.length.should == 1
|
34
|
+
Dummy.first.restrict!('-').fluffies.empty?.should == true
|
46
35
|
end
|
47
36
|
end
|
48
37
|
|
49
38
|
context "(belongs_to)" do
|
50
39
|
it "passes subject" do
|
51
|
-
Fluffy.first.restrict('!').dummy.protector_subject.should == '!'
|
40
|
+
Fluffy.first.restrict!('!').dummy.protector_subject.should == '!'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "loads" do
|
44
|
+
Fluffy.first.restrict!('!').dummy.should be_a_kind_of(Dummy)
|
45
|
+
Fluffy.first.restrict!('-').dummy.should == nil
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end
|
@@ -59,7 +53,7 @@ shared_examples_for "a model" do
|
|
59
53
|
protect do; scope { none }; end
|
60
54
|
end
|
61
55
|
|
62
|
-
@dummy.first.restrict('!').visible?.should == false
|
56
|
+
@dummy.first.restrict!('!').visible?.should == false
|
63
57
|
end
|
64
58
|
|
65
59
|
it "marks allowed" do
|
@@ -67,7 +61,7 @@ shared_examples_for "a model" do
|
|
67
61
|
protect do; scope { limit(5) }; end
|
68
62
|
end
|
69
63
|
|
70
|
-
@dummy.first.restrict('!').visible?.should == true
|
64
|
+
@dummy.first.restrict!('!').visible?.should == true
|
71
65
|
end
|
72
66
|
end
|
73
67
|
|
@@ -79,7 +73,7 @@ shared_examples_for "a model" do
|
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
82
|
-
dummy = @dummy.first.restrict('!')
|
76
|
+
dummy = @dummy.first.restrict!('!')
|
83
77
|
dummy.number.should == nil
|
84
78
|
dummy[:number].should == nil
|
85
79
|
dummy.read_attribute(:number).should_not == nil
|
@@ -97,13 +91,13 @@ shared_examples_for "a model" do
|
|
97
91
|
|
98
92
|
it "marks blocked" do
|
99
93
|
dummy = @dummy.new(string: 'bam', number: 1)
|
100
|
-
dummy.restrict('!').creatable?.should == false
|
94
|
+
dummy.restrict!('!').creatable?.should == false
|
101
95
|
end
|
102
96
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
97
|
+
it "invalidates" do
|
98
|
+
dummy = @dummy.new(string: 'bam', number: 1).restrict!('!')
|
99
|
+
dummy.should invalidate
|
100
|
+
end
|
107
101
|
end
|
108
102
|
|
109
103
|
context "by list of fields" do
|
@@ -117,21 +111,21 @@ shared_examples_for "a model" do
|
|
117
111
|
|
118
112
|
it "marks blocked" do
|
119
113
|
dummy = @dummy.new(string: 'bam', number: 1)
|
120
|
-
dummy.restrict('!').creatable?.should == false
|
114
|
+
dummy.restrict!('!').creatable?.should == false
|
121
115
|
end
|
122
116
|
|
123
117
|
it "marks allowed" do
|
124
118
|
dummy = @dummy.new(string: 'bam')
|
125
|
-
dummy.restrict('!').creatable?.should == true
|
119
|
+
dummy.restrict!('!').creatable?.should == true
|
126
120
|
end
|
127
121
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
122
|
+
it "invalidates" do
|
123
|
+
dummy = @dummy.new(string: 'bam', number: 1).restrict!('!')
|
124
|
+
dummy.should invalidate
|
125
|
+
end
|
132
126
|
|
133
127
|
it "validates" do
|
134
|
-
dummy = @dummy.new(string: 'bam').restrict('!')
|
128
|
+
dummy = @dummy.new(string: 'bam').restrict!('!')
|
135
129
|
dummy.should validate
|
136
130
|
end
|
137
131
|
end
|
@@ -140,28 +134,28 @@ shared_examples_for "a model" do
|
|
140
134
|
before(:each) do
|
141
135
|
@dummy.instance_eval do
|
142
136
|
protect do
|
143
|
-
can :create, string:
|
137
|
+
can :create, string: lambda {|x| x.try(:length) == 5 }
|
144
138
|
end
|
145
139
|
end
|
146
140
|
end
|
147
141
|
|
148
142
|
it "marks blocked" do
|
149
143
|
dummy = @dummy.new(string: 'bam')
|
150
|
-
dummy.restrict('!').creatable?.should == false
|
144
|
+
dummy.restrict!('!').creatable?.should == false
|
151
145
|
end
|
152
146
|
|
153
147
|
it "marks allowed" do
|
154
148
|
dummy = @dummy.new(string: '12345')
|
155
|
-
dummy.restrict('!').creatable?.should == true
|
149
|
+
dummy.restrict!('!').creatable?.should == true
|
156
150
|
end
|
157
151
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
152
|
+
it "invalidates" do
|
153
|
+
dummy = @dummy.new(string: 'bam').restrict!('!')
|
154
|
+
dummy.should invalidate
|
155
|
+
end
|
162
156
|
|
163
157
|
it "validates" do
|
164
|
-
dummy = @dummy.new(string: '12345').restrict('!')
|
158
|
+
dummy = @dummy.new(string: '12345').restrict!('!')
|
165
159
|
dummy.should validate
|
166
160
|
end
|
167
161
|
end
|
@@ -177,21 +171,21 @@ shared_examples_for "a model" do
|
|
177
171
|
|
178
172
|
it "marks blocked" do
|
179
173
|
dummy = @dummy.new(number: 500)
|
180
|
-
dummy.restrict('!').creatable?.should == false
|
174
|
+
dummy.restrict!('!').creatable?.should == false
|
181
175
|
end
|
182
176
|
|
183
177
|
it "marks allowed" do
|
184
178
|
dummy = @dummy.new(number: 2)
|
185
|
-
dummy.restrict('!').creatable?.should == true
|
179
|
+
dummy.restrict!('!').creatable?.should == true
|
186
180
|
end
|
187
181
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
182
|
+
it "invalidates" do
|
183
|
+
dummy = @dummy.new(number: 500).restrict!('!')
|
184
|
+
dummy.should invalidate
|
185
|
+
end
|
192
186
|
|
193
187
|
it "validates" do
|
194
|
-
dummy = @dummy.new(number: 2).restrict('!')
|
188
|
+
dummy = @dummy.new(number: 2).restrict!('!')
|
195
189
|
dummy.should validate
|
196
190
|
end
|
197
191
|
end
|
@@ -208,11 +202,11 @@ shared_examples_for "a model" do
|
|
208
202
|
it "marks blocked" do
|
209
203
|
dummy = @dummy.first
|
210
204
|
dummy.assign_attributes(string: 'bam', number: 1)
|
211
|
-
dummy.restrict('!').updatable?.should == false
|
205
|
+
dummy.restrict!('!').updatable?.should == false
|
212
206
|
end
|
213
207
|
|
214
208
|
it "invalidates" do
|
215
|
-
dummy = @dummy.first.restrict('!')
|
209
|
+
dummy = @dummy.first.restrict!('!')
|
216
210
|
dummy.assign_attributes(string: 'bam', number: 1)
|
217
211
|
dummy.should invalidate
|
218
212
|
end
|
@@ -230,23 +224,23 @@ shared_examples_for "a model" do
|
|
230
224
|
it "marks blocked" do
|
231
225
|
dummy = @dummy.first
|
232
226
|
dummy.assign_attributes(string: 'bam', number: 1)
|
233
|
-
dummy.restrict('!').updatable?.should == false
|
227
|
+
dummy.restrict!('!').updatable?.should == false
|
234
228
|
end
|
235
229
|
|
236
230
|
it "marks allowed" do
|
237
231
|
dummy = @dummy.first
|
238
232
|
dummy.assign_attributes(string: 'bam')
|
239
|
-
dummy.restrict('!').updatable?.should == true
|
233
|
+
dummy.restrict!('!').updatable?.should == true
|
240
234
|
end
|
241
235
|
|
242
236
|
it "invalidates" do
|
243
|
-
dummy = @dummy.first.restrict('!')
|
237
|
+
dummy = @dummy.first.restrict!('!')
|
244
238
|
dummy.assign_attributes(string: 'bam', number: 1)
|
245
239
|
dummy.should invalidate
|
246
240
|
end
|
247
241
|
|
248
242
|
it "validates" do
|
249
|
-
dummy = @dummy.first.restrict('!')
|
243
|
+
dummy = @dummy.first.restrict!('!')
|
250
244
|
dummy.assign_attributes(string: 'bam')
|
251
245
|
dummy.should validate
|
252
246
|
end
|
@@ -256,7 +250,7 @@ shared_examples_for "a model" do
|
|
256
250
|
before(:each) do
|
257
251
|
@dummy.instance_eval do
|
258
252
|
protect do
|
259
|
-
can :update, string:
|
253
|
+
can :update, string: lambda {|x| x.try(:length) == 5 }
|
260
254
|
end
|
261
255
|
end
|
262
256
|
end
|
@@ -264,23 +258,23 @@ shared_examples_for "a model" do
|
|
264
258
|
it "marks blocked" do
|
265
259
|
dummy = @dummy.first
|
266
260
|
dummy.assign_attributes(string: 'bam')
|
267
|
-
dummy.restrict('!').updatable?.should == false
|
261
|
+
dummy.restrict!('!').updatable?.should == false
|
268
262
|
end
|
269
263
|
|
270
264
|
it "marks allowed" do
|
271
265
|
dummy = @dummy.first
|
272
266
|
dummy.assign_attributes(string: '12345')
|
273
|
-
dummy.restrict('!').updatable?.should == true
|
267
|
+
dummy.restrict!('!').updatable?.should == true
|
274
268
|
end
|
275
269
|
|
276
270
|
it "invalidates" do
|
277
|
-
dummy = @dummy.first.restrict('!')
|
271
|
+
dummy = @dummy.first.restrict!('!')
|
278
272
|
dummy.assign_attributes(string: 'bam')
|
279
273
|
dummy.should invalidate
|
280
274
|
end
|
281
275
|
|
282
276
|
it "validates" do
|
283
|
-
dummy = @dummy.first.restrict('!')
|
277
|
+
dummy = @dummy.first.restrict!('!')
|
284
278
|
dummy.assign_attributes(string: '12345')
|
285
279
|
dummy.should validate
|
286
280
|
end
|
@@ -298,23 +292,23 @@ shared_examples_for "a model" do
|
|
298
292
|
it "marks blocked" do
|
299
293
|
dummy = @dummy.first
|
300
294
|
dummy.assign_attributes(number: 500)
|
301
|
-
dummy.restrict('!').updatable?.should == false
|
295
|
+
dummy.restrict!('!').updatable?.should == false
|
302
296
|
end
|
303
297
|
|
304
298
|
it "marks allowed" do
|
305
299
|
dummy = @dummy.first
|
306
300
|
dummy.assign_attributes(number: 2)
|
307
|
-
dummy.restrict('!').updatable?.should == true
|
301
|
+
dummy.restrict!('!').updatable?.should == true
|
308
302
|
end
|
309
303
|
|
310
304
|
it "invalidates" do
|
311
|
-
dummy = @dummy.first.restrict('!')
|
305
|
+
dummy = @dummy.first.restrict!('!')
|
312
306
|
dummy.assign_attributes(number: 500)
|
313
307
|
dummy.should invalidate
|
314
308
|
end
|
315
309
|
|
316
310
|
it "validates" do
|
317
|
-
dummy = @dummy.first.restrict('!')
|
311
|
+
dummy = @dummy.first.restrict!('!')
|
318
312
|
dummy.assign_attributes(number: 2)
|
319
313
|
dummy.should validate
|
320
314
|
end
|
@@ -327,7 +321,7 @@ shared_examples_for "a model" do
|
|
327
321
|
protect do; end
|
328
322
|
end
|
329
323
|
|
330
|
-
@dummy.first.restrict('!').destroyable?.should == false
|
324
|
+
@dummy.first.restrict!('!').destroyable?.should == false
|
331
325
|
end
|
332
326
|
|
333
327
|
it "marks allowed" do
|
@@ -335,7 +329,7 @@ shared_examples_for "a model" do
|
|
335
329
|
protect do; can :destroy; end
|
336
330
|
end
|
337
331
|
|
338
|
-
@dummy.first.restrict('!').destroyable?.should == true
|
332
|
+
@dummy.first.restrict!('!').destroyable?.should == true
|
339
333
|
end
|
340
334
|
|
341
335
|
it "invalidates" do
|
@@ -343,7 +337,7 @@ shared_examples_for "a model" do
|
|
343
337
|
protect do; end
|
344
338
|
end
|
345
339
|
|
346
|
-
@dummy.first.restrict('!').destroy.should == false
|
340
|
+
@dummy.first.restrict!('!').destroy.should == false
|
347
341
|
end
|
348
342
|
|
349
343
|
it "validates" do
|
@@ -351,8 +345,8 @@ shared_examples_for "a model" do
|
|
351
345
|
protect do; can :destroy; end
|
352
346
|
end
|
353
347
|
|
354
|
-
dummy = @dummy.create!.restrict('!')
|
355
|
-
dummy.destroy
|
348
|
+
dummy = @dummy.create!.restrict!('!')
|
349
|
+
dummy.destroy.should == dummy
|
356
350
|
dummy.destroyed?.should == true
|
357
351
|
end
|
358
352
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boris Staal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -48,12 +48,21 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- .gitignore
|
50
50
|
- .rspec
|
51
|
+
- .travis.yml
|
52
|
+
- Appraisals
|
51
53
|
- Gemfile
|
52
54
|
- LICENSE.txt
|
53
55
|
- README.md
|
54
56
|
- Rakefile
|
57
|
+
- gemfiles/AR_3.2.gemfile
|
58
|
+
- gemfiles/AR_3.2.gemfile.lock
|
59
|
+
- gemfiles/AR_4.gemfile
|
60
|
+
- gemfiles/AR_4.gemfile.lock
|
55
61
|
- lib/protector.rb
|
56
62
|
- lib/protector/adapters/active_record.rb
|
63
|
+
- lib/protector/adapters/active_record/association.rb
|
64
|
+
- lib/protector/adapters/active_record/base.rb
|
65
|
+
- lib/protector/adapters/active_record/relation.rb
|
57
66
|
- lib/protector/dsl.rb
|
58
67
|
- lib/protector/version.rb
|
59
68
|
- locales/en.yml
|