tpitale-constant_cache 0.1.1 → 0.1.2
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.
@@ -59,13 +59,8 @@ module ConstantCache
|
|
59
59
|
# Create a constant on the class that pointing to an instance
|
60
60
|
#
|
61
61
|
def set_instance_as_constant
|
62
|
-
unless constant_name.nil?
|
63
|
-
|
64
|
-
msg = "Constant #{self.class.to_s}::#{constant_name} has already been defined"
|
65
|
-
raise ConstantCache::DuplicateConstantError, msg
|
66
|
-
else
|
67
|
-
self.class.const_set(constant_name, self)
|
68
|
-
end
|
62
|
+
unless constant_name.nil? || self.class.const_defined?(constant_name)
|
63
|
+
self.class.const_set(constant_name, self)
|
69
64
|
end
|
70
65
|
end
|
71
66
|
|
@@ -61,9 +61,9 @@ class CacheMethodsTest < Test::Unit::TestCase
|
|
61
61
|
Cached.constants.size.should == size
|
62
62
|
end
|
63
63
|
|
64
|
-
should "raise an exception on duplicate constant" do
|
64
|
+
should "not raise an exception on duplicate constant" do
|
65
65
|
@cached.name = 'buffalo'
|
66
|
-
|
66
|
+
assert_nothing_raised do
|
67
67
|
@cached.set_instance_as_constant
|
68
68
|
@cached.set_instance_as_constant
|
69
69
|
end
|