diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..6b30e78 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 3.0 diff --git a/dtb.gemspec b/dtb.gemspec index b6de504..0b99c23 100644 --- a/dtb.gemspec +++ b/dtb.gemspec @@ -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 diff --git a/lib/dtb/builds_data_table.rb b/lib/dtb/builds_data_table.rb index 34f1005..7f8b352 100644 --- a/lib/dtb/builds_data_table.rb +++ b/lib/dtb/builds_data_table.rb @@ -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 diff --git a/lib/dtb/data_table.rb b/lib/dtb/data_table.rb index a959c8d..d57e619 100644 --- a/lib/dtb/data_table.rb +++ b/lib/dtb/data_table.rb @@ -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] any parameters that should be forwarded to + # @param ... [Array] 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? diff --git a/lib/dtb/options_map.rb b/lib/dtb/options_map.rb index 4af2831..38e0465 100644 --- a/lib/dtb/options_map.rb +++ b/lib/dtb/options_map.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "set" require "active_support/core_ext/object/deep_dup" require_relative "errors" diff --git a/lib/dtb/query.rb b/lib/dtb/query.rb index 4667fa7..b583e90 100644 --- a/lib/dtb/query.rb +++ b/lib/dtb/query.rb @@ -114,11 +114,11 @@ def self.i18n_scope # Run the query, returning the results. # - # @param args [Array] Any arguments given will be forwarded to + # @param ... [Array] 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 = {}) diff --git a/lib/dtb/query_builder.rb b/lib/dtb/query_builder.rb index d4814c2..a8a5efa 100644 --- a/lib/dtb/query_builder.rb +++ b/lib/dtb/query_builder.rb @@ -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) @@ -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] Splat of any other params that are accepted by + # @param ... [Array] 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 @@ -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] Splat of any arguments needed by the Proc. + # @param args [Array] 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. diff --git a/test/column_test.rb b/test/column_test.rb index 18c0e4a..18c8eba 100644 --- a/test/column_test.rb +++ b/test/column_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::ColumnTest < MiniTest::Test +class DTB::ColumnTest < Minitest::Test def setup I18n.backend.translations.clear super diff --git a/test/data_table_test.rb b/test/data_table_test.rb index d2fdc68..7221b63 100644 --- a/test/data_table_test.rb +++ b/test/data_table_test.rb @@ -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") diff --git a/test/dtb_test.rb b/test/dtb_test.rb index de19a00..00bf213 100644 --- a/test/dtb_test.rb +++ b/test/dtb_test.rb @@ -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 diff --git a/test/filter_set_test.rb b/test/filter_set_test.rb index 1b545f4..00e04d4 100644 --- a/test/filter_set_test.rb +++ b/test/filter_set_test.rb @@ -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 diff --git a/test/filter_test.rb b/test/filter_test.rb index befce17..33a0f29 100644 --- a/test/filter_test.rb +++ b/test/filter_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::FilterTest < MiniTest::Test +class DTB::FilterTest < Minitest::Test def setup I18n.backend.translations.clear super @@ -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 diff --git a/test/has_columns_test.rb b/test/has_columns_test.rb index 648ef2a..ae04b2c 100644 --- a/test/has_columns_test.rb +++ b/test/has_columns_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::HasColumnsTest < MiniTest::Test +class DTB::HasColumnsTest < Minitest::Test class TestClass include DTB::HasColumns @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/test/has_default_implementation_test.rb b/test/has_default_implementation_test.rb index f01fb10..422145f 100644 --- a/test/has_default_implementation_test.rb +++ b/test/has_default_implementation_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::HasDefaultImplementationTest < MiniTest::Test +class DTB::HasDefaultImplementationTest < Minitest::Test class FailedQuery include DTB::HasDefaultImplementation end diff --git a/test/has_empty_state_test.rb b/test/has_empty_state_test.rb index 795c99b..70c6688 100644 --- a/test/has_empty_state_test.rb +++ b/test/has_empty_state_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::HasEmptyStateTest < MiniTest::Test +class DTB::HasEmptyStateTest < Minitest::Test def setup I18n.backend.translations.clear super @@ -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 diff --git a/test/has_filters_test.rb b/test/has_filters_test.rb index 9311d59..a718479 100644 --- a/test/has_filters_test.rb +++ b/test/has_filters_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::HasFiltersTest < MiniTest::Test +class DTB::HasFiltersTest < Minitest::Test class TestClass include DTB::HasFilters @@ -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"}) diff --git a/test/has_options_test.rb b/test/has_options_test.rb index 897d5f9..04a7861 100644 --- a/test/has_options_test.rb +++ b/test/has_options_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::HasOptionsTest < MiniTest::Test +class DTB::HasOptionsTest < Minitest::Test class TestClass include DTB::HasOptions diff --git a/test/has_url_test.rb b/test/has_url_test.rb index 13bc3b1..e53f546 100644 --- a/test/has_url_test.rb +++ b/test/has_url_test.rb @@ -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 diff --git a/test/options_map_test.rb b/test/options_map_test.rb index d6de28c..b572971 100644 --- a/test/options_map_test.rb +++ b/test/options_map_test.rb @@ -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) diff --git a/test/query_builder_set_test.rb b/test/query_builder_set_test.rb index d5c914d..a43009a 100644 --- a/test/query_builder_set_test.rb +++ b/test/query_builder_set_test.rb @@ -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 } diff --git a/test/query_builder_test.rb b/test/query_builder_test.rb index 8666e66..a27462e 100644 --- a/test/query_builder_test.rb +++ b/test/query_builder_test.rb @@ -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 } diff --git a/test/query_test.rb b/test/query_test.rb index 1a6b591..6912a9e 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -2,7 +2,7 @@ require "test_helper" -class DTB::QueryTest < MiniTest::Test +class DTB::QueryTest < Minitest::Test class TestQuery < DTB::Query default_scope { [] } diff --git a/test/test_helper.rb b/test/test_helper.rb index 0e7ab96..e3683fd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,8 @@ require "dtb" require "minitest/autorun" +require "ostruct" +require "debug" class EvaluationContext extend ActiveModel::Translation