Skip to content

Commit

Permalink
Fix the tests to match the new gem versions
Browse files Browse the repository at this point in the history
* MiniTest was removed and we only have Minitest now
* I18n returns capitalized errors for "Translation missing"
* Run standard:fix to remove references to named splats when unneeded
  • Loading branch information
foca committed Feb 13, 2024
1 parent 586a112 commit 540ab25
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 3.0
2 changes: 1 addition & 1 deletion dtb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
Rails.
DESC
spec.homepage = "https://github.com/foca/dtb"
spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
spec.required_ruby_version = Gem::Requirement.new(">= 3.0")

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
Expand Down
6 changes: 3 additions & 3 deletions lib/dtb/builds_data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module BuildsDataTable
class_methods do
# Instantiates this object and then calls #to_data_table
#
# @param args any arguments will be forwarded to the constructor.
# @param ... any arguments will be forwarded to the constructor.
# @return (see #to_data_table)
def to_data_table(*args)
new(*args).to_data_table
def to_data_table(...)
new(...).to_data_table
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/dtb/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class DataTable
# been run yet.
# @return [Datatable] the data table with the results of running the query.
#
# @overload build(object, *args)
# @overload build(object, ...)
# @param object [#to_data_table] an object that implements +#to_data_table+.
# @param args [Array<Object>] any parameters that should be forwarded to
# @param ... [Array<Object>] any parameters that should be forwarded to
# the +object+'s +#to_data_table+ method.
# @return [Datatable] the data table with the results of running the query.
# @see BuildsDataTable
def self.build(query, *args, **opts)
new(**query.to_data_table(*args, **opts))
def self.build(query, ...)
new(**query.to_data_table(...))
end

# @!method any?
Expand Down
1 change: 0 additions & 1 deletion lib/dtb/options_map.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "set"
require "active_support/core_ext/object/deep_dup"
require_relative "errors"

Expand Down
6 changes: 3 additions & 3 deletions lib/dtb/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def self.i18n_scope

# Run the query, returning the results.
#
# @param args [Array<Object>] Any arguments given will be forwarded to
# @param ... [Array<Object>] Any arguments given will be forwarded to
# #initialize
# @return (see #run)
def self.run(*args)
new(*args).run
def self.run(...)
new(...).run
end

# @!method initialize(params = {}, options = {})
Expand Down
14 changes: 7 additions & 7 deletions lib/dtb/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class QueryBuilder

# @param name [Symbol] The QueryBuilder's name.
# @param opts [Hash] Any options that need to be set. See also {HasOptions}.
# @yield [scope, *args] The given block will be used by {#call} to modify
# @yield [scope, ...] The given block will be used by {#call} to modify
# the given input scope
# @raise (see HasOptions#initialize)
def initialize(name, opts = {}, &query)
Expand All @@ -82,15 +82,15 @@ def initialize(name, opts = {}, &query)
# input +scope+ or the output of the Proc.
#
# @param scope [Object] the "query" being built.
# @param args [Array<Object>] Splat of any other params that are accepted by
# @param ... [Array<Object>] Splat of any other params that are accepted by
# this QueryBuilder's Proc.
# @return [Object] the modified "query" or the input +scope+.
#
# @see #evaluate?
def call(scope, *args)
def call(scope, ...)
if evaluate?
@applied = true
evaluate(scope, *args)
evaluate(scope, ...)
else
scope
end
Expand All @@ -99,11 +99,11 @@ def call(scope, *args)
# Evaluates a Proc in the context of this QueryBuilder's +context+, as given
# in the options.
#
# @param args [Array<Object>] Splat of any arguments needed by the Proc.
# @param args [Array<Object>] Any arguments will be forwarded to the Proc.
# @param with [Proc] A Proc. Defaults to this QueryBuilder's main Proc.
# @api private
def evaluate(*args, with: @query)
options[:context].instance_exec(*args, &with)
def evaluate(*args, with: @query, **opts)
options[:context].instance_exec(*args, **opts, &with)
end

# @return [Boolean] Whether this QueryBuilder's Proc has been used or not.
Expand Down
2 changes: 1 addition & 1 deletion test/column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::ColumnTest < MiniTest::Test
class DTB::ColumnTest < Minitest::Test
def setup
I18n.backend.translations.clear
super
Expand Down
2 changes: 1 addition & 1 deletion test/data_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::DataTableTest < MiniTest::Test
class DTB::DataTableTest < Minitest::Test
def test_builds_data_table_from_query_class
data_table = DTB::DataTable.build(TestQuery, {}, url: "/list")

Expand Down
2 changes: 1 addition & 1 deletion test/dtb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTBTest < MiniTest::Test
class DTBTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::DTB::VERSION
end
Expand Down
2 changes: 1 addition & 1 deletion test/filter_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::FilterSetTest < MiniTest::Test
class DTB::FilterSetTest < Minitest::Test
def test_provides_a_namespace_for_form_params
filters = DTB::FilterSet.new([])
assert_equal :filters, filters.namespace
Expand Down
4 changes: 2 additions & 2 deletions test/filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::FilterTest < MiniTest::Test
class DTB::FilterTest < Minitest::Test
def setup
I18n.backend.translations.clear
super
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_resolves_label_and_placeholder_from_context_i18n_hierarchy

