Skip to content
Extraits de code Groupes Projets
Valider 16d7ccdf rédigé par Raphael's avatar Raphael
Parcourir les fichiers

fix youtube title stting

parent 936f7fdb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -23,6 +23,7 @@ class Comment < ActiveRecord::Base
validates_presence_of :text, :post
serialize :youtube_titles, Hash
before_save do
get_youtube_title text
end
......
......@@ -17,6 +17,7 @@ class StatusMessage < Post
attr_accessible :message
serialize :youtube_titles, Hash
before_save do
get_youtube_title message
end
......
......@@ -23,6 +23,7 @@ class CreateSchema < ActiveRecord::Migration
t.string :guid
t.text :creator_signature
t.text :post_creator_signature
t.text :youtube_titles
t.timestamps
end
add_index :comments, :guid, :unique => true
......@@ -86,6 +87,7 @@ class CreateSchema < ActiveRecord::Migration
t.string :remote_photo_name
t.string :random_string
t.string :image #carrierwave's column
t.text :youtube_titles
t.timestamps
end
......
......@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.string "guid"
t.text "creator_signature"
t.text "post_creator_signature"
t.text "youtube_titles"
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -120,6 +121,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.string "remote_photo_name"
t.string "random_string"
t.string "image"
t.text "youtube_titles"
t.datetime "created_at"
t.datetime "updated_at"
end
......
......@@ -10,12 +10,12 @@ module YoutubeTitles
title || I18n.t('application.helper.video_title.unknown')
end
def get_youtube_title text
self[:youtube_titles] ||= {}
self.youtube_titles ||= {}
youtube_match = text.match(YOUTUBE_ID_REGEX)
return unless youtube_match
video_id = youtube_match[1]
unless self[:youtube_titles][video_id]
self[:youtube_titles][video_id] = youtube_title_for(video_id)
unless self.youtube_titles[video_id]
self.youtube_titles[video_id] = youtube_title_for(video_id)
end
end
YOUTUBE_ID_REGEX = /youtube\.com.*?v=([A-Za-z0-9_\\\-]+)/ unless defined? YOUTUBE_ID_REGEX
......
......@@ -31,7 +31,7 @@ describe StatusMessagesController do
response.should be_success
end
end
describe '#create' do
let(:status_message_hash) {
{ :status_message => {
......
......@@ -266,7 +266,7 @@ describe Comment do
comment = user.build_comment url, :on => @message
comment.save!
comment[:youtube_titles].should == {video_id => expected_title}
Comment.find(comment.id).youtube_titles.should == {video_id => expected_title}
end
end
end
......@@ -100,7 +100,7 @@ describe StatusMessage do
post = @user.build_post :status_message, :message => url, :to => @aspect.id
post.save!
post[:youtube_titles].should == {video_id => expected_title}
Post.find(post.id).youtube_titles.should == {video_id => expected_title}
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter