Skip to content

Commit

Permalink
@improve Test OK! - Make setup and teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroig committed Feb 2, 2011
1 parent 259ca61 commit 0231c04
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 24 deletions.
10 changes: 6 additions & 4 deletions test/admin_index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ class User < ActiveRecord::Base
elastic_index
end

#TODO figure out how to have one setup and one teardown

def test_prune_index
@local_index = ''
index = User.index_name
3.times.each do
Escargot::LocalIndexing.create_index_for_model(User)
@local_index = $elastic_search_client.current_index_version(index)
end
User.refresh_index
sleep(1)
assert $elastic_search_client.index_versions(index).size > 1
assert $elastic_search_client.index_versions(index).include? $elastic_search_client.current_index_version(index)
$elastic_search_client.prune_index_versions(index)
assert $elastic_search_client.index_versions(index).size == 1
end

def teardown
User.delete_index
end
end
7 changes: 7 additions & 0 deletions test/distributed_index_creation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ def test_index_rotation
# check that there are no traces of the older index
assert_equal User.search_count, 2
end

def teardown
User.delete_all
User.delete_index
LegacyUser.delete_all
LegacyUser.delete_index
end
end
5 changes: 4 additions & 1 deletion test/index_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ def test_asciifolding_option

results = User.search("pedrin")
assert_equal results.total_entries, 1

User.delete_all
User.delete_index
end
end
end
7 changes: 6 additions & 1 deletion test/indexed_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ def test_indexed_content
assert_equal User.search_count("Peter AND foo:FOO"), 2
end

end
def teardown
User.delete_all
User.delete_index
end

end
10 changes: 8 additions & 2 deletions test/local_index_creation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class LocalIndexCreation < Test::Unit::TestCase
load_schema

class ::User < ActiveRecord::Base
class User < ActiveRecord::Base
elastic_index :updates => false
end

Expand All @@ -17,6 +17,7 @@ def test_fast_index_creation
10.times do
Escargot::LocalIndexing.create_index_for_model(User)
end
sleep(1)
end

def test_indexing_rotation
Expand All @@ -42,4 +43,9 @@ def test_indexing_rotation
assert_equal results.total_entries, 2
end

end
def teardown
User.delete_all
User.delete_index
end

end
7 changes: 6 additions & 1 deletion test/mappings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ def test_not_analyzed_property
assert_equal User.search_count('name=pedro'), 0
assert_equal User.search_count('name="Pedro el Viejo"'), 1
end
end

def teardown
User.delete_all
User.delete_index
end
end
5 changes: 5 additions & 0 deletions test/nrt_enqueue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def setup
User.create(:name => 'Jamie the Flying Machine')
end

def teardown
User.delete_all
User.delete_index
end

def test_document_creation
# the Resque tasks have not run yet, so there should be nothing in the index
# but now run the Resque tasks and check that the index is good
Expand Down
5 changes: 5 additions & 0 deletions test/nrt_immediate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def setup
User.create(:name => 'Jamie the Flying Machine')
end

def teardown
User.delete_all
User.delete_index
end

def test_document_creation
User.refresh_index
assert_equal 5, User.search_count
Expand Down
5 changes: 5 additions & 0 deletions test/nrt_immediate_with_refresh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def setup
User.create(:name => 'Jamie the Flying Machine')
end

def teardown
User.delete_all
User.delete_index
end

def test_document_creation
assert_equal 5, User.search_count
results = User.search("wise")
Expand Down
9 changes: 3 additions & 6 deletions test/search_multiple_models_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ class RenewUser < ActiveRecord::Base
end

def setup
User.delete_all
User.delete_index
LegacyUser.delete_all
LegacyUser.delete_index
RenewUser.delete_all
RenewUser.delete_index

Escargot.flush_all_indexed_models

User.new(:name => 'Cote').save!
User.new(:name => 'Grillo').save!
Expand Down Expand Up @@ -59,6 +55,7 @@ def teardown


def test_search_multiple_models

# Search "Cote" in all Models
assert_equal Escargot.search("Cote").total_entries, 5

Expand Down
5 changes: 5 additions & 0 deletions test/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def setup
Escargot::LocalIndexing.create_index_for_model(User)
end

def teardown
User.delete_all
User.delete_index
end

def test_search_count
results = User.search("peter")
assert_equal results.total_entries, 2
Expand Down
9 changes: 0 additions & 9 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
require 'test/unit'
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))

# we define globally the model here so that User.find() will find the class existing
class User < ActiveRecord::Base
end

class LegacyUser < ActiveRecord::Base
set_primary_key :legacy_id
end


def load_schema
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
Expand Down

0 comments on commit 0231c04

Please sign in to comment.