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
|
self.status_message.update_photos_counter if status_message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after_destroy do
|
||||||
|
self.status_message.update_photos_counter if status_message
|
||||||
|
end
|
||||||
|
|
||||||
def clear_empty_status_message
|
def clear_empty_status_message
|
||||||
if self.status_message_guid && self.status_message.text_and_photos_blank?
|
if self.status_message_guid && self.status_message.text_and_photos_blank?
|
||||||
self.status_message.destroy
|
self.status_message.destroy
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,14 @@ class StatusMessage < Post
|
||||||
|
|
||||||
has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid
|
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
|
# 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_accessible :text, :provider_display_name
|
||||||
attr_accessor :oembed_url
|
attr_accessor :oembed_url
|
||||||
|
|
||||||
after_create :create_mentions
|
after_create :create_mentions
|
||||||
|
|
||||||
after_create :queue_gather_oembed_data, :if => :contains_oembed_url_in_text?
|
after_create :queue_gather_oembed_data, :if => :contains_oembed_url_in_text?
|
||||||
|
|
||||||
#scopes
|
#scopes
|
||||||
|
|
@ -192,8 +191,8 @@ class StatusMessage < Post
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def presence_of_content
|
def presence_of_content
|
||||||
if text_and_photos_blank?
|
unless text_and_photos_blank?
|
||||||
errors[:base] << 'Status message requires a message or at least one photo'
|
errors[:base] << "Cannot destory a StatusMessage with text and/or photos present"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,17 +227,19 @@ describe Photo do
|
||||||
}.should change(Photo, :count).by(-1)
|
}.should change(Photo, :count).by(-1)
|
||||||
end
|
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 {
|
expect {
|
||||||
@photo2.destroy
|
@photo2.destroy
|
||||||
}.should change(StatusMessage, :count).by(-1)
|
}.should change(StatusMessage, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not delete parent status message iff message had other content' do
|
it 'will not delete parent status message if message had other content' do
|
||||||
expect {
|
|
||||||
@status_message.text = "Some text"
|
@status_message.text = "Some text"
|
||||||
@status_message.save
|
@status_message.save
|
||||||
@status_message.reload
|
@status_message.reload
|
||||||
|
|
||||||
|
expect {
|
||||||
|
@photo2.status_message.reload
|
||||||
@photo2.destroy
|
@photo2.destroy
|
||||||
}.should_not change(StatusMessage, :count)
|
}.should_not change(StatusMessage, :count)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue