rails-i18nterface 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -11
  3. data/Rakefile +13 -2
  4. data/app/controllers/rails_i18nterface/translate_controller.rb +10 -24
  5. data/app/helpers/rails_i18nterface/translate_helper.rb +12 -19
  6. data/app/views/rails_i18nterface/translate/index.html.erb +91 -105
  7. data/config/initializers/missing_translation.rb +4 -2
  8. data/lib/rails-i18nterface.rb +1 -0
  9. data/lib/rails-i18nterface/cache.rb +3 -3
  10. data/lib/rails-i18nterface/keys.rb +21 -11
  11. data/lib/rails-i18nterface/sourcefiles.rb +38 -19
  12. data/lib/rails-i18nterface/translation.rb +34 -0
  13. data/lib/rails-i18nterface/utils.rb +13 -9
  14. data/lib/rails-i18nterface/version.rb +1 -1
  15. data/lib/rails-i18nterface/yamlfile.rb +1 -1
  16. data/spec/controllers/translate_controller_spec.rb +72 -51
  17. data/spec/internal/app/controllers/application_controller.rb +2 -1
  18. data/spec/internal/app/models/article.rb +1 -0
  19. data/spec/internal/db/schema.rb +2 -0
  20. data/spec/internal/log/test.log +0 -2370
  21. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/0PMwId9157j93ZuEBNCPa71HO-BWiCNHuiZtCkqHovk.cache +1 -0
  22. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/172YbT7Y9QCTtQpYWCn3GiUa1XYF30IZjymEsgPF2r4.cache +1 -0
  23. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1RE9Nc-99pz5dq3J_WTniU9ihuoYrOprEnGvyXAa5cY.cache +1 -0
  24. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1vT4QnCK-tMzI13mEL_FMuTrb5BgAdA3XBhVxNv4-r8.cache +1 -0
  25. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3V-PndZUHey8S35jzCvUM5n8ObasIDurRCq_RlH0jKo.cache +0 -0
  26. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3l6G7l7GutWzjmS7bo548k2NQXCbu3FuG0RCqtNuUL8.cache +2 -0
  27. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/4vXT_Tqow4flv0JjTjeIZO4MHOerMmqrPSyHiyf3SYE.cache +2 -0
  28. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/7Ki489aXvXh1c80Q1MzMtZpbfnotMDd6A3yHY-HEecw.cache +1 -0
  29. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/9kyHNOVXEDTe7kg34AKp3C9rb7GbxRKGQYV0smgM01I.cache +1 -0
  30. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/DgOE4dVOvx7Kg6yuTxyUSupElQF47xWnXtMcz2TXBaw.cache +2 -0
  31. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/FZqMgA_zpqV7sBthUsaF-loYETVrVCEtlxczLF730GY.cache +1 -0
  32. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/M-S52Jney4p15fjNRm25zSHatM5QqthKsrEU_Q7GTVA.cache +1 -0
  33. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/PaP9vMCDQ63NoJWLaM8fSu0YeRy-eLKbArpgNOm8Z_4.cache +1 -0
  34. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/UHhQ3Te4YSyiy1iqqTRt4nt2dyXqSXxkwAkjepufrsY.cache +2 -0
  35. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/VOKFuKrh87uBuA6qI4LzN8vVjP5mXjzL0j-iaq5sNNg.cache +2 -0
  36. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/Vjw0tPMcLKXFR62wwfemKkM4UCNkbPeERe-8KqFrez0.cache +0 -0
  37. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/YGEo5ly-YOZRgLRVZp1HmXC1FVjMcAWo8Pc006mVUEc.cache +0 -0
  38. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/_RHrJ0guSCf-x6bLKcowvNq4a-4N5p1m_5Abxsef-Zw.cache +0 -0
  39. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/bZt89CxopsDo8--1TGPUMLxKV-mDvRqFMTNNZOfnN08.cache +0 -0
  40. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/frFXg-urENHAZ5rXQ1GpQfRRjJu9Fp_-RvTvn9UugJc.cache +0 -0
  41. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/gaOEShTR6QyHBz9Pv5Ylz1vVWcNP7Dz2DRcuDIl52cs.cache +3 -0
  42. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/mr2V_uFvIXsHQ7VrC70TymoM9CO0RMKHzQgBkn3deHw.cache +1 -0
  43. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/nbwa8EHOBiuE0pKOTtnWN0gAQOC27loObjVaVMX_wZE.cache +0 -0
  44. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/oQxOm6wUSyQ0jKnI8eKFRJLgEQ-dFvxofYtnbn-haqA.cache +1 -0
  45. data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/v6huIOApjM-My2aA3RhSsO6U2my-O0Ht7A0lo0YKqPI.cache +2 -0
  46. data/spec/internal/tmp/translation_strings +2 -1
  47. data/spec/lib/cache_spec.rb +32 -29
  48. data/spec/lib/keys_spec.rb +77 -66
  49. data/spec/lib/sourcefiles_spec.rb +53 -50
  50. data/spec/lib/utils_spec.rb +55 -29
  51. data/spec/lib/yamlfile_spec.rb +2 -2
  52. data/spec/requests/search_spec.rb +4 -4
  53. data/spec/selenium/nav_spec.rb +23 -0
  54. data/spec/selenium/sauce.rb +68 -0
  55. data/spec/selenium/translation_spec.rb +19 -0
  56. data/spec/spec_helper.rb +19 -18
  57. metadata +225 -74
  58. data/app/helpers/rails_i18nterface/application_helper.rb +0 -6
  59. data/config/initializers/rails_i18nterface/missing_translation.rb +0 -13
  60. data/spec/internal/app/views/categories/category.erb +0 -1
