Commit 86aac3efddd05006c12002224208f39c6232faa6

Authored by Braulio Bhavamitra
2 parents a2a9a8bb 894bfc48

Merge branch 'new_video_plugin' into 'master'

Fixes for video plugin

- Add migration to rename type of blocks on database
- Fix visualization of  video gallery article

See merge request !897
app/views/cms/edit.html.erb
... ... @@ -4,7 +4,7 @@
4 4 <%= render :partial => 'archived_warning', :locals => {:article => @article} %>
5 5 <% end %>
6 6 <div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'>
7   -<%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
  7 +<%= labelled_form_for 'article', :html => { :multipart => true, :class => "#{@type} #{@type.to_css_class}" } do |f| %>
8 8  
9 9 <%= hidden_field_tag("type", @type) if @type %>
10 10  
... ...
plugins/video/db/migrate/20160115185550_rename_video_block.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class RenameVideoBlock < ActiveRecord::Migration
  2 + def up
  3 + execute("UPDATE blocks SET type = 'VideoPlugin::VideoBlock' WHERE type = 'VideoBlock'")
  4 + end
  5 +
  6 + def down
  7 + say "this migration can't be reverted"
  8 + end
  9 +end
  10 +
... ...
plugins/video/public/style.css
... ... @@ -63,4 +63,9 @@
63 63 width: 100%;
64 64 margin-left: auto;
65 65 margin-right: auto;
66   -}
67 66 \ No newline at end of file
  67 +}
  68 +
  69 +form.video-plugin_video .type-text input,
  70 +form.video-plugin_video .type-textarea textarea {
  71 + width: 100%;
  72 +}
... ...
plugins/video/test/unit/video_galery_block_test.rb
... ... @@ -21,7 +21,7 @@ class VideoGalleryBlockViewTest &lt; ActionView::TestCase
21 21  
22 22 content = render_block_content(block)
23 23  
24   - assert_equal content, "\n"
  24 + assert_equal content, ""
25 25 end
26 26  
27 27 should 'render nothing with an empty gallery message when there are no children' do
... ... @@ -51,7 +51,7 @@ class VideoGalleryBlockViewTest &lt; ActionView::TestCase
51 51  
52 52 content = render_block_content(block)
53 53  
54   - assert_tag_in_string content, tag: 'div', content: "\n #{body}\n "
  54 + assert_match body, content
55 55 assert_tag_in_string content, tag: 'em', content: _('(empty video gallery)')
56 56 end
57 57 end
... ...
plugins/video/test/unit/video_galery_test.rb
... ... @@ -13,4 +13,25 @@ class VideoGaleryTest &lt; ActiveSupport::TestCase
13 13 assert_equal VideoPlugin::VideoGallery.description, _('A gallery of link to videos that are hosted elsewhere.')
14 14 end
15 15  
  16 + should 'render nothing with an empty gallery message when there are no children' do
  17 + video_gallery = VideoPlugin::VideoGallery.new
  18 + video_gallery.children = []
  19 + video_gallery.stubs(:body).returns('Video gallery body')
  20 +
  21 + content = instance_eval(&video_gallery.to_html)
  22 + assert_tag_in_string content, tag: 'em', content: _('(empty video gallery)')
  23 + end
  24 +
  25 + should 'render the body and a empty gallery message when there are no children' do
  26 + body = "Video Gallery Body"
  27 + video_gallery = VideoPlugin::VideoGallery.new
  28 + video_gallery.children = []
  29 + video_gallery.expects(:body).twice.returns(body)
  30 +
  31 + content = instance_eval(&video_gallery.to_html)
  32 +
  33 + assert_match body, content
  34 + assert_tag_in_string content, tag: 'em', content: _('(empty video gallery)')
  35 + end
  36 +
16 37 end
... ...
plugins/video/views/blocks/video_gallery.html.erb
1   -<% extend VideoPlugin::VideoGalleryHelper %>
2   -
3 1 <% if block.video_gallery_id.present?
4 2 video_gallery = VideoPlugin::VideoGallery.find(block.video_gallery_id) %>
5 3  
6   - <% unless video_gallery.body.blank? %>
7   - <div>
8   - <%= video_gallery.body %>
9   - </div>
10   - <hr/>
11   - <% end %>
  4 + <%= render :partial => 'shared/video_gallery', :locals => {:video_gallery => video_gallery} %>
12 5  
13   - <% if video_gallery.children.empty? %>
14   - <em><%= _('(empty video gallery)') %></em>
15   - <% else %>
16   - <%= list_videos(:contents=>video_gallery.children) %>
17   - <% end %>
18 6 <% end %>
... ...
plugins/video/views/cms/video_plugin/_video.html.erb
1 1 <%= required_fields_message %>
2 2  
3 3 <div>
4   -<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
5   -<%= required labelled_form_field _('URL of the video'), text_field(:article, :video_url, :size => 80) %>
  4 +<%= required f.text_field('name') %>
  5 +<%= required labelled_form_field _('URL of the video'), text_field(:article, :video_url) %>
6 6 <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %>
7 7 <%= render :partial => 'general_fields' %>
8 8 <%= render :partial => 'translatable' %>
... ...
plugins/video/views/cms/video_plugin/_video_gallery.html.erb
1 1 <%= required_fields_message %>
2 2  
3   -<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  3 +<%= required f.text_field('name', :maxlength => 150) %>
4 4 <%= render :partial => 'general_fields' %>
5 5  
6 6 <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %>
... ...
plugins/video/views/content_viewer/video_plugin/_video_gallery.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => 'shared/video_gallery', :locals => {:video_gallery => video_gallery} %>
... ...
plugins/video/views/shared/_video_gallery.html.erb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<% extend VideoPlugin::VideoGalleryHelper %>
  2 +
  3 +<% unless video_gallery.body.blank? %>
  4 + <div>
  5 + <%= video_gallery.body %>
  6 + </div>
  7 + <hr/>
  8 +<% end %>
  9 +
  10 +<% if video_gallery.children.empty? %>
  11 + <em><%= _('(empty video gallery)') %></em>
  12 +<% else %>
  13 + <%= list_videos(:contents=>video_gallery.children) %>
  14 +<% end %>
... ...
test/functional/cms_controller_test.rb
... ... @@ -1738,7 +1738,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1738 1738 [Blog, TinyMceArticle, Forum].each do |klass|
1739 1739 a = fast_create(klass, :profile_id => profile.id)
1740 1740 get :edit, :profile => profile.identifier, :id => a.id
1741   - assert_tag :tag => 'form', :attributes => {:class => klass.to_s}
  1741 + assert_tag :tag => 'form', :attributes => {:class => "#{a.type} #{a.type.to_css_class}"}
1742 1742 end
1743 1743 end
1744 1744  
... ...