has_handle_fallback 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/seamusabshere/has_handle_fallback"
12
12
  gem.authors = ["Seamus Abshere"]
13
13
  gem.add_dependency 'activerecord', '~>2.3.4'
14
+ gem.add_dependency 'validates_decency_of', '~>1.5.0'
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,3 +1,5 @@
1
+ require 'validates_decency_of'
2
+
1
3
  module HasHandleFallback
2
4
  SUB_REGEXP = '\_\-a-zA-Z0-9'
3
5
  REGEXP = /\A[#{SUB_REGEXP}]+\z/
@@ -22,6 +24,7 @@ module HasHandleFallback
22
24
  has_handle_fallback_options[:fallback_column] = fallback_column.to_s
23
25
  has_handle_fallback_options[:handle_column] = options.delete(:handle_column) || 'handle'
24
26
 
27
+ validates_decency_of has_handle_fallback_options[:fallback_column]
25
28
  validate :handle_is_valid
26
29
  end
27
30
  end
@@ -73,6 +76,10 @@ module HasHandleFallback
73
76
  errors.add self.class.has_handle_fallback_options[:handle_column], "must be #{HasHandleFallback::LENGTH_RANGE} characters in length"
74
77
  end
75
78
 
79
+ if ValidatesDecencyOf.indecent? raw
80
+ errors.add self.class.has_handle_fallback_options[:handle_column], "is indecent"
81
+ end
82
+
76
83
  # validates_uniqueness_of :handle, :case_sensitive => false, :allow_nil => true
77
84
  if self.class.exists? [ "#{self.class.quoted_table_name}.`#{self.class.primary_key}` <> ? AND LOWER(#{self.class.quoted_table_name}.`#{self.class.has_handle_fallback_options[:handle_column]}`) = ?", id, raw.downcase ]
78
85
  errors.add self.class.has_handle_fallback_options[:handle_column], "isn't unique"
@@ -49,6 +49,10 @@ class TestHasHandleFallback < Test::Unit::TestCase
49
49
  assert_equal false, Person.new(:email => 'pierre.bourdieu@example.com', :handle => ' ').valid?
50
50
  end
51
51
 
52
+ def test_cannot_have_indecent_handle
53
+ assert_equal false, Person.new(:email => 'pierre.bourdieu@example.com', :handle => 'scuntshorpe').valid?
54
+ end
55
+
52
56
  def test_is_careful_with_things_that_look_like_emails
53
57
  assert_equal 'pierrebourdieu', Person.new(:email => 'pierre.bourdieu@example.com').handle
54
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_handle_fallback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.3.4
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: validates_decency_of
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.0
34
+ version:
25
35
  description: Make it easy to use handles (callsigns/monikers/usernames) in URLs, even if they might be blank.
26
36
  email: seamus@abshere.net
27
37
  executables: []