Skip to content

Commit

Permalink
rails: 6.1 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Alexandre Meyer <[email protected]>
  • Loading branch information
pierre committed Jun 24, 2023
1 parent 6e3295d commit 663b639
Show file tree
Hide file tree
Showing 41 changed files with 99 additions and 100 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
database-password: 'root'
database-port: '3306'
docker-compose-file: 'docker-compose.ci.mysql.yml'
- ruby-version: 'jruby-9.4.2.0'
- ruby-version: 'jruby-9.3.10.0'
database-adapter: 'mariadb'
database-user: 'root'
database-password: 'root'
Expand All @@ -36,7 +36,7 @@ jobs:
database-password: 'postgres'
database-port: '5432'
docker-compose-file: 'docker-compose.ci.postgresql.yml'
- ruby-version: 'jruby-9.4.2.0'
- ruby-version: 'jruby-9.3.10.0'
database-adapter: 'postgresql'
database-user: 'postgres'
database-password: 'postgres'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
ruby-version: 2.6.10
- name: Install gems
run: |
bundle config path vendor/bundle
Expand Down
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ Style/Documentation:

Style/EmptyElse:
EnforcedStyle: empty

Style/HashSyntax:
Enabled: false

Style/ExplicitBlockArgument:
Enabled: false
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'
ruby '>= 3.1.0'
ruby '>= 2.6.0'

gemspec

Expand All @@ -18,7 +18,7 @@ group :development do
gem 'simplecov'

if defined?(JRUBY_VERSION)
git 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'master' do
git 'https://github.com/jruby/activerecord-jdbc-adapter', branch: 'v61.2' do
gem 'activerecord-jdbc-adapter'
# Add the drivers
gem 'jdbc-mariadb'
Expand All @@ -40,4 +40,4 @@ gem 'killbill-client', git: 'https://github.com/killbill/killbill-client-ruby.gi
# gem 'killbill-client', '3.2.0'

# gem 'kenui', :path => '../killbill-email-notifications-ui'
gem 'kenui', git: 'https://github.com/killbill/killbill-email-notifications-ui.git', branch: 'master'
# gem 'kenui', git: 'https://github.com/killbill/killbill-email-notifications-ui.git', branch: 'master'
2 changes: 1 addition & 1 deletion app/controllers/kaui/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def trigger_invoice
render template: 'kaui/invoices/show'
else
# Redirect to fetch payments, etc.
redirect_to invoice_path(invoice.invoice_id, account_id:), notice: "Generated invoice #{invoice.invoice_number} for target date #{invoice.target_date}"
redirect_to invoice_path(invoice.invoice_id, account_id: account_id), notice: "Generated invoice #{invoice.invoice_number} for target date #{invoice.target_date}"
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/kaui/admin_tenants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ def catalog_by_effective_date

catalog << { version_date: data[:version_date],
currencies: data[:currencies],
plans: }
plans: plans }
end

{ catalog: }
{ catalog: catalog }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/audit_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def history
error = e.message
end

{ audits: audit_logs_with_history, error: }
{ audits: audit_logs_with_history, error: error }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/charges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def new
currency = params[:currency] || 'USD'
end

@charge = Kaui::InvoiceItem.new(account_id: params.require(:account_id), invoice_id:, amount:, currency:)
@charge = Kaui::InvoiceItem.new(account_id: params.require(:account_id), invoice_id: invoice_id, amount: amount, currency: currency)
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/credits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def new
currency = params[:currency] || 'USD'
end

@credit = Kaui::Credit.new(account_id: params.require(:account_id), invoice_id:, amount:, currency:)
@credit = Kaui::Credit.new(account_id: params.require(:account_id), invoice_id: invoice_id, amount: amount, currency: currency)
end

def create
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/kaui/engine_controller_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ def paginate(searcher, data_extractor, formatter)
pages.each { |page| json[:data] << formatter.call(page) }

respond_to do |format|
format.json { render json: }
format.json { render json: json }
end
end

def promise(&)
def promise
# Evaluation starts immediately
::Concurrent::Promises.future do
# https://github.com/rails/rails/issues/26847
Rails.application.executor.wrap(&)
Rails.application.executor.wrap do
yield
end
end
end

