phrasing 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile.lock +3 -1
  3. data/app/helpers/inline_helper.rb +1 -1
  4. data/lib/phrasing/version.rb +1 -1
  5. data/spec/dummy/Rakefile +7 -0
  6. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  7. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  8. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  9. data/spec/dummy/app/controllers/site_controller.rb +5 -0
  10. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  11. data/spec/dummy/app/helpers/phrasing_helper.rb +12 -0
  12. data/spec/dummy/app/mailers/.gitkeep +0 -0
  13. data/spec/dummy/app/models/.gitkeep +0 -0
  14. data/spec/dummy/app/views/layouts/application.html.erb +12 -0
  15. data/spec/dummy/app/views/site/index.html.erb +3 -0
  16. data/spec/dummy/config.ru +4 -0
  17. data/spec/dummy/config/application.rb +45 -0
  18. data/spec/dummy/config/boot.rb +10 -0
  19. data/spec/dummy/config/database.yml +25 -0
  20. data/spec/dummy/config/environment.rb +5 -0
  21. data/spec/dummy/config/environments/development.rb +28 -0
  22. data/spec/dummy/config/environments/production.rb +61 -0
  23. data/spec/dummy/config/environments/test.rb +39 -0
  24. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/spec/dummy/config/initializers/inflections.rb +10 -0
  26. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  27. data/spec/dummy/config/initializers/phrasing.rb +8 -0
  28. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  29. data/spec/dummy/config/initializers/session_store.rb +8 -0
  30. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  31. data/spec/dummy/config/locales/en.yml +7 -0
  32. data/spec/dummy/config/routes.rb +3 -0
  33. data/spec/dummy/db/.gitkeep +0 -0
  34. data/spec/dummy/db/development.sqlite3 +0 -0
  35. data/spec/dummy/db/migrate/20131120000855_create_phrasing_phrases.phrasing_rails_engine.rb +11 -0
  36. data/spec/dummy/db/migrate/20131120000856_create_phrasing_phrase_versions.phrasing_rails_engine.rb +10 -0
  37. data/spec/dummy/db/schema.rb +31 -0
  38. data/spec/dummy/db/test.sqlite3 +0 -0
  39. data/spec/dummy/lib/assets/.gitkeep +0 -0
  40. data/spec/dummy/log/.gitkeep +0 -0
  41. data/spec/dummy/log/development.log +26 -0
  42. data/spec/dummy/log/test.log +53313 -0
  43. data/spec/dummy/public/404.html +26 -0
  44. data/spec/dummy/public/422.html +26 -0
  45. data/spec/dummy/public/500.html +26 -0
  46. data/spec/dummy/public/favicon.ico +0 -0
  47. data/spec/dummy/script/rails +6 -0
  48. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  49. data/spec/dummy/tmp/cache/assets/test/sprockets/1524a8ae0986ae8836d789001277cb2a +0 -0
  50. data/spec/dummy/tmp/cache/assets/test/sprockets/2577540db9b91552e445c6f71fe549a5 +0 -0
  51. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  52. data/spec/dummy/tmp/cache/assets/test/sprockets/5e5dccf46135893ba5aa04b2f6dcb9c2 +0 -0
  53. data/spec/dummy/tmp/cache/assets/test/sprockets/61d7673b6096c7fe71678968db1270e8 +0 -0
  54. data/spec/dummy/tmp/cache/assets/test/sprockets/668ce79999306d7c256f7c849c29384a +0 -0
  55. data/spec/dummy/tmp/cache/assets/test/sprockets/7f0eeee40ad7d0ee3deb01c58a3c9604 +0 -0
  56. data/spec/dummy/tmp/cache/assets/test/sprockets/9bb92a90f001d659da46cceb6760405d +0 -0
  57. data/spec/dummy/tmp/cache/assets/test/sprockets/b247b072c0cb3d44ce31c524e74253c9 +0 -0
  58. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  59. data/spec/dummy/tmp/cache/assets/test/sprockets/e1058f33db77649b2d01d1c4e7a32cbc +0 -0
  60. data/spec/dummy/tmp/cache/assets/test/sprockets/e64cfbce519bf7c3f6b387e85dabc7b7 +0 -0
  61. data/spec/factories/phrasing_phrases.rb +12 -0
  62. data/spec/features/dummy_spec.rb +77 -0
  63. data/spec/features/phrasing_spec.rb +314 -0
  64. data/spec/lib/phrasing_spec.rb +50 -0
  65. data/spec/models/phrasing_phrase_spec.rb +50 -0
  66. data/spec/spec_helper.rb +12 -0
  67. metadata +81 -33
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ sequence :string do |n|
3
+ "string%09d" % n
4
+ end
5
+
6
+ factory :phrasing_phrase do
7
+ key { FactoryGirl.generate(:string) }
8
+ value { FactoryGirl.generate(:string) }
9
+ locale I18n.default_locale
10
+ end
11
+ end
12
+
@@ -0,0 +1,77 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ feature "use #t" do
6
+
7
+ it "should see the header phrase" do
8
+ FactoryGirl.create(:phrasing_phrase, key: 'site.index.header', value: 'The Header')
9
+ visit root_path
10
+ page.should have_content 'The Header'
11
+ end
12
+
13
+ it "creates a phrasing_phrase if the yaml has an entry" do
14
+ PhrasingPhrase.find_by_key('site.index.header').should be_nil
15
+ visit root_path
16
+ PhrasingPhrase.find_by_key('site.index.header').should_not be_nil
17
+ end
18
+
19
+ it "creates a phrasing_phrase if the yaml does not have an entry" do
20
+ PhrasingPhrase.find_by_key('site.index.intro').should be_nil
21
+ visit root_path
22
+ PhrasingPhrase.find_by_key('site.index.intro').should_not be_nil
23
+ end
24
+
25
+ it "shows the phrasing_phrase instead of the yaml" do
26
+ FactoryGirl.create(:phrasing_phrase, key: 'site.index.header', value: 'A different header')
27
+ visit root_path
28
+ page.should_not have_content 'The Header'
29
+ page.should have_content 'A different header'
30
+ end
31
+
32
+ it "allows to treat every translation as html safe" do
33
+ FactoryGirl.create(:phrasing_phrase, key: 'site.index.header', value: '<strong>Strong header</strong>')
34
+ visit root_path
35
+ page.should have_content 'Strong header'
36
+ visit root_path
37
+ page.should_not have_content '<strong>Strong header</strong>'
38
+ page.should have_content 'Strong header'
39
+ end
40
+ end
41
+
42
+ feature "locales" do
43
+
44
+ it "displays different text based on users' locale" do
45
+ FactoryGirl.create(:phrasing_phrase, locale: 'en', key: 'site.index.intro', value: 'world')
46
+ FactoryGirl.create(:phrasing_phrase, locale: 'es', key: 'site.index.intro', value: 'mundo')
47
+
48
+ I18n.locale = :en
49
+ visit root_path
50
+ page.should have_content 'world'
51
+ page.should_not have_content 'mundo'
52
+
53
+ I18n.locale = :es
54
+ visit root_path
55
+ page.should have_content 'mundo'
56
+ page.should_not have_content 'world'
57
+
58
+ I18n.locale = :fa
59
+ visit root_path
60
+ page.should_not have_content 'world'
61
+ page.should_not have_content 'mundo'
62
+
63
+ I18n.locale = :en # reset
64
+ end
65
+
66
+ end
67
+
68
+ feature "yaml" do
69
+
70
+ it "on first visit values should be same as keys" do
71
+ visit root_path
72
+ PhrasingPhrase.find_by_key('site.index.intro').value.should == 'site.index.intro'
73
+ PhrasingPhrase.find_by_key('site.index.header').value.should == 'site.index.header'
74
+ PhrasingPhrase.count.should == 2
75
+ end
76
+
77
+ end
@@ -0,0 +1,314 @@
1
+ #encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ feature "phrasing index" do
7
+
8
+ before do
9
+ FactoryGirl.create(:phrasing_phrase, :key => "foo", :value => "bar")
10
+ visit phrasing_phrases_path
11
+ end
12
+
13
+ it "has a nav bar" do
14
+ click_link 'Import / Export'
15
+ click_link 'Help'
16
+ click_link 'Phrases'
17
+ end
18
+
19
+ it " shows phrases" do
20
+ page.should have_content 'foo'
21
+ page.should have_content 'bar'
22
+ end
23
+
24
+ it "allows search by key" do
25
+ fill_in 'search', :with => 'foo'
26
+ click_button 'Search'
27
+ page.should have_content 'foo'
28
+ page.should have_content 'bar'
29
+ end
30
+
31
+ it "allows search by key" do
32
+ fill_in 'search', :with => 'xfoo'
33
+ click_button 'Search'
34
+ page.should_not have_content 'foo'
35
+ page.should_not have_content 'bar'
36
+ end
37
+
38
+ it "allows search by value" do
39
+ fill_in 'search', :with => 'bar'
40
+ click_button 'Search'
41
+ page.should have_content 'foo'
42
+ page.should have_content 'bar'
43
+ end
44
+
45
+ it "allows search by value" do
46
+ fill_in 'search', :with => 'xbar'
47
+ click_button 'Search'
48
+ page.should_not have_content 'foo'
49
+ page.should_not have_content 'bar'
50
+ end
51
+
52
+ it "searches in the middles of strings" do
53
+ FactoryGirl.create(:phrasing_phrase, :key => "site.index.something")
54
+ fill_in 'search', :with => 'index'
55
+ click_button 'Search'
56
+ page.should have_content 'site.index.something'
57
+ end
58
+
59
+ it "can show all" do
60
+ FactoryGirl.create(:phrasing_phrase, :key => "foe", :value => "beer")
61
+ click_button 'Search'
62
+ page.should have_content 'foo'
63
+ page.should have_content 'foe'
64
+ end
65
+
66
+ context "more than one locale" do
67
+
68
+ before do
69
+ PhrasingPhrase.destroy_all
70
+ FactoryGirl.create(:phrasing_phrase, key: "foo", value: "bar1", locale: "en")
71
+ FactoryGirl.create(:phrasing_phrase, key: "foo", value: "bar2", locale: "fa")
72
+ FactoryGirl.create(:phrasing_phrase, key: "foo", value: "bar3", locale: "it")
73
+ end
74
+
75
+ it "nil locale, blank search" do
76
+ # impossible for user to replicate this case
77
+ visit phrasing_phrases_path('search' => '', 'commit' => 'Search')
78
+ page.should have_content 'bar1'
79
+ page.should_not have_content 'bar2'
80
+ page.should_not have_content 'bar3'
81
+ end
82
+
83
+ it "nil locale, present search" do
84
+ # impossible for user to replicate this case
85
+ visit phrasing_phrases_path('search' => 'foo', 'commit' => 'Search')
86
+ page.should have_content 'bar1'
87
+ page.should_not have_content 'bar2'
88
+ page.should_not have_content 'bar3'
89
+ visit phrasing_phrases_path('search' => 'fuu', 'commit' => 'Search')
90
+ page.should_not have_content 'foo'
91
+ end
92
+
93
+ it "blank locale, foo search" do
94
+ # impossible for user to replicate this case
95
+ visit phrasing_phrases_path('locale' => '', 'commit' => 'Search')
96
+ page.should have_content 'foo'
97
+ end
98
+
99
+ it "blank locale, blank search" do
100
+ select '', :from => 'locale'
101
+ click_button 'Search'
102
+ page.should have_content 'bar1'
103
+ page.should have_content 'bar2'
104
+ page.should have_content 'bar3'
105
+ end
106
+
107
+ it "blank locale, present search" do
108
+ select '', :from => 'locale'
109
+ fill_in 'search', :with => 'foo'
110
+ click_button 'Search'
111
+ page.should have_content 'bar1'
112
+ page.should have_content 'bar2'
113
+ page.should have_content 'bar3'
114
+ fill_in 'search', :with => 'fuu'
115
+ click_button 'Search'
116
+ page.should_not have_content 'foo'
117
+ end
118
+
119
+ it "present locale, foo search" do
120
+ # impossible for user to replicate this case
121
+ visit phrasing_phrases_path('locale' => 'en', 'commit' => 'Search')
122
+ page.should have_content 'foo'
123
+ end
124
+
125
+ it "present locale, blank search" do
126
+ select 'en', :from => 'locale'
127
+ click_button 'Search'
128
+ page.should have_content 'bar1'
129
+ page.should_not have_content 'bar2'
130
+ page.should_not have_content 'bar3'
131
+ select 'fa', :from => 'locale'
132
+ click_button 'Search'
133
+ page.should_not have_content 'bar1'
134
+ page.should have_content 'bar2'
135
+ page.should_not have_content 'bar3'
136
+ select 'it', :from => 'locale'
137
+ click_button 'Search'
138
+ page.should_not have_content 'bar1'
139
+ page.should_not have_content 'bar2'
140
+ page.should have_content 'bar3'
141
+ end
142
+
143
+ it "present locale, present search" do
144
+ select 'en', :from => 'locale'
145
+ fill_in 'search', :with => 'foo'
146
+ click_button 'Search'
147
+ page.should have_content 'bar1'
148
+ page.should_not have_content 'bar2'
149
+ page.should_not have_content 'bar3'
150
+ select 'fa', :from => 'locale'
151
+ fill_in 'search', :with => 'foo'
152
+ click_button 'Search'
153
+ page.should_not have_content 'bar1'
154
+ page.should have_content 'bar2'
155
+ page.should_not have_content 'bar3'
156
+ select 'it', :from => 'locale'
157
+ fill_in 'search', :with => 'foo'
158
+ click_button 'Search'
159
+ page.should_not have_content 'bar1'
160
+ page.should_not have_content 'bar2'
161
+ page.should have_content 'bar3'
162
+ select 'en', :from => 'locale'
163
+ fill_in 'search', :with => 'fuu'
164
+ click_button 'Search'
165
+ page.should_not have_content 'foo'
166
+ end
167
+
168
+ end
169
+
170
+ end
171
+
172
+ feature "phrasing edit" do
173
+ before do
174
+ FactoryGirl.create(:phrasing_phrase, :key => "foo", :value => "bar")
175
+ visit phrasing_phrases_path
176
+ end
177
+
178
+ scenario "visit edit form" do
179
+ fill_in 'search', :with => 'foo'
180
+ click_button 'Search'
181
+ click_link 'foo'
182
+ fill_in "phrasing_phrase[value]", :with => 'baz'
183
+ end
184
+ end
185
+
186
+ feature "phrasing update" do
187
+ before do
188
+ FactoryGirl.create(:phrasing_phrase, :key => "foo", :value => "bar")
189
+ visit phrasing_phrases_path
190
+ fill_in 'search', :with => 'foo'
191
+ click_button 'Search'
192
+ click_link 'foo'
193
+ end
194
+
195
+ scenario "update" do
196
+ fill_in "phrasing_phrase[value]", :with => 'baz'
197
+ click_button "Update"
198
+ current_path.should == phrasing_phrases_path
199
+ PhrasingPhrase.find_by_key("foo").value.should == 'baz'
200
+ page.should have_content "foo updated!"
201
+ end
202
+ end
203
+
204
+ feature "downloading and uploading yaml files" do
205
+ before do
206
+ end
207
+
208
+ it "round-trips the YAML" do
209
+ FactoryGirl.create(:phrasing_phrase, :key => "a.foo1", :value => "bar1")
210
+ FactoryGirl.create(:phrasing_phrase, :key => "a.foo2:", :value => "bar2")
211
+ FactoryGirl.create(:phrasing_phrase, :key => "a.b.foo3", :value => "bar3")
212
+ FactoryGirl.create(:phrasing_phrase, :key => "c.foo4", :value => "bar4")
213
+ FactoryGirl.create(:phrasing_phrase, :key => 2, :value => "bar5")
214
+ assert PhrasingPhrase.count == 5
215
+
216
+ visit import_export_phrasing_phrases_path
217
+
218
+ click_link 'Download as YAML'
219
+ PhrasingPhrase.destroy_all
220
+ assert PhrasingPhrase.count == 0
221
+
222
+ yaml = page.source
223
+ file = Tempfile.new 'phrasing'
224
+ file.write yaml
225
+ file.close
226
+
227
+ visit import_export_phrasing_phrases_path
228
+ attach_file "file", file.path
229
+ click_button "Upload"
230
+ file.unlink
231
+
232
+ assert PhrasingPhrase.count == 5
233
+ assert PhrasingPhrase.find_by_key("a.foo1").value == "bar1"
234
+ assert PhrasingPhrase.find_by_key("a.foo2:").value == "bar2"
235
+ assert PhrasingPhrase.find_by_key("a.b.foo3").value == "bar3"
236
+ assert PhrasingPhrase.find_by_key("c.foo4").value == "bar4"
237
+ assert PhrasingPhrase.find_by_key(2).value == "bar5"
238
+ end
239
+
240
+ it "round-trips the yaml with complicated text" do
241
+ value = "“hello world“ üokåa®fgsdf;::fs;kdf"
242
+ FactoryGirl.create(:phrasing_phrase, :key => "a.foo", :value => value)
243
+
244
+ visit import_export_phrasing_phrases_path
245
+ click_link 'Download as YAML'
246
+ PhrasingPhrase.destroy_all
247
+
248
+ yaml = page.source
249
+ file = Tempfile.new 'phrasing'
250
+ file.write yaml
251
+ file.close
252
+
253
+ visit import_export_phrasing_phrases_path
254
+ attach_file "file", file.path
255
+ click_button "Upload"
256
+ file.unlink
257
+ assert PhrasingPhrase.find_by_key("a.foo").value == value
258
+ end
259
+
260
+ it "gives 400 on bad upload" do
261
+ file = Tempfile.new 'phrasing'
262
+ file.write "<<<%%#$W%s"
263
+ file.close
264
+
265
+ visit import_export_phrasing_phrases_path
266
+ attach_file "file", file.path
267
+ click_button "Upload"
268
+ file.unlink
269
+ page.status_code.should == 400
270
+ page.should have_content("There was an error processing your upload!")
271
+ assert PhrasingPhrase.count == 0
272
+ end
273
+
274
+ end
275
+
276
+ feature "locales" do
277
+ before do
278
+ end
279
+
280
+ it "imports yaml containing multiple locales" do
281
+ file = Tempfile.new 'phrasing'
282
+ file.write <<-YAML
283
+ en:
284
+ hello: world
285
+ es:
286
+ hello: mundo
287
+ YAML
288
+ file.close
289
+
290
+ visit import_export_phrasing_phrases_path
291
+ attach_file "file", file.path
292
+ click_button "Upload"
293
+ file.unlink
294
+
295
+ assert PhrasingPhrase.count == 2
296
+ a = PhrasingPhrase.where(locale: 'en').first
297
+ assert a.key == 'hello'
298
+ assert a.value == 'world'
299
+ b = PhrasingPhrase.where(locale: 'es').first
300
+ assert b.key == 'hello'
301
+ assert b.value == 'mundo'
302
+ end
303
+
304
+ it "exports yaml containing multiple locales" do
305
+ FactoryGirl.create(:phrasing_phrase, locale: 'en', key: 'hello', value: 'world')
306
+ FactoryGirl.create(:phrasing_phrase, locale: 'es', key: 'hello', value: 'mundo')
307
+
308
+ visit download_phrasing_phrases_path
309
+ yaml = page.source
310
+ assert yaml =~ /en:\s*hello: world/
311
+ assert yaml =~ /es:\s*hello: mundo/
312
+ end
313
+
314
+ end