Protect ourselves from problems with youtube title serialization by rescuing type mismatches in the marshaller.

This commit is contained in:
Raphael Sofaer 2011-08-09 14:03:44 -07:00
parent e9d993b8f6
commit a4e54a7b05
2 changed files with 18 additions and 0 deletions

View file

@ -131,6 +131,18 @@ class StatusMessage < Post
end
end
def unserialize_attribute attr_name
if attr_name == "youtube_titles"
begin
super
rescue ActiveRecord::SerializationTypeMismatch
{}
end
else
super
end
end
protected
def message_or_photos_present?

View file

@ -45,6 +45,12 @@ describe YoutubeTitles do
StatusMessage.find(@post.id).youtube_titles
}.should_not raise_error
end
it 'can be re-marshalled if it is serializaed incorrectly' do
StatusMessage.where(:id => @post.id).update_all(:youtube_titles => "this is not yaml")
lambda {
StatusMessage.find(@post.id).youtube_titles
}.should_not raise_error
end
end
describe "YOUTUBE_ID_REGEX" do