weeler 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rspec +1 -1
  4. data/.travis.yml +7 -2
  5. data/CHANGELOG.md +149 -1
  6. data/LICENSE.txt +2 -2
  7. data/README.md +83 -1
  8. data/app/.DS_Store +0 -0
  9. data/app/assets/javascripts/weeler/init.js.coffee +13 -2
  10. data/app/assets/javascripts/weeler/lib/notify.js +18 -0
  11. data/app/assets/javascripts/weeler/lib/sortable.js +9 -0
  12. data/app/assets/stylesheets/weeler/init.css.erb +2 -1
  13. data/app/assets/stylesheets/weeler/style.css.scss +22 -0
  14. data/app/controllers/concerns/weeler/section_seo.rb +16 -0
  15. data/app/controllers/weeler/administration_controller.rb +11 -0
  16. data/app/controllers/weeler/application_controller.rb +5 -0
  17. data/app/controllers/weeler/base_controller.rb +16 -12
  18. data/app/controllers/weeler/configuration_controller.rb +9 -0
  19. data/app/controllers/weeler/content_controller.rb +12 -0
  20. data/app/controllers/weeler/home_controller.rb +5 -2
  21. data/app/controllers/weeler/seo_items_controller.rb +24 -0
  22. data/app/controllers/weeler/settings_controller.rb +21 -0
  23. data/app/controllers/weeler/static_sections_controller.rb +19 -0
  24. data/app/controllers/weeler/translations_controller.rb +36 -18
  25. data/app/models/concerns/weeler/seoable.rb +61 -0
  26. data/app/models/concerns/weeler/sluger.rb +32 -0
  27. data/app/models/settings.rb +2 -0
  28. data/app/models/weeler/seo.rb +9 -0
  29. data/app/views/kaminari/{_first_page.html.erb → weeler/_first_page.html.erb} +1 -1
  30. data/app/views/kaminari/{_gap.html.erb → weeler/_gap.html.erb} +1 -1
  31. data/app/views/kaminari/{_last_page.html.erb → weeler/_last_page.html.erb} +1 -1
  32. data/app/views/kaminari/{_next_page.html.erb → weeler/_next_page.html.erb} +1 -1
  33. data/app/views/kaminari/{_page.html.erb → weeler/_page.html.erb} +0 -0
  34. data/app/views/kaminari/{_paginator.html.erb → weeler/_paginator.html.erb} +1 -1
  35. data/app/views/kaminari/{_prev_page.html.erb → weeler/_prev_page.html.erb} +1 -1
  36. data/app/views/layouts/weeler/base.html.haml +22 -0
  37. data/{lib/generators/weeler/templates/views/weeler/example/index.html.erb → app/views/weeler/administration/_filter.html.haml} +0 -0
  38. data/app/views/weeler/administration/_header_row.html.haml +5 -0
  39. data/app/views/weeler/administration/_row.html.haml +5 -0
  40. data/app/views/weeler/administration/_side_navbar.html.haml +8 -0
  41. data/app/views/weeler/administration/index.html.haml +17 -0
  42. data/app/views/weeler/administration/welcome.html.haml +5 -0
  43. data/app/views/weeler/base/_flash.html.haml +3 -0
  44. data/app/views/weeler/base/_footer.html.haml +2 -0
  45. data/app/views/weeler/base/_header_navbar.html.haml +19 -0
  46. data/app/views/weeler/base/_side_navbar.html.haml +2 -0
  47. data/app/views/weeler/configuration/_side_navbar.html.haml +12 -0
  48. data/app/views/weeler/configuration/index.html.haml +3 -0
  49. data/app/views/weeler/content/_error_messages.html.haml +5 -0
  50. data/app/views/weeler/content/_form.html.haml +6 -0
  51. data/app/views/weeler/content/_list.html.haml +23 -0
  52. data/app/views/weeler/content/_object_seo.html.haml +31 -0
  53. data/app/views/weeler/content/_side_navbar.html.haml +17 -0
  54. data/app/views/weeler/content/_sortable_list.html.haml +24 -0
  55. data/app/views/weeler/content/edit.html.haml +2 -0
  56. data/app/views/weeler/content/index.html.haml +10 -0
  57. data/app/views/weeler/content/new.html.haml +2 -0
  58. data/app/views/weeler/content/welcome.html.haml +3 -0
  59. data/app/views/weeler/home/_side_navbar.html.haml +8 -0
  60. data/app/views/weeler/home/about.html.haml +15 -0
  61. data/app/views/weeler/home/index.html.haml +3 -0
  62. data/app/views/weeler/seo_items/edit.html.haml +28 -0
  63. data/app/views/weeler/seo_items/index.html.haml +15 -0
  64. data/app/views/weeler/settings/index.html.haml +19 -0
  65. data/app/views/weeler/static_sections/show.html.haml +26 -0
  66. data/app/views/weeler/translations/_form.html.haml +27 -0
  67. data/app/views/weeler/translations/_translation.html.haml +11 -0
  68. data/app/views/weeler/translations/edit.html.haml +14 -0
  69. data/app/views/weeler/translations/index.html.haml +76 -0
  70. data/app/views/weeler/translations/new.html.haml +13 -0
  71. data/lib/.DS_Store +0 -0
  72. data/lib/generators/weeler/.DS_Store +0 -0
  73. data/lib/generators/weeler/install_generator.rb +30 -26
  74. data/lib/generators/weeler/templates/assets/javascripts/weeler/app/index.js +2 -0
  75. data/lib/generators/weeler/templates/assets/stylesheets/weeler/app/index.css +4 -0
  76. data/lib/generators/weeler/templates/controllers/weeler/application_controller.rb +6 -0
  77. data/lib/generators/weeler/templates/initializers/weeler.rb +30 -2
  78. data/lib/generators/weeler/templates/migrations/create_weeler_seos.rb +14 -0
  79. data/lib/generators/weeler/templates/migrations/create_weeler_settings.rb +17 -0
  80. data/lib/generators/weeler/templates/migrations/translate_weeler_seos.rb +15 -0
  81. data/lib/generators/weeler/templates/views/weeler/.keep +0 -0
  82. data/lib/i18n/backend/weeler.rb +102 -22
  83. data/lib/i18n/backend/weeler/dedupe.rb +31 -0
  84. data/lib/i18n/backend/weeler/exporter.rb +67 -5
  85. data/lib/i18n/backend/weeler/html_checker.rb +41 -0
  86. data/lib/i18n/backend/weeler/importer.rb +30 -13
  87. data/lib/i18n/backend/weeler/translation.rb +12 -7
  88. data/lib/i18n/humanize_missing_translations.rb +1 -0
  89. data/lib/i18n/weeler.rb +8 -2
  90. data/lib/tasks/weeler.rake +8 -0
  91. data/lib/weeler.rb +80 -7
  92. data/lib/weeler/.DS_Store +0 -0
  93. data/lib/weeler/action_controller/acts/restful.rb +185 -0
  94. data/lib/weeler/action_dispatch/routing/mapper.rb +87 -0
  95. data/lib/weeler/action_view/helpers/form_helper.rb +13 -0
  96. data/lib/weeler/action_view/helpers/image_form_helper.rb +84 -0
  97. data/lib/weeler/action_view/helpers/translation_helper.rb +15 -0
  98. data/lib/weeler/deprecator.rb +9 -0
  99. data/lib/weeler/engine.rb +18 -4
  100. data/lib/weeler/version.rb +7 -1
  101. data/rspec.html +426 -147
  102. data/spec/.DS_Store +0 -0
  103. data/spec/controllers/translations_controller_spec.rb +76 -5
  104. data/spec/dummy/app/controllers/weeler/posts_controller.rb +3 -7
  105. data/spec/dummy/app/models/post.rb +17 -0
  106. data/spec/dummy/app/models/translation.rb +2 -0
  107. data/spec/dummy/config/locales/en.yml +4 -1
  108. data/spec/dummy/config/routes.rb +3 -3
  109. data/spec/dummy/db/development.sqlite3 +0 -0
  110. data/spec/dummy/db/migrate/20140123083704_create_weeler_seos.rb +14 -0
  111. data/spec/dummy/db/migrate/20140123083705_create_weeler_settings.rb +17 -0
  112. data/spec/dummy/db/migrate/{20131015144900_create_weeler_translations.rb → 20140123083706_create_weeler_translations.rb} +0 -0
  113. data/spec/dummy/db/migrate/20140123083707_translate_weeler_seos.rb +15 -0
  114. data/spec/dummy/db/migrate/20140718103237_create_posts.rb +12 -0
  115. data/spec/dummy/db/migrate/20140726151210_create_translations.rb +12 -0
  116. data/spec/dummy/db/schema.rb +59 -1
  117. data/spec/dummy/db/test.sqlite3 +0 -0
  118. data/spec/dummy/log/development.log +221 -0
  119. data/spec/factories/dummy_posts.rb +6 -0
  120. data/spec/fixtures/.DS_Store +0 -0
  121. data/spec/routing/routes_spec.rb +4 -4
  122. data/spec/spec_helper.rb +14 -3
  123. data/spec/weeler/action_controller/acts/restful_spec.rb +155 -0
  124. data/spec/weeler/action_view/helpers/form_helper_spec.rb +26 -0
  125. data/spec/weeler/action_view/helpers/translation_helper_spec.rb +16 -0
  126. data/spec/weeler/i18n/backend/weeler/dedupe_spec.rb +21 -0
  127. data/spec/weeler/i18n/backend/weeler/exporter_spec.rb +2 -4
  128. data/spec/weeler/i18n/backend/weeler/importer_spec.rb +5 -2
  129. data/spec/weeler/i18n/backend/weeler_spec.rb +121 -23
  130. data/weeler.gemspec +15 -7
  131. metadata +207 -85
  132. data/.DS_Store +0 -0
  133. data/app/assets/stylesheets/weeler/vendor/bootstrap.css +0 -6086
  134. data/app/views/layouts/weeler/base.html.erb +0 -40
  135. data/app/views/weeler/home/about.html.erb +0 -16
  136. data/app/views/weeler/home/index.html.erb +0 -4
  137. data/app/views/weeler/shared/_flash.html.erb +0 -17
  138. data/app/views/weeler/shared/_footer.html.erb +0 -3
  139. data/app/views/weeler/shared/_header_navbar.html.erb +0 -18
  140. data/app/views/weeler/shared/_side_navbar.html.erb +0 -14
  141. data/app/views/weeler/translations/_form.html.erb +0 -43
  142. data/app/views/weeler/translations/_translation.html.erb +0 -11
  143. data/app/views/weeler/translations/edit.html.erb +0 -19
  144. data/app/views/weeler/translations/index.html.erb +0 -103
  145. data/app/views/weeler/translations/new.html.erb +0 -19
  146. data/lib/generators/weeler/templates/controllers/weeler/example_controller.rb.example +0 -7
  147. data/lib/i18n/backend/weeler/exporter/active_record.rb +0 -37
  148. data/lib/i18n/backend/weeler/exporter/active_record_relation.rb +0 -38
  149. data/lib/i18n/backend/weeler/store_procs.rb +0 -39
  150. data/lib/weeler/route_mapper.rb +0 -41
  151. data/spec/dummy/db/production.sqlite3 +0 -0
  152. data/spec/dummy/log/test.log +0 -88454
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :dummy_post, class: Post do
3
+ title "Foo bar"
4
+ body "Foo baar bazaar"
5
+ end
6
+ end
Binary file
@@ -28,14 +28,14 @@ describe Weeler::Engine.routes do
28
28
  before do
