spec/integration/integration_helper.rb in lhm-2.0.0 vs spec/integration/integration_helper.rb in lhm-2.1.0

- old
+ new

@@ -1,21 +1,11 @@ # Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias # Schmidt +require 'test_helper' +require 'yaml' +$password = YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/database.yml")["password"] rescue nil -require File.expand_path(File.dirname(__FILE__)) + "/../bootstrap" - -begin - require 'active_record' - begin - require 'mysql2' - rescue LoadError - require 'mysql' - end -rescue LoadError - require 'dm-core' - require 'dm-mysql-adapter' -end require 'lhm/table' require 'lhm/sql_helper' require 'lhm/connection' module IntegrationHelper @@ -40,15 +30,16 @@ ActiveRecord::Base.establish_connection( :adapter => defined?(Mysql2) ? 'mysql2' : 'mysql', :host => '127.0.0.1', :database => 'lhm', :username => 'root', - :port => port + :port => port, + :password => $password ) adapter = ActiveRecord::Base.connection elsif defined?(DataMapper) - adapter = DataMapper.setup(:default, "mysql://root@localhost:#{port}/lhm") + adapter = DataMapper.setup(:default, "mysql://root:#{$password}@localhost:#{port}/lhm") end Lhm.setup(adapter) unless defined?(@@cleaned_up) Lhm.cleanup(true) @@ -129,11 +120,11 @@ query = "select count(*) from #{ table } where #{ column } = '#{ value }'" select_value(query).to_i end def count_all(table) - query = "select count(*) from #{ table }" + query = "select count(*) from `#{ table }`" select_value(query).to_i end def index_on_columns?(table_name, cols, type = :non_unique) key_name = Lhm::SqlHelper.idx_name(table_name, cols) @@ -143,11 +134,11 @@ def index?(table_name, key_name, type = :non_unique) non_unique = type == :non_unique ? 1 : 0 !!select_one(%Q< - show indexes in #{ table_name } + show indexes in `#{ table_name }` where key_name = '#{ key_name }' and non_unique = #{ non_unique } >) end @@ -160,15 +151,32 @@ end # # Misc # - + def capture_stdout out = StringIO.new $stdout = out yield return out.string ensure $stdout = ::STDOUT + end + + def simulate_failed_migration + Lhm::Entangler.class_eval do + alias_method :old_after, :after + def after + true + end + end + + yield + ensure + Lhm::Entangler.class_eval do + undef_method :after + alias_method :after, :old_after + undef_method :old_after + end end end