Expand Down
16 changes: 8 additions & 8 deletions app/controllers/kaui/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def account_search(search_query, search_by = nil, fast = 0, options = {})
elsif true?(fast)
redirect_to account_path(account.account_id) and return
else
redirect_to accounts_path(q: search_query, fast:) and return
redirect_to accounts_path(q: search_query, fast: fast) and return
end
end
end
Expand All @@ -73,7 +73,7 @@ def invoice_search(search_query, search_by = nil, fast = 0, options = {})
elsif true?(fast)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
else
redirect_to account_invoices_path(account_id: invoice.account_id, q: search_query, fast:) and return
redirect_to account_invoices_path(account_id: invoice.account_id, q: search_query, fast: fast) and return
end
end
end
Expand All @@ -100,7 +100,7 @@ def payment_search(search_query, search_by = nil, fast = 0, options = {})
elsif true?(fast)
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
else
redirect_to account_payments_path(account_id: payment.account_id, q: search_query, fast:) and return
redirect_to account_payments_path(account_id: payment.account_id, q: search_query, fast: fast) and return
end
end
end
Expand Down Expand Up @@ -167,7 +167,7 @@ def custom_field_search(search_query, search_by = nil, fast = 0, options = {})
if custom_field.blank?
search_error("No custom field matches \"#{search_query}\"")
else
redirect_to custom_fields_path(q: search_query, fast:)
redirect_to custom_fields_path(q: search_query, fast: fast)
end
else
unsupported_external_key_search('CUSTOM FIELD')
Expand Down Expand Up @@ -206,7 +206,7 @@ def tag_search(search_query, search_by = nil, fast = 0, options = {})
if tag.blank?
search_error("No tag matches \"#{search_query}\"")
else
redirect_to tags_path(q: search_query, fast:)
redirect_to tags_path(q: search_query, fast: fast)
end
else
unsupported_external_key_search('TAG')
Expand All @@ -217,7 +217,7 @@ def tag_definition_search(search_query, search_by = nil, fast = 0, options = {})
if search_by == 'ID'
begin
Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
redirect_to tag_definitions_path(q: search_query, fast:)
redirect_to tag_definitions_path(q: search_query, fast: fast)
rescue KillBillClient::API::NotFound => _e
search_error("No tag definition matches \"#{search_query}\"")
end
Expand All @@ -228,12 +228,12 @@ def tag_definition_search(search_query, search_by = nil, fast = 0, options = {})
if tag_definition.blank?
begin
Kaui::TagDefinition.find_by_id(search_query, 'NONE', options)
redirect_to tag_definitions_path(q: search_query, fast:) and return
redirect_to tag_definitions_path(q: search_query, fast: fast) and return
rescue KillBillClient::API::NotFound => _e
search_error("No tag definition matches \"#{search_query}\"")
end
else
redirect_to tag_definitions_path(q: search_query, fast:)
redirect_to tag_definitions_path(q: search_query, fast: fast)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/invoice_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def update
end

