weeler 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/README.md +4 -0
  4. data/app/.DS_Store +0 -0
  5. data/app/assets/.DS_Store +0 -0
  6. data/app/assets/javascripts/.DS_Store +0 -0
  7. data/app/assets/javascripts/weeler.js.coffee +8 -0
  8. data/app/assets/javascripts/weeler/.DS_Store +0 -0
  9. data/app/assets/javascripts/weeler/bootstrap-fileupload.js +169 -0
  10. data/app/assets/javascripts/weeler/bootstrap.js +1992 -0
  11. data/app/assets/javascripts/weeler/bootstrap.rowlink.js +71 -0
  12. data/app/assets/javascripts/weeler/bootstrap.switch.js +382 -0
  13. data/app/assets/javascripts/weeler/jquery.pnotify.js +912 -0
  14. data/app/assets/stylesheets/.DS_Store +0 -0
  15. data/app/assets/stylesheets/weeler.css +9 -0
  16. data/app/assets/stylesheets/weeler/.DS_Store +0 -0
  17. data/app/assets/stylesheets/weeler/bootstrap-fileupload.css +132 -0
  18. data/app/assets/stylesheets/weeler/bootstrap.css +6086 -0
  19. data/app/assets/stylesheets/weeler/bootstrap.min.css +9 -0
  20. data/app/assets/stylesheets/weeler/bootstrap.rowlink.css +50 -0
  21. data/app/assets/stylesheets/weeler/bootstrap.spinner.css +43 -0
  22. data/app/assets/stylesheets/weeler/bootstrap.switch.css +408 -0
  23. data/app/assets/stylesheets/weeler/jquery.pnotify.css +84 -0
  24. data/app/assets/stylesheets/weeler/style.css.scss.erb +48 -0
  25. data/app/controllers/weeler/base_controller.rb +16 -0
  26. data/app/controllers/weeler/home_controller.rb +8 -0
  27. data/app/controllers/weeler/translations_controller.rb +151 -0
  28. data/app/views/kaminari/_first_page.html.erb +13 -0
  29. data/app/views/kaminari/_gap.html.erb +8 -0
  30. data/app/views/kaminari/_last_page.html.erb +13 -0
  31. data/app/views/kaminari/_next_page.html.erb +14 -0
  32. data/app/views/kaminari/_page.html.erb +12 -0
  33. data/app/views/kaminari/_paginator.html.erb +23 -0
  34. data/app/views/kaminari/_prev_page.html.erb +13 -0
  35. data/app/views/layouts/weeler/base.html.erb +86 -0
  36. data/app/views/weeler/home/about.html.erb +16 -0
  37. data/app/views/weeler/home/index.html.erb +4 -0
  38. data/app/views/weeler/translations/_form.html.erb +43 -0
  39. data/app/views/weeler/translations/_translation.html.erb +11 -0
  40. data/app/views/weeler/translations/edit.html.erb +19 -0
  41. data/app/views/weeler/translations/index.html.erb +106 -0
  42. data/app/views/weeler/translations/new.html.erb +19 -0
  43. data/config/initializers/weeler_mime_types.rb +1 -0
  44. data/lib/.DS_Store +0 -0
  45. data/lib/generators/weeler/.DS_Store +0 -0
  46. data/lib/generators/weeler/install_generator.rb +73 -0
  47. data/lib/generators/weeler/templates/initializers/weeler.rb +7 -0
  48. data/lib/generators/weeler/templates/migrations/create_weeler_translations.rb +16 -0
  49. data/lib/i18n/.DS_Store +0 -0
  50. data/lib/i18n/backend/.DS_Store +0 -0
  51. data/lib/i18n/backend/weeler.rb +76 -0
  52. data/lib/i18n/backend/weeler/store_procs.rb +39 -0
  53. data/lib/i18n/backend/weeler/translation.rb +118 -0
  54. data/lib/i18n/humanize_missing_translations.rb +11 -0
  55. data/lib/i18n/weeler.rb +6 -0
  56. data/lib/weeler.rb +25 -1
  57. data/lib/weeler/.DS_Store +0 -0
  58. data/lib/weeler/engine.rb +11 -0
  59. data/lib/weeler/route_mapper.rb +41 -0
  60. data/lib/weeler/version.rb +1 -1
  61. data/rspec.html +454 -0
  62. data/spec/.DS_Store +0 -0
  63. data/spec/controllers/translations_controller_spec.rb +41 -0
  64. data/spec/dummy/README.rdoc +28 -0
  65. data/spec/dummy/Rakefile +6 -0
  66. data/spec/dummy/app/assets/images/.keep +0 -0
  67. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  68. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  69. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  70. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  71. data/spec/dummy/app/controllers/weeler/posts_controller.rb +7 -0
  72. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  73. data/spec/dummy/app/mailers/.keep +0 -0
  74. data/spec/dummy/app/models/.keep +0 -0
  75. data/spec/dummy/app/models/concerns/.keep +0 -0
  76. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  77. data/spec/dummy/bin/bundle +3 -0
  78. data/spec/dummy/bin/rails +4 -0
  79. data/spec/dummy/bin/rake +4 -0
  80. data/spec/dummy/config.ru +4 -0
  81. data/spec/dummy/config/application.rb +23 -0
  82. data/spec/dummy/config/boot.rb +5 -0
  83. data/spec/dummy/config/database.yml +25 -0
  84. data/spec/dummy/config/environment.rb +5 -0
  85. data/spec/dummy/config/environments/development.rb +29 -0
  86. data/spec/dummy/config/environments/production.rb +80 -0
  87. data/spec/dummy/config/environments/test.rb +36 -0
  88. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/spec/dummy/config/initializers/inflections.rb +16 -0
  91. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  92. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  93. data/spec/dummy/config/initializers/session_store.rb +3 -0
  94. data/spec/dummy/config/initializers/weeler.rb +2 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/spec/dummy/config/locales/en.yml +23 -0
  97. data/spec/dummy/config/routes.rb +5 -0
  98. data/spec/dummy/db/development.sqlite3 +0 -0
  99. data/spec/dummy/db/migrate/20131015144900_create_weeler_translations.rb +16 -0
  100. data/spec/dummy/db/production.sqlite3 +0 -0
  101. data/spec/dummy/db/schema.rb +29 -0
  102. data/spec/dummy/db/test.sqlite3 +0 -0
  103. data/spec/dummy/lib/assets/.keep +0 -0
  104. data/spec/dummy/log/.keep +0 -0
  105. data/spec/dummy/log/development.log +19 -0
  106. data/spec/dummy/log/production.log +4 -0
  107. data/spec/dummy/log/test.log +38396 -0
  108. data/spec/dummy/public/404.html +58 -0
  109. data/spec/dummy/public/422.html +58 -0
  110. data/spec/dummy/public/500.html +57 -0
  111. data/spec/dummy/public/favicon.ico +0 -0
  112. data/spec/factories/translations.rb +7 -0
  113. data/spec/routing/routes_spec.rb +140 -0
  114. data/spec/spec_helper.rb +54 -0
  115. data/spec/weeler/.DS_Store +0 -0
  116. data/spec/weeler/i18n_backend_weeler_spec.rb +169 -0
  117. data/spec/weeler/i18n_humanize_missing_translations_spec.rb +18 -0
  118. data/weeler.gemspec +14 -0
  119. metadata +354 -3
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :translation, class: I18n::Backend::Weeler::Translation do
3
+ locale "en"
4
+ key "title"
5
+ value "This is weeler"
6
+ end
7
+ end
@@ -0,0 +1,140 @@
1
+ require "spec_helper"
2
+
3
+ describe Weeler::Engine.routes do
4
+
5
+
6
+ after(:all) do
7
+ # reset dummy app routes
8
+ Dummy::Application.reload_routes!
9
+ end
10
+
11
+ describe "#mount Weeler::Engine" do
12
+ before do
13
+ routes.draw do
14
+ mount_weeler_at "/weeler-admin"
15
+ end
16
+ end
17
+
18
+ it "/weeler returns home" do
19
+ expect(get: "/weeler-admin").to route_to(
20
+ "action"=>"index",
21
+ "controller"=>"weeler/home"
22
+ )
23
+ end
24
+
25
+ end
26
+
27
+ describe "#add_menu_item" do
28
+ before do
29
+ routes.draw do
30
+ mount_weeler_at '/admin' do
31
+ weeler_resources :mini_posts, include_in_weeler_menu: true
32
+ end
33
+ end
34
+ end
35
+
36
+ it "adds resource to weeler menu item" do
37
+ expect(Weeler.menu_items.size).to eq(1)
38
+ expect(Weeler.menu_items[0]).to eq(:mini_posts)
39
+ end
40
+ end
41
+
42
+ describe "#weeler_resources" do
43
+ before do
44
+ routes.draw do
45
+ mount_weeler_at '/admin' do
46
+ weeler_resources :posts
47
+ end
48
+ end
49
+ end
50
+
51
+ it "mounts resources index route" do
52
+ expect(get: "/admin/posts/").to route_to(
53
+ "action"=>"index",
54
+ "controller"=>"weeler/posts",
55
+ )
56
+ end
57
+
58
+ it "mounts resource create route" do
59
+ expect(post: "/admin/posts/").to route_to(
60
+ "action"=>"create",
61
+ "controller"=>"weeler/posts",
62
+ )
63
+ end
64
+
65
+ it "mounts resource new route" do
66
+ expect(get: "/admin/posts/new").to route_to(
67
+ "action"=>"new",
68
+ "controller"=>"weeler/posts",
69
+ )
70
+ end
71
+
72
+ it "mounts resource edit route" do
73
+ expect(get: "/admin/posts/1/edit").to route_to(
74
+ "action"=>"edit",
75
+ "controller"=>"weeler/posts",
76
+ "id"=>"1"
77
+ )
78
+ end
79
+
80
+ it "mounts resource show route" do
81
+ expect(get: "/admin/posts/1").to route_to(
82
+ "action"=>"show",
83
+ "controller"=>"weeler/posts",
84
+ "id"=>"1"
85
+ )
86
+ end
87
+
88
+ it "mounts resource update route" do
89
+ expect(put: "/admin/posts/1").to route_to(
90
+ "action"=>"update",
91
+ "controller"=>"weeler/posts",
92
+ "id"=>"1"
93
+ )
94
+ end
95
+
96
+ it "mounts resource destroy route" do
97
+ expect(delete: "/admin/posts/1").to route_to(
98
+ "action"=>"destroy",
99
+ "controller"=>"weeler/posts",
100
+ "id"=>"1"
101
+ )
102
+ end
103
+
104
+ context "when destroy route is skiped within with only: option" do
105
+ before do
106
+ routes.draw do
107
+ mount_weeler_at '/admin' do
108
+ weeler_resources :posts, only: [:index]
109
+ end
110
+ end
111
+ end
112
+
113
+ it "does not mount destroy confirm route" do
114
+ expect(:delete => "/weeler/posts/1/confirm_destroy").not_to be_routable
115
+ end
116
+ end
117
+
118
+ context "when custom block given" do
119
+ before do
120
+ routes.draw do
121
+ mount_weeler_at '/admin' do
122
+ weeler_resources :posts, only: [:index] do
123
+ member do
124
+ get :download
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ it "calls it within resources method" do
132
+ expect(get: "/admin/posts/1/download").to route_to(
133
+ "action"=>"download",
134
+ "controller"=>"weeler/posts",
135
+ "id"=>"1"
136
+ )
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,54 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+
6
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
+ require 'rspec/rails'
8
+ require 'rspec/autorun'
9
+ require 'factory_girl'
10
+ require 'capybara/rspec'
11
+ require 'database_cleaner'
12
+ # require 'capybara-webkit'
13
+ require 'shoulda-matchers'
14
+ # require 'support/helpers'
15
+ # require 'timecop'
16
+
17
+
18
+ Rails.backtrace_cleaner.remove_silencers!
19
+ # Load support files
20
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
21
+
22
+ RSpec.configure do |config|
23
+ config.mock_with :rspec
24
+ config.use_transactional_fixtures = false
25
+ config.infer_base_class_for_anonymous_controllers = false
26
+ config.order = "random"
27
+
28
+ config.color_enabled = true
29
+
30
+ config.add_formatter(:progress)
31
+ config.add_formatter(:html, 'rspec.html')
32
+
33
+ # config.include Rails.application.routes.url_helpers
34
+
35
+ # FactoryGirl
36
+ config.include FactoryGirl::Syntax::Methods
37
+
38
+ Capybara.javascript_driver = :webkit
39
+
40
+ # disable empty translation creation
41
+ Weeler.create_missing_translations = true
42
+
43
+ config.before(:each) do
44
+ DatabaseCleaner.strategy = :truncation
45
+ DatabaseCleaner.start
46
+ end
47
+
48
+ config.after do
49
+ # Timecop.return
50
+ DatabaseCleaner.clean
51
+ end
52
+ end
53
+
54
+ Dir["#{File.dirname(__FILE__)}/factories/*.rb"].each { |f| require f }
Binary file
@@ -0,0 +1,169 @@
1
+ require "spec_helper"
2
+
3
+ describe I18n::Backend::Weeler do
4
+
5
+ describe "#interpolations" do
6
+
7
+ it "can persist" do
8
+ translation = I18n::Backend::Weeler::Translation.new(:key => 'foo', :value => 'bar', :locale => :en)
9
+ translation.interpolations = %w(count name)
10
+ translation.save
11
+ expect(translation.valid?).to be(true)
12
+ end
13
+
14
+ end
15
+
16
+ describe "#store_translations" do
17
+
18
+ it "finds one locale" do
19
+ expect(I18n.backend.available_locales.count).to be(1)
20
+ end
21
+
22
+ it "finds all existing locales if theres is translations in other locale" do
23
+ translation = I18n::Backend::Weeler::Translation.new(:key => 'foo', :value => 'bar', :locale => :lv)
24
+ translation.interpolations = %w(count name)
25
+ translation.save
26
+ expect(I18n.backend.available_locales.count).to be(2)
27
+ end
28
+
29
+ end
30
+
31
+ describe "#value" do
32
+
33
+ it "returns boolean if translation boolean" do
34
+ true_t = I18n::Backend::Weeler::Translation.create(:key => 'valid', :value => true, :locale => :en)
35
+ false_t = I18n::Backend::Weeler::Translation.create(:key => 'invalid', :value => false, :locale => :en)
36
+
37
+ expect(true_t.value).to be(true)
38
+ expect(false_t.value).to be(false)
39
+
40
+ end
41
+
42
+ #it "runs kernel if translation is_proc" do
43
+ # proc = I18n::Backend::Weeler::Translation.create(:key => 'valid', :value => "p 'This ir proc!'", :locale => :en, :is_proc => true)
44
+
45
+ # expect(proc.value).to receive(:warn).with /Message/
46
+ #end
47
+
48
+ end
49
+
50
+ describe "#lookup" do
51
+ #it "show warning" do
52
+ # expect(I18n::Backend::Weeler::Translation.lookup("foo", "|")).to receive(:warn).with /Message/
53
+ #end
54
+ end
55
+
56
+ describe "groups" do
57
+
58
+ before(:all) do
59
+ I18n.backend.store_translations(:en, :group2 => { :test2 => 'bar' } )
60
+ I18n.backend.store_translations(:en, :group1 => { :test => 'bar' })
61
+ I18n.backend.store_translations(:en, :group1 => { :test3 => 'bar' })
62
+ @groups = I18n::Backend::Weeler::Translation.groups
63
+ end
64
+
65
+ it "returns 2 groups" do
66
+ expect(@groups.size).to eq(2)
67
+ end
68
+
69
+ it "returns ordered list" do
70
+ expect(@groups[0]).to eq("group1")
71
+ expect(@groups[1]).to eq("group2")
72
+ end
73
+ end
74
+
75
+ describe "#store_translations" do
76
+ it "store_translations does not allow ambiguous keys (1)" do
77
+ I18n::Backend::Weeler::Translation.delete_all
78
+ I18n.backend.store_translations(:en, :foo => 'foo')
79
+ I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
80
+ I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
81
+
82
+ translations = I18n::Backend::Weeler::Translation.locale(:en).lookup('foo')
83
+ expect(translations.map(&:value)).to eq(%w(bar baz))
84
+
85
+ expect(I18n.t(:foo)).to eq({ :bar => 'bar', :baz => 'baz' })
86
+ end
87
+
88
+ it "store_translations does not allow ambiguous keys (2)" do
89
+ I18n::Backend::Weeler::Translation.delete_all
90
+ I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
91
+ I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
92
+ I18n.backend.store_translations(:en, :foo => 'foo')
93
+
94
+ translations = I18n::Backend::Weeler::Translation.locale(:en).lookup('foo')
95
+ expect(translations.map(&:value)).to eq(%w(foo))
96
+
97
+ expect(I18n.t(:foo)).to eq('foo')
98
+ end
99
+
100
+ it "can store translations with keys that are translations containing special chars" do
101
+ I18n.backend.store_translations(:es, :"Pagina's" => "Pagina's" )
102
+ expect(I18n.t(:"Pagina's", :locale => :es)).to eq("Pagina's")
103
+ end
104
+ end
105
+
106
+ describe "#lookup" do
107
+
108
+ it "returns translation" do
109
+ FactoryGirl.create(:translation)
110
+ expect(I18n.t("title")).to eq("This is weeler")
111
+ end
112
+
113
+ context "missing translations" do
114
+
115
+ it "persists the key" do
116
+ I18n.t('hello')
117
+
118
+ expect(I18n::Backend::Weeler::Translation.count).to eq(1)
119
+ expect(I18n::Backend::Weeler::Translation.locale(:en).find_by_key('hello')).to_not be(nil)
120
+ end
121
+
122
+ it "lookup does not persist the key twice" do
123
+ 2.times { I18n.t('foo.bar.baz') }
124
+ expect(I18n::Backend::Weeler::Translation.count).to eq(1)
125
+ expect(I18n::Backend::Weeler::Translation.locale(:en).find_by_key('foo.bar.baz')).to_not be(nil)
126
+ end
127
+
128
+ it "lookup persists interpolation keys when looked up directly" do
129
+ I18n.t('foo.bar.baz', :cow => "lucy" )
130
+ translation_stub = I18n::Backend::Weeler::Translation.locale(:en).lookup('foo.bar.baz').first
131
+ expect(translation_stub.interpolates?(:cow)).to be(true)
132
+ end
133
+
134
+ it "creates one stub per pluralization" do
135
+ I18n.t('foo', :count => 999)
136
+ translations = I18n::Backend::Weeler::Translation.locale(:en).where key: %w{ foo.zero foo.one foo.other }
137
+ expect(translations.length).to be(3)
138
+ end
139
+
140
+ it "creates no stub for base key in pluralization" do
141
+ I18n.t('foo', :count => 999)
142
+ expect(I18n::Backend::Weeler::Translation.locale(:en).lookup("foo").count).to be(3)
143
+ expect(I18n::Backend::Weeler::Translation.locale(:en).find_by(key: "foo")).to be(nil)
144
+ end
145
+
146
+ it "creates a stub when a custom separator is used" do
147
+ I18n.t('foo|baz', :separator => '|')
148
+ I18n::Backend::Weeler::Translation.locale(:en).lookup("foo.baz").first.update_attributes!(:value => 'baz!')
149
+ expect(I18n.t('foo|baz', :separator => '|')).to eq('baz!')
150
+ end
151
+
152
+ it "creates a stub per pluralization when a custom separator is used" do
153
+ I18n.t('foo|bar', :count => 999, :separator => '|')
154
+ translations = I18n::Backend::Weeler::Translation.locale(:en).where key: %w{ foo.bar.zero foo.bar.one foo.bar.other }
155
+ expect(translations.length).to be(3)
156
+ end
157
+
158
+ it "creates a stub when a custom separator is used and the key contains the flatten separator (a dot character)" do
159
+ key = 'foo|baz.zab'
160
+ I18n.t(key, :separator => '|')
161
+ I18n::Backend::Weeler::Translation.locale(:en).lookup("foo.baz\001zab").first.update_attributes!(:value => 'baz!')
162
+ expect(I18n.t(key, :separator => '|')).to eq('baz!')
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+
169
+ end