From 09069e2ea1e29527affa012f4d6409455360ee34 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Sun, 18 May 2014 11:10:19 -0300 Subject: [PATCH] fixing unit tests --- plugins/display_content/lib/display_content_block.rb | 9 +++++---- plugins/display_content/test/unit/display_content_block_test.rb | 18 +++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index aae391b..20fc876 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -15,6 +15,8 @@ class DisplayContentBlock < Block N_('December') ] + AVAILABLE_SECTIONS = ['publish_date', 'title', 'abstract', 'body', 'image' ,'tags'] + settings_items :nodes, :type => Array, :default => [] settings_items :sections, :type => Array, @@ -27,7 +29,7 @@ class DisplayContentBlock < Block {:value => 'image', :checked => false}, {:value => 'tags', :checked => false}] settings_items :display_folder_children, :type => :boolean, :default => true - settings_items :types, :type => Array, :default => ['UploadedFile'] + settings_items :types, :type => Array def self.description _('Display your contents') @@ -112,12 +114,11 @@ class DisplayContentBlock < Block include ActionController::UrlWriter def content(args={}) - nodes_conditions = nodes.blank? ? '' : " articles.id IN(:nodes) " + nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) " nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children -# docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : " AND (#{nodes_conditions})"}", {:nodes => self.nodes, :types => (types || VALID_CONTENT)}]) - docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types)", {:nodes => self.nodes, :types => (self.types || VALID_CONTENT)}]) + 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)}]) block_title(title) + content_tag('ul', docs.map {|item| diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index ae1f35f..dfeb173 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -370,7 +370,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') block = DisplayContentBlock.new - block.sections = [{:name => 'Abstract', :checked => true}] + block.sections = [{:value => 'abstract', :checked => true}] block.nodes = [a1.id, a2.id] box = mock() block.stubs(:box).returns(box) @@ -423,7 +423,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Title', :checked => true}] + block.sections = [{:value => 'title', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -437,7 +437,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Abstract', :checked => true}] + block.sections = [{:value => 'abstract', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -451,7 +451,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Body', :checked => true}] + block.sections = [{:value => 'body', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -464,7 +464,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - assert block.display_section?({:name => 'Title', :checked => true}) + assert block.display_section?({:value => 'title', :checked => true}) end should 'display_attribute be true if the attribute was chosen' do @@ -472,7 +472,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - block.sections = [{:name => 'Body', :checked => true}] + block.sections = [{:value => 'body', :checked => true}] section = block.sections.first assert block.display_section?(section) @@ -483,7 +483,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - assert block.display_section?({:name => 'Publish date', :checked => true}) + assert block.display_section?({:value => 'publish_date', :checked => true}) end should 'show publishd date if defined by user' do @@ -492,7 +492,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Publish date', :checked => true}] + block.sections = [{:value => 'publish_date', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -545,13 +545,13 @@ class DisplayContentBlockTest < ActiveSupport::TestCase profile = create_user('testuser').person Article.delete_all a1 = fast_create(PluginArticle, :name => 'test article 1', :profile_id => profile.id) - env = fast_create(Environment) env.enable_plugin(Plugin1) block = DisplayContentBlock.new box = mock() box.stubs(:owner).returns(profile) + Noosfero::Plugin.stubs(:all).returns(['DisplayContentBlockTest::Plugin1']) box.stubs(:environment).returns(env) block.stubs(:box).returns(box) assert_equal [a1], block.articles_of_parent -- libgit2 0.21.2