From 57338c4f4d287bb7e99ff70bb13e66b2c44db8b0 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 11 Nov 2014 16:10:44 -0300 Subject: [PATCH] Using plugin namespace on video_plugin models --- plugins/video/lib/ext/article.rb | 4 +++- plugins/video/lib/video.rb | 145 ------------------------------------------------------------------------------------------------------------------------------------------------- plugins/video/lib/video_block.rb | 62 -------------------------------------------------------------- plugins/video/lib/video_gallery.rb | 63 --------------------------------------------------------------- plugins/video/lib/video_gallery_helper.rb | 18 ------------------ plugins/video/lib/video_plugin.rb | 6 +----- plugins/video/lib/video_plugin/video.rb | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/lib/video_plugin/video_block.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/lib/video_plugin/video_gallery.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/video/lib/video_plugin/video_gallery_helper.rb | 18 ++++++++++++++++++ plugins/video/test/functional/video_plugin_environment_design_controller_test.rb | 4 ++-- plugins/video/test/functional/video_plugin_profile_design_controller_test.rb | 4 ++-- plugins/video/test/unit/video_block_test.rb | 68 ++++++++++++++++++++++++++++++++++---------------------------------- plugins/video/test/unit/video_plugin_test.rb | 2 +- 14 files changed, 331 insertions(+), 333 deletions(-) delete mode 100644 plugins/video/lib/video.rb delete mode 100644 plugins/video/lib/video_block.rb delete mode 100644 plugins/video/lib/video_gallery.rb delete mode 100644 plugins/video/lib/video_gallery_helper.rb create mode 100644 plugins/video/lib/video_plugin/video.rb create mode 100644 plugins/video/lib/video_plugin/video_block.rb create mode 100644 plugins/video/lib/video_plugin/video_gallery.rb create mode 100644 plugins/video/lib/video_plugin/video_gallery_helper.rb diff --git a/plugins/video/lib/ext/article.rb b/plugins/video/lib/ext/article.rb index 7225424..27bdc7d 100644 --- a/plugins/video/lib/ext/article.rb +++ b/plugins/video/lib/ext/article.rb @@ -2,10 +2,12 @@ require_dependency 'article' class Article + #FIXME This should be done via hotspot def self.folder_types_with_video - self.folder_types_without_video << 'VideoGallery' + self.folder_types_without_video << 'VideoPugin::VideoGallery' end + #FIXME This should be done via hotspot class << self alias_method_chain :folder_types, :video end diff --git a/plugins/video/lib/video.rb b/plugins/video/lib/video.rb deleted file mode 100644 index 4301ba2..0000000 --- a/plugins/video/lib/video.rb +++ /dev/null @@ -1,145 +0,0 @@ -require 'noosfero/translatable_content' -require 'application_helper' -require 'net/http' - -class Video < Article - - settings_items :video_url, :type => :string, :default => 'http://' - settings_items :video_width, :type => :integer, :default => 499 - settings_items :video_height, :type => :integer, :default => 353 - #youtube, vimeo, file - settings_items :video_provider, :type => :string - settings_items :video_format, :type => :string - settings_items :video_id, :type => :string - settings_items :video_thumbnail_url, :type => :string, :default => '/plugins/video/images/video_generic_thumbnail.jpg' - settings_items :video_thumbnail_width, :type=> :integer - settings_items :video_thumbnail_height, :type=> :integer - settings_items :video_duration, :type=> :integer, :default => 0 - - attr_accessible :video_url - - before_save :detect_video - - def self.type_name - _('Video') - end - - def can_display_versions? - true - end - - def self.short_description - _('Embedded Video') - end - - def self.description - _('Display embedded videos.') - end - - include ActionView::Helpers::TagHelper - def to_html(options={}) - article = self - proc do - render :partial => 'content_viewer/video', :locals => {:article => article} - end - end - - def fitted_width - 499 - end - - def fitted_height - ((fitted_width * self.video_height) / self.video_width).to_i - end - - def thumbnail_fitted_width - 80 - end - - def thumbnail_fitted_height - ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i - end - - def no_browser_support_message - '

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

