Commit 8d612e1b3036394b8553a0a41e205eec32e4a931

Authored by Eduardo Passos
Committed by Eduardo Passos
1 parent c5b5a296

Add method to destroy images from communities when a profile is removed

few image_destroy adjustments
lib/acts_as_having_image.rb
... ... @@ -2,7 +2,7 @@ module ActsAsHavingImage
2 2  
3 3 module ClassMethods
4 4 def acts_as_having_image
5   - belongs_to :image
  5 + belongs_to :image, dependent: :destroy
6 6 scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ]
7 7 scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ]
8 8 self.send(:include, ActsAsHavingImage)
... ... @@ -19,4 +19,4 @@ module ActsAsHavingImage
19 19  
20 20 end
21 21  
22 22 -ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
  23 +ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
23 24 \ No newline at end of file
... ...
test/unit/profile_test.rb
... ... @@ -110,6 +110,16 @@ class ProfileTest < ActiveSupport::TestCase
110 110 assert_equal total - mine, Article.count
111 111 end
112 112  
  113 + should 'remove images when removing profile' do
  114 + profile = build(Profile, :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')})
  115 + image = profile.image
  116 + image.save!
  117 + profile.destroy
  118 + assert_raise ActiveRecord::RecordNotFound do
  119 + image.reload
  120 + end
  121 + end
  122 +
113 123 def test_should_avoid_reserved_identifiers
114 124 Profile::RESERVED_IDENTIFIERS.each do |identifier|
115 125 assert_invalid_identifier identifier
... ...