Commit 38f01f5cbaa709bf65b1a824e8447bf509c3f045

Authored by Antonio Terceiro
1 parent e9e51add

ActionItem1146: limit must be a number, or nil

app/models/recent_documents_block.rb
@@ -12,7 +12,7 @@ class RecentDocumentsBlock < Block @@ -12,7 +12,7 @@ class RecentDocumentsBlock < Block
12 _('This block lists your recent content.') 12 _('This block lists your recent content.')
13 end 13 end
14 14
15 - settings_items :limit 15 + settings_items :limit, :type => :integer, :default => 5
16 16
17 include ActionController::UrlWriter 17 include ActionController::UrlWriter
18 def content 18 def content
lib/acts_as_having_settings.rb
@@ -31,6 +31,7 @@ module ActsAsHavingSettings @@ -31,6 +31,7 @@ module ActsAsHavingSettings
31 val.nil? ? (#{default}.is_a?(String) ? gettext(#{default}) : #{default}) : val 31 val.nil? ? (#{default}.is_a?(String) ? gettext(#{default}) : #{default}) : val
32 end 32 end
33 def #{setting}=(value) 33 def #{setting}=(value)
  34 + value = nil if (value.is_a?(String) && value.blank?)
34 send(self.class.settings_field)[:#{setting}] = self.class.acts_as_having_settings_type_cast(value, #{data_type.inspect}) 35 send(self.class.settings_field)[:#{setting}] = self.class.acts_as_having_settings_type_cast(value, #{data_type.inspect})
35 end 36 end
36 CODE 37 CODE
test/unit/acts_as_having_settings_test.rb
@@ -7,6 +7,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase @@ -7,6 +7,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase
7 settings_items :flag, :type => :boolean 7 settings_items :flag, :type => :boolean
8 settings_items :flag_disabled_by_default, :type => :boolean, :default => false 8 settings_items :flag_disabled_by_default, :type => :boolean, :default => false
9 settings_items :name, :type => :string, :default => N_('ENGLISH TEXT') 9 settings_items :name, :type => :string, :default => N_('ENGLISH TEXT')
  10 + settings_items :number, :type => :integer
10 end 11 end
11 12
12 should 'store settings in a hash' do 13 should 'store settings in a hash' do
@@ -74,4 +75,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase @@ -74,4 +75,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase
74 assert_equal true, obj.flag 75 assert_equal true, obj.flag
75 end 76 end
76 77
  78 + should 'store nil when set to empty string' do
  79 + obj = TestClass.new
  80 + obj.number = ''
  81 + assert_nil obj.number
  82 + end
  83 +
77 end 84 end
test/unit/recent_documents_block_test.rb
@@ -44,6 +44,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase @@ -44,6 +44,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase
44 assert_no_match /href=.*\/testinguser\/first/, output 44 assert_no_match /href=.*\/testinguser\/first/, output
45 end 45 end
46 46
  47 + should 'have a default limit of items' do
  48 + block.limit = nil
  49 + assert_equal 5, block.limit
  50 + end
  51 +
47 should 'display a link to sitemap with title "All content"' do 52 should 'display a link to sitemap with title "All content"' do
48 expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) 53 expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)
49 expects(:_).with('All content').returns('All content') 54 expects(:_).with('All content').returns('All content')