Commit cccac6a3ecdce779469c8ca205a5e5cffa537b28
Exists in
master
and in
29 other branches
Merge branch 'image-destroy' into 'master'
Image destroy See merge request !479
Showing
2 changed files
with
12 additions
and
2 deletions
Show diff stats
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 | ... | ... |