Skip to content

Ruby 3.0 ArgumentError: wrong number of arguments error with Caching #506

@taketo1113

Description

@taketo1113

It raises the error of wrong number of arguments when exec Cell::Caching#render_state with conditionals helper method in ruby 3.0.

Steps to reproduce

ref: taketo1113@1fb75e0

  it "with cache condition helper method" do
    WithCondition = Class.new(Cell::ViewModel) do
      cache :show, if: :enable_cache?, expires_in: 10

      def show
        "Test"
      end

      def cache_store
        STORE
      end

      def enable_cache?
        true
      end
    end

    _(WithCondition.new.(:show)).must_equal("Test")
  end

Expected behavior

It will pass test WithCondition cell with keyword args.

Actual behavior

It raises the below error.

  1) Error:
CacheTest#test_0006_with cache condition helper method:
ArgumentError: wrong number of arguments (given 1, expected 0)
    /__path__/cells/test/cache_test.rb:126:in `enable_cache?'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:9:in `call'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:9:in `public_send'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:9:in `call!'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:36:in `evaluate_method'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:50:in `call'
    /__path__/cells/vendor/bundle/ruby/3.0.0/gems/trailblazer-option-0.1.2/lib/trailblazer/option.rb:50:in `block in build'
    /__path__/cells/lib/cell/caching.rb:62:in `cache?'
    /__path__/cells/lib/cell/caching.rb:48:in `render_state'
    /__path__/cells/lib/cell/view_model.rb:92:in `call'
    /__path__/cells/test/cache_test.rb:131:in `block in <class:CacheTest>'

115 runs, 157 assertions, 0 failures, 1 errors, 0 skips

Focus on failing tests:
ruby test/cache_test.rb -l 114

It is empty hash value([{}]) in cache_filter_args at Cell::Caching#render_state.
Then call helper method with wrong args ([{}]) in Cell::Caching#cache?.

https://github.com/trailblazer/cells/blob/master/lib/cell/caching.rb#L46

      cache_filter_args = args + [kws]

# cache_filter_args => [{}]
# args => []
# kws => {}
# **kws =>

System configuration

  • ruby: 3.0.5
  • cells: (github master branch)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions