Skip to content

Commit

Permalink
Updated youtube id video regex to handle some more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed May 30, 2012
1 parent 46debe0 commit 9ac8914
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
2 changes: 1 addition & 1 deletion app/models/spree/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Video < ActiveRecord::Base
validates_uniqueness_of :youtube_ref, :scope => [:product_id]

after_validation do
youtube_ref.match(/^.*((youtu.be\/)|(v\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/) { |m| self.youtube_ref = m[-1] }
youtube_ref.match(/(v=|\/)([\w-]+)(&.+)?$/) { |m| self.youtube_ref = m[2] }
end
end
end
8 changes: 7 additions & 1 deletion spec/models/video_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
video.update_attributes :youtube_ref => 'iJ4T9CQA0UM'
video.reload.youtube_ref.should == 'iJ4T9CQA0UM'

video.update_attributes :youtube_ref => 'http://youtu.be/9xtn36e2shw'
video.update_attributes :youtube_ref => 'http://youtu.be/9xtn36e2shw'
video.reload.youtube_ref.should == '9xtn36e2shw'

video.update_attributes :youtube_ref => 'http://www.youtube.com/watch?v=M6Ctprmv-cs&feature=player_embedded'
video.reload.youtube_ref.should == 'M6Ctprmv-cs'

video.update_attributes :youtube_ref => 'http://www.youtube.com/watch?feature=player_embedded&v=M6Ctprmv-cs'
video.reload.youtube_ref.should == 'M6Ctprmv-cs'
end

it "should not allow two of same videos attached to a product" do
Expand Down
2 changes: 1 addition & 1 deletion spree_videos.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_videos'
s.version = '1.2.2'
s.version = '1.2.3'
s.summary = 'Adds youtube videos to Spree commerce products'
s.description = 'Add multiuple youtube videos, and a thumbnail selector' +
'for those products to a Spree commerce product'
Expand Down

0 comments on commit 9ac8914

Please sign in to comment.