+
+ def test_path_partitioning_works_on_integer_id(klass = FileAttachment)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = 1
+
+ begin
+ assert_equal ["0000", "0001", "bar.txt"], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partitioning_works_on_integer_id, FileAttachment
+
+ def test_path_partitioning_with_string_id_works_by_generating_hash(klass = FileAttachmentWithStringId)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = "hello world some long string"
+ hash = Digest::SHA512.hexdigest("hello world some long string")
+
+ begin
+ assert_equal [
+ hash[0..31],
+ hash[32..63],
+ hash[64..95],
+ hash[96..127],
+ "bar.txt"
+ ], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partitioning_with_string_id_works_by_generating_hash, FileAttachmentWithStringId
+
+ def test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid(klass = FileAttachmentWithUuid)
+ attachment_model klass
+
+ # Create a random attachment object, doesn't matter what.
+ attachment = upload_file :filename => '/files/rails.png'
+ old_id = attachment.id
+ attachment.id = "0c0743b698483569dc65909a8cdb3bf9"
+
+ begin
+ assert_equal [
+ "0c0743b698483569",
+ "dc65909a8cdb3bf9",
+ "bar.txt"
+ ], attachment.send(:partitioned_path, "bar.txt")
+ ensure
+ attachment.id = old_id
+ end
+ end
+
+ test_against_subclass :test_path_partition_string_id_hashing_is_turned_off_if_id_is_uuid, FileAttachmentWithUuid
+end