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