29
29
  routes.draw do
30
30
  mount_weeler_at '/admin' do
31
- weeler_resources :mini_posts, include_in_weeler_menu: true
31
+ weeler_resources :mini_posts, include_in_weeler_menu: true
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
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)
37
+ expect(Weeler.content_menu_items.size).to eq(1)
38
+ expect(Weeler.content_menu_items[0][:name]).to eq("Mini_posts")
39
39
  end
40
40
  end
41
41
 
@@ -137,4 +137,4 @@ describe Weeler::Engine.routes do
137
137
  end
138
138
  end
139
139
  end
140
- end
140
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,12 @@
1
+ require 'simplecov'
1
2
  require 'coveralls'
2
- Coveralls.wear!
3
+
4
+ # SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
5
+
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ minimum_coverage(90)
9
+ end
3
10
 
4
11
  ENV['RAILS_ENV'] ||= 'test'
5
12
 
@@ -24,12 +31,12 @@ RSpec.configure do |config|
24
31
  config.infer_base_class_for_anonymous_controllers = false
25
32
  config.order = "random"
26
33
 
27
- config.color_enabled = true
34
+ # config.color_enabled = true
28
35
 
29
36
  config.add_formatter(:progress)
30
37
  config.add_formatter(:html, 'rspec.html')
