class FunctionalFragmentCachingTest

Public Instance Methods

setup() click to toggle source
Calls superclass method BaseCachingTest#setup
# File actionmailer/test/caching_test.rb, line 113
def setup
  super
  @store = ActiveSupport::Cache::MemoryStore.new
  @mailer = CachingMailer.new
  @mailer.perform_caching = true
  @mailer.cache_store = @store
end
test_fragment_cache_instrumentation() click to toggle source
# File actionmailer/test/caching_test.rb, line 172
def test_fragment_cache_instrumentation
  @mailer.enable_fragment_cache_logging = true
  payload = nil

  subscriber = proc do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    payload = event.payload
  end

  ActiveSupport::Notifications.subscribed(subscriber, "read_fragment.action_mailer") do
    @mailer.fragment_cache
  end

  assert_equal "caching_mailer", payload[:mailer]
  assert_equal [ :views, "caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache")}", :caching ], payload[:key]
ensure
  @mailer.enable_fragment_cache_logging = true
end
test_fragment_caching() click to toggle source
# File actionmailer/test/caching_test.rb, line 121
def test_fragment_caching
  email = @mailer.fragment_cache
  expected_body = "\"Welcome\""

  assert_match expected_body, email.body.encoded
  assert_match expected_body,
    @store.read("views/caching_mailer/fragment_cache:#{template_digest("caching_mailer/fragment_cache")}/caching")
end
test_fragment_caching_in_partials() click to toggle source
# File actionmailer/test/caching_test.rb, line 130
def test_fragment_caching_in_partials
  email = @mailer.fragment_cache_in_partials
  expected_body = "Old fragment caching in a partial"
  assert_match(expected_body, email.body.encoded)

  assert_match(expected_body,
    @store.read("views/caching_mailer/_partial:#{template_digest("caching_mailer/_partial")}/caching"))
end
test_fragment_caching_options() click to toggle source
# File actionmailer/test/caching_test.rb, line 147
def test_fragment_caching_options
  time = Time.now
  email = @mailer.fragment_caching_options
  expected_body = "No Digest"

  assert_match expected_body, email.body.encoded
  Time.stub(:now, time + 11) do
    assert_nil @store.read("views/no_digest")
  end
end
test_fragment_caching_with_options() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 241
def test_fragment_caching_with_options
  time = Time.now
  get :fragment_cached_with_options
  assert_response :success
  expected_body = "<body>\n<p>ERB</p>\n</body>\n"

  assert_equal expected_body, @response.body
  Time.stub(:now, time + 11) do
    assert_nil @store.read("views/with_options")
  end
end
test_fragment_caching_with_variant() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 300
def test_fragment_caching_with_variant
  get :formatted_fragment_cached_with_variant, format: "html", params: { v: :phone }
  assert_response :success
  expected_body = "<body>\n<p>PHONE</p>\n</body>\n"

  assert_equal expected_body, @response.body

  assert_equal "<p>PHONE</p>",
    @store.read("views/functional_caching/formatted_fragment_cached_with_variant:#{template_digest("functional_caching/formatted_fragment_cached_with_variant")}/fragment")
end
test_html_formatted_fragment_caching() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 278
def test_html_formatted_fragment_caching
  get :formatted_fragment_cached, format: "html"
  assert_response :success
  expected_body = "<body>\n<p>ERB</p>\n</body>\n"

  assert_equal expected_body, @response.body

  assert_equal "<p>ERB</p>",
    @store.read("views/functional_caching/formatted_fragment_cached:#{template_digest("functional_caching/formatted_fragment_cached")}/fragment")
end
test_multipart_fragment_caching() click to toggle source
# File actionmailer/test/caching_test.rb, line 158
def test_multipart_fragment_caching
  email = @mailer.multipart_cache

  expected_text_body = "\"Welcome text\""
  expected_html_body = "\"Welcome html\""
  encoded_body = email.body.encoded
  assert_match expected_text_body, encoded_body
  assert_match expected_html_body, encoded_body
  assert_match expected_text_body,
               @store.read("views/text_caching")
  assert_match expected_html_body,
               @store.read("views/html_caching")
end
test_render_inline_before_fragment_caching() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 253
def test_render_inline_before_fragment_caching
  get :inline_fragment_cached
  assert_response :success
  assert_match(/Some inline content/, @response.body)
  assert_match(/Some cached content/, @response.body)
  assert_match("Some cached content",
    @store.read("views/functional_caching/inline_fragment_cached:#{template_digest("functional_caching/inline_fragment_cached")}/test.host/functional_caching/inline_fragment_cached"))
end
test_skip_fragment_cache_digesting() click to toggle source
# File actionmailer/test/caching_test.rb, line 139
def test_skip_fragment_cache_digesting
  email = @mailer.skip_fragment_cache_digesting
  expected_body = "No Digest"

  assert_match expected_body, email.body.encoded
  assert_match expected_body, @store.read("views/no_digest")
end
test_skipping_fragment_cache_digesting() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 232
def test_skipping_fragment_cache_digesting
  get :fragment_cached_without_digest, format: "html"
  assert_response :success
  expected_body = "<body>\n<p>ERB</p>\n</body>\n"

  assert_equal expected_body, @response.body
  assert_equal "<p>ERB</p>", @store.read("views/nodigest")
end
test_xml_formatted_fragment_caching() click to toggle source
# File actionpack/test/controller/caching_test.rb, line 289
def test_xml_formatted_fragment_caching
  get :formatted_fragment_cached, format: "xml"
  assert_response :success
  expected_body = "<body>\n  <p>Builder</p>\n</body>\n"

  assert_equal expected_body, @response.body

  assert_equal "  <p>Builder</p>\n",
    @store.read("views/functional_caching/formatted_fragment_cached:#{template_digest("functional_caching/formatted_fragment_cached")}/fragment")
end

Private Instance Methods

template_digest(name) click to toggle source
# File actionmailer/test/caching_test.rb, line 193
def template_digest(name)
  ActionView::Digestor.digest(name: name, finder: @mailer.lookup_context)
end