bartzon-validates_blacklist 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/bartzon-validates_blacklist.gemspec +1 -1
- data/lib/validates_blacklist/validates.rb +3 -0
- data/spec/validates_blacklist_spec.rb +15 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Add the follow to each model you want to have validated:
|
|
29
29
|
|
30
30
|
Adding a blacklisted value is as easy as:
|
31
31
|
|
32
|
-
|
32
|
+
User.add_to_blacklist('value')
|
33
33
|
|
34
34
|
Per default the scope will be inherited from the options specified in the call to validates_blacklist. This can be changed by doing:
|
35
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -42,11 +42,14 @@ module ValidatesBlacklist
|
|
42
42
|
module InstanceMethods
|
43
43
|
private
|
44
44
|
def blacklisted_columns
|
45
|
+
result = true
|
45
46
|
blacklist_options[:columns].each do |field|
|
46
47
|
if self.class.blacklisted?(self.send(field))
|
47
48
|
errors.add(field, blacklist_options[:message])
|
49
|
+
result = false
|
48
50
|
end
|
49
51
|
end
|
52
|
+
result
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -15,6 +15,14 @@ class UserWithAllOptions < UserWithoutOptions
|
|
15
15
|
:scope => 'User'
|
16
16
|
end
|
17
17
|
|
18
|
+
class UserWithValidations < User
|
19
|
+
validate :other_validation
|
20
|
+
|
21
|
+
def other_validation
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
describe "ValidatesBlacklist" do
|
19
27
|
def create_blacklist(value, scope=nil)
|
20
28
|
ValidatesBlacklist::Blacklist.create!(:value => value, :scope => scope)
|
@@ -47,6 +55,13 @@ describe "ValidatesBlacklist" do
|
|
47
55
|
user = User.new
|
48
56
|
user.errors.should be_empty
|
49
57
|
end
|
58
|
+
|
59
|
+
it "should allow multiple validate calls" do
|
60
|
+
user = UserWithValidations.new
|
61
|
+
user.should_receive(:other_validation).once
|
62
|
+
user.should_receive(:blacklisted_columns).once
|
63
|
+
user.valid?
|
64
|
+
end
|
50
65
|
|
51
66
|
describe "a model with blacklists" do
|
52
67
|
before(:each) do
|