Kaui::Tag.set_for_invoice(invoice_id, tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to kaui_engine.invoice_path(invoice_id, account_id:), notice: 'Invoice tags successfully set'
redirect_to kaui_engine.invoice_path(invoice_id, account_id: account_id), notice: 'Invoice tags successfully set'
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/kaui/date_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def format_date(date, timezone)

# If not, convert into account timezone and return the date part only
parsed_date = DateTime.parse(date.to_s).in_time_zone(timezone)
parsed_date.to_fs(:date_only)
parsed_date.to_s(:date_only)
end

def truncate_millis(date_s)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/kaui/plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def installed_plugins
plugin_key = plugin.plugin_key
installed_plugins << {
# Unique identifier chosen by the user and used for kpm operations
plugin_key:,
plugin_key: plugin_key,
# Notes:
# * plugin.plugin_name comes from kpm and is arbitrary (see Utils.get_plugin_name_from_file_path in the kpm codebase for instance)
# * plugin_name here is the plugin name as seen by Kill Bill and is typically defined in the Activator.java (this value is the one that matters for plugin configuration)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/kaui/uuid_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def truncate_uuid(uuid)

def object_id_popover(object_id, placement = 'right', title = nil)
content_tag(:span, truncate_uuid(object_id),
id: "#{object_id}-popover", class: 'object-id-popover', title:,
id: "#{object_id}-popover", class: 'object-id-popover', title: title,
data: {
id: object_id,
placement:
placement: placement
})
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/kaui/account_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
module Kaui
class AccountEmail < KillBillClient::Model::AccountEmailAttributes
def self.find_all_sorted_by_account_id(account_id, audit = 'NONE', options = {})
emails = Kaui::Account.new(account_id:).emails(audit, options)
emails = Kaui::Account.new(account_id: account_id).emails(audit, options)
emails.map { |email| Kaui::AccountEmail.new(email.to_hash) }.sort
end

def create(user = nil, reason = nil, comment = nil, options = {})
account = Kaui::Account.new(account_id:)
account = Kaui::Account.new(account_id: account_id)
account.add_email(email, user, reason, comment, options)
end

def destroy(user = nil, reason = nil, comment = nil, options = {})
account = Kaui::Account.new(account_id:)
account = Kaui::Account.new(account_id: account_id)
account.remove_email(email, user, reason, comment, options)
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/kaui/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def fix_transaction_state(payment_id, transaction_id, transaction_status, user =
{ transactionStatus: transaction_status }.to_json,
{},
{
user:,
reason:,
comment:
user: user,
reason: reason,
comment: comment
}.merge(options)
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/kaui/killbill_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module ClassMethods
# Invoked by the KillbillAuthenticatable strategy to lookup the user
# before attempting authentication
def find_for_killbill_authentication(kb_username)
find_for_authentication(kb_username:) ||
new(kb_username:)
find_for_authentication(kb_username: kb_username) ||
new(kb_username: kb_username)
rescue KillBillClient::API::Unauthorized => _e
# Multi-Tenancy was enabled, but the tenant_id couldn't be retrieved because of bad credentials
nil
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/killbill_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def authenticate!
return false unless valid_password?

user = params[:user] || {}
kb_authenticate!(user[:kb_username], { username: user[:kb_username], password: })
kb_authenticate!(user[:kb_username], { username: user[:kb_username], password: password })
end
end

Expand Down Expand Up @@ -77,7 +77,7 @@ def token
unless user.authenticated_with_killbill?
scope = opts[:scope]
auth.logout(scope)
throw(:warden, scope:, reason: 'Kill Bill session expired')
throw(:warden, scope: scope, reason: 'Kill Bill session expired')
end
end

Expand Down
6 changes: 3 additions & 3 deletions kaui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.summary = 'Killbill Admin UI mountable engine'
s.description = 'Rails UI plugin for Killbill administration.'

s.required_ruby_version = '>= 2.7.0'
s.required_ruby_version = '>= 2.6.0'

s.license = 'Apache License (2.0)'

Expand Down Expand Up @@ -38,12 +38,12 @@ Gem::Specification.new do |s|
s.add_dependency 'jquery-ui-rails'
s.add_dependency 'js-routes'
s.add_dependency 'jwt'
s.add_dependency 'kenui'
s.add_dependency 'kenui', '~> 2.1.0'
s.add_dependency 'killbill-client'
s.add_dependency 'money-rails'
s.add_dependency 'mustache-js-rails'
s.add_dependency 'popper_js', '~> 2.11.5'
s.add_dependency 'rails', '~> 7.0'
s.add_dependency 'rails', '~> 6.1'
s.add_dependency 'sass'
s.add_dependency 'sassc-rails', '>= 2.1.0'
s.add_dependency 'sass-rails'
Expand Down
9 changes: 0 additions & 9 deletions lib/kaui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,3 @@ def self.config
}
end
end

# ruby-1.8 compatibility
module Kernel
def define_singleton_method(*args, &)
class << self
self
end.send(:define_method, *args, &)
end
end
2 changes: 1 addition & 1 deletion lib/kaui/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Kaui
VERSION = '3.0.1'
VERSION = '2.2.0'
end
2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
config.load_defaults 6.1

# Configuration for the application, engines, and railties goes here.
#
Expand Down
6 changes: 3 additions & 3 deletions test/functional/kaui/account_emails_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AccountEmailsControllerTest < Kaui::FunctionalTestHelper
test 'should handle Kill Bill errors during creation' do
account_id = SecureRandom.uuid.to_s
post :create,
params: { account_id:,
params: { account_id: account_id,
account_email: {
email: '[email protected]'
} }
Expand All @@ -31,7 +31,7 @@ class AccountEmailsControllerTest < Kaui::FunctionalTestHelper

test 'should handle Kill Bill errors during deletion' do
account_id = 'invalid-id'
delete :destroy, params: { account_id:, id: '[email protected]' }
delete :destroy, params: { account_id: account_id, id: '[email protected]' }
assert_redirected_to account_path(account_id)
end

Expand All @@ -45,7 +45,7 @@ class AccountEmailsControllerTest < Kaui::FunctionalTestHelper
params: {
account_id: @account.account_id,
account_email: {
email:
email: email
}
}
assert_redirected_to account_path(@account.account_id)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/kaui/account_tags_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Kaui
class AccountTagsControllerTest < Kaui::FunctionalTestHelper
test 'should handle Kill Bill errors when getting edit screen' do
account_id = '1234'
get :edit, params: { account_id: }
get :edit, params: { account_id: account_id }
assert_redirected_to account_path(account_id)
end

Expand Down
Loading

0 comments on commit 663b639

Please sign in to comment.