' - end - - private - - YOUTUBE_ID_FORMAT = '\w-' - - def detect_video - if is_youtube? - self.video_provider = 'youtube' - self.video_id = extract_youtube_id - url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json" - resp = Net::HTTP.get_response(URI.parse(url)) - buffer = resp.body - vid = JSON.parse(buffer) - self.video_thumbnail_url = vid['thumbnail_url'] - self.video_width = vid['width'] - self.video_height = vid['height'] - self.video_thumbnail_width = vid['thumbnail_width'] - self.video_thumbnail_height = vid['thumbnail_height'] - url = "http://gdata.youtube.com/feeds/api/videos/#{self.video_id}?alt=json"; - resp = Net::HTTP.get_response(URI.parse(url)) - buffer = resp.body - vid = JSON.parse(buffer) - self.video_duration = vid['entry']['media$group']['media$content'][0]['duration'] - elsif is_vimeo? - self.video_provider = 'vimeo' - self.video_id = extract_vimeo_id - url = "http://vimeo.com/api/v2/video/#{self.video_id}.json" - resp = Net::HTTP.get_response(URI.parse(url)) - buffer = resp.body - vid = JSON.parse(buffer) - vid = vid[0] - #raise vid.to_yaml - self.video_thumbnail_url = vid['thumbnail_large'] - self.video_width = vid['width'] - self.video_height = vid['height'] - self.video_thumbnail_width = 640 - self.video_thumbnail_height = 360 - elsif true - self.video_format = detect_format - self.video_provider = 'file' - end - end - - def detect_format - video_type = 'video/unknown' - if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url - video_type='video/mp4' - elsif /.webm/i =~ self.video_url - video_type='video/webm' - elsif /.og[vg]/i =~ self.video_url - video_type='video/ogg' - end - video_type - end - - def is_youtube? - video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false - end - - def is_vimeo? - video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false - end - - def is_video_file? - video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false - end - - def extract_youtube_id - return nil unless is_youtube? - youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match[1] unless youtube_match.nil? - end - - def extract_vimeo_id - return nil unless is_vimeo? - vimeo_match = video_url.match('([[:digit:]]*)$') - vimeo_match[1] unless vimeo_match.nil? - end -end \ No newline at end of file diff --git a/plugins/video/lib/video_block.rb b/plugins/video/lib/video_block.rb deleted file mode 100644 index d6be6d5..0000000 --- a/plugins/video/lib/video_block.rb +++ /dev/null @@ -1,62 +0,0 @@ -class VideoBlock < Block - - attr_accessible :url, :width, :height - - settings_items :url, :type => :string, :default => "" - settings_items :width, :type => :integer, :default => 400 - settings_items :height, :type => :integer, :default => 315 - - YOUTUBE_ID_FORMAT = '\w-' - - def is_youtube? - url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false - end - - def is_vimeo? - url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false - end - - def is_video_file? - url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false - end - - def format_embed_video_url_for_youtube - "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? - end - - def format_embed_video_url_for_vimeo - "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? - end - - def self.description - _('Display a Video') - end - - def help - _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') - end - - def content(args={}) - block = self - - proc do - render :file => 'video_block', :locals => { :block => block } - end - end - - private - - def extract_youtube_id - return nil unless is_youtube? - youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") - youtube_match[1] unless youtube_match.nil? - end - - def extract_vimeo_id - return nil unless is_vimeo? - vimeo_match = url.match('([[:digit:]]*)$') - vimeo_match[1] unless vimeo_match.nil? - end - -end diff --git a/plugins/video/lib/video_gallery.rb b/plugins/video/lib/video_gallery.rb deleted file mode 100644 index e1dd855..0000000 --- a/plugins/video/lib/video_gallery.rb +++ /dev/null @@ -1,63 +0,0 @@ -class VideoGallery < Folder - - def self.type_name - _('Video Gallery') - end - - settings_items :thumbnail_width, :type => :integer, :default => 50 - settings_items :thumbnail_height, :type => :integer, :default => 50 - settings_items :videos_per_row, :type => :integer, :default => 5 - - validate :not_belong_to_blog - - def not_belong_to_blog - errors.add(:parent, "A video gallery should not belong to a blog.") if parent && parent.blog? - end - - acts_as_having_settings :field => :setting - - xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' - - include WhiteListFilter - filter_iframes :body - def iframe_whitelist - profile && profile.environment && profile.environment.trusted_sites_for_iframe - end - - def self.short_description - _('Video Gallery') - end - - def self.description - _('A gallery of link to videos that are hosted elsewhere.') - end - - include ActionView::Helpers::TagHelper - def to_html(options = {}) - video_gallery = self - proc do - render :partial => 'content_viewer/video_gallery', :locals => {:video_gallery => video_gallery} - end - end - - def video_gallery? - true - end - - def can_display_hits? - false - end - - def accept_comments? - false - end - - def self.icon_name(article = nil) - 'Video gallery' - end - - def news(limit = 30, highlight = false) - profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) - end - -end diff --git a/plugins/video/lib/video_gallery_helper.rb b/plugins/video/lib/video_gallery_helper.rb deleted file mode 100644 index c474ca2..0000000 --- a/plugins/video/lib/video_gallery_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -module VideoGalleryHelper - - def list_videos(configure={}) - configure[:recursive] ||= false - configure[:list_type] ||= :folder - if !configure[:contents].blank? - configure[:contents] = configure[:contents].paginate( - :order => "updated_at DESC", - :per_page => 16, - :page => params[:npage] - ) - render :file => 'shared/video_list', :locals => configure - else - content_tag('em', _('(empty folder)')) - end - end - -end \ No newline at end of file diff --git a/plugins/video/lib/video_plugin.rb b/plugins/video/lib/video_plugin.rb index fb30beb..2359ab2 100644 --- a/plugins/video/lib/video_plugin.rb +++ b/plugins/video/lib/video_plugin.rb @@ -1,7 +1,3 @@ -require_dependency File.dirname(__FILE__) + '/video_block' -require_dependency File.dirname(__FILE__) + '/video' -require_dependency File.dirname(__FILE__) + '/video_gallery' - class VideoPlugin < Noosfero::Plugin def self.plugin_name @@ -14,7 +10,7 @@ class VideoPlugin < Noosfero::Plugin def self.extra_blocks { - VideoBlock => {} + VideoPlugin::VideoBlock => {} } end diff --git a/plugins/video/lib/video_plugin/video.rb b/plugins/video/lib/video_plugin/video.rb new file mode 100644 index 0000000..446a8d0 --- /dev/null +++ b/plugins/video/lib/video_plugin/video.rb @@ -0,0 +1,145 @@ +require 'noosfero/translatable_content' +require 'application_helper' +require 'net/http' + +class VideoPlugin::Video < Article + + settings_items :video_url, :type => :string, :default => 'http://' + settings_items :video_width, :type => :integer, :default => 499 + settings_items :video_height, :type => :integer, :default => 353 + #youtube, vimeo, file + settings_items :video_provider, :type => :string + settings_items :video_format, :type => :string + settings_items :video_id, :type => :string + settings_items :video_thumbnail_url, :type => :string, :default => '/plugins/video/images/video_generic_thumbnail.jpg' + settings_items :video_thumbnail_width, :type=> :integer + settings_items :video_thumbnail_height, :type=> :integer + settings_items :video_duration, :type=> :integer, :default => 0 + + attr_accessible :video_url + + before_save :detect_video + + def self.type_name + _('Video') + end + + def can_display_versions? + true + end + + def self.short_description + _('Embedded Video') + end + + def self.description + _('Display embedded videos.') + end + + include ActionView::Helpers::TagHelper + def to_html(options={}) + article = self + proc do + render :partial => 'content_viewer/video', :locals => {:article => article} + end + end + + def fitted_width + 499 + end + + def fitted_height + ((fitted_width * self.video_height) / self.video_width).to_i + end + + def thumbnail_fitted_width + 80 + end + + def thumbnail_fitted_height + ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i + end + + def no_browser_support_message + '

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

