diff --git a/lib/acts_as_having_image.rb b/lib/acts_as_having_image.rb index 9ddea12..7c695c7 100644 --- 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 diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 1b9665a..02d039d 100644 --- 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 -- libgit2 0.21.2