diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml
new file mode 100644
index 0000000..4d90c0a
--- /dev/null
+++ b/.github/workflows/ruby.yml
@@ -0,0 +1,41 @@
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
+# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
+
+name: Ruby
+
+on:
+ push:
+ branches: ['master']
+ pull_request:
+ branches: ['master']
+ schedule:
+ - cron: '0 0 * * 0'
+
+permissions:
+ contents: read
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ ruby-version: ['3.0', '3.1', '3.2']
+ activerecord: ['6.0', '6.1', '7.0', '7.1']
+ env:
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.activerecord }}.gemfile
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Ruby
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
+ # uses: ruby/setup-ruby@v1
+ uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ${{ matrix.ruby-version }}
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
+ - name: Run tests
+ run: bundle exec rake
diff --git a/.gitignore b/.gitignore
index 212d705..80ae087 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ test/dummy/.sass-cache
vendor/bundle
Gemfile.lock
.ruby-version
+gemfiles/*.gemfile.lock
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 6721194..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-sudo: false
-cache: bundler
-language: ruby
-rvm:
- - 2.3.0
- - 2.1.8
- - 2.2.4
- - ruby-head
- - 2.0
- - 1.9
-matrix:
- allow_failures:
- - rvm: ruby-head
- - rvm: 2.0
- - rvm: 1.9
- fast_finish: true
-notifications:
- slack:
- secure: nGQv46FQ3FlYh9wKnshCucxN4MqQVPwflNunrICiHqfo0+6lHPijZY783BILolnKJuFIXccgjZrQ/tQjKBwaLEXEHMWWIUgq0xuO7GpQiamgdrar7Ohdv5nbVl5el/YJk2ok1tPEmIHGtgLqDPvGEDbDiR2x0N5gy6Po836NzOY=
diff --git a/Appraisals b/Appraisals
new file mode 100644
index 0000000..ded12be
--- /dev/null
+++ b/Appraisals
@@ -0,0 +1,15 @@
+appraise "rails-6.0" do
+ gem 'rails', '6.0.6.1'
+end
+
+appraise "rails-6.1" do
+ gem 'rails', '~> 6.1'
+end
+
+appraise "rails-7.0" do
+ gem 'rails', '7.0.8.4'
+end
+
+appraise "rails-7.1" do
+ gem 'rails', '~> 7.1'
+end
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0777a9..219d114 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,19 @@
### Unreleased
+### Version 6.0.0
+
+- Furthermore support Rails 7.0
+- Removing the dependencies for sprocket-rails as a consequences of that gem no longer needed in Rails 7
+
+### Version 5.0.0
+
+- Add dependencies to support Rails 6.1
+- parent_name is deprecated in rails 6 and gone in 6.1
+- Update I18n translation function
+- Change assertion function in spec
+- Bump ruby version to be at least 3.0
+
### Version 4.0.0
- [Pull Request 28](https://github.com/winston/rails_utils/pull/28) - [Development] remove `.ruby-version` file - by @JuanitoFatas
diff --git a/README.md b/README.md
index 040c137..b514c5d 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,20 @@
Rails helpers based on opinionated project practices. Useful for structuring CSS and JavaScript,
display title of the page, and flash messages with Bootstrap.
+## Forkception
+
+This repo is a fork of:
+
+- The [fonglh](https://github.com/fonglh/rails_utils) gem
+- which is the fork of the original gem maintained by [Winston](https://github.com/winston/rails_utils)
+
+## Requirements
+
+- Ruby >= 3.0, <= 3.2
+- Rails >= 6.0, <= 7.1
+
+The library might work for the higher version, however it's only tested for the specs mentioned above.
+
## Installation
Add rails_utils to your application's Gemfile:
@@ -36,7 +50,7 @@ you can use `page_class` to include the controller name and action name as CSS c
becomes
```html
-
+
...
```
@@ -79,9 +93,7 @@ When controller and action is `animes#show` you can easily use `page_title` like
becomes
```html
-
- Animes Show
-
+Animes Show
```
Besides, it supports I18n and interpolation:
@@ -104,9 +116,7 @@ Pass in `anime_name`:
becomes
```html
-
- Showing anime of: Frozen
-
+Showing anime of: Frozen
```
### #`javascript_initialization`
@@ -130,13 +140,17 @@ compiles to:
```html
```
@@ -196,7 +210,7 @@ Minitest-ed. To run all tests, just run `rake` or `rake test`.
## Author
-Rails Utils is maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.com).
+Rails Utils is originally maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.com).
[You should follow Winston on Twitter](https://www.twitter.com/winstonyw), or find out more on [WinstonYW](http://www.winstonyw.com) and [LinkedIn](http://sg.linkedin.com/in/winstonyw).
@@ -204,8 +218,5 @@ Rails Utils is maintained by [Winston Teo](mailto:winstonyw+rails_utils@gmail.co
Copyright © 2013-2016 Winston Teo Yong Wei. Free software, released under the MIT license.
-
[version-badge]: https://badge.fury.io/rb/rails_utils.svg
[rubygems]: https://rubygems.org/gems/rails_utils
-[travis-badge]: https://travis-ci.org/winston/rails_utils.svg
-[travis]: https://travis-ci.org/winston/rails_utils
diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile
new file mode 100644
index 0000000..e050d93
--- /dev/null
+++ b/gemfiles/rails_6.0.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "rails", "6.0.6.1"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile
new file mode 100644
index 0000000..c34b486
--- /dev/null
+++ b/gemfiles/rails_6.1.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "rails", "~> 6.1"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile
new file mode 100644
index 0000000..af711ee
--- /dev/null
+++ b/gemfiles/rails_7.0.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "rails", "7.0.8.4"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile
new file mode 100644
index 0000000..1d906c3
--- /dev/null
+++ b/gemfiles/rails_7.1.gemfile
@@ -0,0 +1,7 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "rails", "~> 7.1"
+
+gemspec path: "../"
diff --git a/lib/rails_utils.rb b/lib/rails_utils.rb
index e9351a1..dca88d1 100644
--- a/lib/rails_utils.rb
+++ b/lib/rails_utils.rb
@@ -27,12 +27,12 @@ def page_title(options={})
@page_title ||= begin
default_page_title = "#{page_controller_class.capitalize} #{page_action_class.capitalize}"
i18n_options = { default: default_page_title }.merge!(options)
- I18n.t("#{page_controller_class}.#{page_action_class}.title", i18n_options)
+ I18n.t("#{page_controller_class}.#{page_action_class}.title", **i18n_options)
end
end
def javascript_initialization(options = {})
- application_name = Rails.application.class.parent_name
+ application_name = Rails.application.class.module_parent_name
js_namespace_name = page_controller_class_underscored
js_function_name = page_action_class
diff --git a/lib/rails_utils/version.rb b/lib/rails_utils/version.rb
index 30e4b7a..0de1fe9 100644
--- a/lib/rails_utils/version.rb
+++ b/lib/rails_utils/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module RailsUtils
- VERSION = "4.0.0"
+ VERSION = "6.0.0"
end
diff --git a/rails_utils.gemspec b/rails_utils.gemspec
index 6c54fca..dc2d011 100644
--- a/rails_utils.gemspec
+++ b/rails_utils.gemspec
@@ -7,17 +7,20 @@ require "rails_utils/version"
Gem::Specification.new do |s|
s.name = "rails_utils"
s.version = RailsUtils::VERSION
- s.authors = ["Winston Teo"]
- s.email = ["winston.yongwei+rails_utils@gmail.com"]
- s.homepage = "https://github.com/winston/rails_utils"
+ s.authors = ["Bivan Alzacky Harmanto"]
+ s.email = ["bivan.alzacky@gmail.com"]
+ s.homepage = "https://github.com/Coursemology/rails_utils"
s.summary = "Rails helpers based on opinionated project practices."
s.description = "Rails helpers based on opinionated project practices. Currently useful for structuring CSS and JS."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
- s.add_dependency "rails", ">=3.2"
+ s.required_ruby_version = ">= 3.0"
+
+ s.add_dependency "rails", ">= 6"
s.add_development_dependency "minitest" , ">= 4.7.5"
+ s.add_development_dependency "appraisal", "~> 2.1"
s.add_development_dependency "mocha"
s.license = 'MIT'
diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb
index dd719fe..71e68c6 100644
--- a/test/dummy/config/application.rb
+++ b/test/dummy/config/application.rb
@@ -1,10 +1,8 @@
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
-# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
-require "sprockets/railtie"
require "rails/test_unit/railtie"
Bundler.require(*Rails.groups)
@@ -55,10 +53,10 @@ class Application < Rails::Application
# config.active_record.whitelist_attributes = true
# Enable the asset pipeline
- config.assets.enabled = true
+ # config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
- config.assets.version = '1.0'
+ # config.assets.version = '1.0'
end
end
diff --git a/test/rails_utils_test.rb b/test/rails_utils_test.rb
index b0711bf..9eaf191 100644
--- a/test/rails_utils_test.rb
+++ b/test/rails_utils_test.rb
@@ -3,7 +3,13 @@
describe "RailsUtils::ActionViewExtensions" do
let(:controller) { ActionController::Base.new }
let(:request) { ActionDispatch::Request.new(flash: {}) }
- let(:view) { ActionView::Base.new }
+ let(:view) do
+ if Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR == 0
+ ActionView::Base.new
+ else
+ ActionView::Base.new({}, {}, "")
+ end
+ end
before do
controller.request = request
@@ -15,10 +21,10 @@
let(:controller_class) { "AnimeController" }
let(:controller_name) { "anime" }
- before { controller.stubs(:class).returns(controller_class) }
-
it "returns controller name" do
- view.page_controller_class.must_equal controller_name
+ controller.stub :class, controller_class do
+ assert_equal(view.page_controller_class, controller_name)
+ end
end
end
@@ -26,10 +32,10 @@
let(:controller_class) { "Super::Awesome::AnimeController" }
let(:controller_name) { "super_awesome_anime" }
- before { controller.stubs(:class).returns(controller_class) }
-
it "returns controller name" do
- view.page_controller_class.must_equal controller_name
+ controller.stub :class, controller_class do
+ assert_equal(view.page_controller_class, controller_name)
+ end
end
end
@@ -39,14 +45,21 @@
before do
RailsUtils.configure do |config|
+ @rails_selector_format = config.selector_format
config.selector_format = :hyphenated
end
+ end
- controller.stubs(:class).returns(controller_class)
+ after do
+ RailsUtils.configure do |config|
+ config.selector_format = @rails_selector_format
+ end
end
it "returns controller name" do
- view.page_controller_class.must_equal controller_name
+ controller.stub :class, controller_class do
+ assert_equal(view.page_controller_class, controller_name)
+ end
end
end
@@ -56,14 +69,14 @@
before do
RailsUtils.configure do |config|
- config.selector_format = "underscored"
+ config.selector_format = :underscored
end
-
- controller.stubs(:class).returns(controller_class)
end
it "returns controller name" do
- view.page_controller_class.must_equal controller_name
+ controller.stub :class, controller_class do
+ assert_equal(view.page_controller_class, controller_name)
+ end
end
end
end
@@ -81,10 +94,10 @@
[ "custom" , "custom" ],
].each do |action_name, expected|
describe "when ##{action_name}" do
- before { controller.stubs(:action_name).returns(action_name) }
-
it "returns #{expected}" do
- view.page_action_class.must_equal expected
+ controller.stub :action_name, action_name do
+ assert_equal(view.page_action_class, expected)
+ end
end
end
end
@@ -94,39 +107,45 @@
let(:controller_name) { "anime" }
let(:action_name) { "custom" }
- before do
- view.stubs(:page_controller_class).returns(controller_name)
- view.stubs(:page_action_class).returns(action_name)
- end
-
it "uses page_controller_class and page_action_class" do
- view.page_class.must_equal "#{controller_name} #{action_name}"
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_class, "#{controller_name} #{action_name}")
+ end
+ end
end
end
describe "#page_title" do
let(:controller_name) { "anime" }
- before do
- view.stubs(:page_controller_class).returns(controller_name)
- view.stubs(:page_action_class).returns(action_name)
- end
-
describe 'when translation is missing' do
let(:action_name) { "random" }
let(:default_translation) { "#{controller_name.capitalize} #{action_name.capitalize}" }
it "combines page_controller_class and page_action_class" do
- view.page_title.must_equal default_translation
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_title, default_translation)
+ end
+ end
end
it "uses :default provided by gem user" do
- view.page_title(default: 'my custom default').must_equal 'my custom default'
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_title(default: 'my custom default'), 'my custom default')
+ end
+ end
end
it "calling multiple times reuses first result (template renders before layout)" do
- view.page_title(default: 'my custom default').must_equal 'my custom default'
- view.page_title.must_equal 'my custom default'
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_title(default: 'my custom default'), 'my custom default')
+ assert_equal(view.page_title, 'my custom default')
+ end
+ end
end
end
@@ -136,7 +155,11 @@
before { I18n.backend.store_translations("en", { controller_name.to_sym => { action_name.to_sym => { title: "An awesome title" } }}) }
it "translates page title" do
- view.page_title.must_equal "An awesome title"
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_title, "An awesome title")
+ end
+ end
end
end
@@ -146,7 +169,11 @@
before { I18n.backend.store_translations("en", { controller_name.to_sym => { action_name.to_sym => { title: "An awesome title, %{name}" } }}) }
it "translates page title" do
- view.page_title(name: "bro").must_equal "An awesome title, bro"
+ view.stub :page_controller_class, controller_name do
+ view.stub :page_action_class, action_name do
+ assert_equal(view.page_title(name: "bro"), "An awesome title, bro")
+ end
+ end
end
end
end
@@ -155,21 +182,29 @@
let(:controller_class) { "Awesome::AnimeController" }
let(:controller_name) { "awesome_anime" }
- before do
- controller.stubs(:class).returns(controller_class)
- controller.stubs(:action_name).returns(action_name)
- end
+ # before do
+ # controller.stubs(:class).returns(controller_class)
+ # controller.stubs(:action_name).returns(action_name)
+ # end
describe "when controller name and action name are standard" do
let(:action_name) { "custom" }
it "invokes application" do
- view.javascript_initialization.must_match "Dummy.init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ assert_match("Dummy.init();", view.javascript_initialization)
+ end
+ end
end
it "invokes controller and action javascript" do
- view.javascript_initialization.must_match "Dummy.#{controller_name}.init();"
- view.javascript_initialization.must_match "Dummy.#{controller_name}.#{action_name}.init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ assert_match("Dummy.#{controller_name}.init();", view.javascript_initialization)
+ assert_match("Dummy.#{controller_name}.#{action_name}.init();", view.javascript_initialization)
+ end
+ end
end
end
@@ -177,7 +212,11 @@
let(:action_name) { "create" }
it "replaces create with new" do
- view.javascript_initialization.must_match "Dummy.#{controller_name}.new.init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ assert_match("Dummy.#{controller_name}.new.init();", view.javascript_initialization)
+ end
+ end
end
end
@@ -185,7 +224,11 @@
let(:action_name) { "update" }
it "replaces update with create" do
- view.javascript_initialization.must_match "Dummy.#{controller_name}.edit.init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ assert_match("Dummy.#{controller_name}.edit.init();", view.javascript_initialization)
+ end
+ end
end
end
@@ -193,8 +236,12 @@
let(:action_name) { "update" }
it "uses the custom js init method" do
- view.content_for(:js_init_method) { "custom" }
- view.javascript_initialization.must_match "Dummy.#{controller_name}.custom.init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ view.content_for(:js_init_method) { "custom" }
+ assert_match("Dummy.#{controller_name}.custom.init();", view.javascript_initialization)
+ end
+ end
end
end
@@ -202,7 +249,11 @@
let(:action_name) { "update" }
it "does not generate an additional javascript method" do
- view.javascript_initialization.wont_match "Dummy.#{controller_name}..init();"
+ controller.stub :class, controller_class do
+ controller.stub :action_name, action_name do
+ refute_includes("Dummy.#{controller_name}..init();", view.javascript_initialization)
+ end
+ end
end
end
end
@@ -231,11 +282,11 @@ def set_flash(key, message)
before { set_flash key, expected_message }
it "prints class '#{expected_class}'" do
- view.flash_messages.must_match expected_class
+ assert_match(expected_class, view.flash_messages)
end
it "prints message '#{expected_message}'" do
- view.flash_messages.must_match expected_message
+ assert_match(expected_message, view.flash_messages)
end
end
end
@@ -243,54 +294,54 @@ def set_flash(key, message)
describe "when bootstrap is present" do
it "can fade in and out" do
set_flash :alert, "not important"
- view.flash_messages.must_match(/fade in/)
+ assert_match(/fade in/, view.flash_messages)
end
it "can be dismissed" do
set_flash :alert, "not important"
- view.flash_messages.must_match(/data-dismiss=.*alert/)
+ assert_match(/data-dismiss=.*alert/, view.flash_messages)
end
end
describe "options" do
it "can allow override of button content (default 'x')" do
set_flash :alert, "not important"
- view.flash_messages.must_match %r{>x}
- view.flash_messages(button_html: '').must_match %r{button type="button" class="close"}
+ assert_match(%r{>x}, view.flash_messages)
+ assert_match(%r{button type="button" class="close"}, view.flash_messages(button_html: ''))
end
it "can allow override of button css class (default 'close')" do
set_flash :alert, "not important"
- view.flash_messages.must_match %r{>x}
- view.flash_messages(button_class: 'abc def').must_match %r{button type="button" class="abc def"}
+ assert_match(%r{>x}, view.flash_messages)
+ assert_match(%r{button type="button" class="abc def"}, view.flash_messages(button_class: 'abc def'))
end
end
it "should strip "
- view.flash_messages.wont_match "