Conversation
…-rails-omakase source
…pplication helper, and update test assertions for consistency. Added metadata for MFA requirement in gemspec and improved path handling in helper methods.
… for Heroicons initializer - Updated README.md to include installation steps and configuration options for default icon type and CSS classes. - Refactored application helper to use configuration values for icon type and class. - Introduced a new generator to create a Heroicons initializer file. - Added a configuration class to manage default settings for the gem.
There was a problem hiding this comment.
Pull request overview
This pull request introduces a configuration system for the heroicons-rails gem that allows users to customize default icon types and CSS classes, along with a Rails generator for easy setup. It also includes code style improvements, test refactoring, and dependency updates throughout the codebase.
Changes:
- Added configuration system with
Heroicons::Configurationclass and related methods to customize default icon types and CSS classes - Created a Rails generator (
heroicons:install) to generate a configuration initializer - Updated Ruby version specification, refactored tests for consistency, and modernized code style across multiple files
Reviewed changes
Copilot reviewed 20 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/heroicons/configuration.rb | New configuration class with default_type and default_class attributes |
| lib/heroicons-rails.rb | Added configuration methods (configuration, configure, reset_configuration!) to Heroicons module |
| lib/generators/heroicons/install_generator.rb | New Rails generator to create configuration initializer |
| lib/generators/heroicons/templates/initializer.rb | Template for Heroicons configuration initializer |
| app/helpers/heroicons/application_helper.rb | Updated icon_tag helper to use configurable defaults and improved path handling |
| README.md | Added installation, configuration, and usage documentation |
| test/heroicons_rails/rails_test.rb | Refactored tests to use assert_includes and improved assertions |
| test/test_helper.rb | Code style improvements (array literals, string interpolation) |
| test/dummy/bin/setup | Modified system! method definition with splat operator |
| test/dummy/config/puma.rb | Updated ENV.fetch syntax to use two-argument form |
| test/dummy/config/initializers/filter_parameter_logging.rb | Changed array to symbol array literal |
| test/dummy/config/environments/production.rb | Changed STDOUT to $stdout and updated logger configuration |
| test/dummy/config/environments/development.rb | Removed extra blank line |
| test/dummy/app/controllers/dashboard_controller.rb | Changed parent class from ActionController::Base to ApplicationController |
| rakelib/move_to_assets.rake | Added environment dependency and changed mkdir to mkdir_p |
| lib/heroicons/version.rb | Added .freeze to VERSION constant |
| lib/heroicons/errors.rb | Fixed indentation of private method |
| heroicons-rails.gemspec | Code style improvements and added rubygems_mfa_required metadata |
| bin/test | Changed $: to $LOAD_PATH |
| bin/rails | New file for Rails engine commands |
| Rakefile | Changed single quotes to double quotes for consistency |
| Gemfile | Reorganized gems and switched to GitHub reference for rubocop-rails-omakase |
| Gemfile.lock | Updated Rails from edge to 8.1.2 and updated all dependencies |
| .ruby-version | Changed Ruby version from 3.4.5 to 4.0.0 |
Comments suppressed due to low confidence (1)
test/heroicons_rails/rails_test.rb:114
- Tests may fail or produce inconsistent results if configuration is modified during tests. Since the configuration is stored as a memoized instance variable at the module level, any test that modifies Heroicons.configuration will affect subsequent tests. Consider adding a setup method that calls Heroicons.reset_configuration! to ensure tests start with clean configuration state.
class Heroicons::RailsTest < ActiveSupport::TestCase
include Heroicons::ApplicationHelper
# Mock Rails' raw helper for testing
def raw(content)
content.html_safe
end
test "it has a version number" do
assert Heroicons::VERSION
end
test "icon_tag works with dash format string names" do
result = icon_tag("academic-cap")
assert_includes result, 'class="w-6 h-6"', "Should include default classes"
assert_includes result, "<svg", "Should contain SVG markup"
assert_not result.include?("Icon Not Found"), "Should find the icon file"
end
test "icon_tag works with different icon types" do
# Test outline (default)
outline_result = icon_tag("academic-cap", type: :outline)
assert_includes outline_result, "<svg", "Outline icon should render"
# Test solid
solid_result = icon_tag("academic-cap", type: :solid)
assert_includes solid_result, "<svg", "Solid icon should render"
end
test "icon_tag converts symbol to string" do
symbol_result = icon_tag(:"academic-cap")
string_result = icon_tag("academic-cap")
# Both should work and produce similar results
assert_includes symbol_result, "<svg", "Symbol parameter should work"
assert_includes string_result, "<svg", "String parameter should work"
end
test "icon_tag applies custom CSS classes" do
result = icon_tag("academic-cap", class: "custom-class text-red-500")
assert_includes result, 'class="custom-class text-red-500"', "Should apply custom classes"
end
test "icon_tag raises error for non-existent icons" do
error = assert_raises(Heroicons::IconNotFoundError) do
icon_tag("non-existent-icon")
end
assert_equal "non-existent-icon", error.icon_name
assert_equal :outline, error.icon_type
assert(error.searched_paths.any? { |path| path.include?("non-existent-icon.svg") })
assert_includes error.message, "Icon 'non-existent-icon' of type 'outline' not found"
end
test "icon_tag raises error with correct type for non-existent icons" do
error = assert_raises(Heroicons::IconNotFoundError) do
icon_tag("non-existent-icon", type: :solid)
end
assert_equal "non-existent-icon", error.icon_name
assert_equal :solid, error.icon_type
end
test "icon_tag works with more dash format icons" do
%w[
x-mark
chevron-left
arrow-left-circle
document-plus
].each do |icon_name|
result = icon_tag(icon_name)
assert_includes result, "<svg", "Icon #{icon_name} should render successfully"
assert_not result.include?("Icon Not Found"), "Icon #{icon_name} should be found"
end
end
test "icon_tag preserves dash format in file paths" do
# This test ensures we're not converting dashes to underscores
result = icon_tag("academic-cap")
# Icon should be found and rendered correctly
assert_includes result, "<svg", "Should render SVG when icon is found"
assert_includes result, 'class="w-6 h-6"', "Should include default classes"
end
test "icon_tag error message preserves dash format" do
# Test that error messages show dash format, not underscore
error = assert_raises(Heroicons::IconNotFoundError) do
icon_tag("fake-icon-name")
end
assert(error.searched_paths.any? { |path| path.include?("fake-icon-name.svg") })
assert_not(error.searched_paths.any? { |path| path.include?("fake_icon_name.svg") })
end
test "icon_tag supports underscored names with conversion" do
# Use underscored icon name - should work by converting to dash
result = icon_tag("academic_cap")
# Should render the icon (converts underscore to dash)
assert_includes result, "<svg", "Should render SVG even with underscored name"
assert_includes result, 'class="w-6 h-6"', "Should include default classes"
# The icon should be found because academic_cap -> academic-cap conversion works
assert_not result.include?("Icon Not Found"), "Should find icon after underscore to dash conversion"
end
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| module Heroicons | ||
| class Configuration | ||
| attr_accessor :default_type, :default_class | ||
|
|
||
| def initialize | ||
| @default_type = :outline | ||
| @default_class = "w-6 h-6" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
The new configuration system lacks test coverage. Since other functions in the test suite have comprehensive coverage, tests should be added to verify that the Configuration class works correctly, including tests for setting custom default_type and default_class values, using the configure block, and ensuring that reset_configuration! properly resets to defaults.
| def configuration | ||
| @configuration ||= Configuration.new | ||
| end | ||
|
|
||
| def configure | ||
| yield(configuration) | ||
| end | ||
|
|
||
| def reset_configuration! | ||
| @configuration = Configuration.new | ||
| end | ||
| end |
There was a problem hiding this comment.
The configuration methods (configuration, configure, and reset_configuration!) lack test coverage. Since other parts of the codebase have comprehensive test coverage, tests should be added to verify that these methods work correctly, including testing the configure block, accessing configuration values through Heroicons.configuration, and ensuring reset_configuration! properly clears the memoized configuration.
| options[:type] ||= Heroicons.configuration.default_type | ||
| options[:class] ||= Heroicons.configuration.default_class |
There was a problem hiding this comment.
The updated icon_tag helper that uses Heroicons.configuration lacks test coverage. Since other icon_tag behavior has tests, tests should be added to verify that the helper correctly uses configured default_type and default_class values when they are set via configuration, and falls back to the defaults when no custom configuration is provided.
| require "rails/generators" | ||
|
|
||
| module Heroicons | ||
| module Generators | ||
| class InstallGenerator < Rails::Generators::Base | ||
| source_root File.expand_path("templates", __dir__) | ||
|
|
||
| desc "Creates a Heroicons initializer file" | ||
|
|
||
| def copy_initializer | ||
| template "initializer.rb", "config/initializers/heroicons.rb" | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
The Rails generator lacks test coverage. Since this is a new feature and other parts of the codebase have comprehensive test coverage, tests should be added to verify that the generator creates the initializer file at the correct path with the expected template content.
… improve gemspec for Ruby 3.3 compatibility - Updated .rubocop.yml to target Ruby 3.3 and exclude specific files. - Refactored application helper to normalize icon names and improve error handling for missing icons. - Updated heroicons-rails.gemspec to require Ruby version 3.3 or higher. - Enhanced configuration class with thread-safe singleton methods. - Adjusted test cases to verify error messages and paths for non-existent icons.
- Introduced tests to verify default configuration values for icon_tag, including default class and type. - Added tests to ensure custom configuration values override defaults correctly. - Implemented checks to confirm that configuration resets restore default settings. - Enhanced error handling tests for non-existent icons with custom configurations.
This pull request introduces a configuration system for the
heroicons-railsgem, allowing users to customize default icon types and CSS classes. It also adds a Rails generator for easy setup, updates documentation, and makes several improvements and fixes throughout the codebase and tests.Configuration system and generator:
Heroicons::Configurationclass and related methods to theHeroiconsmodule, enabling configuration of default icon type and CSS classes (lib/heroicons/configuration.rb,lib/heroicons-rails.rb). [1] [2]heroicons:install) to create a configuration initializer, and provided a template for it (lib/generators/heroicons/install_generator.rb,lib/generators/heroicons/templates/initializer.rb). [1] [2]Helper and usage updates:
icon_taghelper to use configurable defaults for icon type and CSS class, and improved path handling (app/helpers/heroicons/application_helper.rb). [1] [2] [3]Documentation improvements:
README.mdto document the new installation steps, configuration options, and usage instructions. [1] [2] [3]Testing and compatibility:
assert_includesand improving error assertions (test/heroicons_rails/rails_test.rb). [1] [2] [3] [4] [5].ruby-version,Gemfile,heroicons-rails.gemspec). [1] [2] [3]Miscellaneous improvements:
rakelib/move_to_assets.rake,test/dummy/app/controllers/dashboard_controller.rb, etc.). [1] [2] [3]These changes collectively enhance the flexibility, usability, and maintainability of the
heroicons-railsgem.