From 63d83c9ebd7f2120da7dbe4b422710e93acdd059 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 24 Mar 2024 19:06:56 +0530 Subject: [PATCH 1/4] [#133] Fix that we were trying use regex to match ID as single digit and this did not work for more than 10 files in id --- README.md | 4 ++-- .../rails/active_record/mount_uploadcare_file_group.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e0ac9c3..cc9cf78 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ The helper is detecting the value of the `multiple` property based on the mount ### File and Group wrappers When you mount either Uploadcare File or Group to an attribute, this attribute is getting wrapped with -a Uploadcare object. This feature adds some usefull methods to the attribute. +a Uploadcare object. This feature adds some useful methods to the attribute. #### Uploadcare File @@ -300,7 +300,7 @@ class Post < ApplicationRecord end ``` -And then you create a new Post object specifying a CDN-url for your prevously uploaded Uploadcare file: +And then you create a new Post object specifying a CDN-url for your previously uploaded Uploadcare file: ```console $ post = Post.create(picture: "https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/") diff --git a/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb b/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb index 9d2fe10..4a50bc1 100644 --- a/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb +++ b/lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb @@ -13,7 +13,7 @@ module ActiveRecord module MountUploadcareFileGroup extend ActiveSupport::Concern - GROUP_ID_REGEX = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b~\d/.freeze + GROUP_ID_REGEX = /\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b~\d+/.freeze def build_uploadcare_file_group(attribute) cdn_url = attributes[attribute.to_s].to_s From 8d99b6290f4be5ef7dd8f41fe3e9f4a6a030c79c Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 24 Mar 2024 19:49:03 +0530 Subject: [PATCH 2/4] Add specs for group id matching on GROUP_ID_REGEX --- .../rails/active_record/mount_uploadcare_group_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb b/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb index 9dc6be9..5fbcc8f 100644 --- a/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +++ b/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb @@ -29,4 +29,14 @@ def initialize expect(Post).to respond_to(:has_uploadcare_file_group_for_gallery?) end end + + describe "GROUP_ID_REGEX" do + it 'properly extracts out group id from the cdn url' do + extracted_group_id = Uploadcare::Rails::IdExtractor.call('https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~11/', subject::GROUP_ID_REGEX) + expect(extracted_group_id).to eq("dc140069-62b1-4ee0-b603-18e2062e26e4~11") + + extracted_group_id = Uploadcare::Rails::IdExtractor.call('https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~1/', subject::GROUP_ID_REGEX) + expect(extracted_group_id).to eq("dc140069-62b1-4ee0-b603-18e2062e26e4~1") + end + end end From fb5bb2ee088f2f191cb44ca4f250fa5cf7cdc595 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 24 Mar 2024 20:02:31 +0530 Subject: [PATCH 3/4] Add changelog and prepare for release --- CHANGELOG.md | 6 ++++++ lib/uploadcare/rails/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f11413b..b08ad14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 3.4.1 — 2024-03-24 + +### Fixed + +* Fixed invalid group id error when >= 10 files are uploaded when using `mount_uploadcare_file_group`. + ## 3.4.0 — 2024-03-05 ### Fixed diff --git a/lib/uploadcare/rails/version.rb b/lib/uploadcare/rails/version.rb index bc96092..cef1375 100644 --- a/lib/uploadcare/rails/version.rb +++ b/lib/uploadcare/rails/version.rb @@ -2,6 +2,6 @@ module Uploadcare module Rails - VERSION = '3.4.0' + VERSION = '3.4.1' end end From 8ca23b108addc44758fcc414d8b5f1014c33714d Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Sun, 24 Mar 2024 20:04:10 +0530 Subject: [PATCH 4/4] Rubocop fixes --- .../active_record/mount_uploadcare_group_spec.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb b/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb index 5fbcc8f..fc265e4 100644 --- a/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb +++ b/spec/uploadcare/rails/active_record/mount_uploadcare_group_spec.rb @@ -30,13 +30,17 @@ def initialize end end - describe "GROUP_ID_REGEX" do + describe 'GROUP_ID_REGEX' do it 'properly extracts out group id from the cdn url' do - extracted_group_id = Uploadcare::Rails::IdExtractor.call('https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~11/', subject::GROUP_ID_REGEX) - expect(extracted_group_id).to eq("dc140069-62b1-4ee0-b603-18e2062e26e4~11") - - extracted_group_id = Uploadcare::Rails::IdExtractor.call('https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~1/', subject::GROUP_ID_REGEX) - expect(extracted_group_id).to eq("dc140069-62b1-4ee0-b603-18e2062e26e4~1") + extracted_group_id = Uploadcare::Rails::IdExtractor.call( + 'https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~11/', subject::GROUP_ID_REGEX + ) + expect(extracted_group_id).to eq('dc140069-62b1-4ee0-b603-18e2062e26e4~11') + + extracted_group_id = Uploadcare::Rails::IdExtractor.call( + 'https://ucarecdn.com/dc140069-62b1-4ee0-b603-18e2062e26e4~1/', subject::GROUP_ID_REGEX + ) + expect(extracted_group_id).to eq('dc140069-62b1-4ee0-b603-18e2062e26e4~1') end end end