diff --git a/lib/cell/caching.rb b/lib/cell/caching.rb index 3cd516af..149719f1 100644 --- a/lib/cell/caching.rb +++ b/lib/cell/caching.rb @@ -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) diff --git a/test/cache_test.rb b/test/cache_test.rb index 786032fe..35859907 100644 --- a/test/cache_test.rb +++ b/test/cache_test.rb @@ -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