spec/feature/remove_attachment_spec.rb in saviour-0.5.2 vs spec/feature/remove_attachment_spec.rb in saviour-0.5.3

- old
+ new

@@ -3,11 +3,11 @@ describe "remove attachment" do before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) } let(:uploader) { Class.new(Saviour::BaseUploader) { - store_dir { "/store/dir" } + store_dir { "/store/dir/#{model.id}/#{attached_as}" } } } let(:klass) { a = Class.new(Test) { include Saviour::Model } @@ -76,8 +76,50 @@ a.remove_file! end expect(a.file.read).to be_falsey expect(a[:file]).to be_nil + end + end + + context "with followers" do + context "when configured to destroy followers" do + let(:klass) { + a = Class.new(Test) { include Saviour::Model } + a.attach_file :file, uploader + a.attach_file :file_thumb, uploader, follow: :file, dependent: :destroy + a + } + + it "does not remove followers when using dependent: :ignore on the remove call" do + a = klass.create! file: StringIO.new("some contents without a filename") + expect(a.file_thumb.read).to eq "some contents without a filename" + + a.remove_file!(dependent: :ignore) + + expect(a.file_thumb?).to be_truthy + expect(a.file_thumb.read).to eq "some contents without a filename" + expect(a.file?).to be_falsey + end + end + + context "when configured to ignore followers" do + let(:klass) { + a = Class.new(Test) { include Saviour::Model } + a.attach_file :file, uploader + a.attach_file :file_thumb, uploader, follow: :file, dependent: :ignore + a + } + + it "does remove followers when using dependent: :destroy on the remove call" do + a = klass.create! file: StringIO.new("some contents without a filename") + expect(a.file_thumb.read).to eq "some contents without a filename" + + a.remove_file!(dependent: :destroy) + + expect(a.file_thumb?).to be_falsey + expect(a.file_thumb.read).to be_nil + expect(a.file?).to be_falsey + end end end end