Commit 284c21df91da77703fd679aa534de2fb417cbbb4
Exists in
send_email_to_admins
and in
5 other branches
Merge branch 'refactor_video_plugin' into 'master'
Refactor video plugin This puts the plugin in the standards set by BoxesHelper, improve test coverage and remove an unused view. Travis build: https://travis-ci.org/rafamanzo/noosfero/builds/127621024 See merge request !891
Showing
9 changed files
with
84 additions
and
68 deletions
Show diff stats
plugins/video/lib/video_plugin/video_block.rb
@@ -36,14 +36,6 @@ class VideoPlugin::VideoBlock < Block | @@ -36,14 +36,6 @@ class VideoPlugin::VideoBlock < Block | ||
36 | _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') | 36 | _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') |
37 | end | 37 | end |
38 | 38 | ||
39 | - def content(args={}) | ||
40 | - block = self | ||
41 | - | ||
42 | - proc do | ||
43 | - render :file => 'video_block', :locals => { :block => block } | ||
44 | - end | ||
45 | - end | ||
46 | - | ||
47 | private | 39 | private |
48 | 40 | ||
49 | def extract_youtube_id | 41 | def extract_youtube_id |
plugins/video/lib/video_plugin/video_gallery_block.rb
@@ -14,16 +14,6 @@ class VideoPlugin::VideoGalleryBlock < Block | @@ -14,16 +14,6 @@ class VideoPlugin::VideoGalleryBlock < Block | ||
14 | _('This block presents a video gallery') | 14 | _('This block presents a video gallery') |
15 | end | 15 | end |
16 | 16 | ||
17 | - def content(args={}) | ||
18 | - block = self | ||
19 | - if video_gallery_id.present? | ||
20 | - video_gallery = VideoPlugin::VideoGallery.find(video_gallery_id) | ||
21 | - proc do | ||
22 | - render :partial => 'content_viewer/video_plugin/video_gallery', :locals => {:video_gallery => video_gallery} | ||
23 | - end | ||
24 | - end | ||
25 | - end | ||
26 | - | ||
27 | def list_my_galleries | 17 | def list_my_galleries |
28 | Article.owner_video_galleries(owner) | 18 | Article.owner_video_galleries(owner) |
29 | end | 19 | end |
plugins/video/test/unit/video_block_test.rb
@@ -208,12 +208,4 @@ class VideoBlockTest < ActiveSupport::TestCase | @@ -208,12 +208,4 @@ class VideoBlockTest < ActiveSupport::TestCase | ||
208 | refute block.is_video_file? | 208 | refute block.is_video_file? |
209 | end | 209 | end |
210 | 210 | ||
211 | - should 'display video block partial' do | ||
212 | - block = VideoPlugin::VideoBlock.new | ||
213 | - self.expects(:render).with(:file => 'video_block', :locals => { | ||
214 | - :block => block | ||
215 | - }) | ||
216 | - instance_eval(& block.content) | ||
217 | - end | ||
218 | - | ||
219 | end | 211 | end |
plugins/video/test/unit/video_galery_block_test.rb
@@ -10,3 +10,48 @@ class VideoGaleryBlockTest < ActiveSupport::TestCase | @@ -10,3 +10,48 @@ class VideoGaleryBlockTest < ActiveSupport::TestCase | ||
10 | end | 10 | end |
11 | 11 | ||
12 | end | 12 | end |
13 | + | ||
14 | +require 'boxes_helper' | ||
15 | + | ||
16 | +class VideoGalleryBlockViewTest < ActionView::TestCase | ||
17 | + include BoxesHelper | ||
18 | + | ||
19 | + should 'render nothing without a video_gallery_id' do | ||
20 | + block = VideoPlugin::VideoGalleryBlock.new | ||
21 | + | ||
22 | + content = render_block_content(block) | ||
23 | + | ||
24 | + assert_equal content, "\n" | ||
25 | + end | ||
26 | + | ||
27 | + should 'render nothing with an empty gallery message when there are no children' do | ||
28 | + block = VideoPlugin::VideoGalleryBlock.new | ||
29 | + block.video_gallery_id = 42 | ||
30 | + | ||
31 | + body = "" | ||
32 | + video_gallery = VideoPlugin::VideoGallery.new | ||
33 | + video_gallery.children = [] | ||
34 | + video_gallery.expects(:body).returns(body) | ||
35 | + VideoPlugin::VideoGallery.expects(:find).with(block.video_gallery_id).returns(video_gallery) | ||
36 | + | ||
37 | + content = render_block_content(block) | ||
38 | + | ||
39 | + assert_tag_in_string content, tag: 'em', content: _('(empty video gallery)') | ||
40 | + end | ||
41 | + | ||
42 | + should 'render the body and a empty gallery message when there are no children' do | ||
43 | + block = VideoPlugin::VideoGalleryBlock.new | ||
44 | + block.video_gallery_id = 42 | ||
45 | + | ||
46 | + body = "Video Gallery Body" | ||
47 | + video_gallery = VideoPlugin::VideoGallery.new | ||
48 | + video_gallery.children = [] | ||
49 | + video_gallery.expects(:body).twice.returns(body) | ||
50 | + VideoPlugin::VideoGallery.expects(:find).with(block.video_gallery_id).returns(video_gallery) | ||
51 | + | ||
52 | + content = render_block_content(block) | ||
53 | + | ||
54 | + assert_tag_in_string content, tag: 'div', content: "\n #{body}\n " | ||
55 | + assert_tag_in_string content, tag: 'em', content: _('(empty video gallery)') | ||
56 | + end | ||
57 | +end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +<h3 class="block-title"> | ||
2 | + <span><%=block.title%></span> | ||
3 | +</h3> | ||
4 | +<div class="video-block-data"> | ||
5 | + <% if block.is_youtube? %> | ||
6 | + <div class='youtube'> | ||
7 | + <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_youtube, :width => block.width, :height => block.height }%> | ||
8 | + </div> | ||
9 | + <% elsif block.is_vimeo? %> | ||
10 | + <div class='vimeo'> | ||
11 | + <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_vimeo, :width => block.width, :height => block.height }%> | ||
12 | + </div> | ||
13 | + <% elsif block.is_video_file? %> | ||
14 | + <div class='video'> | ||
15 | + <%= render :partial => 'box_organizer/html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | ||
16 | + </div> | ||
17 | + <% else %> | ||
18 | + <span class='alert-block'><%= _("Register a valid url (Vimeo, Youtube, video files)") %></span> | ||
19 | + <% end %> | ||
20 | + | ||
21 | +</div> |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +<% extend VideoPlugin::VideoGalleryHelper %> | ||
2 | + | ||
3 | +<% if block.video_gallery_id.present? | ||
4 | + video_gallery = VideoPlugin::VideoGallery.find(block.video_gallery_id) %> | ||
5 | + | ||
6 | + <% unless video_gallery.body.blank? %> | ||
7 | + <div> | ||
8 | + <%= video_gallery.body %> | ||
9 | + </div> | ||
10 | + <hr/> | ||
11 | + <% end %> | ||
12 | + | ||
13 | + <% if video_gallery.children.empty? %> | ||
14 | + <em><%= _('(empty video gallery)') %></em> | ||
15 | + <% else %> | ||
16 | + <%= list_videos(:contents=>video_gallery.children) %> | ||
17 | + <% end %> | ||
18 | +<% end %> |
plugins/video/views/content_viewer/video_plugin/_video_gallery.html.erb
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
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 %> |
plugins/video/views/video_block.html.erb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -<h3 class="block-title"> | ||
2 | - <span><%=block.title%></span> | ||
3 | -</h3> | ||
4 | -<div class="video-block-data"> | ||
5 | - <% if block.is_youtube? %> | ||
6 | - <div class='youtube'> | ||
7 | - <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_youtube, :width => block.width, :height => block.height }%> | ||
8 | - </div> | ||
9 | - <% elsif block.is_vimeo? %> | ||
10 | - <div class='vimeo'> | ||
11 | - <%= render :partial => 'box_organizer/iframe_video_block', :locals => { :url => block.format_embed_video_url_for_vimeo, :width => block.width, :height => block.height }%> | ||
12 | - </div> | ||
13 | - <% elsif block.is_video_file? %> | ||
14 | - <div class='video'> | ||
15 | - <%= render :partial => 'box_organizer/html5_video_block', :locals => { :url => block.url, :width => block.width, :height => block.height }%> | ||
16 | - </div> | ||
17 | - <% else %> | ||
18 | - <span class='alert-block'><%= _("Register a valid url (Vimeo, Youtube, video files)") %></span> | ||
19 | - <% end %> | ||
20 | - | ||
21 | -</div> |
plugins/video/views/video_gallery_block.html.erb