Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ArgumentError: wrong number of arguments for Cell:: Caching #507

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/cell/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def render_state(state, *args, **kws)
state = state.to_sym

# Before Ruby 3.0, this wasn't necessary, but since cache filters don't receive kwargs as per the "old" (existing cells version) implementation, we can make it one array.
cache_filter_args = args + [kws]
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
cache_filter_args = args + [**kws]
else
cache_filter_args = args
cache_filter_args += [**kws] if kws.size > 0
end

return super(state, *args, **kws) unless cache?(state, *cache_filter_args)

Expand Down
20 changes: 20 additions & 0 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,24 @@ def cache_store
# cache hit for the second render
_(SongCell.new.(:show, "Album", title: "IT", part: "1")).must_equal("Album IT 1")
end

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
end