test/integration_test.rb in paperclip-2.2.6 vs test/integration_test.rb in paperclip-2.2.7

- old
+ new

@@ -37,18 +37,20 @@ context "redefining its attachment styles" do setup do Dummy.class_eval do has_attached_file :avatar, :styles => { :thumb => "150x25#" } + has_attached_file :avatar, :styles => { :thumb => "150x25#", :dynamic => lambda { |a| '50x50#' } } end @d2 = Dummy.find(@dummy.id) @d2.avatar.reprocess! @d2.save end should "create its thumbnails properly" do assert_match /\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"` + assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:dynamic)}"` end end end context "A model that modifies its original" do @@ -92,11 +94,11 @@ assert File.exists?(@dummy.avatar.path(:large)) end context "and deleted" do setup do - @dummy.avatar = nil + @dummy.avatar.clear @dummy.save end should "not have a large file in the right place anymore" do assert ! File.exists?(@saved_path) @@ -231,11 +233,11 @@ saved_paths.each do |p| assert File.exists?(p) end - @dummy.avatar = nil + @dummy.avatar.clear assert_nil @dummy.avatar_file_name assert @dummy.valid? assert @dummy.save saved_paths.each do |p| @@ -254,46 +256,42 @@ assert_equal @dummy.avatar.path(style), @d2.avatar.path(style) end saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.path(s) } - @d2.avatar = nil + @d2.avatar.clear assert @d2.save saved_paths.each do |p| assert ! File.exists?(p) end end - should "know the difference between good files, bad files, not files, and nil" do + should "know the difference between good files, bad files, and not files" do expected = @dummy.avatar.to_file @dummy.avatar = "not a file" assert @dummy.valid? assert_equal expected.path, @dummy.avatar.path expected.close @dummy.avatar = @bad_file assert ! @dummy.valid? - @dummy.avatar = nil - assert @dummy.valid?, @dummy.errors.inspect end - should "know the difference between good files, bad files, not files, and nil when validating" do + should "know the difference between good files, bad files, and not files when validating" do Dummy.validates_attachment_presence :avatar @d2 = Dummy.find(@dummy.id) @d2.avatar = @file assert @d2.valid?, @d2.errors.full_messages.inspect @d2.avatar = @bad_file assert ! @d2.valid? - @d2.avatar = nil - assert ! @d2.valid? end should "be able to reload without saving and not have the file disappear" do @dummy.avatar = @file assert @dummy.save - @dummy.avatar = nil + @dummy.avatar.clear assert_nil @dummy.avatar_file_name @dummy.reload assert_equal "5k.png", @dummy.avatar_file_name end @@ -312,20 +310,10 @@ assert @dummy.avatar = @dummy2.avatar @dummy.save assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` end - - should "work when assigned a nil file" do - @dummy2.avatar = nil - @dummy2.save - - @dummy.avatar = @dummy2.avatar - @dummy.save - - assert !@dummy.avatar? - end end end context "A model with an attachments association and a Paperclip attachment" do @@ -419,11 +407,11 @@ saved_keys.each do |key| assert key.exists? end - @dummy.avatar = nil + @dummy.avatar.clear assert_nil @dummy.avatar_file_name assert @dummy.valid? assert @dummy.save saved_keys.each do |key| @@ -442,10 +430,10 @@ assert_equal @dummy.avatar.to_file(style).to_s, @d2.avatar.to_file(style).to_s end saved_keys = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s) } - @d2.avatar = nil + @d2.avatar.clear assert @d2.save saved_keys.each do |key| assert ! key.exists? end