spec/feature/crud_workflows_spec.rb in saviour-0.5.10 vs spec/feature/crud_workflows_spec.rb in saviour-0.5.11

- old
+ new

@@ -121,10 +121,18 @@ file_thumb: Saviour::StringSource.new("foo", "file.txt") ) end end end + + it "can be created from another saviour attachment" do + a = klass.create! file: Saviour::StringSource.new("contents", "file.txt") + b = klass.create! file: a.file + + expect(b.file.read).to eq "contents" + expect(b.file.filename).to eq "file.txt" + end end describe "deletion" do it do with_test_file("example.xml") do |example| @@ -161,10 +169,27 @@ a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt") expect(Saviour::Config.storage.read(a[:file])).to eq "foo" end + it "does not generate an extra query when saving the file with only attached changes" do + a = klass.create! + + expect_to_yield_queries(count: 1) do + a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt") + end + end + + it "does generate an extra query when saving the file with an extra change" do + a = klass.create! + + expect_to_yield_queries(count: 2) do + a.update_attributes! name: "Text", + file: Saviour::StringSource.new("foo", "file.txt") + end + end + context do let(:klass) { a = Class.new(Test) { include Saviour::Model } a.attach_file :file, uploader a.attach_file :file_thumb, uploader @@ -172,12 +197,11 @@ } it "saves to db only once with multiple file attachments" do a = klass.create! - # 2 update's, first empty and then 1 with the two attributes expected_query = %Q{UPDATE "tests" SET "file" = '/store/dir/file.txt', "file_thumb" = '/store/dir/file.txt'} - expect_to_yield_queries(count: 2, including: [expected_query]) do + expect_to_yield_queries(count: 1, including: [expected_query]) do a.update_attributes!( file: Saviour::StringSource.new("foo", "file.txt"), file_thumb: Saviour::StringSource.new("foo", "file.txt") ) end