bartzon-validates_blacklist 0.0.2 → 0.0.3
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 +9 -1
- data/VERSION +1 -1
- data/bartzon-validates_blacklist.gemspec +1 -1
- data/lib/validates_blacklist/validates.rb +6 -0
- data/spec/validates_blacklist_spec.rb +17 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -25,4 +25,12 @@ Add the follow to each model you want to have validated:
|
|
25
25
|
:message => "" # optional, defaults to "is not allowed"
|
26
26
|
:scope => nil # optional, set this to for instance a class name to allow blacklist validation per class
|
27
27
|
|
28
|
-
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Adding a blacklisted value is as easy as:
|
31
|
+
|
32
|
+
User.add_to_blacklist('value')
|
33
|
+
|
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
|
+
|
36
|
+
User.add_to_blacklist('value', :scope => 'Foo)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -31,6 +31,12 @@ module ValidatesBlacklist
|
|
31
31
|
end
|
32
32
|
list.map(&:value).map(&:downcase)
|
33
33
|
end
|
34
|
+
|
35
|
+
def add_to_blacklist(value, options={})
|
36
|
+
scope = blacklist_options[:scope] if blacklist_options[:scope]
|
37
|
+
scope = options[:scope] if options[:scope]
|
38
|
+
ValidatesBlacklist::Blacklist.create!(:value => value.downcase, :scope => scope)
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
module InstanceMethods
|
@@ -107,5 +107,22 @@ describe "ValidatesBlacklist" do
|
|
107
107
|
it "should return the correct scoped blacklist" do
|
108
108
|
UserWithAllOptions.blacklist.should == ['u_scoped']
|
109
109
|
end
|
110
|
+
|
111
|
+
describe "when adding blacklist values" do
|
112
|
+
it "should allow adding without a scope" do
|
113
|
+
ValidatesBlacklist::Blacklist.should_receive(:create!).with(:value => 'foo', :scope => nil)
|
114
|
+
User.add_to_blacklist('Foo')
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should allow adding with an inherited scope" do
|
118
|
+
ValidatesBlacklist::Blacklist.should_receive(:create!).with(:value => 'foo', :scope => 'User')
|
119
|
+
UserWithAllOptions.add_to_blacklist('Foo')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should allow adding with an explicit scope" do
|
123
|
+
ValidatesBlacklist::Blacklist.should_receive(:create!).with(:value => 'foo', :scope => 'Zoink')
|
124
|
+
UserWithAllOptions.add_to_blacklist('Foo', :scope => 'Zoink')
|
125
|
+
end
|
126
|
+
end
|
110
127
|
end
|
111
128
|
end
|