Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made human_(attr) return nil if no (attr)_cd value is set; added test…

… to cover this case
  • Loading branch information...
commit 8b5a024343c81a78723f9f3ddc6f805471495963 1 parent ae480ad
Mike Brown authored
Showing with 6 additions and 0 deletions.
  1. +1 −0  lib/simple_enum.rb
  2. +5 −0 test/simple_enum_test.rb
View
1  lib/simple_enum.rb
@@ -209,6 +209,7 @@ def as_enum(enum_cd, values, options = {})
enum_attr = :"#{attr_name.downcase}_enum_hash"
define_method("human_#{enum_cd}") do
+ return nil if self.send(enum_cd).nil?
self.class.human_enum_name(attr_name, self.send(enum_cd))
end
View
5 test/simple_enum_test.rb
@@ -232,4 +232,9 @@ def test_deprecation_warning_when_using_enum_name_eq_column_name
ActiveSupport::Deprecation.behavior = original_behavior
end
end
+
+ def test_human_name_for_nil_value
+ d = Dummy.new
+ assert_nil(d.human_gender)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.