Commit 09069e2ea1e29527affa012f4d6409455360ee34

Authored by Leandro Santos
1 parent b8e132f6

fixing unit tests

plugins/display_content/lib/display_content_block.rb
... ... @@ -15,6 +15,8 @@ class DisplayContentBlock < Block
15 15 N_('December')
16 16 ]
17 17  
  18 + AVAILABLE_SECTIONS = ['publish_date', 'title', 'abstract', 'body', 'image' ,'tags']
  19 +
18 20 settings_items :nodes, :type => Array, :default => []
19 21 settings_items :sections,
20 22 :type => Array,
... ... @@ -27,7 +29,7 @@ class DisplayContentBlock < Block
27 29 {:value => 'image', :checked => false},
28 30 {:value => 'tags', :checked => false}]
29 31 settings_items :display_folder_children, :type => :boolean, :default => true
30   - settings_items :types, :type => Array, :default => ['UploadedFile']
  32 + settings_items :types, :type => Array
31 33  
32 34 def self.description
33 35 _('Display your contents')
... ... @@ -112,12 +114,11 @@ class DisplayContentBlock < Block
112 114  
113 115 include ActionController::UrlWriter
114 116 def content(args={})
115   - nodes_conditions = nodes.blank? ? '' : " articles.id IN(:nodes) "
  117 + nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) "
116 118 nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children
117 119  
118   -# docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : " AND (#{nodes_conditions})"}", {:nodes => self.nodes, :types => (types || VALID_CONTENT)}])
119 120  
120   - docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types)", {:nodes => self.nodes, :types => (self.types || VALID_CONTENT)}])
  121 + docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => (self.types.blank? ? VALID_CONTENT : self.types)}])
121 122  
122 123 block_title(title) +
123 124 content_tag('ul', docs.map {|item|
... ...
plugins/display_content/test/unit/display_content_block_test.rb
... ... @@ -370,7 +370,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
370 370 a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2')
371 371  
372 372 block = DisplayContentBlock.new
373   - block.sections = [{:name => 'Abstract', :checked => true}]
  373 + block.sections = [{:value => 'abstract', :checked => true}]
374 374 block.nodes = [a1.id, a2.id]
375 375 box = mock()
376 376 block.stubs(:box).returns(box)
... ... @@ -423,7 +423,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
423 423  
424 424 block = DisplayContentBlock.new
425 425 block.nodes = [a.id]
426   - block.sections = [{:name => 'Title', :checked => true}]
  426 + block.sections = [{:value => 'title', :checked => true}]
427 427 box = mock()
428 428 block.stubs(:box).returns(box)
429 429 box.stubs(:owner).returns(profile)
... ... @@ -437,7 +437,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
437 437  
438 438 block = DisplayContentBlock.new
439 439 block.nodes = [a.id]
440   - block.sections = [{:name => 'Abstract', :checked => true}]
  440 + block.sections = [{:value => 'abstract', :checked => true}]
441 441 box = mock()
442 442 block.stubs(:box).returns(box)
443 443 box.stubs(:owner).returns(profile)
... ... @@ -451,7 +451,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
451 451  
452 452 block = DisplayContentBlock.new
453 453 block.nodes = [a.id]
454   - block.sections = [{:name => 'Body', :checked => true}]
  454 + block.sections = [{:value => 'body', :checked => true}]
455 455 box = mock()
456 456 block.stubs(:box).returns(box)
457 457 box.stubs(:owner).returns(profile)
... ... @@ -464,7 +464,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
464 464  
465 465 block = DisplayContentBlock.new
466 466  
467   - assert block.display_section?({:name => 'Title', :checked => true})
  467 + assert block.display_section?({:value => 'title', :checked => true})
468 468 end
469 469  
470 470 should 'display_attribute be true if the attribute was chosen' do
... ... @@ -472,7 +472,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
472 472  
473 473 block = DisplayContentBlock.new
474 474  
475   - block.sections = [{:name => 'Body', :checked => true}]
  475 + block.sections = [{:value => 'body', :checked => true}]
476 476 section = block.sections.first
477 477  
478 478 assert block.display_section?(section)
... ... @@ -483,7 +483,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
483 483  
484 484 block = DisplayContentBlock.new
485 485  
486   - assert block.display_section?({:name => 'Publish date', :checked => true})
  486 + assert block.display_section?({:value => 'publish_date', :checked => true})
487 487 end
488 488  
489 489 should 'show publishd date if defined by user' do
... ... @@ -492,7 +492,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
492 492  
493 493 block = DisplayContentBlock.new
494 494 block.nodes = [a.id]
495   - block.sections = [{:name => 'Publish date', :checked => true}]
  495 + block.sections = [{:value => 'publish_date', :checked => true}]
496 496 box = mock()
497 497 block.stubs(:box).returns(box)
498 498 box.stubs(:owner).returns(profile)
... ... @@ -545,13 +545,13 @@ class DisplayContentBlockTest < ActiveSupport::TestCase
545 545 profile = create_user('testuser').person
546 546 Article.delete_all
547 547 a1 = fast_create(PluginArticle, :name => 'test article 1', :profile_id => profile.id)
548   -
549 548 env = fast_create(Environment)
550 549 env.enable_plugin(Plugin1)
551 550  
552 551 block = DisplayContentBlock.new
553 552 box = mock()
554 553 box.stubs(:owner).returns(profile)
  554 + Noosfero::Plugin.stubs(:all).returns(['DisplayContentBlockTest::Plugin1'])
555 555 box.stubs(:environment).returns(env)
556 556 block.stubs(:box).returns(box)
557 557 assert_equal [a1], block.articles_of_parent
... ...