31
38
 
32
- # config.include Rails.application.routes.url_helpers
39
+ config.include Rails.application.routes.url_helpers
33
40
 
34
41
  # FactoryGirl
35
42
  config.include FactoryGirl::Syntax::Methods
@@ -44,6 +51,10 @@ RSpec.configure do |config|
44
51
  DatabaseCleaner.start
45
52
  end
46
53
 
54
+ config.before(:all) do
55
+ I18n.available_locales = [:en, :lv]
56
+ end
57
+
47
58
  config.after do
48
59
  # Timecop.return
49
60
  DatabaseCleaner.clean
@@ -0,0 +1,155 @@
1
+ require 'spec_helper'
2
+
3
+ describe Weeler::ActionController::Acts::Restful, :type => :controller do
4
+
5
+ before(:each) do
6
+ FactoryGirl.create_list(:dummy_post, 2)
7
+ end
8
+
9
+ before(:all) do
10
+ Dummy::Application.reload_routes!
11
+ end
12
+
13
+ describe "acts_as_restful", :type => :controller do
14
+
15
+ context "permited title with array" do
16
+ controller(Weeler::ContentController) do
17
+ acts_as_restful Post, permit_params: [:title]
18
+ end
19
+
20
+ describe "model" do
21
+ it "returns current controller model" do
22
+ expect(controller.model).to eq(Post)
23
+ end
24
+ end
25
+
26
+ describe "actions" do
27
+ describe "GET #index" do
28
+ it "returns success" do
29
+ get "index"
30
+ response.should be_success
31
+ end
32
+
33
+ it "assigns posts" do
34
+ get "index"
35
+ expect(assigns(:items).size).to eq(2)
36
+ end
37
+ end
38
+
39
+ describe "POST #create" do
40
+ it "redirects to edit path" do
41
+ post "create", post: attributes_for(:dummy_post)
42
+ post = Post.last
43
+ expect(response).to redirect_to("http://test.host/anonymous/#{post.id}/edit")
44
+ end
45
+
46
+ it "sets only permited params" do
47
+ post "create", post: attributes_for(:dummy_post, body: "Heila")
48
+ post = Post.last
49
+ expect(post.title).to eq("Foo bar")
50
+ expect(post.body).to eq(nil)
51
+ end
52
+ end
53
+
54
+ describe "GET #edit" do
55
+ it "returns success status" do
56
+ get "edit", id: Post.last.id
57
+ response.should be_success
58
+ end
59
+ end
60
+
61
+ describe "GET #new" do
62
+ it "returns success status" do
63
+ get "new"
64
+ response.should be_success
65
+ end
66
+ end
67
+
68
+ describe "PUT #update" do
69
+ it "sets only permited params" do
70
+ post = Post.last
71
+ put "update", id: post.id, post: {title: "Shivauva", body: "Another world!"}
72
+ post.reload
73
+ expect(post.title).to eq("Shivauva")
74
+ expect(post.body).to eq("Foo baar bazaar")
75
+ end
76
+ end
77
+
78
+ describe "DELETE #destroy" do
79
+ it "destroys item" do
80
+ post = Post.last
81
+ delete "destroy", id: post.id
82
+ expect { post.reload }.to raise_error(ActiveRecord::RecordNotFound)
83
+ end
84
+ end
85
+
86
+ specify "POST #order" do
87
+ routes.draw { post "order" => "anonymous#order" }
88
+
89
+ post "order", orders: "order[]=2&order[]=1"
90
+ post1 = Post.order(sequence: :asc).first
91
+ post2 = Post.order(sequence: :asc).last
92
+ expect(post1.sequence).to eq(0)
93
+ expect(post2.sequence).to eq(1)
94
+ expect(response.body).to eq("all ok")
95
+ end
96
+ end
97
+ end
98
+
99
+ context "no permited params" do
100
+ controller(Weeler::ContentController) do
101
+ acts_as_restful Post
102
+ end
103
+
104
+ describe "actions" do
105
+ describe "POST #create" do
106
+ it "sets only permited params" do
107
+ post "create", post: attributes_for(:dummy_post, title: "Foo lala", body: "Heila")
108
+ post = Post.last
109
+ expect(post.title).to eq(nil)
110
+ expect(post.body).to eq(nil)
111
+ end
112
+
113
+ it "warns developer" do
114
+ controller.should_receive(:warn).with("[UNPERMITED PARAMS] To permiting {\"title\"=>\"Foo lala\", \"body\"=>\"Heila\"} params, add 'permit_params: [:title, :body]' option to 'acts_as_restful'")
115
+ post "create", post: attributes_for(:dummy_post, title: "Foo lala", body: "Heila")
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ context "permited all with block" do
122
+ controller(Weeler::ContentController) do
123
+ acts_as_restful Post, permit_params: -> (params) { params.require(:post).permit! }
124
+ end
125
+
126
+ describe "actions" do
127
+ describe "POST #create" do
128
+ it "sets only permited params" do
129
+ post "create", post: attributes_for(:dummy_post, title: "Foo lala", body: "Heila")
130
+ post = Post.last
131
+ expect(post.title).to eq("Foo lala")
132
+ expect(post.body).to eq("Heila")
133
+ end
134
+ end
135
+ end
136
+
137
+ end
138
+
139
+ context "permited all with block" do
140
+ controller(Weeler::ContentController) do
141
+ acts_as_restful Post, order_by: {id: :desc}, permit_params: [:title]
142
+ end
143
+
144
+ describe "GET #index" do
145
+ it "users order by for ordering" do
146
+ get "index"
147
+ expect(assigns(:items).first.id).to eq(2)
148
+ expect(assigns(:items).last.id).to eq(1)
149
+ end
150
+ end
151
+ end
152
+
153
+
154
+ end
155
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Weeler::ActionView::Helpers::FormHelper, :type => :helper do
4
+
5
+ let(:resource) { FactoryGirl.build :dummy_post }
6
+ let(:helper) { ActionView::Helpers::FormBuilder.new(:post, resource, self, {})}
7
+
8
+ describe :image_upload_field do
9
+ let(:output) {
10
+ helper.image_upload_field :image
11
+ }
12
+
13
+ it 'create file field' do
14
+ expect(output).to include '<input class="form-control" id="post_image" name="post[image]" type="file" />'
15
+ end
16
+
17
+ it 'creates a label' do
18
+ expect(output).to include '<label'
19
+ end
20
+
21
+ it "creates img preview tag" do
22
+ expect(output).to include '<img alt="Original" src="/images/original.jpg" style="height: 80px;" />'
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Weeler::ActionView::Helpers::TranslationHelper, :type => :helper do
4
+
5
+ describe :translate do
6
+
7
+ let(:output) {
8
+ helper.translate "not.existing.key"
9
+ }
10
+
11
+ it 'dont renders key' do
12
+ expect(output).to eq('<span class="translation_missing" title="translation missing: en.not.existing.key">Key</span>')
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe I18n::Backend::Weeler::Dedupe do
4
+
5
+ describe "#dedupe" do
6
+
7
+ context "empty db" do
8
+ before(:each) do
9
+ 3.times { I18n::Backend::Weeler::Translation.create(locale: :en, key: "weeler.dublicate") }
10
+ I18n::Backend::Weeler::Translation.dedupe
11
+ end
12
+
13
+ it "translation stores all translation in each locale" do
14
+ expect(I18n::Backend::Weeler::Translation.locale(:en).where(key: "weeler.dublicate").size).to eq(1)
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -44,10 +44,8 @@ describe I18n::Backend::Weeler::Exporter do
44
44
  I18n.backend.store_translations(:en, foo: {two: nil })
