fix specs; move presence_of_content validation check into a before_destory to play nicely with federation
This commit is contained in:
parent
31fda67dd3
commit
e9b6da605f
3 changed files with 20 additions and 15 deletions
|
|
@ -31,6 +31,10 @@ class Photo < ActiveRecord::Base
|
|||
self.status_message.update_photos_counter if status_message
|
||||
end
|
||||
|
||||
after_destroy do
|
||||
self.status_message.update_photos_counter if status_message
|
||||
end
|
||||
|
||||
def clear_empty_status_message
|
||||
if self.status_message_guid && self.status_message.text_and_photos_blank?
|
||||
self.status_message.destroy
|
||||
|
|
|
|||
|
|
@ -18,15 +18,14 @@ class StatusMessage < Post
|
|||
|
||||
has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid
|
||||
|
||||
# TODO: disabling presence_of_content() (and its specs in status_message_controller_spec.rb:125) is a quick and dirty fix for federation
|
||||
# a StatusMessage is federated before its photos are so presence_of_content() fails erroneously if no text is present
|
||||
#validate :presence_of_content
|
||||
# therefore, we put the validation in a before_destory callback instead of a validation
|
||||
before_destroy :presence_of_content
|
||||
|
||||
attr_accessible :text, :provider_display_name
|
||||
attr_accessor :oembed_url
|
||||
|
||||
after_create :create_mentions
|
||||
|
||||
after_create :queue_gather_oembed_data, :if => :contains_oembed_url_in_text?
|
||||
|
||||
#scopes
|
||||
|
|
@ -192,8 +191,8 @@ class StatusMessage < Post
|
|||
|
||||
protected
|
||||
def presence_of_content
|
||||
if text_and_photos_blank?
|
||||
errors[:base] << 'Status message requires a message or at least one photo'
|
||||
unless text_and_photos_blank?
|
||||
errors[:base] << "Cannot destory a StatusMessage with text and/or photos present"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -227,17 +227,19 @@ describe Photo do
|
|||
}.should change(Photo, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'will delete parent status message iff message is otherwise empty' do
|
||||
it 'will delete parent status message if message is otherwise empty' do
|
||||
expect {
|
||||
@photo2.destroy
|
||||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'will not delete parent status message iff message had other content' do
|
||||
expect {
|
||||
it 'will not delete parent status message if message had other content' do
|
||||
@status_message.text = "Some text"
|
||||
@status_message.save
|
||||
@status_message.reload
|
||||
|
||||
expect {
|
||||
@photo2.status_message.reload
|
||||
@photo2.destroy
|
||||
}.should_not change(StatusMessage, :count)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue