From 57b07ea3c90d269c699c11bea28a434f5060fde0 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 24 Mar 2016 11:00:41 -0300 Subject: [PATCH] Refactored view code generation for gallery_block --- plugins/gallery_block/lib/gallery_block.rb | 8 -------- plugins/gallery_block/test/unit/gallery_block_test.rb | 35 +++++++++++++++++++++++++++++++++++ plugins/gallery_block/views/blocks/gallery.html.erb | 44 ++++++++++++++++++++++++++++++++++++++++++++ plugins/gallery_block/views/gallery_block.html.erb | 44 -------------------------------------------- 4 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 plugins/gallery_block/views/blocks/gallery.html.erb delete mode 100644 plugins/gallery_block/views/gallery_block.html.erb diff --git a/plugins/gallery_block/lib/gallery_block.rb b/plugins/gallery_block/lib/gallery_block.rb index 3614919..11a4189 100644 --- a/plugins/gallery_block/lib/gallery_block.rb +++ b/plugins/gallery_block/lib/gallery_block.rb @@ -30,12 +30,4 @@ class GalleryBlock < Block def images gallery ? gallery.images : [] end - - def content(args={}) - block = self - proc do - render :file => 'gallery_block', :locals => { :block => block } - end - end - end diff --git a/plugins/gallery_block/test/unit/gallery_block_test.rb b/plugins/gallery_block/test/unit/gallery_block_test.rb index a9024b3..92fbea1 100644 --- a/plugins/gallery_block/test/unit/gallery_block_test.rb +++ b/plugins/gallery_block/test/unit/gallery_block_test.rb @@ -20,3 +20,38 @@ class GalleryBlockTest < ActiveSupport::TestCase end end + +require 'boxes_helper' + +class GalleryBlockViewTest < ActionView::TestCase + include BoxesHelper + + def setup + @community = fast_create(Community) + end + + should 'display the default message for empty gallery' do + block = GalleryBlock.new + block.stubs(:owner).returns(@community) + + ActionView::Base.any_instance.expects(:block_title).returns("") + + content = render_block_content(block) + + assert_match /#{_('Please, edit this block and choose some gallery')}/, content + end + + should "display the gallery's content" do + gallery = fast_create(Gallery, :profile_id => @community.id) + image = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => @community) + block = create(GalleryBlock, :gallery_id => gallery.id) + block.stubs(:owner).returns(@community) + + ActionView::Base.any_instance.expects(:block_title).returns("") + + content = render_block_content(block) + + assert_tag_in_string content, tag: 'img', attributes: {src: image.public_filename(:thumb)} + assert_tag_in_string content, tag: 'span', content: _('Next') + end +end diff --git a/plugins/gallery_block/views/blocks/gallery.html.erb b/plugins/gallery_block/views/blocks/gallery.html.erb new file mode 100644 index 0000000..3bf9443 --- /dev/null +++ b/plugins/gallery_block/views/blocks/gallery.html.erb @@ -0,0 +1,44 @@ +<%= block_title(block.title, block.subtitle) %> + +<% unless block.images.blank? %> + <%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %> + + <%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %> + + +<% else %> + <%= _('Please, edit this block and choose some gallery') %> +<% end %> diff --git a/plugins/gallery_block/views/gallery_block.html.erb b/plugins/gallery_block/views/gallery_block.html.erb deleted file mode 100644 index 3bf9443..0000000 --- a/plugins/gallery_block/views/gallery_block.html.erb +++ /dev/null @@ -1,44 +0,0 @@ -<%= block_title(block.title, block.subtitle) %> - -<% unless block.images.blank? %> - <%= link_to content_tag(:span, _('Previous')), '#', :class => 'gallery-block-prev gallery-block-arrow icon-left' %> - - <%= link_to content_tag(:span, _('Next')), '#', :class => 'gallery-block-next gallery-block-arrow icon-right' %> - - -<% else %> - <%= _('Please, edit this block and choose some gallery') %> -<% end %> -- libgit2 0.21.2