Skip to content

Instantly share code, notes, and snippets.

@claudiob
Last active December 3, 2015 03:02
Show Gist options
  • Save claudiob/37079cf529f80008d022 to your computer and use it in GitHub Desktop.
Save claudiob/37079cf529f80008d022 to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'sprockets', github: 'rails/sprockets'
gem 'sprockets-rails', github: 'rails/sprockets-rails'
gem 'sass-rails', github: 'rails/sass-rails'
end
require 'active_support'
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class CacheNotificationOrderTest < ActiveSupport::TestCase
def setup
@record_size = ActiveSupport::Cache.lookup_store(:memory_store).send(:cached_size, 1, ActiveSupport::Cache::Entry.new("aaaaaaaaaa"))
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10 + 1)
end
def test_that_works_on_rails42_and_fails_on_master
@events = [ ]
ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
@events << ActiveSupport::Notifications::Event.new(*args)
end
@cache.fetch("radiohead") { "House Of Cards" }
assert_equal @events[0].name, 'cache_read.active_support'
assert_equal @events[1].name, 'cache_generate.active_support'
assert_equal @events[2].name, 'cache_write.active_support'
ensure
ActiveSupport::Notifications.unsubscribe(/^cache_(.*)\.active_support$/)
end
end
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails'
end
require 'active_support'
require 'minitest/autorun'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveSupport::TestCase.test_order = :random
class CacheNotificationOrderTest < ActiveSupport::TestCase
def setup
@record_size = ActiveSupport::Cache.lookup_store(:memory_store).send(:cached_size, 1, ActiveSupport::Cache::Entry.new("aaaaaaaaaa"))
@cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10 + 1)
end
def test_that_works_on_rails42_and_fails_on_master
@events = [ ]
ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
@events << ActiveSupport::Notifications::Event.new(*args)
end
@cache.fetch("radiohead") { "House Of Cards" }
assert_equal @events[0].name, 'cache_read.active_support'
assert_equal @events[1].name, 'cache_generate.active_support'
assert_equal @events[2].name, 'cache_write.active_support'
ensure
ActiveSupport::Notifications.unsubscribe(/^cache_(.*)\.active_support$/)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment