fast_gettext 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fast_gettext/cache.rb +42 -0
  3. data/lib/fast_gettext/storage.rb +28 -55
  4. data/lib/fast_gettext/version.rb +1 -1
  5. metadata +105 -73
  6. data/.gitignore +0 -2
  7. data/.travis.yml +0 -17
  8. data/Appraisals +0 -8
  9. data/CHANGELOG +0 -8
  10. data/Gemfile +0 -10
  11. data/Gemfile.lock +0 -52
  12. data/Rakefile +0 -25
  13. data/Readme.md +0 -261
  14. data/benchmark/base.rb +0 -46
  15. data/benchmark/baseline.rb +0 -5
  16. data/benchmark/fast_gettext.rb +0 -18
  17. data/benchmark/i18n_simple.rb +0 -8
  18. data/benchmark/ideal.rb +0 -24
  19. data/benchmark/locale/de.yml +0 -126
  20. data/benchmark/locale/de/LC_MESSAGES/large.mo +0 -0
  21. data/benchmark/misc/threadsave.rb +0 -21
  22. data/benchmark/namespace/fast_gettext.rb +0 -15
  23. data/benchmark/namespace/original.rb +0 -14
  24. data/benchmark/original.rb +0 -22
  25. data/examples/db/migration.rb +0 -22
  26. data/examples/missing_translation_logger.rb +0 -13
  27. data/fast_gettext.gemspec +0 -12
  28. data/gemfiles/rails23.gemfile +0 -14
  29. data/gemfiles/rails23.gemfile.lock +0 -56
  30. data/gemfiles/rails32.gemfile +0 -14
  31. data/gemfiles/rails32.gemfile.lock +0 -112
  32. data/gemfiles/rails40.gemfile +0 -15
  33. data/gemfiles/rails40.gemfile.lock +0 -110
  34. data/spec/aa_unconfigued_spec.rb +0 -21
  35. data/spec/cases/fake_load_path/iconv.rb +0 -2
  36. data/spec/cases/iconv_fallback.rb +0 -22
  37. data/spec/cases/interpolate_i18n_after_fast_gettext.rb +0 -7
  38. data/spec/cases/interpolate_i18n_before_fast_gettext.rb +0 -9
  39. data/spec/cases/safe_mode_can_handle_locales.rb +0 -5
  40. data/spec/fast_gettext/mo_file_spec.rb +0 -35
  41. data/spec/fast_gettext/po_file_spec.rb +0 -35
  42. data/spec/fast_gettext/storage_spec.rb +0 -386
  43. data/spec/fast_gettext/translation_repository/base_spec.rb +0 -24
  44. data/spec/fast_gettext/translation_repository/chain_spec.rb +0 -98
  45. data/spec/fast_gettext/translation_repository/db_spec.rb +0 -114
  46. data/spec/fast_gettext/translation_repository/logger_spec.rb +0 -40
  47. data/spec/fast_gettext/translation_repository/mo_spec.rb +0 -58
  48. data/spec/fast_gettext/translation_repository/po_spec.rb +0 -65
  49. data/spec/fast_gettext/translation_repository/yaml_spec.rb +0 -84
  50. data/spec/fast_gettext/translation_repository_spec.rb +0 -33
  51. data/spec/fast_gettext/translation_spec.rb +0 -363
  52. data/spec/fast_gettext/vendor/iconv_spec.rb +0 -7
  53. data/spec/fast_gettext/vendor/string_spec.rb +0 -101
  54. data/spec/fast_gettext_spec.rb +0 -51
  55. data/spec/fuzzy_locale/de/test.po +0 -22
  56. data/spec/locale/de/LC_MESSAGES/test.mo +0 -0
  57. data/spec/locale/de/LC_MESSAGES/test2.mo +0 -0
  58. data/spec/locale/de/test.po +0 -74
  59. data/spec/locale/de/test2.po +0 -64
  60. data/spec/locale/en/LC_MESSAGES/plural_test.mo +0 -0
  61. data/spec/locale/en/LC_MESSAGES/test.mo +0 -0
  62. data/spec/locale/en/plural_test.po +0 -20
  63. data/spec/locale/en/test.po +0 -59
  64. data/spec/locale/gsw_CH/LC_MESSAGES/test.mo +0 -0
  65. data/spec/locale/gsw_CH/test.po +0 -61
  66. data/spec/locale/yaml/de.yml +0 -25
  67. data/spec/locale/yaml/de2.yml +0 -25
  68. data/spec/locale/yaml/en.yml +0 -21
  69. data/spec/locale/yaml/notfound.yml +0 -2
  70. data/spec/obsolete_locale/de/test.po +0 -21
  71. data/spec/spec_helper.rb +0 -42
  72. data/spec/support/be_accessible_matcher.rb +0 -8