def test_placeholders_default_to_empty
filter = DTB::Filter.new(:bar, value: nil, context: nil)
assert_match(/translation missing/, filter.label)
assert_match(/translation missing/i, filter.label)
assert_equal "", filter.placeholder
end

Expand Down
10 changes: 5 additions & 5 deletions test/has_columns_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasColumnsTest < MiniTest::Test
class DTB::HasColumnsTest < Minitest::Test
class TestClass
include DTB::HasColumns

Expand Down Expand Up @@ -35,7 +35,7 @@ def test_to_data_table_includes_columns
end

def test_with_explicit_query_builder_block
scope = MiniTest::Mock.new
scope = Minitest::Mock.new
scope.expect :select, scope, ["foo column"]

object = TestClass.new
Expand All @@ -47,7 +47,7 @@ def test_with_explicit_query_builder_block
def test_with_default_query_builder_block
# Default block is ->(scope) { scope.select(column_name) }

scope = MiniTest::Mock.new
scope = Minitest::Mock.new
scope.expect :select, scope, [:bar]

object = TestClass.new
Expand All @@ -57,7 +57,7 @@ def test_with_default_query_builder_block
end

def test_presentational_columns_dont_modify_query
scope = MiniTest::Mock.new
scope = Minitest::Mock.new

object = TestClass.new
object.columns[:baz].call(scope)
Expand All @@ -66,7 +66,7 @@ def test_presentational_columns_dont_modify_query
end

def test_with_access_to_query_internal_state
scope = MiniTest::Mock.new
scope = Minitest::Mock.new
scope.expect :select, scope, ["some internal state"]

object = TestClass.new
Expand Down
2 changes: 1 addition & 1 deletion test/has_default_implementation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasDefaultImplementationTest < MiniTest::Test
class DTB::HasDefaultImplementationTest < Minitest::Test
class FailedQuery
include DTB::HasDefaultImplementation
end
Expand Down
4 changes: 2 additions & 2 deletions test/has_empty_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasEmptyStateTest < MiniTest::Test
class DTB::HasEmptyStateTest < Minitest::Test
def setup
I18n.backend.translations.clear
super
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_empty_state_title_and_subtitle
def test_subtitle_and_filtered_subtitle_are_optional
target = NotAnActiveModelTranslation.new

assert_match(/translation missing/, target.empty_state.title)
assert_match(/translation missing/i, target.empty_state.title)
assert_empty target.empty_state.explanation
assert_empty target.empty_state.update_filters
end
Expand Down
6 changes: 3 additions & 3 deletions test/has_filters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasFiltersTest < MiniTest::Test
class DTB::HasFiltersTest < Minitest::Test
class TestClass
include DTB::HasFilters

Expand Down Expand Up @@ -155,8 +155,8 @@ def run
end
end

mock = MiniTest::Mock.new
mock.expect(:where, mock, [{test: "test"}])
mock = Minitest::Mock.new
mock.expect(:where, mock, test: "test")
mock.expect(:tap, mock)

query = cls.new(mock, filters: {test: "test"})
Expand Down
2 changes: 1 addition & 1 deletion test/has_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasOptionsTest < MiniTest::Test
class DTB::HasOptionsTest < Minitest::Test
class TestClass
include DTB::HasOptions

Expand Down
2 changes: 1 addition & 1 deletion test/has_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::HasUrlTest < MiniTest::Test
class DTB::HasUrlTest < Minitest::Test
class TestClass
include DTB::HasUrl
public :override_query_params
Expand Down
2 changes: 1 addition & 1 deletion test/options_map_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::OptionsMapTest < MiniTest::Test
class DTB::OptionsMapTest < Minitest::Test
def test_can_define_valid_options
options = DTB::OptionsMap.new
options.define!(:foo)
Expand Down
2 changes: 1 addition & 1 deletion test/query_builder_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::QueryBuilderSetTest < MiniTest::Test
class DTB::QueryBuilderSetTest < Minitest::Test
def test_evaluates_builders_in_sequence
builder_1 = DTB::QueryBuilder.new(:one) { |val| val + 1 }
builder_2 = DTB::QueryBuilder.new(:two) { |val| val * 2 }
Expand Down
2 changes: 1 addition & 1 deletion test/query_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::QueryBuilderTest < MiniTest::Test
class DTB::QueryBuilderTest < Minitest::Test
def test_evaluates_query_on_scope
builder = DTB::QueryBuilder.new(:test) { |scope| scope + 1 }

Expand Down
2 changes: 1 addition & 1 deletion test/query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "test_helper"

class DTB::QueryTest < MiniTest::Test
class DTB::QueryTest < Minitest::Test
class TestQuery < DTB::Query
default_scope { [] }

Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "dtb"

require "minitest/autorun"
require "ostruct"
require "debug"

class EvaluationContext
extend ActiveModel::Translation
Expand Down

0 comments on commit 540ab25

Please sign in to comment.