[noosfero/noosfero][master] 2 commits: Add method to destroy images from communities when a profile is removed
Bráulio Bhavamitra
gitlab at gitlab.com
Fri Mar 20 15:32:37 BRT 2015
Bráulio Bhavamitra pushed to master at Noosfero / noosfero
Commits:
8d612e1b by Eduardo Passos at 2015-03-12T12:02:15Z
Add method to destroy images from communities when a profile is removed
few image_destroy adjustments
- - - - -
cccac6a3 by Bráulio Bhavamitra at 2015-03-20T18:29:24Z
Merge branch 'image-destroy' into 'master'
Image destroy
See merge request !479
- - - - -
2 changed files:
- lib/acts_as_having_image.rb
- test/unit/profile_test.rb
Changes:
=====================================
lib/acts_as_having_image.rb
=====================================
--- a/lib/acts_as_having_image.rb
+++ b/lib/acts_as_having_image.rb
@@ -2,7 +2,7 @@ module ActsAsHavingImage
module ClassMethods
def acts_as_having_image
- belongs_to :image
+ belongs_to :image, dependent: :destroy
scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ]
scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ]
self.send(:include, ActsAsHavingImage)
@@ -19,4 +19,4 @@ module ActsAsHavingImage
end
-ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
+ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
\ No newline at end of file
=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -110,6 +110,16 @@ class ProfileTest < ActiveSupport::TestCase
assert_equal total - mine, Article.count
end
+ should 'remove images when removing profile' do
+ profile = build(Profile, :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
+ image = profile.image
+ image.save!
+ profile.destroy
+ assert_raise ActiveRecord::RecordNotFound do
+ image.reload
+ end
+ end
+
def test_should_avoid_reserved_identifiers
Profile::RESERVED_IDENTIFIERS.each do |identifier|
assert_invalid_identifier identifier
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/9807e0ad3897fdf502fa7d26aa5c711a83c0739a...cccac6a3ecdce779469c8ca205a5e5cffa537b28
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150320/755adbd4/attachment-0001.html>
More information about the Noosfero-dev
mailing list