From 287bcacd81d963996818b3157cd3799de99d01d9 2014-02-07 08:09:36 From: Jean-Philippe Lang Date: 2014-02-07 08:09:36 Subject: [PATCH] Merged r12848 (#16032). git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12853 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/repository.rb b/app/models/repository.rb index de3ca99..a752fdf 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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? diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index c269df7..1c8ce5a 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -326,6 +326,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