has_handle_fallback 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -21,6 +21,7 @@ module HasHandleFallback
21
21
  class_eval do
22
22
  cattr_accessor :has_handle_fallback_options
23
23
  self.has_handle_fallback_options = {}
24
+ has_handle_fallback_options[:required] = options.delete(:required) || false
24
25
  has_handle_fallback_options[:fallback_column] = fallback_column.to_s
25
26
  has_handle_fallback_options[:handle_column] = options.delete(:handle_column) || 'handle'
26
27
 
@@ -53,8 +54,8 @@ module HasHandleFallback
53
54
  end
54
55
 
55
56
  # allow nils but not blanks
56
- if !raw.nil? and raw.blank?
57
- errors.add self.class.has_handle_fallback_options[:handle_column], "can't be blank if you're presented the opportunity to set it"
57
+ if raw.blank? and (!raw.nil? or has_handle_fallback_options[:required])
58
+ errors.add self.class.has_handle_fallback_options[:handle_column], "can't be blank"
58
59
  end
59
60
 
60
61
  # trapdoor for nil handles
@@ -17,7 +17,7 @@ class Person < ActiveRecord::Base
17
17
  end
18
18
 
19
19
  class Cat < ActiveRecord::Base
20
- has_handle_fallback :name, :handle_column => 'moniker'
20
+ has_handle_fallback :name, :handle_column => 'moniker', :required => true
21
21
  end
22
22
 
23
23
  class TestHasHandleFallback < Test::Unit::TestCase
@@ -36,6 +36,11 @@ class TestHasHandleFallback < Test::Unit::TestCase
36
36
  assert_equal 'PierreBourdieu', pierre.handle
37
37
  end
38
38
 
39
+ def test_can_in_fact_require_handle
40
+ pierre = Cat.new :name => 'Pierre Bourdieu'
41
+ assert_equal false, pierre.valid?
42
+ end
43
+
39
44
  def test_has_validations
40
45
  assert_equal true, Person.new(:email => 'pierre.bourdieu@example.com', :handle => 'Pierre-Bourdieu_99').valid?
41
46
  assert_equal false, Person.new(:email => 'pierre.bourdieu@example.com', :handle => 'Pierre:Bourdieu_99').valid?
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere