Commit 0cdd5cb412578111d4ce9ee124bf068852eb2e7e

Authored by Leandro Santos
Committed by Antonio Terceiro
1 parent 7b716ef9

Add article block on environment context. Closes ActionItem1460

app/controllers/admin/environment_design_controller.rb
... ... @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController
3 3 protect 'edit_environment_design', :environment
4 4  
5 5 def available_blocks
6   - @available_blocks ||= [ LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock ]
  6 + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock ]
7 7 end
8 8  
9 9 end
... ...
app/models/article_block.rb
... ... @@ -40,4 +40,9 @@ class ArticleBlock < Block
40 40 @article = obj
41 41 end
42 42  
  43 + def available_articles
  44 + return [] if self.box.nil? or self.box.owner.nil?
  45 + self.box.owner.kind_of?(Environment) ? self.box.owner.portal_community.articles : self.box.owner.articles
  46 + end
  47 +
43 48 end
... ...
app/views/box_organizer/_article_block.rhtml
1   -<% articles = @block.box.owner.articles.select {|article| !article.folder? } %>
2   -<%= select('block', 'article_id', articles.map {|item| [ item.path, item.id]}) %>
  1 +
  2 +<% if @block.box.owner.kind_of?(Environment) and @block.box.owner.portal_community.nil? %>
  3 + <p id='no_portal_community'>
  4 + <%= _("You don't have an community defined as the portal community. Define it before use this block properly.") %>
  5 + </p>
  6 +<% else %>
  7 + <% articles = @block.available_articles.select {|article| !article.folder? } %>
  8 + <%= select('block', 'article_id', articles.map {|item| [ item.path, item.id]}) %>
  9 +<% end %>
... ...
test/functional/environment_design_controller_test.rb
... ... @@ -5,6 +5,9 @@ require &#39;environment_design_controller&#39;
5 5 class EnvironmentDesignController; def rescue_action(e) raise e end; end
6 6  
7 7 class EnvironmentDesignControllerTest < Test::Unit::TestCase
  8 +
  9 + ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock ]
  10 +
8 11 def setup
9 12 @controller = EnvironmentDesignController.new
10 13 @request = ActionController::TestRequest.new
... ... @@ -23,12 +26,14 @@ class EnvironmentDesignControllerTest &lt; Test::Unit::TestCase
23 26 assert(@controller.available_blocks.all? {|item| item.new.is_a? Block})
24 27 end
25 28  
26   - should 'LinkListBlock is available' do
27   - assert_includes @controller.available_blocks, LinkListBlock
  29 + ALL_BLOCKS.map do |block|
  30 + define_method "test_should_#{block.to_s}_is_available" do
  31 + assert_includes @controller.available_blocks,block
  32 + end
28 33 end
29 34  
30   - should 'SlideshowBlock be available' do
31   - assert_includes @controller.available_blocks, SlideshowBlock
  35 + should 'all available block in test' do
  36 + assert_equal ALL_BLOCKS, @controller.available_blocks
32 37 end
33 38  
34 39 should 'be able to edit LinkListBlock' do
... ... @@ -51,6 +56,125 @@ class EnvironmentDesignControllerTest &lt; Test::Unit::TestCase
51 56 assert_equal [{'name' => 'link 1', 'address' => '/address_1'}], l.links
52 57 end
53 58  
  59 + should 'be able to edit ArticleBlock with portal community' do
  60 + login_as(create_admin_user(Environment.default))
  61 + l = ArticleBlock.create!
  62 + e = Environment.default
  63 + e.boxes.create!
  64 + e.boxes.first.blocks << l
  65 + community = mock()
  66 + Environment.any_instance.stubs(:portal_community).returns(community)
  67 + article = mock()
  68 + community.stubs(:articles).returns([article])
  69 + article.expects(:folder?).returns(false)
  70 + article.expects(:path).returns('some_path')
  71 + article.expects(:id).returns(1)
  72 + get :edit, :id => l.id
  73 + assert_tag :tag => 'select', :attributes => { :id => 'block_article_id' }
  74 + end
  75 +
  76 + should 'be able to edit ArticleBlock without portal community' do
  77 + login_as(create_admin_user(Environment.default))
  78 + l = ArticleBlock.create!
  79 + e = Environment.default
  80 + e.boxes.create!
  81 + e.boxes.first.blocks << l
  82 + community = mock()
  83 + Environment.any_instance.expects(:portal_community).returns(nil)
  84 + get :edit, :id => l.id
  85 + assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' }
  86 + end
  87 +
  88 + should 'be able to edit EnvironmentStatisticsBlock' do
  89 + login_as(create_admin_user(Environment.default))
  90 + b = EnvironmentStatisticsBlock.create!
  91 + e = Environment.default
  92 + e.boxes.create!
  93 + e.boxes.first.blocks << b
  94 + get :edit, :id => b.id
  95 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  96 + end
  97 +
  98 + should 'be able to edit EnterprisesBlock' do
  99 + login_as(create_admin_user(Environment.default))
  100 + b = EnterprisesBlock.create!
  101 + e = Environment.default
  102 + e.boxes.create!
  103 + e.boxes.first.blocks << b
  104 + get :edit, :id => b.id
  105 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  106 + end
  107 +
  108 + should 'be able to edit PeopleBlock' do
  109 + login_as(create_admin_user(Environment.default))
  110 + b = PeopleBlock.create!
  111 + e = Environment.default
  112 + e.boxes.create!
  113 + e.boxes.first.blocks << b
  114 + get :edit, :id => b.id
  115 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  116 + end
  117 +
  118 + should 'be able to edit SlideshowBlock' do
  119 + login_as(create_admin_user(Environment.default))
  120 + b = SlideshowBlock.create!
  121 + e = Environment.default
  122 + e.boxes.create!
  123 + e.boxes.first.blocks << b
  124 + get :edit, :id => b.id
  125 + assert_tag :tag => 'select', :attributes => { :id => 'block_gallery_id' }
  126 + end
  127 +
  128 + should 'be able to edit LoginBlock' do
  129 + login_as(create_admin_user(Environment.default))
  130 + b = LoginBlock.create!
  131 + e = Environment.default
  132 + e.boxes.create!
  133 + e.boxes.first.blocks << b
  134 + get :edit, :id => b.id
  135 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  136 + end
  137 +
  138 + should 'be able to edit RecentDocumentsBlock' do
  139 + login_as(create_admin_user(Environment.default))
  140 + b = RecentDocumentsBlock.create!
  141 + e = Environment.default
  142 + e.boxes.create!
  143 + e.boxes.first.blocks << b
  144 + get :edit, :id => b.id
  145 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  146 + end
  147 +
  148 + should 'be able to edit CommunitiesBlock' do
  149 + login_as(create_admin_user(Environment.default))
  150 + b = CommunitiesBlock.create!
  151 + e = Environment.default
  152 + e.boxes.create!
  153 + e.boxes.first.blocks << b
  154 + get :edit, :id => b.id
  155 + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' }
  156 + end
  157 +
  158 + should 'be able to edit SellersSearchBlock' do
  159 + login_as(create_admin_user(Environment.default))
  160 + b = SellersSearchBlock.create!
  161 + e = Environment.default
  162 + e.boxes.create!
  163 + e.boxes.first.blocks << b
  164 + get :edit, :id => b.id
  165 + assert_tag :tag => 'input', :attributes => { :id => 'block_title' }
  166 + end
  167 +
  168 + should 'be able to edit FeedReaderBlock' do
  169 + login_as(create_admin_user(Environment.default))
  170 + b = FeedReaderBlock.create!
  171 + e = Environment.default
  172 + e.boxes.create!
  173 + e.boxes.first.blocks << b
  174 + get :edit, :id => b.id
  175 + assert_tag :tag => 'input', :attributes => { :id => 'block_address' }
  176 + end
  177 +
54 178 should 'create back link to environment control panel' do
55 179 Environment.default.boxes.create!.blocks << CommunitiesBlock.new
56 180 Environment.default.boxes.create!.blocks << EnterprisesBlock.new
... ... @@ -61,4 +185,11 @@ class EnvironmentDesignControllerTest &lt; Test::Unit::TestCase
61 185 assert_tag :tag => 'a', :attributes => {:href => '/admin'}, :child => {:tag => 'span', :content => "Back to control panel"}
62 186 end
63 187  
  188 + should 'render add a new block functionality' do
  189 + login_as(create_admin_user(Environment.default))
  190 + get :add_block
  191 +
  192 + assert_response :success
  193 + assert_template 'add_block'
  194 + end
64 195 end
... ...
test/unit/article_block_test.rb
... ... @@ -52,4 +52,33 @@ class ArticleBlockTest &lt; Test::Unit::TestCase
52 52 assert_nil block.article_id
53 53 end
54 54  
  55 + should "take available articles with a person as the box owner" do
  56 + person = create_user('testuser').person
  57 + person.articles.delete_all
  58 + assert_equal [], person.articles
  59 + a = person.articles.create!(:name => 'test')
  60 + block = ArticleBlock.create(:article => a)
  61 + person.boxes.first.blocks << block
  62 + block.save!
  63 +
  64 + block.reload
  65 + assert_equal [a],block.available_articles
  66 + end
  67 +
  68 + should "take available articles with an environment as the box owner" do
  69 + env = Environment.create!(:name => 'test env')
  70 + env.articles.destroy_all
  71 + assert_equal [], env.articles
  72 + community = fast_create(Community)
  73 + a = community.articles.create!(:name => 'test')
  74 + env.portal_community=community
  75 + env.save
  76 + block = ArticleBlock.create(:article => a)
  77 + env.boxes.first.blocks << block
  78 + block.save!
  79 +
  80 + block.reload
  81 + assert_equal [a],block.available_articles
  82 + end
  83 +
55 84 end
... ...