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 ...@@ -23,6 +23,7 @@ class Comment < ActiveRecord::Base
validates_presence_of :text, :post validates_presence_of :text, :post
serialize :youtube_titles, Hash
before_save do before_save do
get_youtube_title text get_youtube_title text
end end
......
...@@ -17,6 +17,7 @@ class StatusMessage < Post ...@@ -17,6 +17,7 @@ class StatusMessage < Post
attr_accessible :message attr_accessible :message
serialize :youtube_titles, Hash
before_save do before_save do
get_youtube_title message get_youtube_title message
end end
......
...@@ -23,6 +23,7 @@ class CreateSchema < ActiveRecord::Migration ...@@ -23,6 +23,7 @@ class CreateSchema < ActiveRecord::Migration
t.string :guid t.string :guid
t.text :creator_signature t.text :creator_signature
t.text :post_creator_signature t.text :post_creator_signature
t.text :youtube_titles
t.timestamps t.timestamps
end end
add_index :comments, :guid, :unique => true add_index :comments, :guid, :unique => true
...@@ -86,6 +87,7 @@ class CreateSchema < ActiveRecord::Migration ...@@ -86,6 +87,7 @@ class CreateSchema < ActiveRecord::Migration
t.string :remote_photo_name t.string :remote_photo_name
t.string :random_string t.string :random_string
t.string :image #carrierwave's column t.string :image #carrierwave's column
t.text :youtube_titles
t.timestamps t.timestamps
end end
......
...@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(:version => 0) do ...@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.string "guid" t.string "guid"
t.text "creator_signature" t.text "creator_signature"
t.text "post_creator_signature" t.text "post_creator_signature"
t.text "youtube_titles"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
...@@ -120,6 +121,7 @@ ActiveRecord::Schema.define(:version => 0) do ...@@ -120,6 +121,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.string "remote_photo_name" t.string "remote_photo_name"
t.string "random_string" t.string "random_string"
t.string "image" t.string "image"
t.text "youtube_titles"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
......
...@@ -10,12 +10,12 @@ module YoutubeTitles ...@@ -10,12 +10,12 @@ module YoutubeTitles
title || I18n.t('application.helper.video_title.unknown') title || I18n.t('application.helper.video_title.unknown')
end end
def get_youtube_title text def get_youtube_title text
self[:youtube_titles] ||= {} self.youtube_titles ||= {}
youtube_match = text.match(YOUTUBE_ID_REGEX) youtube_match = text.match(YOUTUBE_ID_REGEX)
return unless youtube_match return unless youtube_match
video_id = youtube_match[1] video_id = youtube_match[1]
unless self[:youtube_titles][video_id] unless self.youtube_titles[video_id]
self[:youtube_titles][video_id] = youtube_title_for(video_id) self.youtube_titles[video_id] = youtube_title_for(video_id)
end end
end end
YOUTUBE_ID_REGEX = /youtube\.com.*?v=([A-Za-z0-9_\\\-]+)/ unless defined? YOUTUBE_ID_REGEX YOUTUBE_ID_REGEX = /youtube\.com.*?v=([A-Za-z0-9_\\\-]+)/ unless defined? YOUTUBE_ID_REGEX
......
...@@ -31,7 +31,7 @@ describe StatusMessagesController do ...@@ -31,7 +31,7 @@ describe StatusMessagesController do
response.should be_success response.should be_success
end end
end end
describe '#create' do describe '#create' do
let(:status_message_hash) { let(:status_message_hash) {
{ :status_message => { { :status_message => {
......
...@@ -266,7 +266,7 @@ describe Comment do ...@@ -266,7 +266,7 @@ describe Comment do
comment = user.build_comment url, :on => @message comment = user.build_comment url, :on => @message
comment.save! comment.save!
comment[:youtube_titles].should == {video_id => expected_title} Comment.find(comment.id).youtube_titles.should == {video_id => expected_title}
end end
end end
end end
...@@ -100,7 +100,7 @@ describe StatusMessage do ...@@ -100,7 +100,7 @@ describe StatusMessage do
post = @user.build_post :status_message, :message => url, :to => @aspect.id post = @user.build_post :status_message, :message => url, :to => @aspect.id
post.save! post.save!
post[:youtube_titles].should == {video_id => expected_title} Post.find(post.id).youtube_titles.should == {video_id => expected_title}
end end
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