45
45
  I18n.backend.store_translations(:lv, foo: {two: "some"})
46
46
 
47
- translations = I18n::Backend::Weeler::Translation.where(key: "foo.one").load
48
- translations.size
47
+ translations = I18n::Backend::Weeler::Translation.where(key: "foo.one")
49
48
  @other_rows = translations.as_xlsx_package.workbook.worksheets[0].rows
50
-
51
49
  end
52
50
 
53
51
  it "should have 2 rows" do
@@ -69,4 +67,4 @@ describe I18n::Backend::Weeler::Exporter do
69
67
 
70
68
  end
71
69
 
72
- end
70
+ end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe I18n::Backend::Weeler::Importer do
4
4
 
5
5
  # This is file with 10 translations and 3 locales.
6
- let(:file_path) {File.dirname(__FILE__) + '/../../../../fixtures/test.xlsx'}
6
+ let(:file_path) { Rack::Test::UploadedFile.new(File.dirname(__FILE__) + '/../../../../fixtures/test.xlsx') }
7
7
 
8
8
  describe :import do
9
9
 
@@ -31,12 +31,15 @@ describe I18n::Backend::Weeler::Importer do
31
31
  context "full db" do
32
32
  before(:each) do
33
33
  I18n::Backend::Weeler::Translation.delete_all
