seamusabshere-validates_decency_of 1.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/MIT-LICENSE ADDED
@@ -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,44 @@
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 String#is_decent? and 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 'seamusabshere-validates_decency_of', :lib => 'validates_decency_of', :source => 'http://gems.github.com'
17
+
18
+ Then be sure to:
19
+
20
+ rake gems:install
21
+
22
+ Example
23
+ =======
24
+
25
+ Using it from String...
26
+
27
+ >> "hello world".is_decent?
28
+ => true
29
+
30
+ >> "-s-h-i-t-t-y-".is_decent?
31
+ => false
32
+
33
+ >> "the town of Scunthorpe".is_decent?
34
+ => false
35
+
36
+ (sorry to the residents of http://en.wikipedia.org/wiki/Scunthorpe)
37
+
38
+ Using it in ActiveRecord...
39
+
40
+ class Message < ActiveRecord::Base
41
+ validates_decency_of :title, :description
42
+ end
43
+
44
+ Copyright (c) 2009 Seamus Abshere, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the validates_decency_of plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the validates_decency_of plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ValidatesDecencyOf'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'validates_decency_of'
data/lib/is_decent.rb ADDED
@@ -0,0 +1,7 @@
1
+ class String
2
+ INDECENT_WORDS = %w(shit piss fuck cunt cocksucker motherfucker tits)
3
+ def is_decent?
4
+ essence = self.downcase.gsub(/[^a-zA-Z]/, '')
5
+ INDECENT_WORDS.detect { |c| essence.include? c }.nil?
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ require 'is_decent'
2
+
3
+ module ValidatesDecencyOf
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ # Uses George Carlin's list of "seven dirty words" to "check for decency" (ahem)
10
+ # http://en.wikipedia.org/wiki/Seven_dirty_words
11
+ # Future versions will support adding/removing from this list
12
+ # Ex:
13
+ #
14
+ # class Message < ActiveRecord::Base
15
+ # validates_decency_of :title, :description
16
+ # end
17
+ #
18
+ # Configuration Options
19
+ #
20
+ # [<tt>:message</tt>] A custom error message (default is: "is invalid")
21
+ #
22
+ def validates_decency_of(*attribute_names)
23
+ options = { :message => 'is invalid' }
24
+ options.merge!(attribute_names.pop) if attribute_names.last.kind_of?(Hash)
25
+ options.merge! :on => :save
26
+ validates_each(attribute_names, options) do |record, attribute_name, value|
27
+ record.errors.add attribute_name, options[:message] unless value.to_s.is_decent?
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ ActiveRecord::Base.class_eval { include ValidatesDecencyOf }
data/rails/init.rb ADDED
@@ -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,22 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe "IsDecent" do
4
+ before do
5
+ @decent = 'Hello world'
6
+ @indecent = 'Hello f*u*c*k*i*n*g world'
7
+ end
8
+
9
+ it "should not die on empty strings" do
10
+ assert_nothing_raised do
11
+ ''.is_decent?
12
+ end
13
+ end
14
+
15
+ it "should recognize decent strings" do
16
+ assert @decent.is_decent?
17
+ end
18
+
19
+ it "should recognize indecent strings" do
20
+ assert !@indecent.is_decent?
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ module ValidatesDecencyOfTest
2
+ module Initializer
3
+ VENDOR_RAILS = File.expand_path('../../../../rails', __FILE__)
4
+ OTHER_RAILS = File.expand_path('../../../rails', __FILE__)
5
+ PLUGIN_ROOT = File.expand_path('../../', __FILE__)
6
+
7
+ def self.rails_directory
8
+ if File.exist?(VENDOR_RAILS)
9
+ VENDOR_RAILS
10
+ elsif File.exist?(OTHER_RAILS)
11
+ OTHER_RAILS
12
+ end
13
+ end
14
+
15
+ def self.load_dependencies
16
+ if rails_directory
17
+ $:.unshift(File.join(rails_directory, 'activesupport', 'lib'))
18
+ $:.unshift(File.join(rails_directory, 'activerecord', 'lib'))
19
+ else
20
+ require 'rubygems' rescue LoadError
21
+ end
22
+
23
+ require 'activesupport'
24
+ require 'activerecord'
25
+ require 'active_support/testing/core_ext/test/unit/assertions'
26
+
27
+ require 'rubygems' rescue LoadError
28
+
29
+ require 'test/spec'
30
+ require 'validates_decency_of'
31
+ end
32
+
33
+ def self.configure_database
34
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
35
+ ActiveRecord::Migration.verbose = false
36
+ end
37
+
38
+ def self.setup_database
39
+ ActiveRecord::Schema.define do
40
+ create_table :messages do |t|
41
+ t.string :title
42
+ t.string :description
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.teardown_database
48
+ ActiveRecord::Base.connection.tables.each do |table|
49
+ ActiveRecord::Base.connection.drop_table(table)
50
+ end
51
+ end
52
+
53
+ def self.start
54
+ load_dependencies
55
+ configure_database
56
+ end
57
+ end
58
+ end
59
+
60
+ ValidatesDecencyOfTest::Initializer.start
61
+
62
+ class Message < ActiveRecord::Base
63
+ validates_decency_of :title, :description
64
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe "ValidatesDecencyOf" do
4
+ before do
5
+ ValidatesDecencyOfTest::Initializer.setup_database
6
+ @decent = Message.create :title => 'Hello world', :description => 'I am clean'
7
+ @indecent = Message.create :title => 'Hello f*u*c*k*i*n*g world', :description => 'I am ~-S-h-I-t-T-y-~'
8
+ end
9
+ after do
10
+ ValidatesDecencyOfTest::Initializer.teardown_database
11
+ end
12
+
13
+ it "should not die on empty strings" do
14
+ @decent.description = nil
15
+ assert @decent.valid?
16
+ end
17
+
18
+ it "should allow decent strings" do
19
+ assert @decent.valid?
20
+ end
21
+
22
+ it "should disallow indecent strings" do
23
+ assert !@indecent.valid?
24
+ assert_not_nil @indecent.errors.on(:title)
25
+ assert_not_nil @indecent.errors.on(:description)
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "validates_decency_of"
3
+ s.version = "1.3"
4
+ s.date = "2009-01-02"
5
+ s.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."
6
+ s.email = "seamus@abshere.net"
7
+ s.homepage = "http://github.com/seamusabshere/validates_decency_of"
8
+ s.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."
9
+ s.has_rdoc = false
10
+ s.authors = "Seamus Abshere"
11
+ s.files = [
12
+ "validates_decency_of.gemspec",
13
+ "lib/is_decent.rb",
14
+ "lib/validates_decency_of.rb",
15
+ "MIT-LICENSE",
16
+ "Rakefile",
17
+ "README",
18
+ "tasks/validates_decency_of_tasks.rake",
19
+ "init.rb",
20
+ "rails/init.rb",
21
+ "test/test_helper.rb"
22
+ ]
23
+ s.test_files = [
24
+ "test/validates_decency_of_test.rb",
25
+ "test/is_decent_test.rb"
26
+ ]
27
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seamusabshere-validates_decency_of
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.3"
5
+ platform: ruby
6
+ authors:
7
+ - Seamus Abshere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-02 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ 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.
17
+ email: seamus@abshere.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - validates_decency_of.gemspec
26
+ - lib/is_decent.rb
27
+ - lib/validates_decency_of.rb
28
+ - MIT-LICENSE
29
+ - Rakefile
30
+ - README
31
+ - tasks/validates_decency_of_tasks.rake
32
+ - init.rb
33
+ - rails/init.rb
34
+ - test/test_helper.rb
35
+ has_rdoc: false
36
+ homepage: http://github.com/seamusabshere/validates_decency_of
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.2.0
58
+ signing_key:
59
+ specification_version: 2
60
+ 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.
61
+ test_files:
62
+ - test/validates_decency_of_test.rb
63
+ - test/is_decent_test.rb