validates_decency_of 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ test/test.sqlite3
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,31 @@
1
+ ValidatesDecencyOf
2
+ =================
3
+
4
+ Uses George Carlin's list of "seven dirty words" to "check for decency" (ahem)
5
+ http://en.wikipedia.org/wiki/Seven_dirty_words
6
+
7
+ It gives you a new ActiveRecord validation, validates_decency_of.
8
+
9
+ Installation
10
+ ============
11
+
12
+ You should be able to run this as a plugin or as a gem.
13
+
14
+ For environment.rb:
15
+
16
+ config.gem 'validates_decency_of'
17
+
18
+ Then be sure to:
19
+
20
+ rake gems:install
21
+
22
+ Example
23
+ =======
24
+
25
+ Using it in ActiveRecord...
26
+
27
+ class Message < ActiveRecord::Base
28
+ validates_decency_of :title, :description
29
+ end
30
+
31
+ Copyright (c) 2010 Seamus Abshere, released under the MIT license.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "validates_decency_of"
8
+ gem.summary = %Q{Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.}
9
+ gem.description = %Q{Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.}
10
+ gem.email = "seamus@abshere.net"
11
+ gem.homepage = "http://github.com/seamusabshere/validates_decency_of"
12
+ gem.authors = ["Seamus Abshere"]
13
+ gem.add_dependency 'activerecord', '~>2.3.4'
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "validates_decency_of #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.5.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'validates_decency_of'
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,31 @@
1
+ # Uses George Carlin's list of "seven dirty words" to "check for decency" (ahem)
2
+ # http://en.wikipedia.org/wiki/Seven_dirty_words
3
+ # Future versions will support adding/removing from this list
4
+ # Ex:
5
+ #
6
+ # class Message < ActiveRecord::Base
7
+ # validates_decency_of :title, :description
8
+ # end
9
+ #
10
+ # Configuration Options
11
+ #
12
+ # [<tt>:message</tt>] A custom error message (default is: "is invalid")
13
+ #
14
+ module ValidatesDecencyOf
15
+ INDECENT_WORDS = %w(shit piss fuck cunt cocksucker motherfucker tits)
16
+ def self.indecent?(str)
17
+ essence = str.to_s.downcase.gsub /[^\.\'a-zA-Z]/, ''
18
+ INDECENT_WORDS.any? { |c| essence.include? c }
19
+ end
20
+
21
+ def validates_decency_of(*attribute_names)
22
+ options = { :message => 'is invalid' }
23
+ options.merge!(attribute_names.pop) if attribute_names.last.kind_of?(Hash)
24
+ options.merge! :on => :save
25
+ validates_each(attribute_names, options) do |record, attribute_name, value|
26
+ record.errors.add attribute_name, options[:message] if ValidatesDecencyOf.indecent? value
27
+ end
28
+ end
29
+ end
30
+
31
+ ActiveRecord::Base.extend ValidatesDecencyOf
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'init')
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :validates_decency_of do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'ruby-debug'
4
+ require 'active_record'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'validates_decency_of'
9
+
10
+ class Test::Unit::TestCase
11
+ end
12
+
13
+ ActiveRecord::Base.establish_connection(
14
+ 'adapter' => 'sqlite3',
15
+ 'database' => 'test/test.sqlite3'
16
+ )
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ ActiveRecord::Schema.define do
4
+ create_table :messages, :force => true do |t|
5
+ t.string :title
6
+ t.string :description
7
+ end
8
+ end
9
+
10
+ class Message < ActiveRecord::Base
11
+ validates_decency_of :title, :description
12
+ end
13
+
14
+ class TestValidatesDecencyOf < Test::Unit::TestCase
15
+ def setup
16
+ @decent = Message.new :title => 'Hello world', :description => 'I am clean'
17
+ @indecent = Message.new :title => 'Hello f*u*c*k*i*n*g world', :description => 'I am ~-S-h-I-t-T-y-~'
18
+ end
19
+
20
+ def test_should_not_die_on_empty_strings
21
+ @decent.description = nil
22
+ assert @decent.valid?
23
+ end
24
+
25
+ def test_should_allow_decent_strings
26
+ assert @decent.valid?
27
+ end
28
+
29
+ def test_should_disallow_indecent_strings
30
+ assert_equal false, @indecent.valid?
31
+ assert @indecent.errors.on(:title)
32
+ assert @indecent.errors.on(:description)
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates_decency_of
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Seamus Abshere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-15 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.4
24
+ version:
25
+ description: Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.
26
+ email: seamus@abshere.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - .gitignore
35
+ - MIT-LICENSE
36
+ - README
37
+ - Rakefile
38
+ - VERSION
39
+ - init.rb
40
+ - install.rb
41
+ - lib/validates_decency_of.rb
42
+ - rails/init.rb
43
+ - tasks/validates_decency_of_tasks.rake
44
+ - test/test_helper.rb
45
+ - test/test_validates_decency_of.rb
46
+ - uninstall.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/seamusabshere/validates_decency_of
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Rails plugin that uses George Carlin's list of seven dirty words (aka swear words, aka cuss words) to check for decency on ActiveRecord model attributes.
75
+ test_files:
76
+ - test/test_helper.rb
77
+ - test/test_validates_decency_of.rb