Project

General

Profile

Actions

Patch #44201

open

Use && instead of & in Attachment#move_to_target_directory! and add test coverage

Added by Martin Glaser about 13 hours ago. Updated about 7 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:

Description

The guard clause in Attachment#move_to_target_directory! (app/models/attachment.rb)
uses the bitwise, non-short-circuiting operator & instead of the logical &&:

def move_to_target_directory!
return unless !new_record? & readable?
...

For boolean operands the result is the same, but & does not short-circuit, so
readable? — which performs a filesystem check via File.readable? — is always
evaluated, even for new records. Using && is the idiomatic choice and restores
short-circuit evaluation.

This patch:
- Replaces & with && in the guard clause.
- Adds unit tests for move_to_target_directory!, which previously had no direct
test coverage: one verifying that a readable, persisted attachment is moved to
its target directory, and one verifying that the method does nothing for a new
record.

Tested against current trunk:
- bundle exec rails test test/unit/attachment_test.rb passes
- bundle exec rubocop reports no offenses

A patch is attached.


Files

Actions #1

Updated by Go MAEDA about 7 hours ago

  • Target version set to 7.0.0

Setting the target version to 7.0.0.

Actions

Also available in: Atom PDF