cells
cells copied to clipboard
Ruby 3.0 ArgumentError: wrong number of arguments error with Caching
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: https://github.com/taketo1113/cells/commit/1fb75e0a9d4f842e5fdd87a51392681879b72f9d
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)