File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,11 +19,13 @@ gem "acts-as-taggable-on", "2.0.6"
1919gem 'airbrake' , '~> 3.1'
2020gem 'validates_email_format_of'
2121gem 'rdoc'
22+ gem 'expiring_memory_store'
2223
2324group :development , :test do
2425 gem 'annotate'
2526 gem 'test-unit'
2627 gem 'thoughtbot-shoulda'
28+ gem 'timecop'
2729end
2830
2931group :production do
Original file line number Diff line number Diff line change 4444 rake (>= 0.8.7 )
4545 builder (3.3.0 )
4646 calendar_date_select (1.16.1 )
47+ expiring_memory_store (0.1.2 )
4748 haml (3.0.25 )
4849 json (1.7.7 )
4950 kgio (2.11.2 )
5758 test-unit (3.1.9 )
5859 power_assert
5960 thoughtbot-shoulda (2.11.1 )
61+ timecop (0.9.10 )
6062 tzinfo (0.3.61 )
6163 unicorn (5.5.1 )
6264 kgio (~> 2.6 )
@@ -77,6 +79,7 @@ DEPENDENCIES
7779 annotate
7880 authorization !
7981 calendar_date_select (= 1.16.1 )
82+ expiring_memory_store
8083 haml (= 3.0.25 )
8184 json (= 1.7.7 )
8285 mysql
@@ -85,6 +88,7 @@ DEPENDENCIES
8588 rdoc
8689 test-unit
8790 thoughtbot-shoulda
91+ timecop
8892 tzinfo (~> 0.3.61 )
8993 unicorn
9094 validates_email_format_of
Original file line number Diff line number Diff line change 1717
1818# Use a different cache store in production
1919# config.cache_store = :mem_cache_store
20+ require 'active_support/cache/expiring_memory_store'
21+ config . cache_store = :expiring_memory_store
2022
2123# Enable serving of images, stylesheets, and javascripts from an asset server
2224# config.action_controller.asset_host = "http://assets.example.com"
Original file line number Diff line number Diff line change 99# Log error messages when you accidentally call methods on nil.
1010config . whiny_nils = true
1111
12- # Show full error reports and disable caching
12+ # Show full error reports and enable caching with ExpiringMemoryStore
1313config . action_controller . consider_all_requests_local = true
14- config . action_controller . perform_caching = false
14+ config . action_controller . perform_caching = true
15+ require 'active_support/cache/expiring_memory_store'
16+ config . cache_store = :expiring_memory_store
1517
1618# Disable request forgery protection in test environment
1719config . action_controller . allow_forgery_protection = false
Original file line number Diff line number Diff line change 11require 'test_helper'
2+ require 'timecop'
23
34class OrganizationsControllerTest < ActionController ::TestCase
4-
5+
6+ def setup
7+ ActionController ::Base . cache_store . clear
8+ end
9+
10+ def test_index_is_cached_for_anonymous_users
11+ get :index
12+ first_body = @response . body
13+
14+ User . current_user = nil
15+ Visit . create! ( :person => people ( :daryl ) , :arrived_at => Time . zone . now )
16+
17+ get :index
18+ second_body = @response . body
19+
20+ assert_equal first_body , second_body , "Expected cached response for anonymous user"
21+ end
22+
23+ def test_index_cache_is_not_used_for_logged_in_users
24+ login_as 'sfbk'
25+
26+ get :index
27+ first_body = @response . body
28+
29+ Visit . create! ( :person => people ( :daryl ) , :arrived_at => Time . zone . now )
30+
31+ get :index
32+ second_body = @response . body
33+
34+ assert_not_equal first_body , second_body , "Expected fresh response for logged-in user"
35+ end
36+
37+ def test_index_cache_expires
38+ get :index
39+ first_body = @response . body
40+
41+ User . current_user = nil
42+ Visit . create! ( :person => people ( :daryl ) , :arrived_at => Time . zone . now )
43+
44+ Timecop . travel ( 25 . hours . from_now ) do
45+ get :index
46+ second_body = @response . body
47+
48+ assert_not_equal first_body , second_body , "Expected cache to expire after 25 hours"
49+ end
50+ end
51+
552 def test_should_get_index
653 get :index
754 assert_response :success
You can’t perform that action at this time.
0 commit comments