34
+ I18n.backend.backends[0].reload_cache
34
35
  I18n.backend.store_translations(:en, welcome: {title: 'fooo'})
35
36
  end
36
37
 
37
38
  it "file import overrides value" do
38
39
  expect(I18n.t(:"welcome.title", :locale => :en)).to eq("fooo")
39
40
  I18n::Backend::Weeler::Translation.import file_path
41
+ Settings.i18n_updated_at = Time.now
42
+
40
43
  expect(I18n.t(:"welcome.title", :locale => :en)).to eq("EN welcome")
41
44
  end
42
45
 
@@ -44,4 +47,4 @@ describe I18n::Backend::Weeler::Importer do
44
47
 
45
48
  end
46
49
 
47
- end
50
+ end
@@ -13,17 +13,38 @@ describe I18n::Backend::Weeler do
13
13
 
14
14
  end
15
15
 
16
- describe "#store_translations" do
16
+ before do
17
+ # isolate each test cases
18
+ Weeler.i18n_cache.clear
19
+ end
17
20
 
18
- it "finds one locale" do
19
- expect(I18n.backend.available_locales.count).to be(1)
21
+ describe "#reload_cache" do
22
+ it "clears translations cache" do
23
+ Weeler.i18n_cache.should_receive(:clear)
24
+ I18n.backend.backends[0].reload_cache
20
25
  end
