rails-i18nterface 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ C:-ActiveSupport::HashWithIndifferentAccess{I"article.key1:EF[I"app/models/article.rb;TI"article.key2;F[I"app/models/article.rb;TI"article.key3;F[I"app/models/article.rb;TI"article.key4;F[I"app/models/article.rb;TI"article.key5;F[I"app/models/article.rb;TI"category_html_erb.key1;F[I"+app/views/categories/category.html.erb;TI"category_erb.key1;F[I"&app/views/categories/category.erb;TI"category_rhtml.key1;F[I"(app/views/categories/category.rhtml;TI"
@@ -7,16 +7,10 @@ describe RailsI18nterface::Cache do
7
7
 
8
8
  before :each do
9
9
  @cachefile = File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__)
10
- @file = File.join(File.dirname(@cachefile), 'test.yml')
11
- @sample = { 'a' => 'a', 'b' => 'b' }
12
- File.open(@file, 'w') do |f|
13
- f.write YAML.dump(@sample)
14
- end
15
10
  end
16
11
 
17
12
  after :each do
18
13
  FileUtils.rm @cachefile if File.exists? @cachefile
19
- FileUtils.rm @file if File.exists? @file
20
14
  end
21
15
 
22
16
  it 'stores cache of an object' do
@@ -28,24 +22,26 @@ describe RailsI18nterface::Cache do
28
22
  it 'reads cache from marshalled file' do
29
23
  a = { a: 'a' }
30
24
  cache_save a, @cachefile
31
- b = cache_load @cachefile, @file
25
+ b = cache_load @cachefile
32
26
  b.should == a
33
27
  end
34
28
 
35
29
  it 'creates the cache if not present' do
36
- b = cache_load @cachefile, @file do
37
- YAML.load_file @file
30
+ b = cache_load @cachefile do
31
+ 20
38
32
  end
39
- b.should == @sample
33
+ File.exists?(@cachefile).should be_true
34
+ b.should == 20
40
35
  end
41
36
 
42
- it 'refreshes the cache if the origin file changed' do
43
- mtime = File.mtime(@file) - 100
44
- File.utime(mtime, mtime, @file)
45
- b = cache_load @cachefile, @file do
46
- YAML.load_file @file
37
+ it 'creates the cache if not present, using an argument' do
38
+ b = cache_load @cachefile, 'something' do |options|
39
+ options
47
40
  end
48
- b.should == @sample
41
+ File.exists?(@cachefile).should be_true
42
+ b.should == 'something'
49
43
  end
50
44
 
45
+
46
+
51
47
  end
@@ -11,36 +11,36 @@ describe RailsI18nterface::Keys do
11
11
  @keys = RailsI18nterface::Keys.new(@root_dir, :sv, :no)
12
12
  end
13
13
 
14
- describe 'to_a' do
15
- it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
16
- @keys.files.keys.map(&:to_s).sort.should == [
17
- 'activerecord.attributes.article.active',
18
- 'activerecord.attributes.article.body',
19
- 'activerecord.attributes.article.created_at',
20
- 'activerecord.attributes.article.title',
21
- 'activerecord.attributes.article.updated_at',
22
- 'activerecord.attributes.topic.created_at',
23
- 'activerecord.attributes.topic.title',
24
- 'activerecord.attributes.topic.updated_at',
25
- 'activerecord.models.article',
26
- 'activerecord.models.topic',
27
- 'article.key1',
28
- 'article.key2',
29
- 'article.key3',
30
- 'article.key4',
31
- 'article.key5',
32
- 'category_erb.key1',
33
- 'category_html_erb.key1',
34
- 'category_rhtml.key1',
35
- 'js.alert'
36
- ]
37
- end
14
+ it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
15
+ @keys.files.keys.map(&:to_s).sort.should == [
16
+ 'activerecord.attributes.article.active',
17
+ 'activerecord.attributes.article.body',
18
+ 'activerecord.attributes.article.created_at',
19
+ 'activerecord.attributes.article.title',
20
+ 'activerecord.attributes.article.updated_at',
21
+ 'activerecord.attributes.topic.created_at',
22
+ 'activerecord.attributes.topic.title',
23
+ 'activerecord.attributes.topic.updated_at',
24
+ 'activerecord.models.article',
25
+ 'activerecord.models.topic',
26
+ 'article.key1',
27
+ 'article.key2',
28
+ 'article.key3',
29
+ 'article.key4',
30
+ 'article.key5',
31
+ 'category_erb.key1',
32
+ 'category_html_erb.key1',
33
+ 'category_rhtml.key1',
34
+ 'js.alert'
35
+ ]
38
36
  end
39
37
 
40
- describe 'to_hash' do
41
- it 'return a hash with I18n keys and file lists' do
42
- @keys.files[:'article.key3'].should == ['app/models/article.rb']
43
- end
38
+ it 'return a hash with I18n keys and file lists' do
39
+ @keys.files[:'article.key3'].should == ['app/models/article.rb']
40
+ end
41
+
42
+ it 'reloads the translatable strings' do
43
+ @keys.reload(@root_dir).size.should == 123
44
44
  end
45
45
 
46
46
  describe 'i18n_keys' do
@@ -4,6 +4,12 @@ require 'spec_helper'
4
4
 
5
5
  describe RailsI18nterface::Sourcefiles do
6
6
 
7
+ before :each do
8
+ @root_dir = File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__)
9
+ @cache_file = File.join(@root_dir, 'tmp', 'translation_strings')
10
+ FileUtils.rm @cache_file if File.exists? @cache_file
11
+ end
12
+
7
13
  it 'grabs field from schema.rb' do