' + end + + private + + YOUTUBE_ID_FORMAT = '\w-' + + def detect_video + if is_youtube? + self.video_provider = 'youtube' + self.video_id = extract_youtube_id + url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json" + resp = Net::HTTP.get_response(URI.parse(url)) + buffer = resp.body + vid = JSON.parse(buffer) + self.video_thumbnail_url = vid['thumbnail_url'] + self.video_width = vid['width'] + self.video_height = vid['height'] + self.video_thumbnail_width = vid['thumbnail_width'] + self.video_thumbnail_height = vid['thumbnail_height'] + url = "http://gdata.youtube.com/feeds/api/videos/#{self.video_id}?alt=json"; + resp = Net::HTTP.get_response(URI.parse(url)) + buffer = resp.body + vid = JSON.parse(buffer) + self.video_duration = vid['entry']['media$group']['media$content'][0]['duration'] + elsif is_vimeo? + self.video_provider = 'vimeo' + self.video_id = extract_vimeo_id + url = "http://vimeo.com/api/v2/video/#{self.video_id}.json" + resp = Net::HTTP.get_response(URI.parse(url)) + buffer = resp.body + vid = JSON.parse(buffer) + vid = vid[0] + #raise vid.to_yaml + self.video_thumbnail_url = vid['thumbnail_large'] + self.video_width = vid['width'] + self.video_height = vid['height'] + self.video_thumbnail_width = 640 + self.video_thumbnail_height = 360 + elsif true + self.video_format = detect_format + self.video_provider = 'file' + end + end + + def detect_format + video_type = 'video/unknown' + if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url + video_type='video/mp4' + elsif /.webm/i =~ self.video_url + video_type='video/webm' + elsif /.og[vg]/i =~ self.video_url + video_type='video/ogg' + end + video_type + end + + def is_youtube? + video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false + end + + def is_vimeo? + video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false + end + + def is_video_file? + video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false + end + + def extract_youtube_id + return nil unless is_youtube? + youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match[1] unless youtube_match.nil? + end + + def extract_vimeo_id + return nil unless is_vimeo? + vimeo_match = video_url.match('([[:digit:]]*)$') + vimeo_match[1] unless vimeo_match.nil? + end +end diff --git a/plugins/video/lib/video_plugin/video_block.rb b/plugins/video/lib/video_plugin/video_block.rb new file mode 100644 index 0000000..8532bff --- /dev/null +++ b/plugins/video/lib/video_plugin/video_block.rb @@ -0,0 +1,62 @@ +class VideoPlugin::VideoBlock < Block + + attr_accessible :url, :width, :height + + settings_items :url, :type => :string, :default => "" + settings_items :width, :type => :integer, :default => 400 + settings_items :height, :type => :integer, :default => 315 + + YOUTUBE_ID_FORMAT = '\w-' + + def is_youtube? + url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false + end + + def is_vimeo? + url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false + end + + def is_video_file? + url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false + end + + def format_embed_video_url_for_youtube + "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? + end + + def format_embed_video_url_for_vimeo + "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? + end + + def self.description + _('Display a Video') + end + + def help + _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') + end + + def content(args={}) + block = self + + proc do + render :file => 'video_block', :locals => { :block => block } + end + end + + private + + def extract_youtube_id + return nil unless is_youtube? + youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match[1] unless youtube_match.nil? + end + + def extract_vimeo_id + return nil unless is_vimeo? + vimeo_match = url.match('([[:digit:]]*)$') + vimeo_match[1] unless vimeo_match.nil? + end + +end diff --git a/plugins/video/lib/video_plugin/video_gallery.rb b/plugins/video/lib/video_plugin/video_gallery.rb new file mode 100644 index 0000000..49a20c9 --- /dev/null +++ b/plugins/video/lib/video_plugin/video_gallery.rb @@ -0,0 +1,63 @@ +class VideoPlugin::VideoGallery < Folder + + def self.type_name + _('Video Gallery') + end + + settings_items :thumbnail_width, :type => :integer, :default => 50 + settings_items :thumbnail_height, :type => :integer, :default => 50 + settings_items :videos_per_row, :type => :integer, :default => 5 + + validate :not_belong_to_blog + + def not_belong_to_blog + errors.add(:parent, "A video gallery should not belong to a blog.") if parent && parent.blog? + end + + acts_as_having_settings :field => :setting + + xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' + + include WhiteListFilter + filter_iframes :body + def iframe_whitelist + profile && profile.environment && profile.environment.trusted_sites_for_iframe + end + + def self.short_description + _('Video Gallery') + end + + def self.description + _('A gallery of link to videos that are hosted elsewhere.') + end + + include ActionView::Helpers::TagHelper + def to_html(options = {}) + video_gallery = self + proc do + render :partial => 'content_viewer/video_gallery', :locals => {:video_gallery => video_gallery} + end + end + + def video_gallery? + true + end + + def can_display_hits? + false + end + + def accept_comments? + false + end + + def self.icon_name(article = nil) + 'Video gallery' + end + + def news(limit = 30, highlight = false) + profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) + end + +end diff --git a/plugins/video/lib/video_plugin/video_gallery_helper.rb b/plugins/video/lib/video_plugin/video_gallery_helper.rb new file mode 100644 index 0000000..ba5c8ce --- /dev/null +++ b/plugins/video/lib/video_plugin/video_gallery_helper.rb @@ -0,0 +1,18 @@ +module VideoPlugin::VideoGalleryHelper + + def list_videos(configure={}) + configure[:recursive] ||= false + configure[:list_type] ||= :folder + if !configure[:contents].blank? + configure[:contents] = configure[:contents].paginate( + :order => "updated_at DESC", + :per_page => 16, + :page => params[:npage] + ) + render :file => 'shared/video_list', :locals => configure + else + content_tag('em', _('(empty folder)')) + end + end + +end diff --git a/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb b/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb index 2a376b4..6188ad8 100644 --- a/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb +++ b/plugins/video/test/functional/video_plugin_environment_design_controller_test.rb @@ -21,9 +21,9 @@ class EnvironmentDesignControllerTest < ActionController::TestCase @environment.enabled_plugins = ['VideoPlugin'] @environment.save! - VideoBlock.delete_all + VideoPlugin::VideoBlock.delete_all - @block = VideoBlock.new + @block = VideoPlugin::VideoBlock.new @block.box = @environment.boxes.first @block.save! end diff --git a/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb b/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb index 94d2036..9ef35be 100644 --- a/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb +++ b/plugins/video/test/functional/video_plugin_profile_design_controller_test.rb @@ -18,11 +18,11 @@ class ProfileDesignControllerTest < ActionController::TestCase @environment.enabled_plugins = ['VideoPlugin'] @environment.save! - VideoBlock.delete_all + VideoPlugin::VideoBlock.delete_all @box1 = Box.create!(:owner => @profile) @profile.boxes = [@box1] - @block = VideoBlock.new + @block = VideoPlugin::VideoBlock.new @block.box = @box1 @block.save! diff --git a/plugins/video/test/unit/video_block_test.rb b/plugins/video/test/unit/video_block_test.rb index 0ebdae4..880de13 100644 --- a/plugins/video/test/unit/video_block_test.rb +++ b/plugins/video/test/unit/video_block_test.rb @@ -4,94 +4,94 @@ class VideoBlockTest < ActiveSupport::TestCase ### Tests for YouTube should "is_youtube return true when the url contains http://youtube.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://youtube.com/?v=XXXXX" assert block.is_youtube? end should "is_youtube return true when the url contains https://youtube.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "https://youtube.com/?v=XXXXX" assert block.is_youtube? end should "is_youtube return true when the url contains https://www.youtube.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "https://www.youtube.com/?v=XXXXX" assert block.is_youtube? end should "is_youtube return true when the url contains www.youtube.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "www.youtube.com/?v=XXXXX" assert block.is_youtube? end should "is_youtube return true when the url contains youtube.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/?v=XXXXX" assert block.is_youtube? end should "is_youtube return false when the url not contains youtube video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/" assert !block.is_youtube? end should "is_youtube return false when the url contains empty youtube video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/?v=" assert !block.is_youtube? end should "is_youtube return false when the url contains an invalid youtube link" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/?v=XXXXX" assert !block.is_youtube? end should "format embed video for youtube videos" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/?v=XXXXX" assert_match /\/\/www.youtube-nocookie.com\/embed/, block.format_embed_video_url_for_youtube end should "format embed video return nil if is not a youtube url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/?v=XXXXX" assert_nil block.format_embed_video_url_for_youtube end should "extract youtube id from youtube video url's if it's a valid youtube full url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new id = 'oi43jre2d2' block.url = "youtube.com/?v=#{id}" assert_equal id, block.send('extract_youtube_id') end should "extract youtube id from youtube video url's if it has underline and hyphen" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new id = 'oi43_re-d2' block.url = "youtube.com/?v=#{id}" assert_equal id, block.send('extract_youtube_id') end should "extract youtube id from youtube video url's if it's a valid youtube short url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new id = 'oi43jre2d2' block.url = "youtu.be/#{id}" assert_equal id, block.send('extract_youtube_id') end should "extract_youtube_id return nil if the url it's not a valid youtube url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/?v=XXXXX" assert_nil block.send('extract_youtube_id') end should "extract_youtube_id return nil if youtue url there is no id" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "youtube.com/" assert_nil block.send('extract_youtube_id') end @@ -99,111 +99,111 @@ class VideoBlockTest < ActiveSupport::TestCase #### Tests for Vimeo Videos should "is_vimeo return true when the url contains http://vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://vimeo.com/98979" assert block.is_vimeo? end should "is_vimeo return true when the url contains https://vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "https://vimeo.com/989798" assert block.is_vimeo? end should "is_vimeo return true when the url contains https://www.vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "https://www.vimeo.com/98987" assert block.is_vimeo? end should "is_vimeo return true when the url contains www.vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "www.vimeo.com/989798" assert block.is_vimeo? end should "is_vimeo return true when the url contains vimeo.com" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/09898" assert block.is_vimeo? end should "is_vimeo return false when the url not contains vimeo video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/home" assert !block.is_vimeo? end should "is_vimeo return false when the url contains empty vimeo video ID" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/" assert !block.is_vimeo? end should "is_vimeo return false when the url contains an invalid vimeo link" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979" assert !block.is_vimeo? end should "format embed video for vimeo videos" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/09898" assert_match /\/\/player.vimeo.com\/video\/[[:digit:]]+/, block.format_embed_video_url_for_vimeo end should "format embed video return nil if is not a vimeo url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/?v=XXXXX" assert_nil block.format_embed_video_url_for_vimeo end should "extract vimeo id from vimeo video url's if it's a valid vimeo url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new id = '23048239432' block.url = "vimeo.com/#{id}" assert_equal id, block.send('extract_vimeo_id') end should "extract_vimeo_id return nil if the url it's not a valid vimeo url" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.yt.com/XXXXX" assert_nil block.send('extract_vimeo_id') end should "extract_vimeo_id return nil if vimeo url there is no id" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "vimeo.com/" assert_nil block.send('extract_youtube_id') end # Other video formats should "is_video return true if url ends with mp4" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.mp4" assert block.is_video_file? end should "is_video return true if url ends with ogg" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.ogg" assert block.is_video_file? end should "is_video return true if url ends with ogv" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.ogv" assert block.is_video_file? end should "is_video return true if url ends with webm" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.webm" assert block.is_video_file? end should "is_video return false if url ends without mp4, ogg, ogv, webm" do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new block.url = "http://www.vmsd.com/98979.mp4r" assert !block.is_video_file? block.url = "http://www.vmsd.com/98979.oggr" @@ -215,7 +215,7 @@ class VideoBlockTest < ActiveSupport::TestCase end should 'display video block partial' do - block = VideoBlock.new + block = VideoPlugin::VideoBlock.new self.expects(:render).with(:file => 'video_block', :locals => { :block => block }) diff --git a/plugins/video/test/unit/video_plugin_test.rb b/plugins/video/test/unit/video_plugin_test.rb index 36afe76..e423e43 100644 --- a/plugins/video/test/unit/video_plugin_test.rb +++ b/plugins/video/test/unit/video_plugin_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper' class VideoPluginTest < ActiveSupport::TestCase should "return VideoBlock in extra_blocks class method" do - assert VideoPlugin.extra_blocks.keys.include?(VideoBlock) + assert VideoPlugin.extra_blocks.keys.include?(VideoPlugin::VideoBlock) end end -- libgit2 0.21.2