21
26
 
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
+ it "writes last translations update timestamp to cache" do
28
+ Settings.i18n_updated_at = Time.now
29
+ I18n.backend.backends[0].reload_cache
30
+ expect(Weeler.i18n_cache.read('UPDATED_AT')).to eq(Settings.i18n_updated_at)
31
+ end
32
+
33
+ it "loads all translated data to cache" do
34
+ I18n::Backend::Weeler::Translation.create(:key => 'weeler.test.value', :value => "testējam", :locale => :lv)
35
+ I18n::Backend::Weeler::Translation.create(:key => 'weeler.test.value', :value => "testing", :locale => :en)
36
+
37
+ I18n.backend.backends[0].reload_cache
38
+
39
+ expect(Weeler.i18n_cache.read(["lv", "weeler.test.value"]).value).to eq("testējam")
40
+ expect(Weeler.i18n_cache.read(["en", "weeler.test.value"]).value).to eq("testing")
41
+ end
42
+ end
43
+
44
+ describe "#available_locales" do
45
+
46
+ it "finds one locale" do
47
+ expect(I18n.available_locales.count).to be(2)
27
48
  end
28
49
 
29
50
  end
@@ -46,11 +67,31 @@ describe I18n::Backend::Weeler do
46
67
 
47
68
  end