@@ -0,0 +1 @@
1
+ "%Hl��/H5mU�[��I K�s� ~)�i����
@@ -0,0 +1 @@
1
+ "%��$eBzz�q�q��p: ��D�Iz�Q�t�%�
@@ -0,0 +1 @@
1
+ "% &�}ۺ5l��K,RAF,��U�m���hA�
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js?type=application/javascript&id=ca3a7e749f47da8215a7af8a18b4a2f8ae3dd77dabe2c0d8d53fbd4efbbb7217:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{I"environment-version:ETTI"environment-paths;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"pfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"jfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js;TTI"ifile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js;TTI";file-digest://app/assets/javascripts/rails_i18nterface;TTI"Afile-digest://app/assets/javascripts/rails_i18nterface/ender;TTI";file-digest://app/assets/stylesheets/rails_i18nterface;TTI"Afile-digest://app/assets/stylesheets/rails_i18nterface/ender;TTI"\file-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface;TTI"bfile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/ender;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface;TTI"gfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender;TTI"@file-digest://app/assets/javascripts/rails_i18nterface/base;TTI"@file-digest://app/assets/stylesheets/rails_i18nterface/base;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/base;TTI"ffile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base;TT
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"0processors:type=text/css&file_type=text/css;TTI"qfile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface;TT
@@ -0,0 +1 @@
1
+ "%��B�����șo�$'�A�d��L���xR�U
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js?type=application/javascript&pipeline=self&id=0e24e105e05d47978596535199ade26a05f6f721cd0e9bf76895824db8df0251:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"ifile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js;TT
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css?type=text/css&id=b6cba33efb2835dbb344633979db7cd0105fe0e6cf2d3e125a4eac2c0db2255e:ET
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js?type=application/javascript&pipeline=self&id=a9740c285b53359e30411a2ee1f51fb3bf188aff8eebacde8de233d02a3b7e2f:ET
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js?type=application/javascript&pipeline=self&id=4e30a07808cb3134b85e36db6db8f1853e9acc7957aee14c53196bf9fe0860ba:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{I"environment-version:ETTI"environment-paths;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"pfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js;TTI";file-digest://app/assets/javascripts/rails_i18nterface;TTI"Afile-digest://app/assets/javascripts/rails_i18nterface/ender;TTI";file-digest://app/assets/stylesheets/rails_i18nterface;TTI"Afile-digest://app/assets/stylesheets/rails_i18nterface/ender;TTI"\file-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface;TTI"bfile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/ender;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface;TTI"gfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender;TTI"jfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js;TTI"@file-digest://app/assets/javascripts/rails_i18nterface/base;TTI"@file-digest://app/assets/stylesheets/rails_i18nterface/base;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/base;TTI"ffile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base;TTI"ifile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js;TT
@@ -0,0 +1,2 @@
1
+ "%k7
2
+ |>}�q�F���ϼSZk�ʯȄ�숺
@@ -0,0 +1,3 @@
1
+ [o:Set:
2
+ @hash{
3
+ I"environment-version:ETTI"environment-paths;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"qfile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface;TT
@@ -0,0 +1 @@
1
+ "%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
@@ -0,0 +1 @@
1
+ I"�/home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css?type=text/css&pipeline=self&id=a404df2f972b01180a1b326f0a9aeaebf33288a077ff894c4e7f5ec3c3ede9d6:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"jfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js;TT
@@ -1 +1,2 @@
1
- C:-ActiveSupport::HashWithIndifferentAccess{I"article.key1:EF[I"app/models/article.rb;FI"article.key2;F[I"app/models/article.rb;FI"article.key3;F[I"app/models/article.rb;FI"article.key4.zero;F[I"app/models/article.rb;FI"article.key4.one;F[@I"article.key4.other;F[@I"article.key5;F[I"app/models/article.rb;FI"article.key6.zero;F[I"app/models/article.rb;FI"article.key6.one;F[@I"article.key6.other;F[@I"category_erb.key1;F[I"&app/views/categories/category.erb;FI"category_html_erb.key1;F[I"+app/views/categories/category.html.erb;FI"category_rhtml.key1;F[I"(app/views/categories/category.rhtml;FI"
1
+ C:-ActiveSupport::HashWithIndifferentAccess{I"
2
+ title:EF[I".app/controllers/application_controller.rb;FI"article.key1;F[I"app/models/article.rb;FI"article.key2;F[I"app/models/article.rb;FI"article.key3;F[I"app/models/article.rb;FI"article.key4.zero;F[I"app/models/article.rb;FI"article.key4.one;F[@I"article.key4.other;F[@I"article.key5;F[I"app/models/article.rb;FI"article.key6.zero;F[I"app/models/article.rb;FI"article.key6.one;F[@I"article.key6.other;F[@I"symbol_key;F[I"app/models/article.rb;FI"category_html_erb.key1;F[I"+app/views/categories/category.html.erb;FI"category_rhtml.key1;F[I"(app/views/categories/category.rhtml;FI"
@@ -5,43 +5,46 @@ require 'spec_helper'
5
5
  describe RailsI18nterface::Cache do
6
6
  include RailsI18nterface::Cache
7
7
 
8
- before :each do
9
- @cachefile = File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__)
10
- end
8
+ let(:cachefile) { File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__) }
11
9
 
12
- after :each do
13
- FileUtils.rm @cachefile if File.exists? @cachefile
14
- end
10
+ after { FileUtils.rm cachefile if File.exists? cachefile }
15
11
 
16
- it 'stores cache of an object' do
17
- a = { a: 'a' }
18
- cache_save a, @cachefile
19
- File.exists?(@cachefile).should be_true
12
+ describe '.save' do
13
+ let(:a) { { a: 'a' } }
14
+ before { cache_save a, cachefile }
15
+ it 'stores cache of an object' do
16
+ expect(File.exists? cachefile).to be_truthy
17
+ end
20
18
  end
21
19
 
22
- it 'reads cache from marshalled file' do
23
- a = { a: 'a' }
24
- cache_save a, @cachefile
25
- b = cache_load @cachefile
26
- b.should == a
27
- end
20
+ describe '.load' do
21
+ context 'reads cache from marshalled file' do
22
+ let(:a) { { a: 'a' } }
23
+ let(:b) { cache_load cachefile }
24
+ before { cache_save a, cachefile }
25
+ it { expect(b).to eq a }
26
+ end
28
27
 
29
- it 'creates the cache if not present' do
30
- b = cache_load @cachefile do
31
- 20
28
+ context 'when the cache if not present' do
29
+ before {
30
+ @b = cache_load cachefile do
31
+ 20
32
+ end
33
+ }
34
+ it { expect(@b).to be 20 }
35
+ it { expect(File.exists? cachefile).to be_truthy }
32
36
  end
33
- File.exists?(@cachefile).should be_true
34
- b.should == 20
35
- end
36
37
 
37
- it 'creates the cache if not present, using an argument' do
38
- b = cache_load @cachefile, 'something' do |options|
39
- options
38
+ context 'when the cache if not present, using an argument' do
39
+ before {
40
+ @b = cache_load cachefile, 'something' do |options|
41
+ options
42
+ end
43
+ }
44
+ it { expect(@b).to eq 'something' }
45
+ it { expect(File.exists? cachefile).to be_truthy }
40
46
  end
41
- File.exists?(@cachefile).should be_true
42
- b.should == 'something'
43
47
  end
44
48
 
45
49
 
46
-
47
- end
50
+ end
@@ -3,16 +3,13 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RailsI18nterface::Keys do
6
-
7
6
  include RailsI18nterface::Utils
8
7
 
9
- before(:each) do
10
- @root_dir = File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__)
11
- @keys = RailsI18nterface::Keys.new(@root_dir, :sv, :no)
12
- end
8
+ let(:root_dir) { File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__) }
9
+ let(:keys) { RailsI18nterface::Keys.new(root_dir, :sv, :no) }
13
10
 
14
- it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
15
- @keys.files.keys.map(&:to_s).sort.should == [
11
+ describe '.files' do
12
+ let(:expected) { [
16
13
  'activerecord.attributes.article.active',
17
14
  'activerecord.attributes.article.body',
18
15
  'activerecord.attributes.article.created_at',
@@ -33,86 +30,100 @@ describe RailsI18nterface::Keys do
33
30
  'article.key6.one',
34
31
  'article.key6.other',
35
32
  'article.key6.zero',
36
- 'category_erb.key1',
37
33
  'category_html_erb.key1',
38
34
  'category_rhtml.key1',
39
- 'js.alert'
40
- ]
35
+ 'js.alert',
36
+ 'symbol_key',
37
+ 'title'
38
+ ] }
39
+ it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
40
+ expect(keys.files.keys.sort).to eq expected
41
+ end
42
+ end
43
+
44
+ describe "sorts by keys" do
45
+ #before { allow(keys).to receive(:lookup).with('en', 'article.key6.zero').and_return('xxx') }
46
+ it { expect(keys.sort_keys.last).to eq 'title' }
41
47
  end
42
48
 
43
- it 'return a hash with I18n keys and file lists' do
44
- @keys.files[:'article.key3'].should == ['app/models/article.rb']
49
+ describe "sorts by translation" do
50
+ it { expect(keys.sort_keys('text').last).to eq 'time.pm' }
45
51
  end
46
52
 
47
- it 'reloads the translatable strings' do
48
- size = @keys.all_keys.size
49
- @keys.reload(@root_dir).size.should == size
53
+ describe 'return a hash with I18n keys and file lists' do
54
+ it { expect(keys.files[:'article.key3']).to eq ['app/models/article.rb'] }
55
+ end
56
+
57
+ describe 'reloads the translatable strings' do
58
+ let(:size) { keys.all_keys.size }
59
+ it { expect(keys.reload(root_dir).size).to be size }
50
60
  end
51
61
 
52
62
  describe 'i18n_keys' do
53
- before(:each) do
63
+ before do
54
64
  I18n.backend.send(:init_translations) unless I18n.backend.initialized?
55
65
  end
56
66
 
57
- it 'should return all keys in the I18n backend translations hash' do
58
- I18n.backend.should_receive(:translations).and_return(translations)
59
- @keys.i18n_keys(:en).should == ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
67
+ describe 'should return all keys in the I18n backend translations hash' do
68
+ before { allow(I18n.backend).to receive(:translations).and_return(translations) }
69
+ it { expect(keys.i18n_keys :en).to eq ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about'] }
60
70
  end
61
71
 
62
72
  describe 'untranslated_keys' do
63
- before(:each) do
64
- I18n.backend.stub!(:translations).and_return(translations)
65
- end
73
+ let(:expected) {
74
+ {
75
+ sv: ['articles.new.page_title', 'categories.flash.created', 'empty'],
76
+ no: ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
77
+ }
78
+ }
79
+ before { allow(I18n.backend).to receive(:translations).and_return(translations) }
66
80
 
67
81
  it 'should return a hash with keys with missing translations in each locale' do
68
- @keys.untranslated_keys.should == {
69
- :sv => ['articles.new.page_title', 'categories.flash.created', 'empty'],
70
- :no => ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
71
- }
82
+ expect(keys.untranslated_keys).to eq expected
72
83
  end
73
84
  end
74
85
 
75
86
  describe 'missing_keys' do
76
- before(:each) do
77
- @file_path = File.join(@root_dir, 'config', 'locales', 'en.yml')
78
- yaml = RailsI18nterface::Yamlfile.new(@root_dir, :en)
87
+ let(:file_path) { File.join(root_dir, 'config', 'locales', 'en.yml') }
88
+ before do
89
+ yaml = RailsI18nterface::Yamlfile.new(root_dir, :en)
79
90
  yaml.write({
80
- :en => {
81
- :home => {
82
- :page_title => false,
83
- :intro => {
84
- :one => 'intro one',
85
- :other => 'intro other'
91
+ en: {
92
+ home: {
93
+ page_title: false,
94
+ intro: {
95
+ one: 'intro one',
96
+ other: 'intro other'
86
97
  }
87
98
  }
88
99
  }
89
100
  })
101
+ allow(keys).to receive(:files).and_return({
102
+ :'home.page_title' => 'app/views/home/index.rhtml',
103
+ :'home.intro' => 'app/views/home/index.rhtml',
104
+ :'home.signup' => 'app/views/home/_signup.rhtml',
105
+ :'about.index.page_title' => 'app/views/about/index.rhtml'
106
+ })
90
107
  end
91
108
 
92
109
  after(:each) do
93
- FileUtils.rm(@file_path) if File.exists? @file_path
110
+ FileUtils.rm(file_path) if File.exists? file_path
94
111
  end
95
112
 
96
113
  it 'should return a hash with keys that are not in the locale file' do
97
- @keys.stub!(:files).and_return({
98
- :'home.page_title' => 'app/views/home/index.rhtml',
99
- :'home.intro' => 'app/views/home/index.rhtml',
100
- :'home.signup' => 'app/views/home/_signup.rhtml',
101
- :'about.index.page_title' => 'app/views/about/index.rhtml'
102
- })
103
- @keys.missing_keys.size.should == 24
114
+ expect(keys.missing_keys.sort[0]).to eq "activerecord.attributes.article.active"
104
115
  end
105
116
  end
106
117
 
107
118
 
108
119
  describe 'translated_locales' do
109
- before(:each) do
110
- I18n.stub!(:default_locale).and_return(:en)
111
- I18n.stub!(:available_locales).and_return([:sv, :no, :en, :root])
120
+ before do
121
+ allow(I18n).to receive(:default_locale).and_return(:en)
122
+ allow(I18n).to receive(:available_locales).and_return([:sv, :no, :en, :root])
112
123
  end
113
124
 
114
125
  it 'returns all avaiable except :root and the default' do
115
- RailsI18nterface::Keys.translated_locales.should == [:sv, :no]
126
+ expect(RailsI18nterface::Keys.translated_locales).to eq [:sv, :no]
116
127
  end
117
128
  end
118
129
 
@@ -125,25 +136,25 @@ describe RailsI18nterface::Keys do
125
136
 
126
137
  def translations
127
138
  {
128
- :en => {
129
- :home => {
130
- :about => 'This site is about making money'
139
+ en: {
140
+ home: {
141
+ about: 'This site is about making money'
131
142
  },
132
- :articles => {
133
- :new => {
134
- :page_title => 'New Article'
143
+ articles: {
144
+ new: {
145
+ page_title: 'New Article'
135
146
  }
136
147
  },
137
- :categories => {
138
- :flash => {
139
- :created => 'Category created'
148
+ categories: {
149
+ flash: {
150
+ created: 'Category created'
140
151
  }
141
152
  },
142
- :empty => nil
153
+ empty: nil
143
154
  },
144
- :sv => {
145
- :home => {
146
- :about => false
155
+ sv: {
156
+ home: {
157
+ about: false
147
158
  }
148
159
  }
149
160
  }
@@ -161,14 +172,14 @@ describe RailsI18nterface::Keys do
161
172
 
162
173
  def deep_hash
163
174
  {
164
- :pressrelease => {
165
- :label => {
166
- :one => 'Pressmeddelande',
167
- :other => 'Pressmeddelanden'
175
+ pressrelease: {
176
+ label: {
177
+ one: 'Pressmeddelande',
178
+ other: 'Pressmeddelanden'
168
179
  }
169
180
  },
170
- :article => 'Artikel',
171
- :category => ''
181
+ article: 'Artikel',
182
+ category: ''
172
183
  }
173
184
  end
174
185
 
@@ -4,70 +4,73 @@ 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
7
+ let(:root_dir) { File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__) }
8
+ let(:cache_file) { File.join(root_dir, 'tmp', 'translation_strings') }
12
9
 
13
- it 'grabs field from schema.rb' do
14
- expected = {
15
- 'activerecord.models.article'=>['db/schema.rb'],
16
- 'activerecord.attributes.article.title'=>['db/schema.rb'],
17
- 'activerecord.attributes.article.body'=>['db/schema.rb'],
18
- 'activerecord.attributes.article.created_at'=>['db/schema.rb'],
19
- 'activerecord.attributes.article.updated_at'=>['db/schema.rb'],
20
- 'activerecord.attributes.article.active'=>['db/schema.rb'],
21
- 'activerecord.models.topic'=>['db/schema.rb'],
22
- 'activerecord.attributes.topic.title'=>['db/schema.rb'],
23
- 'activerecord.attributes.topic.created_at'=>['db/schema.rb'],
24
- 'activerecord.attributes.topic.updated_at'=>['db/schema.rb']
25
- }
26
- hash = RailsI18nterface::Sourcefiles.extract_activerecords(@root_dir)
27
- hash.should == expected
28
- end
10
+ after { FileUtils.rm cache_file if File.exists? cache_file}
29
11
 
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 == 24
12
+ describe '.hash' do
13
+ let(:expected) { {
14
+ 'activerecord.models.article' => ['db/schema.rb'],
15
+ 'activerecord.attributes.article.title' => ['db/schema.rb'],
16
+ 'activerecord.attributes.article.body' => ['db/schema.rb'],
17
+ 'activerecord.attributes.article.created_at' => ['db/schema.rb'],
18
+ 'activerecord.attributes.article.updated_at' => ['db/schema.rb'],
19
+ 'activerecord.attributes.article.active' => ['db/schema.rb'],
20
+ 'activerecord.models.topic' => ['db/schema.rb'],
21
+ 'activerecord.attributes.topic.title' => ['db/schema.rb'],
22
+ 'activerecord.attributes.topic.created_at' => ['db/schema.rb'],
23
+ 'activerecord.attributes.topic.updated_at' => ['db/schema.rb']
24
+ } }
25
+ let(:hash) { RailsI18nterface::Sourcefiles.extract_activerecords(root_dir) }
26
+ it 'grabs field from schema.rb' do
27
+ expect(hash).to eq expected
28
+ end
34
29
  end
35
30
 
36
- it 'populates from plural form when a :count is passed as param' do
37
- file = File.join(@root_dir, 'app/models/article.rb')
38
- keys = RailsI18nterface::Sourcefiles.populate_keys(@root_dir, file)
39
- keys[:"article.key3.zero"].should == nil
40
- keys[:"article.key4.zero"].should == ["app/models/article.rb"]
41
- keys[:"article.key4.one"].should == ["app/models/article.rb"]
42
- keys[:"article.key4.other"].should == ["app/models/article.rb"]
31
+ describe '.allfiles' do
32
+ before { @allfiles = RailsI18nterface::Sourcefiles.load_files(root_dir) }
33
+ it 'extracts translatable string from code source' do
34
+ expect(File.exists? cache_file).to be_truthy
35
+ expect(@allfiles['title']).to eq ['app/controllers/application_controller.rb']
36
+ end
43
37
  end
44
38
 
45
- it 'populates from plural form when a :count => is passed as param' do
46
- file = File.join(@root_dir, 'app/models/article.rb')
47
- keys = RailsI18nterface::Sourcefiles.populate_keys(@root_dir, file)
48
- keys[:"article.key6.zero"].should == ["app/models/article.rb"]
49
- keys[:"article.key6.one"].should == ["app/models/article.rb"]
50
- keys[:"article.key6.other"].should == ["app/models/article.rb"]
39
+ describe '.keys' do
40
+ let(:file) { File.join(root_dir, 'app/models/article.rb') }
41
+ let(:keys) { RailsI18nterface::Sourcefiles.populate_keys(root_dir, file) }
42
+ it 'populates from plural form when a :count is passed as param' do
43
+ expect(keys[:'article.key3.zero']).to be_nil
44
+ expect(keys[:'article.key4.zero']).to eq ['app/models/article.rb']
45
+ expect(keys[:'article.key4.one']).to eq ['app/models/article.rb']
46
+ expect(keys[:'article.key4.other']).to eq ['app/models/article.rb']
47
+ end
48
+ it 'populates from plural form when a :count => is passed as param' do
49
+ expect(keys[:'article.key6.zero']).to eq ['app/models/article.rb']
50
+ expect(keys[:'article.key6.one']).to eq ['app/models/article.rb']
51
+ expect(keys[:'article.key6.other']).to eq ['app/models/article.rb']
52
+ end
51
53
  end
52
54
 
53
55
  describe 'refreshing' do
54
- before :each do
55
- RailsI18nterface::Sourcefiles.load_files(@root_dir)
56
- @testfile = File.join(@root_dir,'app','views','test.html.erb')
56
+ let(:testfile) { File.join(root_dir, 'app', 'views', 'test.html.erb') }
57
+
58
+ before do
59
+ RailsI18nterface::Sourcefiles.load_files(root_dir)
60
+ File.open(File.join(root_dir, 'app', 'views', 'test.html.erb'),'w') do |f|
61
+ f.puts "<%= t('something') %>"
62
+ end
63
+ @allfiles = RailsI18nterface::Sourcefiles.refresh(root_dir)
57
64
  end
58
65
 
59
- after :each do
60
- FileUtils.rm @testfile if File.exists? @testfile
61
- FileUtils.rm @cache_file if File.exists? @cache_file
66
+ after do
67
+ FileUtils.rm testfile if File.exists? testfile
68
+ FileUtils.rm cache_file if File.exists? cache_file
62
69
  end
63
70
 
64
71
  it 'refreshes translatable strings cache' do
65
- File.open(File.join(@root_dir,'app','views','test.html.erb'),'w') do |f|
66
- f.puts "<%= t('something') %>"
67
- end
68
- y = RailsI18nterface::Sourcefiles.refresh(@root_dir)
69
- y.size.should == 25
72
+ expect(@allfiles['something']).to eq ['app/views/test.html.erb']
70
73
  end
71
74
  end
72
75
 
73
- end
76
+ end