diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index 0ea4888..5d22985 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -12,7 +12,7 @@ class RecentDocumentsBlock < Block _('This block lists your recent content.') end - settings_items :limit + settings_items :limit, :type => :integer, :default => 5 include ActionController::UrlWriter def content diff --git a/lib/acts_as_having_settings.rb b/lib/acts_as_having_settings.rb index 4b421f3..ac5e7b4 100644 --- a/lib/acts_as_having_settings.rb +++ b/lib/acts_as_having_settings.rb @@ -31,6 +31,7 @@ module ActsAsHavingSettings val.nil? ? (#{default}.is_a?(String) ? gettext(#{default}) : #{default}) : val end def #{setting}=(value) + value = nil if (value.is_a?(String) && value.blank?) send(self.class.settings_field)[:#{setting}] = self.class.acts_as_having_settings_type_cast(value, #{data_type.inspect}) end CODE diff --git a/test/unit/acts_as_having_settings_test.rb b/test/unit/acts_as_having_settings_test.rb index 696c394..65ee19d 100644 --- a/test/unit/acts_as_having_settings_test.rb +++ b/test/unit/acts_as_having_settings_test.rb @@ -7,6 +7,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase settings_items :flag, :type => :boolean settings_items :flag_disabled_by_default, :type => :boolean, :default => false settings_items :name, :type => :string, :default => N_('ENGLISH TEXT') + settings_items :number, :type => :integer end should 'store settings in a hash' do @@ -74,4 +75,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase assert_equal true, obj.flag end + should 'store nil when set to empty string' do + obj = TestClass.new + obj.number = '' + assert_nil obj.number + end + end diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index 183b1df..1f91372 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -44,6 +44,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase assert_no_match /href=.*\/testinguser\/first/, output end + should 'have a default limit of items' do + block.limit = nil + assert_equal 5, block.limit + end + should 'display a link to sitemap with title "All content"' do expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) expects(:_).with('All content').returns('All content') -- libgit2 0.21.2