Commit 38f01f5cbaa709bf65b1a824e8447bf509c3f045
1 parent
e9e51add
Exists in
master
and in
29 other branches
ActionItem1146: limit must be a number, or nil
Showing
4 changed files
with
14 additions
and
1 deletions
Show diff stats
app/models/recent_documents_block.rb
lib/acts_as_having_settings.rb
... | ... | @@ -31,6 +31,7 @@ module ActsAsHavingSettings |
31 | 31 | val.nil? ? (#{default}.is_a?(String) ? gettext(#{default}) : #{default}) : val |
32 | 32 | end |
33 | 33 | def #{setting}=(value) |
34 | + value = nil if (value.is_a?(String) && value.blank?) | |
34 | 35 | send(self.class.settings_field)[:#{setting}] = self.class.acts_as_having_settings_type_cast(value, #{data_type.inspect}) |
35 | 36 | end |
36 | 37 | CODE | ... | ... |
test/unit/acts_as_having_settings_test.rb
... | ... | @@ -7,6 +7,7 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase |
7 | 7 | settings_items :flag, :type => :boolean |
8 | 8 | settings_items :flag_disabled_by_default, :type => :boolean, :default => false |
9 | 9 | settings_items :name, :type => :string, :default => N_('ENGLISH TEXT') |
10 | + settings_items :number, :type => :integer | |
10 | 11 | end |
11 | 12 | |
12 | 13 | should 'store settings in a hash' do |
... | ... | @@ -74,4 +75,10 @@ class ActsAsHavingSettingsTest < Test::Unit::TestCase |
74 | 75 | assert_equal true, obj.flag |
75 | 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 | 84 | end | ... | ... |
test/unit/recent_documents_block_test.rb
... | ... | @@ -44,6 +44,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
44 | 44 | assert_no_match /href=.*\/testinguser\/first/, output |
45 | 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 | 52 | should 'display a link to sitemap with title "All content"' do |
48 | 53 | expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) |
49 | 54 | expects(:_).with('All content').returns('All content') | ... | ... |