8
14
  expected = {
9
15
  'activerecord.models.article'=>['db/schema.rb'],
@@ -17,9 +23,34 @@ describe RailsI18nterface::Sourcefiles do
17
23
  'activerecord.attributes.topic.created_at'=>['db/schema.rb'],
18
24
  'activerecord.attributes.topic.updated_at'=>['db/schema.rb']
19
25
  }
20
- root_dir = File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__)
21
- hash = RailsI18nterface::Sourcefiles.extract_activerecords(root_dir)
26
+ hash = RailsI18nterface::Sourcefiles.extract_activerecords(@root_dir)
22
27
  hash.should == expected
23
28
  end
24
29
 
30
+ it 'extracts translatable string from code source' do
31
+ x = RailsI18nterface::Sourcefiles.load_files(@root_dir)
32
+ File.exists?(@cache_file).should be_true
33
+ x.size.should == 19
34
+ end
35
+
36
+ describe 'refreshing' do
37
+ before :each do
38
+ RailsI18nterface::Sourcefiles.load_files(@root_dir)
39
+ @testfile = File.join(@root_dir,'app','views','test.html.erb')
40
+ end
41
+
42
+ after :each do
43
+ FileUtils.rm @testfile if File.exists? @testfile
44
+ FileUtils.rm @cache_file if File.exists? @cache_file
45
+ end
46
+
47
+ it 'refreshes translatable strings cache' do
48
+ File.open(File.join(@root_dir,'app','views','test.html.erb'),'w') do |f|
49
+ f.puts "<%= t('something') %>"
50
+ end
51
+ y = RailsI18nterface::Sourcefiles.refresh(@root_dir)
52
+ y.size.should == 20
53
+ end
54
+ end
55
+
25
56
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  if ENV['COV']
4
4
  require 'simplecov'
5
+ require 'coveralls'
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
5
10
  SimpleCov.start do
6
11
  add_filter '/spec/'
7
12
  add_filter '/config/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-i18nterface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2013-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -200,7 +200,6 @@ files:
200
200
  - lib/rails-i18nterface/cache.rb
201
201
  - lib/rails-i18nterface/utils.rb
202
202
  - lib/rails-i18nterface/engine.rb
