Project

General

Profile

Patch #44201 ยป attachment_move_to_target_directory.diff

Martin Glaser, 2026-06-20 21:11

View differences:

app/models/attachment.rb
443 443

  
444 444
  # Moves an existing attachment to its target directory
445 445
  def move_to_target_directory!
446
    return unless !new_record? & readable?
446
    return unless !new_record? && readable?
447 447

  
448 448
    src = diskfile
449 449
    self.disk_directory = target_directory
test/unit/attachment_test.rb
388 388
    assert a.readable?
389 389
  end
390 390

  
391
  def test_move_to_target_directory_should_move_readable_file_to_target_directory
392
    a = Attachment.find(20)
393
    assert a.disk_directory.blank?
394
    # Create a real file at the root of the files directory for this fixture
395
    File.write(a.diskfile, 'test file at the root of files directory')
396
    src = a.diskfile
397
    assert a.readable?
398

  
399
    a.move_to_target_directory!
400

  
401
    a.reload
402
    assert_equal '2012/05', a.disk_directory
403
    assert a.readable?
404
    assert File.exist?(a.diskfile)
405
    assert_not_equal src, a.diskfile
406
    assert_not File.exist?(src)
407
  end
408

  
409
  def test_move_to_target_directory_should_do_nothing_for_new_record
410
    a = Attachment.new
411
    assert a.new_record?
412
    assert_nil a.move_to_target_directory!
413
  end
414

  
391 415
  test "Attachmnet.attach_files should attach the file" do
392 416
    issue = Issue.first
393 417
    assert_difference 'Attachment.count' do
    (1-1/1)