48
69
 
49
- describe "#lookup" do
50
- it "show warning" do
51
- I18n::Backend::Weeler::Translation.should_receive(:warn).with("[DEPRECATION] Giving a separator to Translation.lookup is deprecated. You can change the internal separator by overwriting FLATTEN_SEPARATOR.")
52
- I18n::Backend::Weeler::Translation.lookup("foo", "|")
70
+ describe "#html?" do
71
+ before(:all) do
72
+ @html_key_translation = I18n::Backend::Weeler::Translation.create(:key => 'methods.body_html', :value => "Super duper", :locale => :en)
73
+ @html_value_translation = I18n::Backend::Weeler::Translation.create(:key => 'methods.body', :value => "Super <b>duper</b>", :locale => :en)
74
+ @html_fake_value_translation = I18n::Backend::Weeler::Translation.create(:key => 'methods.body_fake', :value => "Super < b", :locale => :en)
75
+ end
76
+
77
+ it "is true if key is html" do
78
+ expect(@html_key_translation.html?).to be(true)
53
79
  end
80
+
81
+ it "is true if value contains html" do
82
+ expect(@html_value_translation.html?).to be(true)
83
+ end
84
+
85
+ it "is false if value not contains html" do
86
+
87
+ expect(@html_fake_value_translation.html?).to be(false)
88
+ end
89
+
90
+ end
91
+
92
+ describe "#lookup" do
93
+
94
+
54
95
  end
55
96
 
56
97
  describe "groups" do
@@ -75,14 +116,17 @@ describe I18n::Backend::Weeler do
75
116
  describe "#store_translations" do
76
117
  it "store_translations does not allow ambiguous keys (1)" do
77
118
  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' })
119
+
120
+ I18n.backend.store_translations(:en, foo: 'foo')
121
+ I18n.backend.store_translations(:en, foo: { bar: 'bar' })
122
+ I18n.backend.store_translations(:en, foo: { baz: 'baz' })
123
+
124
+ I18n.backend.backends[0].reload_cache
81
125
 
82
126
  translations = I18n::Backend::Weeler::Translation.locale(:en).lookup('foo')
83
127
  expect(translations.map(&:value)).to eq(%w(bar baz))
84
128
 
85
- expect(I18n.t(:foo)).to eq({ :bar => 'bar', :baz => 'baz' })
129
+ expect(I18n.t(:foo)).to eq("Foo") # no translation
86
130
  end
87
131
 
88
132
  it "store_translations does not allow ambiguous keys (2)" do
@@ -92,29 +136,81 @@ describe I18n::Backend::Weeler do
92
136
  I18n.backend.store_translations(:en, :foo => 'foo')
93
137
 
94
138
  translations = I18n::Backend::Weeler::Translation.locale(:en).lookup('foo')
95
- expect(translations.map(&:value)).to eq(%w(foo))
139
+ expect(translations.map(&:value)).to eq(%w(foo))
96
140
 
97
- expect(I18n.t(:foo)).to eq('foo')
141
+ expect(I18n.t(:foo)).to eq('foo')
98
142
  end
99
143
 
100
144
  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")
145
+ I18n.backend.store_translations(:en, :"Pagina's" => "Pagina's" )
146
+ expect(I18n.t(:"Pagina's", :locale => :en)).to eq("Pagina's")
103
147
  end
