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,22 +18,21 @@ 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
|
||||||
scope :where_person_is_mentioned, lambda { |person|
|
scope :where_person_is_mentioned, lambda { |person|
|
||||||
joins(:mentions).where(:mentions => {:person_id => person.id})
|
joins(:mentions).where(:mentions => {:person_id => person.id})
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :commented_by, lambda { |person|
|
scope :commented_by, lambda { |person|
|
||||||
select('DISTINCT posts.*').joins(:comments).where(:comments => {:author_id => person.id})
|
select('DISTINCT posts.*').joins(:comments).where(:comments => {:author_id => person.id})
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +66,7 @@ class StatusMessage < Post
|
||||||
def raw_message=(text)
|
def raw_message=(text)
|
||||||
write_attribute(:text, text)
|
write_attribute(:text, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def nsfw?
|
def nsfw?
|
||||||
self.raw_message.include?('#nsfw')
|
self.raw_message.include?('#nsfw')
|
||||||
end
|
end
|
||||||
|
|
@ -177,7 +176,7 @@ class StatusMessage < Post
|
||||||
|
|
||||||
def queue_gather_oembed_data
|
def queue_gather_oembed_data
|
||||||
Resque.enqueue(Jobs::GatherOEmbedData, self.id, self.oembed_url)
|
Resque.enqueue(Jobs::GatherOEmbedData, self.id, self.oembed_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contains_oembed_url_in_text?
|
def contains_oembed_url_in_text?
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ describe Photo do
|
||||||
@photo = Photo.diaspora_initialize(
|
@photo = Photo.diaspora_initialize(
|
||||||
:author => @user.person, :user_file => @image)
|
:author => @user.person, :user_file => @image)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the persons diaspora handle' do
|
it 'sets the persons diaspora handle' do
|
||||||
@photo.diaspora_handle.should == @user.person.diaspora_handle
|
@photo.diaspora_handle.should == @user.person.diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
@ -83,7 +83,7 @@ describe Photo do
|
||||||
context "with a url" do
|
context "with a url" do
|
||||||
it 'saves the photo' do
|
it 'saves the photo' do
|
||||||
url = "https://service.com/user/profile_image"
|
url = "https://service.com/user/profile_image"
|
||||||
|
|
||||||
photo_stub = stub.as_null_object
|
photo_stub = stub.as_null_object
|
||||||
photo_stub.should_receive(:remote_unprocessed_image_url=).with(url)
|
photo_stub.should_receive(:remote_unprocessed_image_url=).with(url)
|
||||||
Photo.stub(:new).and_return(photo_stub)
|
Photo.stub(:new).and_return(photo_stub)
|
||||||
|
|
@ -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
|
||||||
|
@status_message.text = "Some text"
|
||||||
|
@status_message.save
|
||||||
|
@status_message.reload
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
@status_message.text = "Some text"
|
@photo2.status_message.reload
|
||||||
@status_message.save
|
|
||||||
@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