Commit 486e450c98f4730bd066262e929845ce4baad4fc

Authored by Daniela Feitosa
1 parent 083d29d3

blocks: make sure limit is integer on get_limit

Blocks configured before the definition of limit type were strings and were
crashing
Showing 2 changed files with 8 additions and 1 deletions   Show diff stats
app/models/block.rb
@@ -23,7 +23,7 @@ class Block < ActiveRecord::Base @@ -23,7 +23,7 @@ class Block < ActiveRecord::Base
23 end 23 end
24 24
25 def get_limit 25 def get_limit
26 - [0,limit].max 26 + [0,limit.to_i].max
27 end 27 end
28 28
29 def embed_code 29 def embed_code
test/unit/block_test.rb
@@ -330,4 +330,11 @@ class BlockTest < ActiveSupport::TestCase @@ -330,4 +330,11 @@ class BlockTest < ActiveSupport::TestCase
330 block.save! 330 block.save!
331 assert !block.display_to_user?(person_friend) 331 assert !block.display_to_user?(person_friend)
332 end 332 end
  333 +
  334 + should 'get limit as a number when limit is string' do
  335 + block = RecentDocumentsBlock.new
  336 + block.settings[:limit] = '5'
  337 + assert block.get_limit.is_a?(Fixnum)
  338 + end
  339 +
333 end 340 end