Commit 4036bff7f2c30a414ffc0e332c467f7966624bc4

Authored by Carlos Purificação
1 parent b3e9a31e
Exists in caching-rails4

Added test

Showing 1 changed file with 74 additions and 0 deletions   Show diff stats
test/functional/block_cache_test.rb 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +require 'test_helper'
  2 +
  3 +# Controllers to be tested
  4 +class CachingTestController < HomeController
  5 +
  6 +end
  7 +
  8 +# Test case
  9 +class BlockCacheTest < ActionController::TestCase
  10 +
  11 + CACHE_DIR = 'block_cache_test'
  12 + FILE_STORE_PATH = Rails.root.join('tmp/test', CACHE_DIR)
  13 +
  14 + tests CachingTestController
  15 +
  16 + def setup
  17 + #super
  18 +
  19 + ActionController::Base.perform_caching = true
  20 + ActionController::Base.page_cache_directory = FILE_STORE_PATH
  21 + ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
  22 +
  23 + FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
  24 + FileUtils.mkdir_p(FILE_STORE_PATH)
  25 +
  26 + @environment = Environment.default
  27 + @environment.enable_plugin('EventPlugin')
  28 +
  29 + @environment.locales.delete_if {|key, value| key != "en" }
  30 +
  31 + box = Box.create!(:owner => @environment)
  32 + @block = EventPlugin::EventBlock.create!(:box => box)
  33 +
  34 + @person = fast_create(Person, :environment_id => @environment.id)
  35 + @event1 = Event.create!(:name=>'Event 1', :profile =>@person)
  36 +
  37 + end
  38 +
  39 + # Event item CSS selector
  40 + ev = '.event-plugin_event-block ul.events li.event[itemscope]' +
  41 + '[itemtype="http://data-vocabulary.org/Event"] '
  42 +
  43 + def teardown
  44 + FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
  45 + ActionController::Base.perform_caching = false
  46 + end
  47 +
  48 + should 'update event block cache' do
  49 + @event1.slug = 'event1a'
  50 + @event1.start_date = DateTime.now
  51 + @event1.end_date = DateTime.now + 3.day
  52 + @event1.save!
  53 +
  54 + get :index
  55 + entries = Dir.entries(FILE_STORE_PATH)
  56 + # Assert cache dir was created
  57 + assert entries.count == 3
  58 +
  59 + assert_select ev + 'time.duration[itemprop="endDate"]', /4 days/
  60 +
  61 + # Change the event
  62 + @event1.reload
  63 + @event1.start_date = DateTime.now
  64 + @event1.end_date = DateTime.now + 5.day
  65 + @event1.save!
  66 +
  67 + get :index
  68 +
  69 + entries = Dir.entries(FILE_STORE_PATH)
  70 +
  71 + assert_select ev + 'time.duration[itemprop="endDate"]', /6 days/
  72 + end
  73 +
  74 +end
0 75 \ No newline at end of file
... ...