Commit 70820f22578cd783089730f8857663939b0cdae3

Authored by Leandro Santos
1 parent 0759f7f1

add unit tests related with block store for Block model

Showing 2 changed files with 18 additions and 76 deletions   Show diff stats
app/models/block.rb
... ... @@ -132,26 +132,6 @@ class Block < ActiveRecord::Base
132 132 self.name.gsub('Block','')
133 133 end
134 134  
135   - #FIXME make this test
136   - def self.default_preview
137   - "/images/block_preview.png"
138   - end
139   -
140   -# #FIXME remove this code
141   -# def self.previews_path
142   -# previews = Dir.glob(File.join(images_filesystem_path, 'previews/*')).map do |path|
143   -# File.join(images_base_url_path, 'previews', File.basename(path))
144   -# end
145   -# end
146   -
147   -# #FIXME remove this code
148   -# def self.icon_path
149   -# icon_path = File.join(images_base_url_path, 'icon.png')
150   -#puts File.join(images_filesystem_path, 'icon.png').inspect
151   -##"/plugins/container_block/images/handle_e.png"
152   -# File.exists?(File.join(images_filesystem_path, 'icon.png')) ? icon_path : default_icon_path
153   -# end
154   -
155 135 # Returns the content to be used for this block.
156 136 #
157 137 # This method can return several types of objects:
... ... @@ -267,21 +247,23 @@ class Block < ActiveRecord::Base
267 247 duplicated_block
268 248 end
269 249  
270   - #FIXME make this test
271 250 def self.previews_path
272 251 base_name = self.name.split('::').last.underscore
273 252 Dir.glob(File.join('blocks', base_name,'previews/*'))
274 253 end
275 254  
276   - #FIXME make this test
277 255 def self.icon_path
278 256 basename = self.name.split('::').last.underscore
279 257 File.join('blocks', basename, 'icon.png')
280 258 end
281 259  
282   - #FIXME make this test
283 260 def self.default_icon_path
284 261 'icon_block.png'
285 262 end
286 263  
  264 + def self.default_preview_path
  265 + "block_preview.png"
  266 + end
  267 +
  268 +
287 269 end
... ...
test/unit/block_test.rb
... ... @@ -294,69 +294,29 @@ class BlockTest < ActiveSupport::TestCase
294 294  
295 295 should 'previews_path return the array of preview images' do
296 296 class NewBlock < Block; end
297   - Dir.stubs(:glob).returns(['/path/1', 'path/2'])
298   - expected = ['blocks/block_test/new_block/previews/1', 'blocks/block_test/new_block/previews/2']
  297 + expected = ['path/1', 'path/2']
  298 + Dir.expects(:glob).with('blocks/new_block/previews/*').returns(expected)
299 299 assert_equivalent expected, NewBlock.previews_path
300 300 end
301 301  
302 302 should 'return the icon block path' do
303 303 class NewBlock < Block; end
304   - File.expects(:exists?).returns(true)
305   - expected_path = 'path/icon.png'
306   - File.stubs(:join).returns(expected_path)
307   - assert_equal expected_path, NewBlock.icon_path
308   - end
309   -
310   - should 'return the icon block path for plugin blocks' do
311   - module SomeContext class SomeContext::CustomBlock1 < Block; end;;end
312   -# class SomeContext::CustomBlock2 < Block; end;
313   -#BreadcrumbsPlugin::ContentBreadcrumbsBlock
314   - class Plugin1 < Noosfero::Plugin
315   - def self.extra_blocks
316   - {
317   - CustomBlock1 => {},
318   - CustomBlock2 => {}
319   - }
320   - end
321   - end
322   -
323   -#Block.stubs(:images_filesystem_path).returns('/path')
324   -#CustomBlock1.stubs(:images_filesystem_path).returns('/path')
325   -File.stubs(:exists?).with('/home/81665687568/Owncloud/projetos/noosfero/public/images/blocks/block_test/custom_block1/icon.pn').returns(true)
326   -# File.exists?(File.join(images_filesystem_path, 'icon.png')) ? icon_path : default_icon_path
327   -
328   -
329   -# def self.images_filesystem_path
330   -# Rails.root.join('public', 'images', images_base_url_path)
331   -# end
332   -#
333   -# def self.images_base_url_path
334   -# File.join('blocks', self.name.underscore)
335   -# end
336   -
337   -
338   - Environment.destroy_all
339   - e = fast_create(Environment, :is_default => true)
340   -
341   -# Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1', 'ProfileTest::Plugin2'])
342   - e.enable_plugin(Plugin1)
343   -
344   -# class NewBlock < Block; end
345   -# Dir.stubs(:glob).returns(['/path/1', 'path/2'])
346   -# expected = ['blocks/block_test/new_block/previews/1', 'blocks/block_test/new_block/previews/2']
347   -# class NewBlock < Block; end
348   -# File.expects(:exists?).returns(true)
349   -# expected_path = 'path/icon.png'
350   -# File.stubs(:join).returns(expected_path)
351   -#/plugins/container_block/images/handle_e.png
352   - assert_equal '', SomeContext::CustomBlock1.icon_path
  304 + assert_equal 'blocks/new_block/icon.png', NewBlock.icon_path
353 305 end
354 306  
  307 + should 'return the icon block path for blocks inside modules' do
  308 + module SomeModule class NewBlock < Block; end; end
  309 + assert_equal 'blocks/new_block/icon.png', SomeModule::NewBlock.icon_path
  310 + end
355 311  
356 312 should 'return the default icon for blocks without icon' do
357 313 class NewBlock < Block; end
358   - File.expects(:exists?).returns(false)
359   - assert_equal 'icon_block.png', NewBlock.icon_path
  314 + assert_equal 'icon_block.png', NewBlock.default_icon_path
  315 + end
  316 +
  317 + should 'return the default preview path for blocks without preview images' do
  318 + class NewBlock < Block; end
  319 + assert_equal 'block_preview.png', NewBlock.default_preview_path
360 320 end
361 321  
362 322 should 'previews_path return an empty array if there is no preview image' do
... ...