203
- - lib/rails-i18nterface/storage.rb
204
203
  - lib/rails-i18nterface/yamlfile.rb
205
204
  - lib/rails-i18nterface/version.rb
206
205
  - MIT-LICENSE
@@ -217,13 +216,13 @@ files:
217
216
  - spec/internal/app/assets/stylesheets/application.css
218
217
  - spec/internal/app/controllers/application_controller.rb
219
218
  - spec/internal/log/test.log
219
+ - spec/internal/tmp/translation_strings
220
220
  - spec/internal/config/routes.rb
221
221
  - spec/internal/config/database.yml
222
222
  - spec/internal/db/schema.rb
223
223
  - spec/internal/db/combustion_test.sqlite
224
224
  - spec/requests/search_spec.rb
225
225
  - spec/lib/utils_spec.rb
226
- - spec/lib/storage_spec.rb
227
226
  - spec/lib/cache_spec.rb
228
227
  - spec/lib/yamlfile_spec.rb
229
228
  - spec/lib/keys_spec.rb
@@ -245,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
244
  version: '0'
246
245
  segments:
247
246
  - 0
248
- hash: -998383263
247
+ hash: -901846675
249
248
  required_rubygems_version: !ruby/object:Gem::Requirement
250
249
  none: false
251
250
  requirements:
@@ -254,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
253
  version: '0'
255
254
  segments:
256
255
  - 0
257
- hash: -998383263
256
+ hash: -901846675
258
257
  requirements: []
259
258
  rubyforge_project:
260
259
  rubygems_version: 1.8.25
@@ -273,13 +272,13 @@ test_files:
273
272
  - spec/internal/app/assets/stylesheets/application.css
274
273
  - spec/internal/app/controllers/application_controller.rb
275
274
  - spec/internal/log/test.log
275
+ - spec/internal/tmp/translation_strings
276
276
  - spec/internal/config/routes.rb
277
277
  - spec/internal/config/database.yml
278
278
  - spec/internal/db/schema.rb
279
279
  - spec/internal/db/combustion_test.sqlite
280
280
  - spec/requests/search_spec.rb
281
281
  - spec/lib/utils_spec.rb
282
- - spec/lib/storage_spec.rb
283
282
  - spec/lib/cache_spec.rb
284
283
  - spec/lib/yamlfile_spec.rb
285
284
  - spec/lib/keys_spec.rb
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module RailsI18nterface
4
- class Storage
5
-
6
- include Utils
7
-
8
- attr_accessor :locale
9
-
10
- def initialize(locale)
11
- self.locale = locale.to_sym
12
- end
13
-
14
- def write_to_file
15
- Yamlfile.new(file_path).write(remove_blanks(keys))
16
- end
17
-
18
- def self.root_dir
19
- Rails.root
20
- end
21
-
22
- private
23
-
24
- def keys
25
- { locale => I18n.backend.send(:translations)[locale] }
26
- end
27
-
28
- def file_path
29
- File.join(self.class.root_dir, 'config', 'locales', "#{locale}.yml")
30
- end
31
- end
32
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe RailsI18nterface::Storage do
6
- describe 'write_to_file' do
7
- before(:each) do
8
- @storage = RailsI18nterface::Storage.new(:en)
9
- end
10
-
11
- it 'writes all I18n messages for a locale to YAML file' do
12
- I18n.backend.should_receive(:translations).and_return(translations)
13
- @storage.stub!(:file_path).and_return(file_path)
14
- file = mock(:file)
15
- file.should_receive(:write).with(translations)
16
- RailsI18nterface::Yamlfile.should_receive(:new).with(file_path).and_return(file)
17
- @storage.write_to_file
18
- end
19
-
20
- def file_path
21
- File.join(File.dirname(__FILE__), 'files', 'en.yml')
22
- end
23
-
24
- def translations
25
- {
26
- en: {
27
- article: {
28
- title: 'One Article'
29
- },
30
- category: 'Category'
31
- }
32
- }
33
- end
34
- end
35
- end