-
-
Notifications
You must be signed in to change notification settings - Fork 408
/
test_helper.rb
80 lines (65 loc) · 1.84 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# encoding: utf-8
$: << "lib"
$: << File.expand_path(File.dirname(__FILE__))
require 'rubygems'
require 'test/unit'
require 'mocha'
require 'i18n'
require 'i18n/core_ext/object/meta_class'
require 'time'
require 'yaml'
Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
require filename
end
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
# wtf is wrong with this, why's there Kernel#test?
# class Module
# def self.test(name, &block)
# define_method("test: " + name, &block)
# end
# end
class Test::Unit::TestCase
def self.test(name, &block)
define_method("test: " + name, &block)
end
def teardown
I18n.locale = nil
I18n.default_locale = :en
I18n.load_path = []
I18n.available_locales = nil
I18n.backend = nil
end
def translations
I18n.backend.instance_variable_get(:@translations)
end
def store_translations(*args)
data = args.pop
locale = args.pop || :en
I18n.backend.store_translations(locale, data)
end
def locales_dir
File.dirname(__FILE__) + '/fixtures/locales'
end
def euc_jp(string)
string.encode!(Encoding::EUC_JP)
end
end
def setup_active_record
require 'active_record'
require 'i18n/backend/active_record/store_procs'
if I18n::Backend::Simple.method_defined?(:interpolate_with_deprecated_syntax)
I18n::Backend::Simple.send(:remove_method, :interpolate) rescue NameError
end
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define(:version => 1) do
create_table :translations do |t|
t.string :locale
t.string :key
t.string :value
t.string :interpolations
t.boolean :is_proc, :default => false
end
end
I18n::Backend::ActiveRecord::Translation.send(:include, I18n::Backend::ActiveRecord::StoreProcs)
end