]> source.dussan.org Git - redmine.git/commitdiff
Make sure that Repository#extra_info returns a Hash or nil (#16032).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 6 Feb 2014 20:23:06 +0000 (20:23 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 6 Feb 2014 20:23:06 +0000 (20:23 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12848 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository.rb
test/unit/repository_test.rb

index 0185ca68380cf7532bee12233a2242d1c98d4bff..cfdfba57bee3a8a34f9b2c292c9fa2126aecb955 100644 (file)
@@ -153,6 +153,12 @@ class Repository < ActiveRecord::Base
     end
   end
 
+  # TODO: should return an empty hash instead of nil to avoid many ||{}
+  def extra_info
+    h = read_attribute(:extra_info)
+    h.is_a?(Hash) ? h : nil
+  end
+
   def merge_extra_info(arg)
     h = extra_info || {}
     return h if arg.nil?
index e46f1c54c9808f802f06a78c6567a67bd9098669..8d2e7866acf4702b4c0eb04136b6c98d56c06dc6 100644 (file)
@@ -348,6 +348,12 @@ class RepositoryTest < ActiveSupport::TestCase
     assert_equal true, klass.scm_available
   end
 
+  def test_extra_info_should_not_return_non_hash_value
+    repo = Repository.new
+    repo.extra_info = "foo"
+    assert_nil repo.extra_info
+  end
+
   def test_merge_extra_info
     repo = Repository::Subversion.new(:project => Project.find(3))
     assert !repo.save