104
148
  end
105
149
 
106
150
  describe "#lookup" do
107
151
 
152
+ it "show warning" do
153
+ I18n::Backend::Weeler::Translation.should_receive(:warn).with("[DEPRECATION] Giving a separator to Translation.lookup is deprecated. You can change the internal separator by overwriting FLATTEN_SEPARATOR.")
154
+ I18n::Backend::Weeler::Translation.lookup("foo", "|")
155
+ end
156
+
157
+ context "cache" do
158
+ context "differs from settings timestamp" do
159
+ before do
160
+ Settings.i18n_updated_at = Time.now
161
+ end
162
+
163
+ it "reloads cache" do
164
+ I18n.backend.backends[0].should_receive(:reload_cache)
165
+ I18n.t("cancel", scope: "admin.content")
166
+ end
167
+ end
168
+
169
+ context "is same as updates timestamp" do
170
+ before do
171
+ Weeler.i18n_cache.write('UPDATED_AT', Settings.i18n_updated_at)
172
+ end
173
+
174
+ it "does not reload cache" do
175
+ I18n.backend.backends[0].should_not_receive(:reload_cache)
176
+ I18n.t("cancel", scope: "admin.content")
177
+ end
178
+ end
179
+ end
180
+
108
181
  it "returns translation" do
109
182
  FactoryGirl.create(:translation)
183
+ I18n.backend.backends[0].reload_cache
110
184
  expect(I18n.t("title")).to eq("This is weeler")
111
185
  end
112
186
 
113
187
  context "missing translations" do
114
188
 
115
- it "persists the key" do
189
+ context "exist in yml" do
190
+
191
+ context "new translation" do
192
+
193
+ it "persist it" do
194
+ I18n.t('hello')
195
+ expect(I18n::Backend::Weeler::Translation.locale(:en).find_by_key('hello').value).to eq(I18n.t('hello'))
196
+ end
197
+
198
+ end
199
+
200
+ context "already stored" do
201
+ before(:all) do
202
+ FactoryGirl.create(:translation, key: "weeler.test.cms_title", locale: "en", value: nil)
203
+ end
204
+
205
+ it "saves the fallback backend value" do
206
+ I18n.t('weeler.test.cms_title')
207
+ expect(I18n::Backend::Weeler::Translation.locale(:en).find_by_key('weeler.test.cms_title').value).to eq("Weeler is cool")
208
+ end
209
+ end
210
+ end
211
+
212
+ it "persists the key" do
116
213
  I18n.t('hello')
117
-
118
214
  expect(I18n::Backend::Weeler::Translation.count).to eq(1)
119
215
  expect(I18n::Backend::Weeler::Translation.locale(:en).find_by_key('hello')).to_not be(nil)
120
216
  end
@@ -146,6 +242,7 @@ describe I18n::Backend::Weeler do
146
242
  it "creates a stub when a custom separator is used" do
147
243
  I18n.t('foo|baz', :separator => '|')
148
244
  I18n::Backend::Weeler::Translation.locale(:en).lookup("foo.baz").first.update_attributes!(:value => 'baz!')
245
+ I18n.backend.backends[0].reload_cache
149
246
  expect(I18n.t('foo|baz', :separator => '|')).to eq('baz!')
150
247
  end
151
248
 
@@ -159,6 +256,7 @@ describe I18n::Backend::Weeler do
159
256
  key = 'foo|baz.zab'
160
257
  I18n.t(key, :separator => '|')
161
258
  I18n::Backend::Weeler::Translation.locale(:en).lookup("foo.baz\001zab").first.update_attributes!(:value => 'baz!')
259
+ I18n.backend.backends[0].reload_cache
162
260
  expect(I18n.t(key, :separator => '|')).to eq('baz!')
163
261
  end
164
262
 
@@ -166,4 +264,4 @@ describe I18n::Backend::Weeler do
166
264
 
167
265
  end
168
266
 
169
- end
267
+ end