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

Introduce FragmentCaching with cached:true parameter #51

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 17 additions & 3 deletions test/pbbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ class PbbuilderTemplateTest < ActiveSupport::TestCase
assert_equal "The `:spacer_template' option is not supported in collection rendering.", error.message
end

test "partial by name with caching" do
template = <<-PBBUILDER
racers = [Racer.new(1, "Johnny Test", [], nil, API::Asset.new(url: "https://google.com/test1.svg")), Racer.new(2, "Max Verstappen", [])]
pb.friends partial: "racers/racer", as: :racer, collection: racers, cached: true
PBBUILDER

result = render(template)

assert_equal 2, result.friends.count
assert_nil result.logo
assert_equal "https://google.com/test1.svg", result.friends.first.logo.url
end

test "render collections with partial as arg" do
skip("This will be addressed in future version of a gem")
result = render('pb.friends "racers/racer", as: :racer, collection: [Racer.new(1, "Johnny Test", []), Racer.new(2, "Max Verstappen", [])]')
Expand Down Expand Up @@ -356,9 +369,10 @@ def build_view(options = {})

view = ActionView::Base.with_empty_template_cache.new(lookup_context, assigns, controller)

def view.view_cache_dependencies
[]
end
def view.view_cache_dependencies; [] end
def view.combined_fragment_cache_key(key) [ key ] end
def view.cache_fragment_name(key, *) key end
def view.fragment_name_with_digest(key) key end

view
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def cache
class Racer < Struct.new(:id, :name, :friends, :best_friend, :logo)
extend ActiveModel::Naming
include ActiveModel::Conversion

# For compatibility with ActiveModel::API.
def persisted?
false
end
end

Mime::Type.register "application/vnd.google.protobuf", :pb, [], %w(pb)
Expand Down