Skip to content

Commit

Permalink
use teardown for cleanup, not setup.
Browse files Browse the repository at this point in the history
This solves order dependent issues where the last test
leaked the query cache state. This resulted in the following error:

```
QueryCacheExpiryTest#test_cache_is_expired_by_habtm_delete [test/cases/query_cache_test.rb:275]:
not all expectations were satisfied
unsatisfied expectations:
- expected exactly twice, invoked once: #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x7f93e0c65838>.clear_query_cache(any_parameters)
```
  • Loading branch information
senny committed Jan 16, 2014
1 parent 8e1735e commit f005243
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions activerecord/test/cases/query_cache_test.rb
Expand Up @@ -8,7 +8,7 @@
class QueryCacheTest < ActiveRecord::TestCase class QueryCacheTest < ActiveRecord::TestCase
fixtures :tasks, :topics, :categories, :posts, :categories_posts fixtures :tasks, :topics, :categories, :posts, :categories_posts


def setup teardown do
Task.connection.clear_query_cache Task.connection.clear_query_cache
ActiveRecord::Base.connection.disable_query_cache! ActiveRecord::Base.connection.disable_query_cache!
end end
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_cache_gets_cleared_after_migration
Post.find(1) Post.find(1)


# change the column definition # change the column definition
Post.connection.change_column :posts, :title, :string, :limit => 80 Post.connection.change_column :posts, :title, :string, limit: 80
assert_nothing_raised { Post.find(1) } assert_nothing_raised { Post.find(1) }


# restore the old definition # restore the old definition
Expand All @@ -241,7 +241,6 @@ def test_find


def test_update def test_update
Task.connection.expects(:clear_query_cache).times(2) Task.connection.expects(:clear_query_cache).times(2)

Task.cache do Task.cache do
task = Task.find(1) task = Task.find(1)
task.starting = Time.now.utc task.starting = Time.now.utc
Expand All @@ -251,15 +250,13 @@ def test_update


def test_destroy def test_destroy
Task.connection.expects(:clear_query_cache).times(2) Task.connection.expects(:clear_query_cache).times(2)

Task.cache do Task.cache do
Task.find(1).destroy Task.find(1).destroy
end end
end end


def test_insert def test_insert
ActiveRecord::Base.connection.expects(:clear_query_cache).times(2) ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)

Task.cache do Task.cache do
Task.create! Task.create!
end end
Expand Down

0 comments on commit f005243

Please sign in to comment.