@@ -1,15 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "sqlite3"
8
- gem "rspec"
9
- gem "activerecord"
10
- gem "i18n"
11
- gem "bump"
12
- gem "rails", "~>4.0.0"
13
- gem "protected_attributes"
14
-
15
- gemspec :path=>"../"
@@ -1,110 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/fast_gettext
3
- specs:
4
- fast_gettext (0.7.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actionmailer (4.0.0)
10
- actionpack (= 4.0.0)
11
- mail (~> 2.5.3)
12
- actionpack (4.0.0)
13
- activesupport (= 4.0.0)
14
- builder (~> 3.1.0)
15
- erubis (~> 2.7.0)
16
- rack (~> 1.5.2)
17
- rack-test (~> 0.6.2)
18
- activemodel (4.0.0)
19
- activesupport (= 4.0.0)
20
- builder (~> 3.1.0)
21
- activerecord (4.0.0)
22
- activemodel (= 4.0.0)
23
- activerecord-deprecated_finders (~> 1.0.2)
24
- activesupport (= 4.0.0)
25
- arel (~> 4.0.0)
26
- activerecord-deprecated_finders (1.0.3)
27
- activesupport (4.0.0)
28
- i18n (~> 0.6, >= 0.6.4)
29
- minitest (~> 4.2)
30
- multi_json (~> 1.3)
31
- thread_safe (~> 0.1)
32
- tzinfo (~> 0.3.37)
33
- appraisal (0.5.2)
34
- bundler
35
- rake
36
- arel (4.0.0)
37
- atomic (1.1.13)
38
- builder (3.1.4)
39
- bump (0.4.2)
40
- diff-lcs (1.2.4)
41
- erubis (2.7.0)
42
- hike (1.2.3)
43
- i18n (0.6.5)
44
- mail (2.5.4)
45
- mime-types (~> 1.16)
46
- treetop (~> 1.4.8)
47
- mime-types (1.24)
48
- minitest (4.7.5)
49
- multi_json (1.7.9)
50
- polyglot (0.3.3)
51
- protected_attributes (1.0.3)
52
- activemodel (>= 4.0.0, < 5.0)
53
- rack (1.5.2)
54
- rack-test (0.6.2)
55
- rack (>= 1.0)
56
- rails (4.0.0)
57
- actionmailer (= 4.0.0)
58
- actionpack (= 4.0.0)
59
- activerecord (= 4.0.0)
60
- activesupport (= 4.0.0)
61
- bundler (>= 1.3.0, < 2.0)
62
- railties (= 4.0.0)
63
- sprockets-rails (~> 2.0.0)
64
- railties (4.0.0)
65
- actionpack (= 4.0.0)
66
- activesupport (= 4.0.0)
67
- rake (>= 0.8.7)
68
- thor (>= 0.18.1, < 2.0)
69
- rake (10.1.0)
70
- rspec (2.14.1)
71
- rspec-core (~> 2.14.0)
72
- rspec-expectations (~> 2.14.0)
73
- rspec-mocks (~> 2.14.0)
74
- rspec-core (2.14.5)
75
- rspec-expectations (2.14.2)
76
- diff-lcs (>= 1.1.3, < 2.0)
77
- rspec-mocks (2.14.3)
78
- sprockets (2.10.0)
79
- hike (~> 1.2)
80
- multi_json (~> 1.0)
81
- rack (~> 1.0)
82
- tilt (~> 1.1, != 1.3.0)
83
- sprockets-rails (2.0.0)
84
- actionpack (>= 3.0)
85
- activesupport (>= 3.0)
86
- sprockets (~> 2.8)
87
- sqlite3 (1.3.8)
88
- thor (0.18.1)
89
- thread_safe (0.1.2)
90
- atomic
91
- tilt (1.4.1)
92
- treetop (1.4.15)
93
- polyglot
94
- polyglot (>= 0.3.1)
95
- tzinfo (0.3.37)
96
-
97
- PLATFORMS
98
- ruby
99
-
100
- DEPENDENCIES
101
- activerecord
102
- appraisal
103
- bump
104
- fast_gettext!
105
- i18n
106
- protected_attributes
107
- rails (~> 4.0.0)
108
- rake
109
- rspec
110
- sqlite3
@@ -1,21 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'unconfigured' do
4
- it "gives a useful error message when trying to just translate" do
5
- FastGettext.text_domain = nil
6
- begin
7
- FastGettext._('x')
8
- "".should == "success!?"
9
- rescue FastGettext::Storage::NoTextDomainConfigured
10
- end
11
- end
12
-
13
- it "gives a useful error message when only locale was set" do
14
- FastGettext.locale = 'de'
15
- begin
16
- FastGettext._('x')
17
- "".should == "success!?"
18
- rescue FastGettext::Storage::NoTextDomainConfigured
19
- end
20
- end
21
- end
@@ -1,2 +0,0 @@
1
- #simulate file not found
2
- raise LoadError
@@ -1,22 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
- $LOAD_PATH.unshift File.join('spec','cases','fake_load_path')
3
-
4
- # test that iconv cannot be found
5
- test = 1
6
- begin
7
- require 'iconv'
8
- rescue LoadError
9
- test = 2
10
- end
11
- raise unless test == 2
12
-
13
- # use FastGettext like normal and see if it fails
14
- require 'fast_gettext'
15
-
16
- FastGettext.add_text_domain('test',:path=>File.join('spec','locale'))
17
- FastGettext.text_domain = 'test'
18
- FastGettext.available_locales = ['en','de']
19
- FastGettext.locale = 'de'
20
-
21
- #translate
22
- raise unless FastGettext._('car') == 'Auto'
@@ -1,7 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
- require 'fast_gettext'
3
- raise unless "%{a}" % {:a => 1} == '1'
4
- require 'i18n/core_ext/string/interpolate'
5
- require 'active_support/core_ext/string/output_safety'
6
- raise unless "%{a}" % {:a => 1} == '1'
7
- raise unless "%{a}".html_safe % {:a => 1} == '1'
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
-
3
- require 'i18n/core_ext/string/interpolate'
4
- require 'active_support/core_ext/string/output_safety'
5
- raise unless "%{a}" %{:a => 1} == '1'
6
- raise unless "%{a}".html_safe % {:a => 1} == '1'
7
- require 'fast_gettext'
8
- raise unless "%{a}" %{:a => 1} == '1'
9
- raise unless "%{a}".html_safe % {:a => 1} == '1'
@@ -1,5 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
- require 'fast_gettext'
3
- $SAFE = 1
4
- rep = FastGettext::TranslationRepository.build('safe_test',:path=>File.join('spec','locale'))
5
- print rep.is_a?(FastGettext::TranslationRepository::Mo)
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
-
4
- de_file = File.join('spec','locale','de','LC_MESSAGES','test.mo')
5
- de = FastGettext::MoFile.new(de_file)
6
-
7
- describe FastGettext::MoFile do
8
- before :all do
9
- File.exist?(de_file).should == true
10
- end
11
-
12
- it "parses a file" do
13
- de['car'].should == 'Auto'
14
- end
15
-
16
- it "stores untranslated values as nil" do
17
- de['Untranslated'].should == nil
18
- end
19
-
20
- it "finds pluralized values" do
21
- de.plural('Axis','Axis').should == ['Achse','Achsen']
22
- end
23
-
24
- it "returns empty array when pluralisation could not be found" do
25
- de.plural('Axis','Axis','Axis').should == []
26
- end
27
-
28
- it "can access plurals through []" do
29
- de['Axis'].should == 'Achse' #singular
30
- end
31
-
32
- it "can successfully translate non-ASCII keys" do
33
- de["Umläüte"].should == "Umlaute"
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- require "spec_helper"
2
- require 'fast_gettext/po_file'
3
-
4
- de_file = File.join('spec','locale','de','test.po')
5
- de = FastGettext::PoFile.to_mo_file(de_file)
6
-
7
- describe FastGettext::PoFile do
8
- before :all do
9
- File.exist?(de_file).should == true
10
- end
11
-
12
- it "parses a file" do
13
- de['car'].should == 'Auto'
14
- end
15
-
16
- it "stores untranslated values as nil" do
17
- de['Untranslated'].should == nil
18
- end
19
-
20
- it "finds pluralized values" do
21
- de.plural('Axis','Axis').should == ['Achse','Achsen']
22
- end
23
-
24
- it "returns empty array when pluralisation could not be found" do
25
- de.plural('Axis','Axis','Axis').should == []
26
- end
27
-
28
- it "can access plurals through []" do
29
- de['Axis'].should == 'Achse' #singular
30
- end
31
-
32
- it "unescapes '\\'" do
33
- de["You should escape '\\' as '\\\\'."].should == "Du solltest '\\' als '\\\\' escapen."
34
- end
35
- end
@@ -1,386 +0,0 @@
1
- require "spec_helper"
2
- require 'fast_gettext/translation_repository/base'
3
-
4
- describe 'Storage' do
5
- include FastGettext::Storage
6
-
7
- before do
8
- #reset everything to nil
9
- self.default_available_locales = nil
10
- self.default_text_domain = nil
11
- self.default_locale = nil
12
- self.available_locales = nil
13
- self.text_domain = 'xxx'
14
- send(:_locale=, nil)#nil is not allowed to be set...
15
-
16
- # fake a simple text-domain
17
- translation_repositories[text_domain] = FastGettext::TranslationRepository::Base.new('x')
18
-
19
- default_locale.should == nil
20
- default_available_locales.should == nil
21
- available_locales.should == nil
22
- locale.should == 'en'
23
- text_domain.should == 'xxx'
24
- end
25
-
26
- def thread_safe(method, value_a, value_b)
27
- send("#{method}=",value_a)
28
-
29
- # mess around with other threads
30
- 100.times do
31
- Thread.new {FastGettext.send("#{method}=",value_b)}
32
- end
33
- sleep 0.1 # Ruby 1.9 cannot switch threads fast enough <-> spec fails without this WTF!
34
-
35
- !!(send(method) == value_a)
36
- end
37
-
38
- {
39
- :locale=>['de','en'],
40
- :available_locales=>[['de'],['en']],
41
- :text_domain=>['xx','yy'],
42
- :pluralisation_rule=>[lambda{|x|x==4},lambda{|x|x==1}]
43
- }.each do |method, (value_a, value_b)|
44
- it "stores #{method} thread safe" do
45
- thread_safe(method, value_a, value_b).should == true
46
- end
47
- end
48
-
49
- context "non-thread safe" do
50
- after do
51
- self.translation_repositories.clear
52
- end
53
-
54
- it "stores translation_repositories" do
55
- self.translation_repositories[:x]=1
56
- t = Thread.new{self.translation_repositories[:x]=2}
57
- t.join
58
- self.translation_repositories[:x].should == 2
59
- end
60
- end
61
-
62
- describe :pluralisation_rule do
63
- it "defaults to singular-if-1 when it is not set" do
64
- should_receive(:current_repository).at_least(1).and_return double(:pluralisation_rule => nil)
65
- self.pluralisation_rule = nil
66
- pluralisation_rule.call(1).should == false
67
- pluralisation_rule.call(0).should == true
68
- pluralisation_rule.call(2).should == true
69
- end
70
- end
71
-
72
- describe :default_locale do
73
- it "stores default_locale non-thread-safe" do
74
- thread_safe(:default_locale, 'de', 'en').should == false
75
- end
76
-
77
- it "does not overwrite locale" do
78
- self.locale = 'de'
79
- self.default_locale = 'yy'
80
- self.locale.should == 'de'
81
- end
82
-
83
- it "falls back to default if locale is missing" do
84
- self.default_locale = 'yy'
85
- self.locale.should == 'yy'
86
- end
87
-
88
- it "does not set non-available-locales as default" do
89
- self.available_locales = ['xx']
90
- self.default_locale = 'yy'
91
- self.default_locale.should == nil
92
- end
93
-
94
- it "can set default_locale to nil" do
95
- self.default_locale = 'xx'
96
- self.default_locale = nil
97
- default_locale.should be_nil
98
- end
99
- end
100
-
101
- describe :default_text_domain do
102
- it "stores default_text_domain non-thread safe" do
103
- thread_safe(:default_text_domain, 'xx', 'en').should == false
104
- end
105
-
106
- it "uses default_text_domain when text_domain is not set" do
107
- self.text_domain = nil
108
- self.default_text_domain = 'x'
109
- text_domain.should == 'x'
110
- end
111
-
112
- it "does not use default when domain is set" do
113
- self.text_domain = 'x'
114
- self.default_text_domain = 'y'
115
- text_domain.should == 'x'
116
- end
117
- end
118
-
119
- describe :default_available_locales do
120
- it "stores default_available_locales non-thread-safe" do
121
- thread_safe(:default_available_locales, ['xx'], ['yy']).should == false
122
- end
123
-
124
- it "converts locales to s" do
125
- self.available_locales = [:x]
126
- available_locales.should == ['x']
127
- end
128
-
129
- it "uses default_available_locales when available_locales is not set" do
130
- self.available_locales = nil
131
- self.default_available_locales = ['x']
132
- available_locales.should == ['x']
133
- end
134
-
135
- it "does not use default when available_locales is set" do
136
- self.available_locales = ['x']
137
- self.default_available_locales = ['y']
138
- available_locales.should == ['x']
139
- end
140
- end
141
-
142
- describe :locale do
143
- it "stores everything as long as available_locales is not set" do
144
- self.available_locales = nil
145
- self.locale = 'XXX'
146
- locale.should == 'XXX'
147
- end
148
-
149
- it "is en if no locale and no available_locale were set" do
150
- FastGettext.send(:_locale=,nil)
151
- self.available_locales = nil
152
- locale.should == 'en'
153
- end
154
-
155
- it "does not change the locale if locales was called with nil" do
156
- self.locale = nil
157
- locale.should == 'en'
158
- end
159
-
160
- it "is the first available_locale if one was set" do
161
- self.available_locales = ['de']
162
- locale.should == 'de'
163
- end
164
-
165
- it "does not store a locale if it is not available" do
166
- self.available_locales = ['de']
167
- self.locale = 'en'
168
- locale.should == 'de'
169
- end
170
-
171
- it "set_locale returns the old locale if the new could not be set" do
172
- self.locale = 'de'
173
- self.available_locales = ['de']
174
- self.set_locale('en').should == 'de'
175
- end
176
-
177
- it "set_locale resets to default with :reset_on_unknown" do
178
- self.locale = 'de'
179
- self.available_locales = ['fr']
180
- self.set_locale('en').should == 'fr'
181
- end
182
-
183
- {
184
- 'Opera' => "de-DE,de;q=0.9,en;q=0.8",
185
- 'Firefox' => "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3",
186
- }.each do |browser,accept_language|
187
- it "sets the locale from #{browser} headers" do
188
- FastGettext.available_locales = ['de_DE','de','xx']
189
- FastGettext.locale = 'xx'
190
- FastGettext.locale = accept_language
191
- FastGettext.locale.should == 'de_DE'
192
- end
193
- end
194
-
195
- it "sets a unimportant locale if it is the only available" do
196
- FastGettext.available_locales = ['en','xx']
197
- FastGettext.locale = "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"
198
- FastGettext.locale.should == 'en'
199
- end
200
-
201
- it "sets the locale with the highest wheight" do
202
- FastGettext.available_locales = ['en','de']
203
- FastGettext.locale = "xx-us;q=0.5,de-de,de;q=0.8,en;q=0.9"
204
- FastGettext.locale.should == 'en'
205
- end
206
-
207
- it "sets the locale from languages" do
208
- FastGettext.available_locales = ['de']
209
- FastGettext.locale = "xx-us;q=0.5,de-de;q=0.8,en-uk;q=0.9"
210
- FastGettext.locale.should == 'de'
211
- end
212
-
213
- it "sets locale from comma seperated" do
214
- FastGettext.available_locales = ['de_DE','en','xx']
215
- FastGettext.locale = "de,de-de,en"
216
- FastGettext.locale.should == 'de_DE'
217
- end
218
- end
219
-
220
- describe :silence_errors do
221
- before do
222
- self.text_domain = rand(99999).to_s
223
- end
224
-
225
- after do
226
- self.translation_repositories.clear
227
- end
228
-
229
- it "raises when a textdomain was empty" do
230
- begin
231
- FastGettext._('x')
232
- raise 'NOPE!'
233
- rescue FastGettext::Storage::NoTextDomainConfigured
234
- end
235
- end
236
-
237
- it "can silence errors" do
238
- FastGettext.silence_errors
239
- FastGettext._('x').should == 'x'
240
- end
241
-
242
- it "does not overwrite existing textdomain" do
243
- self.translation_repositories[FastGettext.text_domain] = 1
244
- FastGettext.silence_errors
245
- self.translation_repositories[FastGettext.text_domain].should == 1
246
- end
247
-
248
- it "has ./locale as locale path when silenced" do
249
- FastGettext.silence_errors
250
- FastGettext.locale_path.should == 'locale'
251
- end
252
- end
253
-
254
- describe :current_cache do
255
- before do
256
- FastGettext.text_domain = 'xxx'
257
- FastGettext.available_locales = ['de','en']
258
- FastGettext.locale = 'de'
259
- FastGettext.current_repository.stub(:"[]").with('abc').and_return 'old'
260
- FastGettext.current_repository.stub(:"[]").with('unfound').and_return nil
261
- FastGettext._('abc')
262
- FastGettext._('unfound')
263
- FastGettext.locale = 'en'
264
- end
265
-
266
- it "stores a translation seperate by locale" do
267
- FastGettext.current_cache['abc'].should == nil
268
- end
269
-
270
- it "stores a translation seperate by domain" do
271
- FastGettext.locale = 'de'
272
- FastGettext.text_domain = nil
273
- FastGettext.current_cache['abc'].should == nil
274
- end
275
-
276
- it "cache is restored through setting of default_text_domain" do
277
- FastGettext.locale = 'de'
278
- FastGettext.text_domain = nil
279
- FastGettext.default_text_domain = 'xxx'
280
- FastGettext.current_cache['abc'].should == 'old'
281
- end
282
-
283
- it "cache is restored through setting of default_locale" do
284
- FastGettext.send(:_locale=,nil)#reset locale to nil
285
- FastGettext.default_locale = 'de'
286
- FastGettext.locale.should == 'de'
287
- FastGettext.current_cache['abc'].should == 'old'
288
- end
289
-
290
- it "stores a translation permanently" do
291
- FastGettext.locale = 'de'
292
- FastGettext.current_cache['abc'].should == 'old'
293
- end
294
-
295
- it "stores a unfound translation permanently" do
296
- FastGettext.locale = 'de'
297
- FastGettext.current_cache['unfound'].should == false
298
- end
299
- end
300
-
301
- describe :reload! do
302
- it "reloads all repositories" do
303
- FastGettext.translation_repositories.each do |name, repository|
304
- repository.should_receive(:reload)
305
- end
306
-
307
- FastGettext.reload!
308
- end
309
-
310
- it "clears the cache" do
311
- FastGettext.should_receive(:current_cache=).with({})
312
-
313
- FastGettext.reload!
314
- end
315
- end
316
-
317
- describe :key_exist? do
318
- it "does not find default keys" do
319
- FastGettext._('abcde')
320
- key_exist?('abcde').should be_false
321
- end
322
-
323
- it "finds using the current repository" do
324
- should_receive(:current_repository).and_return '1234'=>'1'
325
- key_exist?('1234').should == true
326
- end
327
-
328
- it "sets the current cache with a found result" do
329
- should_receive(:current_repository).and_return 'xxx'=>'1'
330
- key_exist?('xxx')
331
- current_cache['xxx'].should == '1'
332
- end
333
-
334
- it "does not overwrite an existing cache value" do
335
- current_cache['xxx']='xxx'
336
- key_exist?('xxx')
337
- current_cache['xxx'].should == 'xxx'
338
- end
339
-
340
- it "is false for gettext meta key" do
341
- key_exist?("").should == false
342
- end
343
- end
344
-
345
- describe :cached_find do
346
- it "is nil for gettext meta key" do
347
- cached_find("").should == false
348
- end
349
- end
350
-
351
- describe :format_locale do
352
- it "allows 2-letter locales to be formatted" do
353
- format_locale("de-ch").should == "de_CH"
354
- end
355
-
356
- it "allows 3-letter locales to be formatted" do
357
- format_locale("gsw-ch").should == "gsw_CH"
358
- end
359
- end
360
-
361
- describe :expire_cache_for do
362
- it "expires the cached key" do
363
- should_receive(:current_repository).and_return 'xxx' => 'new string'
364
- current_cache['xxx'] = 'old string'
365
- cached_find('xxx').should == 'old string'
366
- expire_cache_for('xxx')
367
- cached_find('xxx').should == 'new string'
368
- end
369
- end
370
-
371
- describe FastGettext::Storage::NoTextDomainConfigured do
372
- it "shows what to do" do
373
- FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /FastGettext\.add_text_domain/
374
- end
375
-
376
- it "warns when text_domain is nil" do
377
- FastGettext.text_domain = nil
378
- FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /\(nil\)/
379
- end
380
-
381
- it "shows current text_domain" do
382
- FastGettext.text_domain = 'xxx'
383
- FastGettext::Storage::NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/
384
- end
385
- end
386
- end