Skip to content

File Uploader v1#156

Open
alxgsv wants to merge 3 commits intomainfrom
file-uploader-v1
Open

File Uploader v1#156
alxgsv wants to merge 3 commits intomainfrom
file-uploader-v1

Conversation

@alxgsv
Copy link

@alxgsv alxgsv commented Jan 14, 2026

Migrate to File Uploader v1

This PR replaces the legacy jQuery-based widget with the new File Uploader v1, which is built with Web Components for better framework compatibility and modern browser support.

Summary

  • Replace legacy jQuery widget with File Uploader v1
  • Add new view helpers for the File Uploader components
  • Add FormBuilder integration (f.uploadcare_file)
  • Add importmap generator for Rails 7+
  • Add Rails 8.1 support
  • Adopt rubocop-rails-omakase code style

New view helpers

Include tags:

  • uploadcare_include_tag - includes File Uploader CSS and JS from CDN
  • uploadcare_stylesheet_tag - includes only CSS (for importmap/npm setups)

Uploader fields:

  • uploadcare_uploader_field :model, :attribute - model-bound uploader with validation error wrapping
  • uploadcare_uploader_field_tag :name - standalone uploader field
  • uploadcare_uploader(ctx_name:) - just the uploader component (for custom JS handling)

FormBuilder:

  • f.uploadcare_file :attribute - use within form_with/form_for blocks

Generated HTML

The helpers generate all required Web Components automatically:

<%= uploadcare_uploader_field :post, :picture %>

Results in:

<uc-form-input ctx-name="..." name="post[picture]"></uc-form-input>
<uc-config ctx-name="..." pubkey="..." locale="en"></uc-config>
<uc-file-uploader-regular ctx-name="..."></uc-file-uploader-regular>
<uc-upload-ctx-provider ctx-name="..."></uc-upload-ctx-provider>

The <uc-form-input> component handles form synchronization automatically - no manual JavaScript required.

New generator

$ rails g uploadcare_importmap

Sets up File Uploader for Rails 7+ applications using importmaps.

Breaking changes

  • Legacy jQuery widget helpers are removed
  • Widget configuration options (live, manual_start, etc.) are replaced with File Uploader options

Summary by CodeRabbit

  • New Features

    • File Uploader Web Components replace the legacy widget.
    • FormBuilder integration with uploadcare_file helper.
    • Importmap generator and initializer to simplify Rails 7+ setup.
  • Documentation

    • README reorganized with modern Web Components usage, examples, and guidance.
  • Chores

    • Updated Ruby/Rails matrix and added Rails 8.1 testing target.
  • Tests

    • Expanded test coverage for new helpers and include tags.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

Walkthrough

The PR replaces legacy widget integration with a File Uploader Web Components approach, adds importmap generator and initializer template, updates configuration and view helpers (include tags, uploader tags, form builder), updates generator templates and docs, modernizes gemfiles (adds Rails 8.1), standardizes quoting and RuboCop config, and expands tests.

Changes

