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 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.2
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bartzon-validates_blacklist}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bart Zonneveld"]
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bartzon-validates_blacklist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bart Zonneveld