Cohort / File(s) Summary
CI & Lint
.github/workflows/test.yml, .rubocop.yml
Added gemfiles/Gemfile-rails-8-1 to CI matrix; changed matrix Ruby entries to string literals; inherit rubocop config from rubocop-rails-omakase and removed several Exclude blocks.
Gemfiles & Dependencies
Gemfile, gemfiles/* (e.g., gemfiles/Gemfile-rails-7-*, .../Gemfile-rails-8-1)
Standardized to double-quoted strings; replaced rubocop with rubocop-rails-omakase (require: false); added ostruct; converted git-based Rails specs to normal version constraints; added new Rails 8.1 gemfile.
Documentation
README.md
Rewrote docs to replace legacy widget guidance with File Uploader Web Components usage (Include Tag, Importmap, FormBuilder), updated examples and params, and reorganized sections.
Generators & Templates
lib/generators/*, lib/generators/templates/*
Added UploadcareImportmapGenerator to pin importmap and create JS initializer; added uploadcare_js_initializer.js template; reorganized uploadcare_config_template.erb into structured File Uploader sections.
View Helpers - Asset Inclusion
lib/uploadcare/rails/action_view/uploadcare_include_tags.rb
Renamed module to UploadcareIncludeTags; new signature uploadcare_include_tag(version:, solution:, min:, importmap:); added uploadcare_stylesheet_tag, CDN constants, and module-based JS import tag (module import + UC.defineComponents(UC)).
View Helpers - Uploader Components
lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb
New comprehensive helpers: uploadcare_uploader_field, uploadcare_uploader_field_tag, uploadcare_uploader, uploadcare_config_tag, uploadcare_uploader_tag, uploadcare_ctx_provider_tag, uploadcare_form_input_tag; kebab-case attribute normalization; error-wrapping integration.
FormBuilder Integration
lib/uploadcare/rails/action_view/uploadcare_form_builder.rb
Added FormBuilder#uploadcare_file to emit uploader field tied to model attribute, with ctx_name, solution, options, and field error wrapping.
Configuration & Core
lib/uploadcare/rails/configuration.rb, lib/uploadcare-rails.rb, lib/uploadcare/rails.rb, lib/uploadcare/rails/engine.rb
Added FILE_UPLOADER_PARAMS constant and uploader_config_attributes method (snake_case → kebab-case + value formatting); preserved legacy widget params; standardized require string quoting; engine requires new form builder.
API / Upload Modules
lib/uploadcare/rails/api/*, lib/uploadcare/rails/api/upload/*
Standardized require quoting; minor literal changes (e.g., webhook event default string).
Jobs, ActiveRecord, Mongoid & Objects
lib/uploadcare/rails/jobs/*, lib/uploadcare/rails/active_record/*, lib/uploadcare/rails/mongoid/*, lib/uploadcare/rails/objects/*, lib/uploadcare/rails/transformations/*
Mostly quoting and formatting standardization; small additions (private attr_reader :options in image transformations).
Generator Templates & Initializer
lib/generators/templates/uploadcare_js_initializer.js, lib/generators/templates/uploadcare_config_template.erb
Added JS initializer template with commented guidance; reorganized config template with grouped File Uploader options and new properties (security, performance, URL upload, output, localization).
Tests
spec/**/* (notable: action_view/*, active_record/*, api/*)
Added/expanded specs for include tags, uploader tags, and FormBuilder; removed legacy widget spec; updated mount/method tests and formatting changes across many specs.
Gemspec & Misc
uploadcare-rails.gemspec, lib/uploadcare/rails/version.rb
Minor formatting changes; standardized version literal quoting.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Browser
participant View as Rails View Helper
participant Server as Rails App
participant Uploadcare as CDN/UC
Browser->>View: Request rendered page (helper calls)
View->>Server: Render uc-config, uc-file-uploader, uc-form-input tags
Browser->>Uploadcare: Import module script (CDN) -> UC.defineComponents(UC)
Uploadcare-->>Browser: Web Components registered
Browser->>Uploadcare: User interacts, uploads file(s)
Uploadcare->>Browser: Returns file(s) metadata / CDN URLs
Browser->>Server: Submit form (params with file URLs)
Server->>Server: Config/Model processing (mounting, store jobs, validations)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'File Uploader v1' is directly related to the main objective of this PR, which is to replace the legacy jQuery widget with File Uploader v1 Web Components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


🧹 Recent nitpick comments
lib/generators/templates/uploadcare_config_template.erb (1)

143-144: Consider moving metadata to a more appropriate section.

The metadata option is placed under the "Localization" section, but attaching custom metadata to uploaded files isn't related to localization. Consider moving it to the "Output Options" section or creating a dedicated "Upload Metadata" section for better discoverability.

Suggested organization
   # =============================================================================
   # Output Options
   # =============================================================================

   # Output file group instead of individual files when multiple is enabled
   # config.group_output = true
+
+  # Custom metadata to attach to uploaded files
+  # config.metadata = {}

   # =============================================================================
   # Localization
   # =============================================================================

   # Available locales: ar, ca, cs, da, de, el, en, es, et, fr, he, hr, hu, id,
   # it, ja, ko, nb, nl, pl, pt, ro, ru, sk, sr, sv, tr, uk, vi, zh-CN, zh-TW
   config.locale = 'en'
-
-  # Custom metadata to attach to uploaded files
-  # config.metadata = {}

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7209619 and ac1f0e5.

📒 Files selected for processing (5)
  • gemfiles/Gemfile-rails-7-0
  • gemfiles/Gemfile-rails-7-1
  • gemfiles/Gemfile-rails-7-2
  • gemfiles/Gemfile-rails-8-1
  • lib/generators/templates/uploadcare_config_template.erb
🚧 Files skipped from review as they are similar to previous changes (2)
  • gemfiles/Gemfile-rails-8-1
  • gemfiles/Gemfile-rails-7-2
🔇 Additional comments (4)
gemfiles/Gemfile-rails-7-1 (1)

5-15: LGTM! Gemfile updates are well-structured.

The changes appropriately:

  • Switch from GitHub branch tracking to stable version constraints for Rails 7.1
  • Standardize quoting style (aligns with rubocop-rails-omakase conventions)
  • Replace rubocop with rubocop-rails-omakase per the PR's adoption of that code style
  • Add ostruct gem for Ruby 3.5+ compatibility where it's no longer bundled by default
gemfiles/Gemfile-rails-7-0 (1)

5-15: LGTM! Consistent with other Gemfiles in the PR.

The changes mirror Gemfile-rails-7-1, maintaining consistency across the test matrix. The switch from GitHub branch tracking to standard version constraints simplifies dependency resolution and avoids potential instability from tracking development branches.

lib/generators/templates/uploadcare_config_template.erb (2)

24-31: Previous review concern has been addressed.

The async options now correctly default to false with comprehensive documentation about ActiveJob backend requirements. The comments clearly explain:

  • The need for a configured ActiveJob adapter (Sidekiq, Resque, Delayed Job)
  • The dependency relationships with store_files_after_save and delete_files_after_destroy

This is a safer out-of-the-box configuration.


1-165: Well-structured configuration template.

The reorganization into clearly labeled sections (API Keys, File Storage, Caching, File Uploader, Security, etc.) significantly improves readability and discoverability. The documentation link at line 44 and comprehensive locale list at lines 139-140 are helpful additions. The template provides sensible defaults while keeping advanced options commented out.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alxgsv alxgsv force-pushed the file-uploader-v1 branch 3 times, most recently from f293be8 to de09a0c Compare January 14, 2026 15:27
@alxgsv alxgsv marked this pull request as ready for review January 15, 2026 12:26
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@gemfiles/Gemfile-rails-8-1`:
- Around line 1-14: Add the missing ostruct gem to the test Gemfile by adding
gem "ostruct" (without require) to gemfiles/Gemfile-rails-8-1 so specs that use
OpenStruct (e.g., those under spec/uploadcare/rails/objects/file_spec.rb and
spec/uploadcare/rails/active_record/*) work on Ruby 3.3+ where ostruct is no
longer bundled.

In `@lib/generators/templates/uploadcare_config_template.erb`:
- Around line 24-28: The template enables ActiveJob-related flags by default
(config.store_files_async and config.delete_files_async) but lacks guidance
about ActiveJob backend requirements; either set both flags to false by default
to avoid runtime failures for apps without ActiveJob configured, or add an
explanatory comment above these lines indicating that enabling them requires a
configured ActiveJob adapter and queueing system and that they only take effect
when store_files_after_save and delete_files_after_destroy are true; update the
template to implement one of these two safer options and ensure references to
store_files_after_save and delete_files_after_destroy remain in the comment for
clarity.
🧹 Nitpick comments (15)
.github/workflows/test.yml (1)

34-36: Inconsistent quoting of Ruby version.

The test job uses quoted strings for Ruby versions ("3.2", "3.3", "3.4"), but code-analysis uses an unquoted 3.3. For consistency and to prevent potential YAML parsing issues, consider quoting this value as well.

Suggested fix
     strategy:
       matrix:
         ruby-version:
-          - 3.3
+          - "3.3"
.rubocop.yml (1)

4-5: Address mismatch between gemspec and CI Ruby version requirements.

The gemspec declares gem.required_ruby_version = '>= 2.7.0', but the CI matrix tests only Ruby 3.2, 3.3, and 3.4. Either update the gemspec to require Ruby 3.2+ (and set TargetRubyVersion: 3.2 accordingly), or restore Ruby 2.7 testing to the CI matrix to match the declared requirement.

lib/generators/uploadcare_importmap_generator.rb (1)

12-19: Heredoc indentation will produce extra whitespace in importmap.rb.

The <<~RUBY squiggly heredoc removes leading whitespace based on the least-indented line, but the content starts with an empty line and has 8-space indentation. This will append correctly formatted content, but the leading blank line (line 14) may be unintended.

♻️ Minor cleanup suggestion
     append_to_file importmap_path do
       <<~RUBY
-
         # Uploadcare File Uploader
         pin "@uploadcare/file-uploader", to: "https://cdn.jsdelivr.net/npm/@uploadcare/file-uploader@v1/web/file-uploader.min.js"
         pin "uploadcare"
       RUBY
     end
lib/uploadcare/rails/action_view/uploadcare_form_builder.rb (1)

60-70: Consider extracting shared error-handling logic.

The uploadcare_object_has_errors? and uploadcare_error_wrapping methods are duplicated between this file and lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb (lines 157-168). While the slight signature difference (this uses object implicitly vs. explicit parameter) is acceptable, consolidating into a shared module could reduce maintenance burden.

This is minor since both implementations are simple and the duplication is intentional for different contexts (FormBuilder vs. view helper).

lib/uploadcare/rails/action_view/uploadcare_include_tags.rb (1)

71-78: Consider extracting shared CSS URL construction.

The CSS URL building logic (lines 71-76) duplicates lines 38-43 in uploadcare_include_tag. A private helper could reduce this duplication.

♻️ Suggested extraction
private

def uploadcare_css_url(version:, solution:, min:)
  min_suffix = min ? ".min" : ""
  base_path = FILE_UPLOADER_PATH.sub("@v1", "@#{version}")
  css_path = "#{base_path}/uc-file-uploader-#{solution}#{min_suffix}.css"
  URI::HTTPS.build(host: CDN_HOST, path: css_path).to_s
end

Then both methods can call stylesheet_link_tag(uploadcare_css_url(version:, solution:, min:)).

lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb (1)

83-91: Redundant nil check for required keyword argument.

On line 84, ctx_name ||= SecureRandom.uuid is unnecessary because ctx_name: is a required keyword argument (no default value). Callers must provide it or get an ArgumentError. This line could be removed for clarity.

Suggested fix
       def uploadcare_uploader(ctx_name:, solution: "regular", **options)
-        ctx_name ||= SecureRandom.uuid
-
         config = uploadcare_config_tag(ctx_name: ctx_name, **options)
         uploader = uploadcare_uploader_tag(ctx_name: ctx_name, solution: solution)
         ctx_provider = uploadcare_ctx_provider_tag(ctx_name: ctx_name)
README.md (3)

168-175: Documentation improvement: Add descriptive text for "here" link.

The link on line 170 uses "here" as link text, which is flagged by accessibility linters (MD059). Consider making the link text more descriptive.

-- **solution** — solution type. Available names are "regular", "inline", "minimal".
-               Default is "regular". More info about solutions [here](https://uploadcare.com/docs/file-uploader/solutions/).
+- **solution** — solution type. Available names are "regular", "inline", "minimal".
+               Default is "regular". See [File Uploader solutions documentation](https://uploadcare.com/docs/file-uploader/solutions/) for more info.

181-183: Consider removing unnecessary dollar sign prefix in command.

Line 182 shows a shell command with $ prefix but no output. For commands that don't show output, the dollar sign can be omitted per markdown best practices (MD014).

-```console
-$ rails g uploadcare_importmap
-```
+```console
+rails g uploadcare_importmap
+```

223-231: Consider using a heading instead of bold text for "Manual Setup" section.

Line 223 uses bold emphasis (**Manual Setup**) as a de facto heading. Using an actual heading improves document structure and accessibility.

-**Manual Setup**
-
-If you prefer manual setup, create your JavaScript initializer in `app/javascript/uploadcare.js`:
+##### Manual Setup
+
+If you prefer manual setup, create your JavaScript initializer in `app/javascript/uploadcare.js`:
spec/uploadcare/rails/action_view/uploadcare_form_builder_spec.rb (2)

210-213: Move RSpec.configure before the test blocks.

The RSpec.configure block at the end of the file includes UploadcareUploaderTags and FormHelper modules, but this configuration should be placed before the RSpec.describe blocks to ensure the modules are available when tests run. While RSpec processes configuration blocks first regardless of position, placing it at the beginning improves readability and follows convention.

Suggested reorganization
 require 'spec_helper'
 require 'uploadcare/rails/action_view/uploadcare_uploader_tags'
 require 'uploadcare/rails/action_view/uploadcare_form_builder'

+RSpec.configure do |c|
+  c.include Uploadcare::Rails::ActionView::UploadcareUploaderTags, type: :helper
+  c.include ActionView::Helpers::FormHelper, type: :helper
+end
+
 RSpec.describe 'ActionView::Helpers::FormBuilder#uploadcare_file', type: :helper do

And remove lines 210-213 from the end of the file.


42-45: Inline rescue catches all exceptions.

The rescue 'object' catches all exceptions, not just NoMethodError for classes without names. This is generally a code smell, but acceptable in test helper code. Consider being more explicit if this pattern is reused elsewhere.

More explicit alternative
 def form_builder_for(object, object_name: nil)
-  object_name ||= object.class.name.underscore rescue 'object'
+  object_name ||= begin
+    object.class.name.underscore
+  rescue NoMethodError, NameError
+    'object'
+  end
   ActionView::Helpers::FormBuilder.new(object_name, object, self, {})
 end
spec/uploadcare/rails/action_view/uploadcare_include_tags_spec.rb (1)

96-98: Move RSpec.configure before the test blocks for consistency.

Same as the form builder spec - while RSpec processes configuration blocks first, placing it before the describe blocks improves readability.

spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb (2)

96-106: Consider extracting shared mock classes to reduce duplication.

The mock_errors_class definition (lines 96-106) is duplicated from uploadcare_form_builder_spec.rb (lines 12-22). Consider extracting this to a shared support file.

Example shared support file
# spec/support/uploadcare_test_helpers.rb
module UploadcareTestHelpers
  def mock_errors_class
    Class.new do
      def initialize(errors = {})
        `@errors` = errors
      end

      def [](key)
        `@errors`[key] || []
      end
    end
  end
end

RSpec.configure do |c|
  c.include UploadcareTestHelpers, type: :helper
end

407-409: Consider moving RSpec.configure to the top of the file.

For consistency and readability, consider placing the configuration before the describe blocks.

lib/generators/templates/uploadcare_config_template.erb (1)

132-141: Misplaced metadata option under Localization section.

The metadata configuration option (lines 140-141) is unrelated to localization and should be moved to a more appropriate section, such as "Output Options" or "File Uploader Configuration".

Suggested fix
   # =============================================================================
   # Localization
   # =============================================================================
 
   # Available locales: ar, ca, cs, da, de, el, en, es, et, fr, he, hr, hu, id,
   # it, ja, ko, nb, nl, pl, pt, ro, ru, sk, sr, sv, tr, uk, vi, zh-CN, zh-TW
   config.locale = 'en'
-
-  # Custom metadata to attach to uploaded files
-  # config.metadata = {}

Move the metadata option to the "Output Options" section:

   # =============================================================================
   # Output Options
   # =============================================================================
 
   # Output file group instead of individual files when multiple is enabled
   # config.group_output = true
+
+  # Custom metadata to attach to uploaded files
+  # config.metadata = {}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d7e1557 and 7209619.

📒 Files selected for processing (50)
  • .github/workflows/test.yml
  • .rubocop.yml
  • Gemfile
  • README.md
  • gemfiles/Gemfile-rails-7-0
  • gemfiles/Gemfile-rails-7-1
  • gemfiles/Gemfile-rails-7-2
  • gemfiles/Gemfile-rails-8-1
  • lib/generators/templates/uploadcare_config_template.erb
  • lib/generators/templates/uploadcare_js_initializer.js
  • lib/generators/uploadcare_config_generator.rb
  • lib/generators/uploadcare_importmap_generator.rb
  • lib/uploadcare-rails.rb
  • lib/uploadcare/rails.rb
  • lib/uploadcare/rails/action_view/uploadcare_form_builder.rb
  • lib/uploadcare/rails/action_view/uploadcare_include_tags.rb
  • lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb
  • lib/uploadcare/rails/active_record/mount_uploadcare_file.rb
  • lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb
  • lib/uploadcare/rails/api/rest/addons_api.rb
  • lib/uploadcare/rails/api/rest/base.rb
  • lib/uploadcare/rails/api/rest/conversion_api.rb
  • lib/uploadcare/rails/api/rest/file_api.rb
  • lib/uploadcare/rails/api/rest/file_metadata_api.rb
  • lib/uploadcare/rails/api/rest/group_api.rb
  • lib/uploadcare/rails/api/rest/project_api.rb
  • lib/uploadcare/rails/api/rest/webhook_api.rb
  • lib/uploadcare/rails/api/upload/base.rb
  • lib/uploadcare/rails/api/upload/upload_api.rb
  • lib/uploadcare/rails/configuration.rb
  • lib/uploadcare/rails/engine.rb
  • lib/uploadcare/rails/jobs/delete_file_job.rb
  • lib/uploadcare/rails/jobs/store_file_job.rb
  • lib/uploadcare/rails/jobs/store_group_job.rb
  • lib/uploadcare/rails/mongoid/mount_uploadcare_file.rb
  • lib/uploadcare/rails/mongoid/mount_uploadcare_file_group.rb
  • lib/uploadcare/rails/objects/concerns/loadable.rb
  • lib/uploadcare/rails/objects/file.rb
  • lib/uploadcare/rails/objects/group.rb
  • lib/uploadcare/rails/services/files_count_extractor.rb
  • lib/uploadcare/rails/transformations/image_transformations.rb
  • lib/uploadcare/rails/version.rb
  • spec/uploadcare/rails/action_view/uploadcare_form_builder_spec.rb
  • spec/uploadcare/rails/action_view/uploadcare_include_tags_spec.rb
  • spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb
  • spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb
  • spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb
  • spec/uploadcare/rails/api/rest/file_api_spec.rb
  • spec/uploadcare/rails/api/upload/upload_api_spec.rb
  • uploadcare-rails.gemspec
💤 Files with no reviewable changes (1)
  • spec/uploadcare/rails/action_view/uploadcare_widget_tags_spec.rb
🧰 Additional context used
🧬 Code graph analysis (8)
spec/uploadcare/rails/api/rest/file_api_spec.rb (1)
lib/uploadcare/rails/api/rest/file_api.rb (2)
  • store_files (59-61)
  • delete_files (66-68)
spec/uploadcare/rails/action_view/uploadcare_form_builder_spec.rb (2)
spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb (3)
  • initialize (90-92)
  • initialize (98-100)
  • key (102-104)
lib/uploadcare/rails/configuration.rb (1)
  • include (8-136)
spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb (2)
lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb (7)
  • uploadcare_uploader_field_tag (64-71)
  • uploadcare_uploader_field (33-47)
  • uploadcare_uploader (83-91)
  • uploadcare_config_tag (99-121)
  • uploadcare_uploader_tag (124-126)
  • uploadcare_ctx_provider_tag (129-131)
  • uploadcare_form_input_tag (148-152)
lib/uploadcare/rails/configuration.rb (1)
  • include (8-136)
spec/uploadcare/rails/action_view/uploadcare_include_tags_spec.rb (1)
lib/uploadcare/rails/action_view/uploadcare_include_tags.rb (2)
  • uploadcare_include_tag (37-57)
  • uploadcare_stylesheet_tag (71-78)
lib/generators/uploadcare_importmap_generator.rb (1)
lib/generators/uploadcare_config_generator.rb (1)
  • desc (4-12)
lib/uploadcare/rails/action_view/uploadcare_form_builder.rb (1)
lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb (3)
  • uploadcare_uploader_field_tag (64-71)
  • uploadcare_object_has_errors? (158-163)
  • uploadcare_error_wrapping (167-169)
lib/uploadcare/rails/objects/file.rb (1)
lib/uploadcare/rails/transformations/image_transformations.rb (1)
  • call (16-18)
spec/uploadcare/rails/api/upload/upload_api_spec.rb (1)
lib/uploadcare/rails/api/upload/upload_api.rb (2)
  • upload (43-45)
  • upload_files (27-31)
🪛 markdownlint-cli2 (0.18.1)
README.md

170-170: Link text should be descriptive

(MD059, descriptive-link-text)


182-182: Dollar signs used before commands without showing output

(MD014, commands-show-output)


223-223: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (71)
lib/uploadcare/rails/objects/concerns/loadable.rb (2)

3-3: LGTM: Style update aligns with rubocop-rails-omakase.

The quote style change is purely cosmetic and consistent with the PR's adoption of rubocop-rails-omakase code style.


15-15: LGTM: Formatting update aligns with rubocop-rails-omakase.

The spacing change in the array literal is purely cosmetic and consistent with the PR's adoption of rubocop-rails-omakase code style. The logic remains unchanged.

lib/uploadcare/rails/objects/file.rb (4)

3-5: Style changes align with rubocop-rails-omakase.

These double-quote changes are consistent with the stated adoption of rubocop-rails-omakase code style.


14-14: LGTM!

Array spacing follows the adopted rubocop-rails-omakase style convention.


18-23: LGTM!

The array spacing change is purely cosmetic. The transform_url logic correctly joins the CDN URL with the transformations query string using "-", which aligns with how ImageTransformations#call formats its output.


39-48: LGTM!

The else and end keyword alignment with the assignment start is a valid Ruby style for multi-line conditional assignments. Logic remains unchanged.

lib/uploadcare/rails/active_record/mount_uploadcare_file_group.rb (1)

3-7: LGTM!

The double-quoted string style for require statements aligns with the rubocop-rails-omakase style guide adoption mentioned in the PR objectives.

lib/uploadcare/rails/services/files_count_extractor.rb (1)

8-10: LGTM!

Style-only change from single to double quotes. The extraction logic remains correct.

lib/uploadcare/rails/jobs/store_file_job.rb (1)

3-3: LGTM!

Style-only change for the require statement.

lib/uploadcare/rails/version.rb (1)

5-5: LGTM!

Style-only change for the VERSION constant string literal.

lib/uploadcare-rails.rb (1)

3-14: LGTM!

All require statements consistently updated to double-quoted strings, aligning with the rubocop-rails-omakase style adoption.

lib/uploadcare/rails.rb (1)

3-3: LGTM!

Style change aligns with the adopted rubocop-rails-omakase code style.

lib/uploadcare/rails/jobs/delete_file_job.rb (1)

3-3: LGTM!

Style change consistent with the rubocop-rails-omakase adoption.

lib/uploadcare/rails/mongoid/mount_uploadcare_file.rb (1)

3-8: LGTM!

Require statements updated to double quotes for style consistency. No functional changes.

lib/uploadcare/rails/mongoid/mount_uploadcare_file_group.rb (1)

3-8: LGTM!

Require statements updated to double quotes for style consistency. No functional changes.

uploadcare-rails.gemspec (1)

13-15: LGTM!

Array formatting updated to include spaces inside brackets, consistent with rubocop-rails-omakase style.

lib/uploadcare/rails/objects/group.rb (1)

3-5: LGTM — Style changes align with rubocop-rails-omakase adoption.

The updates to double-quoted strings and spacing adjustments are consistent with the PR's code style migration. No functional changes.

Also applies to: 24-24, 47-49

lib/generators/templates/uploadcare_js_initializer.js (1)

1-25: Good template structure with helpful commented examples.

The minimal active code correctly initializes the Web Components. The commented examples for Turbo and Turbolinks event handling provide useful guidance.

One consideration: for Rails apps using Turbo (the default in Rails 7+), users will likely need to uncomment the turbo:load listener (lines 20-22) to ensure the uploader reinitializes on navigation. Consider adding a brief note in the comment indicating this is commonly needed for SPA-style navigation.

lib/uploadcare/rails/active_record/mount_uploadcare_file.rb (1)

3-7: LGTM — Style-only changes to require statements.

No functional changes. The double-quoted strings align with the codebase's style migration.

lib/uploadcare/rails/api/upload/upload_api.rb (1)

3-3: LGTM — String literal style updates only.

No functional changes to the upload API logic.

Also applies to: 30-30

spec/uploadcare/rails/api/upload/upload_api_spec.rb (1)

63-63: LGTM — Formatting adjustment for array spacing.

Minor whitespace change consistent with the codebase style migration. Test behavior unchanged.

.github/workflows/test.yml (1)

10-17: LGTM on matrix updates.

Adding Rails 8.1 to the test matrix and using quoted string literals for Ruby versions is the correct approach—this prevents YAML from interpreting versions like 3.1 as floats.

Gemfile (1)

11-19: LGTM!

Good addition of ostruct for Ruby 3.3+ compatibility (where OpenStruct is no longer part of the default gems). The switch to rubocop-rails-omakase aligns with the PR's adoption of Rails-standard code style.

.rubocop.yml (1)

1-3: LGTM on adopting rubocop-rails-omakase.

Inheriting from rubocop-rails-omakase provides a well-maintained, Rails-aligned RuboCop configuration, reducing custom rule maintenance.

lib/uploadcare/rails/transformations/image_transformations.rb (1)

1-45: LGTM!

The changes are purely formatting updates to align with rubocop-rails-omakase style (double-quoted strings, spacing around array literals). The transformation logic remains unchanged and correct.

spec/uploadcare/rails/active_record/mount_uploadcare_file_spec.rb (3)

11-12: LGTM on Rails stub setup.

The conditional stub_const for Rails and the cache mock properly isolate the test from needing a real Rails environment. This prevents errors when the implementation accesses Rails.cache.


20-30: Good refactor to mirror ActiveRecord's attributes pattern.

The @attributes hash approach better simulates how ActiveRecord models store attributes, making the test more realistic. The explicit picture= writer and attributes accessor provide the necessary interface for the mount behavior.


45-57: Solid test coverage for CDN URL assignment.

The test properly validates that:

  1. The CDN URL is stored in the attributes hash
  2. A Uploadcare::Rails::File object is constructed
  3. The cdn_url accessor returns the original URL
  4. The uuid is correctly extracted from the URL path
lib/generators/uploadcare_importmap_generator.rb (3)

25-27: LGTM on initializer creation.

The method correctly uses copy_file to create the JS initializer, consistent with the pattern used in UploadcareConfigGenerator.


53-55: LGTM on importmap_path helper.

Using Rails.root.join returns a Pathname, which supports the .exist? check used in add_importmap_pins.


43-45: No changes needed. The uploadcare_config_tag helper is properly defined in the codebase and is correctly used in the post-install message.

Likely an incorrect or invalid review comment.

lib/uploadcare/rails/action_view/uploadcare_form_builder.rb (1)

37-55: LGTM on FormBuilder integration.

The uploadcare_file method correctly:

  • Generates a unique ctx_name when not provided
  • Constructs the field name using Rails conventions (object_name[method])
  • Delegates to the template's helper for HTML generation
  • Applies error wrapping when validation errors exist
lib/uploadcare/rails/engine.rb (2)

12-16: LGTM on ActionView helper loading.

The load order is correct - uploadcare_form_builder is loaded after uploadcare_uploader_tags, ensuring the uploadcare_uploader_field_tag helper is available when the FormBuilder extension is required.


3-30: Quote style updates align with rubocop-rails-omakase.

The consistent use of double quotes throughout the file follows the new code style adopted in this PR.

lib/uploadcare/rails/action_view/uploadcare_include_tags.rb (3)

11-12: LGTM on CDN constants.

Centralizing the CDN host and path as constants makes the code more maintainable and ensures consistency across helpers.


37-57: LGTM on include tag implementation.

The method cleanly handles both CDN and importmap modes:

  • Builds URLs using URI::HTTPS.build for safety
  • Early returns CSS-only for importmap mode
  • Uses ES module import pattern for the JS tag
  • safe_join properly combines the tags

84-84: LGTM on module inclusion.

The module is correctly included into ActionView::Base at load time, making the helpers available in all views.

lib/uploadcare/rails/configuration.rb (4)

18-53: Well-structured configuration parameters for the new File Uploader.

The FILE_UPLOADER_PARAMS constant is comprehensive and covers the documented Uploadcare File Uploader options. The inline documentation referencing the configuration docs is helpful.


66-87: Configuration attribute generation looks correct with one edge case consideration.

The uploader_config_attributes method correctly:

  • Converts snake_case to kebab-case
  • Maps public_key to pubkey as required by the File Uploader
  • Handles nil values by skipping them

One minor consideration: format_config_value returns boolean values as-is (line 117), but when these are interpolated into HTML attributes, they render as "true" or "false" strings. This is the expected behavior for uc-config attributes based on the Uploadcare docs.


101-106: Legacy widget method may raise NoMethodError if a parameter is not set.

The method uses public_send(param) for each WIDGET_PARAMS entry. If any parameter doesn't have a corresponding accessor (shouldn't happen given line 64), or if a typo exists in WIDGET_PARAMS, this will fail at runtime. However, since line 64 ensures all params have accessors via attr_accessor, this should be safe.


110-121: Consider consistency between format_config_value and handle_param_value for Array handling.

The new format_config_value joins arrays with commas (line 115), while the legacy handle_param_value joins with spaces (line 129). This is intentional — the File Uploader expects comma-separated values while the legacy widget expected space-separated. The distinction is correct but worth noting for future maintainers.

lib/uploadcare/rails/action_view/uploadcare_uploader_tags.rb (3)

165-169: Error wrapping implementation follows Rails conventions correctly.

The uploadcare_error_wrapping method properly uses instance_exec with ActionView::Base.field_error_proc, matching how Rails' built-in form helpers wrap fields with validation errors. This ensures consistent behavior with standard Rails form fields.


33-47: Model-bound uploader field correctly implements Rails conventions.

The helper properly:

  • Retrieves the model from instance variables (line 35)
  • Generates field names in Rails nested params format (line 38)
  • Applies validation error wrapping when errors exist

This matches how Rails' built-in form helpers like text_field work.


99-121: Manual HTML attribute construction is correct and handles boolean values properly.

The manual attribute generation correctly sidesteps ActionView's special handling of the multiple attribute, and ERB::Util.html_escape appropriately prevents XSS. Uploadcare's uc-config element correctly interprets the string "false" as a falsy value, so boolean false values rendering as attribute="false" works as intended and will properly disable the multiple option.

README.md (1)

252-310: Documentation for Uploader Field and FormBuilder is clear and comprehensive.

The documentation effectively explains:

  • Basic usage with uploadcare_uploader_field
  • Generated Web Components and their purposes
  • Available options with examples
  • FormBuilder integration with f.uploadcare_file

This provides a good developer experience for adopting the new File Uploader.

lib/uploadcare/rails/api/rest/base.rb (1)

1-15: Style-only change aligns with rubocop-rails-omakase adoption.

The change from single to double quotes for require "uploadcare" is consistent with the PR's adoption of rubocop-rails-omakase code style. No functional changes.

lib/uploadcare/rails/jobs/store_group_job.rb (1)

1-14: Style-only change, job implementation is straightforward.

The quote style change aligns with the PR's rubocop-rails-omakase adoption. The job's perform method correctly guards against nil group_id before making the API call.

lib/uploadcare/rails/api/rest/file_metadata_api.rb (1)

3-3: LGTM!

Style-only change aligning with the rubocop-rails-omakase convention for double-quoted strings.

spec/uploadcare/rails/api/rest/file_api_spec.rb (1)

59-59: LGTM!

Array literal spacing updated to match rubocop-rails-omakase style preferences.

Also applies to: 67-67

lib/uploadcare/rails/api/rest/file_api.rb (1)

3-3: LGTM!

Style-only change for double-quoted string consistency across the REST API modules.

lib/uploadcare/rails/api/rest/addons_api.rb (1)

3-3: LGTM!

Consistent with the double-quoted string convention adopted across the codebase.

lib/uploadcare/rails/api/rest/group_api.rb (1)

3-3: LGTM!

Completes the string literal style standardization across the REST API modules.

lib/uploadcare/rails/api/upload/base.rb (1)

3-3: LGTM!

String quote style updated to double quotes, consistent with the rubocop-rails-omakase adoption across the codebase.

lib/uploadcare/rails/api/rest/conversion_api.rb (1)

3-3: LGTM!

Require statement updated to double-quoted string, aligning with the codebase-wide style standardization.

lib/generators/uploadcare_config_generator.rb (1)

5-10: LGTM!

String literals updated to double quotes throughout the generator. Style is now consistent with rubocop-rails-omakase conventions.

lib/uploadcare/rails/api/rest/project_api.rb (1)

3-3: LGTM!

Require statement updated to double-quoted string, consistent with the REST API module standardization.

lib/uploadcare/rails/api/rest/webhook_api.rb (2)

3-3: LGTM!

Require statement updated to double-quoted string.


22-22: LGTM!

Default parameter value updated to double-quoted string. Functionally equivalent, now consistent with the adopted code style.

spec/uploadcare/rails/action_view/uploadcare_form_builder_spec.rb (1)

47-185: Comprehensive test coverage for FormBuilder integration.

The test suite thoroughly covers:

  • Component generation for all uploader elements
  • Name attribute formatting with bracket notation
  • Auto-generated and custom ctx_name handling
  • Multiple solution types (regular, inline, minimal)
  • Options forwarding to config
  • Error wrapping behavior across various scenarios (no errors, field errors, other field errors, nil object, object without errors method)
spec/uploadcare/rails/action_view/uploadcare_include_tags_spec.rb (1)

7-93: Well-structured tests for include tag helpers.

The test suite provides good coverage for both uploadcare_include_tag and uploadcare_stylesheet_tag, including:

  • Default CDN URLs with correct paths
  • Version parameter propagation
  • Solution variants (regular, inline, minimal)
  • Minified vs non-minified asset handling
  • Importmap mode (CSS-only output)
gemfiles/Gemfile-rails-7-2 (1)

5-14: Gemfile dependencies look appropriate for Rails 7.2.

The transition from rubocop to rubocop-rails-omakase aligns with Rails community conventions. Version constraints are reasonable.

gemfiles/Gemfile-rails-7-1 (1)

5-14: Consistent with other Rails Gemfiles.

Dependencies and version constraints match the Rails 7.2 Gemfile, ensuring consistent behavior across Rails versions.

spec/uploadcare/rails/action_view/uploadcare_uploader_tags_spec.rb (3)

21-80: Good coverage for uploadcare_uploader_field_tag.

Tests appropriately verify that this tag-style helper generates all required components without error wrapping, matching the Rails convention where *_tag helpers don't interact with model state.


286-360: Excellent coverage for config merging edge cases.

These tests thoroughly verify the key normalization logic that converts snake_case to kebab-case and properly merges user options with config defaults. The duplicate attribute checks (e.g., expect(tag.scan('img-only=').count).to eq(1)) are particularly valuable for ensuring valid HTML output.


209-240: Good coverage for the headless uploader helper.

Tests correctly verify that uploadcare_uploader generates components without uc-form-input, which is the expected behavior for custom JavaScript handling scenarios.

lib/generators/templates/uploadcare_config_template.erb (3)

4-12: Well-structured API Keys section.

Clear separation with environment variable fallbacks and appropriate commenting of the secret key.


39-82: Comprehensive File Uploader configuration section.

Good coverage of common options with helpful examples and documentation link. The commented defaults allow users to easily customize while understanding available options.


143-161: Clear Image and CDN configuration sections.

Well-organized with appropriate defaults. The cdn_hostname being set to the standard Uploadcare CDN is a sensible default.

gemfiles/Gemfile-rails-7-0 (3)

5-5: Good change from GitHub branch to standard gem source.

Using the standard gem source "~> 7.0.0" instead of tracking the GitHub branch provides better stability for CI testing.


7-14: Well-structured gem declarations with appropriate version constraints.

Consistent double-quoted strings and explicit version constraints. The require: false on mongoid and rubocop-rails-omakase is appropriate since they're optional/development dependencies.


11-11: rubocop-rails-omakase configuration is properly set up.

The .rubocop.yml correctly inherits from rubocop-rails-omakase via inherit_gem: rubocop-rails-omakase: rubocop.yml, and the plain rubocop gem has been removed from all Gemfiles. The switch aligns with the PR objectives and is complete.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Included the 'ostruct' gem in Gemfiles for Rails versions 7.0, 7.1, 7.2, and 8.1 to ensure consistent availability across test environments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant