awesome_translations 0.0.62 → 0.0.63

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/awesome_translations/caches_controller.rb +1 -1
  3. data/app/controllers/awesome_translations/handlers_controller.rb +3 -7
  4. data/config/locales/en.yml +3 -0
  5. data/lib/awesome_translations/cache_database_generator.rb +11 -9
  6. data/lib/awesome_translations/config.rb +2 -2
  7. data/lib/awesome_translations/engine.rb +1 -1
  8. data/lib/awesome_translations/erb_inspector/file_inspector.rb +1 -1
  9. data/lib/awesome_translations/handlers/validations_handler.rb +1 -1
  10. data/lib/awesome_translations/version.rb +1 -1
  11. metadata +4 -287
  12. data/spec/controllers/groups_controller_spec.rb +0 -83
  13. data/spec/controllers/handlers_controller_spec.rb +0 -51
  14. data/spec/controllers/users_controller_spec.rb +0 -21
  15. data/spec/dummy/README.rdoc +0 -28
  16. data/spec/dummy/Rakefile +0 -6
  17. data/spec/dummy/app/assets/config/manifest.js +0 -3
  18. data/spec/dummy/app/assets/javascripts/application.js +0 -0
  19. data/spec/dummy/app/assets/javascripts/translations.js +0 -3
  20. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  21. data/spec/dummy/app/controllers/application_controller.rb +0 -15
  22. data/spec/dummy/app/controllers/locales_controller.rb +0 -6
  23. data/spec/dummy/app/controllers/users_controller.rb +0 -43
  24. data/spec/dummy/app/helpers/application_helper.rb +0 -7
  25. data/spec/dummy/app/mailers/my_mailer.rb +0 -5
  26. data/spec/dummy/app/models/application_record.rb +0 -3
  27. data/spec/dummy/app/models/role.rb +0 -17
  28. data/spec/dummy/app/models/user.rb +0 -8
  29. data/spec/dummy/app/services/application_service.rb +0 -3
  30. data/spec/dummy/app/services/test_translate_service.rb +0 -9
  31. data/spec/dummy/app/views/layouts/application.html.erb +0 -28
  32. data/spec/dummy/app/views/users/_partial_test.html.erb +0 -1
  33. data/spec/dummy/app/views/users/edit.html.liquid +0 -7
  34. data/spec/dummy/app/views/users/index.html.haml +0 -16
  35. data/spec/dummy/app/views/users/show.html.erb +0 -7
  36. data/spec/dummy/bin/bundle +0 -3
  37. data/spec/dummy/bin/rails +0 -4
  38. data/spec/dummy/bin/rake +0 -4
  39. data/spec/dummy/config/application.rb +0 -35
  40. data/spec/dummy/config/boot.rb +0 -5
  41. data/spec/dummy/config/database.yml +0 -25
  42. data/spec/dummy/config/environment.rb +0 -5
  43. data/spec/dummy/config/environments/development.rb +0 -32
  44. data/spec/dummy/config/environments/production.rb +0 -80
  45. data/spec/dummy/config/environments/test.rb +0 -39
  46. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  47. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  48. data/spec/dummy/config/initializers/inflections.rb +0 -16
  49. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  50. data/spec/dummy/config/initializers/secret_token.rb +0 -13
  51. data/spec/dummy/config/initializers/session_store.rb +0 -3
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  53. data/spec/dummy/config/routes.rb +0 -7
  54. data/spec/dummy/config.ru +0 -4
  55. data/spec/dummy/db/awesome_translations.sqlite3 +0 -0
  56. data/spec/dummy/db/development.sqlite3 +0 -0
  57. data/spec/dummy/db/migrate/20141018081559_create_users.rb +0 -9
  58. data/spec/dummy/db/migrate/20141018081640_create_roles.rb +0 -10
  59. data/spec/dummy/db/migrate/20150607110245_add_price_cents_to_roles.rb +0 -5
  60. data/spec/dummy/db/schema.rb +0 -30
  61. data/spec/dummy/db/test.sqlite3 +0 -0
  62. data/spec/dummy/log/development.log +0 -52
  63. data/spec/dummy/log/test.log +0 -1188
  64. data/spec/dummy/public/404.html +0 -58
  65. data/spec/dummy/public/422.html +0 -58
  66. data/spec/dummy/public/500.html +0 -57
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2m/2mnPY9uUnBNkGHLxtFaWv5hB3oA7sY2K1ZtwQlZLnAY.cache +0 -2
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/3N/3NnKgR2TsTI1qCXKZpts0uJzp2dRJcoYp3nnFU6YE4o.cache +0 -2
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/5r/5rpKlqLSFsRCibev7g6MQkIOhWuOah-1KAN3aqV_fYI.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/6E/6ExTs_VkmUe-fovt99Kw8rq-xCfx0_qGsSoldSWScZI.cache +0 -1
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8O/8OrG8phjC9s5-_7GAI2TEmRjsrGsuvq1gnJQPdMm8v8.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8f/8f4REKYOWkNfHexyAVqGXnbOP3vky_ANapWzlRMDeQ4.cache +0 -3
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8n/8n_viDw_qMQaQmqHM0ObPADed5uRyEYo3gDZIiTqUyA.cache +0 -1
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9e/9euY4B26kaHeiqfd1Qc0bsfRjpzmq36X6uqUfaRNtIs.cache +0 -1
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/AB/AB5PxrhEqi8qOm7AmSf-sHDs9ffj_iTsytaHas2ryPA.cache +0 -1
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/AI/AICJO1oM9dzlQ_N1QlHcCN9e8PC0wjtYk7-VmuNdfwg.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ca/CaGQBiCuFgkHQ5gw8ZnGQqO8iP1md3GcllDsmaKBFdQ.cache +0 -2
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ch/ChWez9UVXMuuBpLJMDRGuDmMuXy8gIuFo6794-wBgXc.cache +0 -1
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/D9/D9eOwgl8pLlC7LJu-LL59UeHm9d-CH1mPgsA8j6xkMg.cache +0 -1
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Do/Do83AoOat5W-c1g7piDGy2GMmffsY6JY0Qfuh5PY3GM.cache +0 -2
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Hn/Hn53895nYKzu-g1FJKYS_yszYqCADXasTmN615R_qMQ.cache +0 -1
  83. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/It/ItV7jxV0bfHndR-H3cidDwpTFGhvs0ETLRqCTmZMXB8.cache +0 -1
  84. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/LL/LL0EenAcTXP-UNCqfcKtMF4Z8oDeWvdlwLQfuOVRPdw.cache +0 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Mj/MjwYGG9GkHD1fwwH2bg66EBYl3zCA_mqeDF9otey4-U.cache +0 -3
  86. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/NU/NUN9oO9gyoo-sY32AOLHdDACjLIxisCxXdKd84ou6cs.cache +0 -2
  87. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ob/ObuKkBd-camcT52YpgeuyheU-GDFLZCJnoVtq2plgW0.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Og/Og_HPfE6734sqkQ0_h4EkOOx3Aoq1LABLH9ovjl6Bvw.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pw/Pwuhz_6So_JcSrxT0Uf4VaLhh_FFSJMKxLZFMbS0LNQ.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/R-/R-nohuDiORrLlJJtKc5bQsjIRS8yTQFVR3EIxJx3JZw.cache +0 -1
  91. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/SX/SXA6qKBlsAQ-MLPi7-KPCPcSx9Gg2VR1xa-lCmgipgA.cache +0 -1
  92. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Sb/Sb1Vug319YfPL2Rci1PLMLXJjeIFYcNbHb5hKOvO1eo.cache +0 -2
  93. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/_f/_f0DjbdXTMEPb52THCCF5qbKkDs28tHHnap5ag4jsdU.cache +0 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dT/dTb1O_9BwFdhA3VT1UTxY-XIIoAGDHGHVO9bzRUNIfc.cache +0 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dV/dVTKOfd8qDIHT3VD-4emnl0yAIxcSF1pY0CUESPHwdM.cache +0 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/i0/i0TQIUsntlYrsibtn9YfB3qbI6bj8hLPom8KUfxR078.cache +0 -1
  97. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jF/jFFXBsyFdv_TiNykX219AHs3Q7dQInYRP_80cAWZsgE.cache +0 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/mX/mXfx3VRudxpXrRx1aejtNA5YHOwND3kwWUfvdXHSors.cache +0 -2
  99. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/nG/nGQXdOLWsP4c926DJJBNXFUE0cKfZynnqN5aQ4T1I48.cache +0 -1
  100. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/oX/oXeqOS7RZb4eFbKrraeQtr6TUrXPTueLN_Crp7S0RLE.cache +0 -1
  101. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/p2/p27Ube4R6tciXRc0F8lpz6wUzmXIPxwqz7dKaUYVVuc.cache +0 -1
  102. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/pv/pv6tV3CDkIAmLXdU8EPLlNEkXAKJPufVD4VP30o4fWo.cache +0 -2
  103. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/q6/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +0 -2
  104. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/r5/r5draRYO72lGMZZKpqYbscAWxAawJVG7uO0uyx3iw24.cache +0 -1
  105. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/r7/r7kGQJTsdrqs3i-prYAVnngsoc6uAtrjLTULTJdgy9g.cache +0 -1
  106. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/rI/rITk_65QtUwq61bjRPAksGeJxbLUFfz-sFPnQiZPHjw.cache +0 -3
  107. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/rR/rRS9OkVGJ9Wvs1fwZH-raqD4sXkbV8WmlLGIibYpZmI.cache +0 -0
  108. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/u9/u9nsXMBU9hA4UnH4SDHgk19ev_JNeeiS1-EZDrgStCI.cache +0 -1
  109. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/un/unZXcRqhGJwHvVWJmJ1rTizBZq6H5jF28E5-FHyTYL4.cache +0 -1
  110. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/wP/wP-1NwhQC0Sp_5PHpwAI7N0_N99vLNy0TA2FcMd6zgE.cache +0 -0
  111. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/x7/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +0 -2
  112. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/xr/xrDdkyCzfXr-pIE8gfvD8iFiWPuq9EwuZIl-uU9s0_o.cache +0 -1
  113. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yc/yc3EXb1cvVLmwnk8aQN89bgVFeuwsVz2k2p0mvC2c3c.cache +0 -1
  114. data/spec/factories/group.rb +0 -8
  115. data/spec/factories/handler.rb +0 -11
  116. data/spec/factories/handler_translation.rb +0 -13
  117. data/spec/factories/translation_key.rb +0 -8
  118. data/spec/factories/translation_value.rb +0 -9
  119. data/spec/factories/user.rb +0 -7
  120. data/spec/features/clean_ups_spec.rb +0 -38
  121. data/spec/features/duplicates_spec.rb +0 -61
  122. data/spec/features/movals_spec.rb +0 -60
  123. data/spec/handlers/file_handler_spec.rb +0 -103
  124. data/spec/handlers/model_handler_spec.rb +0 -40
  125. data/spec/handlers/validations_handler_spec.rb +0 -31
  126. data/spec/handlers_spec.rb +0 -9
  127. data/spec/lib/cache_database_generator_spec.rb +0 -59
  128. data/spec/lib/erb_inspector/file_inspector_spec.rb +0 -46
  129. data/spec/lib/erb_inspector/translation_inspector_spec.rb +0 -33
  130. data/spec/lib/erb_inspector_spec.rb +0 -30
  131. data/spec/lib/model_inspector/attribute_spec.rb +0 -18
  132. data/spec/lib/model_inspector_spec.rb +0 -39
  133. data/spec/lib/object_extensions_spec.rb +0 -7
  134. data/spec/lib/translation_migrator_spec.rb +0 -46
  135. data/spec/models/awesome_translations/handler_spec.rb +0 -8
  136. data/spec/models/awesome_translations/translated_value_spec.rb +0 -41
  137. data/spec/models/awesome_translations/translation_spec.rb +0 -54
  138. data/spec/services/test_translate_service_spec.rb +0 -11
  139. data/spec/spec_helper.rb +0 -76
@@ -1,103 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::FileHandler do
4
- let(:handler) { AwesomeTranslations::Handlers::FileHandler.new }
5
-
6
- describe "erb stuff" do # rubocop:disable RSpec/MultipleMemoizedHelpers
7
- let(:users_index_group) { handler.groups.find { |group| group.name == "app/views/users/index.html.haml" } }
8
- let(:users_index_translations) { users_index_group.translations }
9
- let(:users_partial_test_translations) { handler.groups.find { |group| group.name == "app/views/users/_partial_test.html.erb" }.translations }
10
- let(:layout_group) { handler.groups.find { |group| group.name == "app/views/layouts/application.html.erb" } }
11
- let(:layout_translations) { layout_group.translations }
12
-
13
- it "finds translations made with the t method" do
14
- hello_world_translations = users_index_translations.select { |t| t.key == "users.index.hello_world" }.to_a
15
- expect(hello_world_translations.length).to eq 1
16
- end
17
-
18
- it "finds translations in the layout" do
19
- danish_translations = layout_translations.select { |t| t.key == "layouts.application.danish" }.to_a
20
- expect(danish_translations.length).to eq 1
21
- end
22
-
23
- it "doesnt include _ in partial keys" do
24
- partial_test = users_partial_test_translations.select { |t| t.key == "users.partial_test.partial_test" }.to_a
25
- expect(partial_test.length).to eq 1
26
- end
27
-
28
- it "removes special characters when using the custom method" do
29
- current_language_translation = layout_translations.select { |t| t.key == "layouts.application.the_current_language_is" }.to_a
30
- expect(current_language_translation.length).to eq 1
31
- end
32
-
33
- it "has unique translations" do
34
- expect(layout_translations.select { |t| t.key == "layouts.application.hello_world" }.to_a.length).to eq 1
35
- end
36
-
37
- it "sets the correct translation path" do
38
- danish_translation = layout_translations.find { |t| t.key == "layouts.application.danish" }
39
- expect(danish_translation.dir).to eq Rails.root.join("config/locales/awesome_translations/layouts/application").to_s
40
- end
41
- end
42
-
43
- describe "library stuff" do # rubocop:disable RSpec/MultipleMemoizedHelpers
44
- let(:group) { handler.groups.find { |group| group.name == "app/models/role.rb" } }
45
- let(:mailer_group) { handler.groups.find { |group| group.name == "app/mailers/my_mailer.rb" } }
46
- let(:subject_translation) { mailer_group.translations.find { |translation| translation.key == "my_mailer.mailer_action.custom_subject" } }
47
- let(:admin_translation) { group.translations.find { |translation| translation.key == "models.role.administrator" } }
48
- let(:application_helper_group) { handler.groups.find { |group| group.name == "app/helpers/application_helper.rb" } }
49
- let(:hello_world_translation) { application_helper_group.translations.find { |translation| translation.key == "helpers.application_helper.hello_world" } }
50
- let(:users_controller_handler) { handler.groups.find { |group| group.name == "app/controllers/users_controller.rb" } }
51
- let(:update_saved_translation) { users_controller_handler.translations.find { |translation| translation.key == "users.user_was_updated" } }
52
-
53
- it "finds translations made with the t method" do
54
- expect(admin_translation).not_to eq nil
55
- expect(admin_translation.key).to eq "models.role.administrator"
56
- expect(admin_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/models/role"
57
- end
58
-
59
- it "generates keys with method-name for mailers" do
60
- expect(subject_translation.key).to eq "my_mailer.mailer_action.custom_subject"
61
- end
62
-
63
- it "finds translations in arrays" do
64
- moderator_translation = group.translations.find { |translation| translation.key == "models.role.moderator" }
65
- user_translation = group.translations.find { |translation| translation.key == "models.role.user" }
66
-
67
- expect(moderator_translation).not_to eq nil
68
- expect(user_translation).not_to eq nil
69
- end
70
-
71
- it "finds helpers translations using helper_t" do
72
- expect(hello_world_translation.key).to eq "helpers.application_helper.hello_world"
73
- end
74
-
75
- it "finds translations with the controller_t-method" do
76
- expect(update_saved_translation).not_to eq nil
77
- expect(update_saved_translation.key).to eq "users.user_was_updated"
78
- expect(update_saved_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/users"
79
- end
80
- end
81
-
82
- describe "global stuff" do
83
- let(:group) { handler.groups.find { |group| group.name == "app/views/users/show.html.erb" } }
84
- let(:translations) { group.translations.to_a }
85
- let(:yes_translation) { translations.find { |translation| translation.key == "yes" } }
86
-
87
- it "finds the right translations" do
88
- expect(translations.length).to eq 4
89
- end
90
-
91
- it "reads the keys right" do
92
- expect(yes_translation.key).to eq "yes"
93
- end
94
-
95
- it "sets the correct translation path" do
96
- expect(yes_translation.dir).to eq Rails.root.join("config/locales/awesome_translations").to_s
97
- end
98
-
99
- it "detects absolute existing direct translations" do
100
- expect(translations.map(&:key)).to include "activerecord.attributes.users.email"
101
- end
102
- end
103
- end
@@ -1,40 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::ModelHandler do # rubocop:disable RSpec/MultipleMemoizedHelpers
4
- let(:model_handler) { AwesomeTranslations::Handlers::ModelHandler.new }
5
- let(:groups) { model_handler.groups.to_a }
6
- let(:user_group) { model_handler.groups.detect { |group| group.name == "User" } }
7
- let(:role_group) { model_handler.groups.detect { |group| group.name == "Role" } }
8
- let(:translation_keys) { user_group.translations.map(&:key).to_a }
9
- let(:role_translation_keys) { role_group.translations.map(&:key).to_a }
10
-
11
- it "#groups" do
12
- expect(groups.length).to eq 5
13
- end
14
-
15
- describe "#translations_for_group" do # rubocop:disable RSpec/MultipleMemoizedHelpers
16
- it "finds the right number of translations" do
17
- expect(user_group.translations.to_a.length).to eq 7
18
- end
19
-
20
- it "finds the model translations" do
21
- expect(translation_keys).to include "activerecord.models.user.other"
22
- end
23
-
24
- it "finds the attribute translations" do
25
- expect(translation_keys).to include "activerecord.attributes.user.age"
26
- end
27
-
28
- it "finds the has_many association translations" do
29
- expect(translation_keys).to include "activerecord.attributes.user.roles"
30
- end
31
-
32
- it "finds money-rails translations" do
33
- expect(role_translation_keys).to include "activerecord.attributes.role.price"
34
- end
35
- end
36
-
37
- it "finds globalize translations" do
38
- expect(role_translation_keys).to include "activerecord.attributes.role.name"
39
- end
40
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::ValidationsHandler do
4
- let(:validations_handler) { AwesomeTranslations::Handlers::ValidationsHandler.new }
5
- let(:user_group) { validations_handler.groups.find { |group| group.name == "User" } }
6
- let(:blank_email_translation) { user_group.translations.find { |translation| translation.key.include? "email.blank" } }
7
-
8
- it "#groups" do
9
- expect(validations_handler.groups.to_a.length).to eq 5
10
- end
11
-
12
- describe "#translations_for_group" do
13
- it "finds the right number of validation translations" do
14
- expect(user_group.translations.to_a.length).to eq 6
15
- end
16
-
17
- it "finds the right key" do
18
- expect(blank_email_translation.key).to eq "activerecord.errors.models.user.attributes.email.blank"
19
- end
20
-
21
- it "finds the right directory" do
22
- expect(blank_email_translation.dir).to eq Rails.root.join("config/locales/awesome_translations/models/user").to_s
23
- end
24
-
25
- it "finds confirmation translations" do
26
- confirmation_translation = user_group.translations.find { |translation| translation.key.include? "email_confirmation" }
27
- expect(confirmation_translation).not_to be_blank
28
- expect(confirmation_translation.key).to eq "activerecord.errors.models.user.attributes.email_confirmation.confirmation"
29
- end
30
- end
31
- end
@@ -1,9 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers do
4
- it "does not include base in list" do
5
- AwesomeTranslations::Handlers.list.each do |handler|
6
- expect(handler.id.to_s.downcase.include?("base")).to eq false
7
- end
8
- end
9
- end
@@ -1,59 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::CacheDatabaseGenerator do
4
- let(:cache_database_generator) { AwesomeTranslations::CacheDatabaseGenerator.current }
5
- let(:table) { db.tables["handler_translations"] }
6
- let(:db) { cache_database_generator.db }
7
-
8
- before do
9
- locales_path = Rails.root.join("config/locales")
10
- FileUtils.rm_rf(locales_path)
11
- Dir.mkdir(locales_path)
12
-
13
- fake_path = "#{locales_path}/translations.yml"
14
- translations = {
15
- "da" => {
16
- "activerecord" => {
17
- "attributes" => {
18
- "user" => {
19
- "id" => "ID",
20
- "email" => "Email",
21
- "created_at" => "Oprettet d."
22
- }
23
- }
24
- }
25
- }
26
- }
27
-
28
- File.write(fake_path, YAML.dump(translations))
29
- end
30
-
31
- it "#init_database" do
32
- expect(table.name).to eq "handler_translations"
33
- end
34
-
35
- describe "#cache_translations" do
36
- it "#cache_yml_translations" do
37
- cache_database_generator.cache_translations
38
-
39
- translation = AwesomeTranslations::CacheDatabaseGenerator::HandlerTranslation
40
- .joins(:translation_key)
41
- .where(translation_keys: {key: "activerecord.attributes.user.id"})
42
- .first
43
-
44
- expect(translation).not_to eq nil
45
- end
46
-
47
- it "#cache_handler_translations" do
48
- # AwesomeTranslations::CacheDatabaseGenerator::ScannedFile.all.destroy_all
49
- cache_database_generator.cache_handler_translations
50
-
51
- translation = AwesomeTranslations::CacheDatabaseGenerator::HandlerTranslation
52
- .joins(:translation_key)
53
- .where(translation_keys: {key: "activerecord.attributes.user.id"})
54
- .first
55
-
56
- expect(translation).not_to eq nil
57
- end
58
- end
59
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ErbInspector::FileInspector do # rubocop:disable RSpec/MultipleMemoizedHelpers
4
- let(:erb_inspector) do
5
- AwesomeTranslations::ErbInspector.new(
6
- dirs: [Rails.root.to_s]
7
- )
8
- end
9
-
10
- let(:files) { erb_inspector.files.to_a }
11
- let(:file_paths) { files.map(&:file_path) }
12
- let(:js_translations_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/assets/javascripts/translations.js" } }
13
- let(:user_index_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/views/users/index.html.haml" } }
14
- let(:user_edit_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/views/users/edit.html.liquid" } }
15
- let(:user_index_translations) { user_index_inspector.translations.to_a }
16
- let(:hello_world_translation) { user_index_translations.find { |translation| translation.key == ".hello_world" } }
17
-
18
- describe "#translations" do # rubocop:disable RSpec/MultipleMemoizedHelpers
19
- it "finds the right number of translations" do
20
- expect(user_index_translations.length).to eq 3
21
- end
22
-
23
- it "finds javascript translations" do
24
- translation_keys = js_translations_inspector.translations.map(&:key)
25
- translation_full_keys = js_translations_inspector.translations.map(&:full_key)
26
-
27
- expect(translation_keys).to include ".hello_world"
28
- expect(translation_keys).to include "javascripts.absolute.key"
29
-
30
- expect(translation_full_keys).to include "assets.javascripts.translations.hello_world"
31
- expect(translation_full_keys).to include "javascripts.absolute.key"
32
- expect(translation_full_keys).to include "javascripts.absolute.key_with_args"
33
- end
34
-
35
- it "finds liquid translations" do
36
- translation_keys = user_edit_inspector.translations.map(&:key)
37
-
38
- expect(translation_keys).to include ".edit_user"
39
- expect(translation_keys).to include ".test_for_liquid_templates"
40
- expect(translation_keys).to include ".test_for_liquid_templates_with_var_double_quotes"
41
- expect(translation_keys).to include ".test_for_liquid_templates_with_var_single_quotes"
42
- expect(translation_keys).to include ".test_for_liquid_templates_with_escape"
43
- expect(translation_keys).to include ".test_for_liquid_templates_with_var_escape"
44
- end
45
- end
46
- end
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ErbInspector::TranslationInspector do # rubocop:disable RSpec/MultipleMemoizedHelpers
4
- let(:erb_inspector) do
5
- AwesomeTranslations::ErbInspector.new(
6
- dirs: [Rails.root.to_s]
7
- )
8
- end
9
-
10
- let(:files) { erb_inspector.files.to_a }
11
- let(:file_paths) { files.map(&:file_path) }
12
- let(:user_index_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/views/users/index.html.haml" } }
13
- let(:user_index_translations) { user_index_inspector.translations.to_a }
14
- let(:hello_world_translation) { user_index_translations.find { |translation| translation.key == ".hello_world" } }
15
- let(:user_was_created_translation) do
16
- files
17
- .find { |file_inspector| file_inspector.file_path == "app/controllers/users_controller.rb" }
18
- .translations
19
- .find { |translation| translation.key == ".user_was_created" }
20
- end
21
-
22
- it "#full_key" do
23
- expect(hello_world_translation.full_key).to eq "users.index.hello_world"
24
- end
25
-
26
- it "#full_path" do
27
- expect(hello_world_translation.full_path).to eq Rails.root.join("app/views/users/index.html.haml").to_s
28
- end
29
-
30
- it "#dir" do
31
- expect(user_was_created_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/users/create"
32
- end
33
- end
@@ -1,30 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ErbInspector do
4
- let(:erb_inspector) do
5
- AwesomeTranslations::ErbInspector.new(
6
- dirs: [Rails.root.to_s]
7
- )
8
- end
9
-
10
- let(:files) { erb_inspector.files.to_a }
11
- let(:file_paths) { files.map(&:file_path) }
12
-
13
- describe "#files" do
14
- it "finds the right amount of haml-files" do
15
- expect(files.length).to eq 36
16
- end
17
-
18
- it "finds haml-files" do
19
- expect(file_paths).to include "app/views/users/index.html.haml"
20
- end
21
-
22
- it "finds js-files" do
23
- expect(file_paths).to include "app/assets/javascripts/translations.js"
24
- end
25
-
26
- it "finds erb-files" do
27
- expect(file_paths).to include "app/views/users/show.html.erb"
28
- end
29
- end
30
- end
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ModelInspector::Attribute do
4
- let(:user_inspector) { AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector| model_inspector.clazz == User } }
5
- let(:email_attr) { user_inspector.attributes.find { |attribute| attribute.name == "email" } }
6
-
7
- it "#i18n_key" do
8
- expect(email_attr.i18n_key).to eq "activerecord.attributes.user.email"
9
- end
10
-
11
- it "#name" do
12
- expect(email_attr.name).to eq "email"
13
- end
14
-
15
- it "#model_inspector" do
16
- expect(email_attr.model_inspector.clazz).to eq User
17
- end
18
- end
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ModelInspector do
4
- let(:user_inspector) { AwesomeTranslations::ModelInspector.model_classes.find { |model_inspector| model_inspector.clazz == User } }
5
- let(:model_classes) { AwesomeTranslations::ModelInspector.model_classes.map(&:clazz).reject { |clazz| clazz.name.end_with?("::Translation") } }
6
-
7
- it "#model_classes" do
8
- expect(model_classes.to_a.sort_by(&:name)).to eq [ApplicationRecord, Role, User]
9
- end
10
-
11
- it "#engines" do
12
- expected = [ActionView::Railtie, AwesomeTranslations::Engine, MoneyRails::Engine]
13
- expect(AwesomeTranslations::ModelInspector.engines.map(&:class).sort_by(&:name)).to eq expected
14
- end
15
-
16
- it "#class_key" do
17
- expect(user_inspector.class_key).to eq "activerecord.models.user"
18
- end
19
-
20
- it "#class_key_one" do
21
- expect(user_inspector.class_key_one).to eq "activerecord.models.user.one"
22
- end
23
-
24
- it "#class_key_other" do
25
- expect(user_inspector.class_key_other).to eq "activerecord.models.user.other"
26
- end
27
-
28
- it "#attribute_key" do
29
- expect(user_inspector.attribute_key("first_name")).to eq "activerecord.attributes.user.first_name"
30
- end
31
-
32
- it "#snake_name" do
33
- expect(user_inspector.snake_name).to eq "user"
34
- end
35
-
36
- it "#attributes" do
37
- expect(user_inspector.attributes.map(&:name).to_a).to eq %w[id email password age]
38
- end
39
- end
@@ -1,7 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::ObjectExtensions do
4
- it "detects the correct key" do
5
- expect(t(".test")).to eq "translation missing: en.spec.lib.object_extensions_spec.test"
6
- end
7
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::TranslationMigrator do
4
- let!(:handler) { create :handler }
5
- let!(:translation_key) { create :translation_key, handler: handler, key: "some.key" }
6
- let!(:translation_value) { create :translation_value, translation_key: translation_key }
7
- let!(:handler_translation) { create :handler_translation, translation_key: translation_key, handler: handler }
8
- let(:content) do
9
- {
10
- "en" => {
11
- "some" => {
12
- "key" => "something"
13
- }
14
- }
15
- }
16
- end
17
-
18
- before do
19
- File.unlink(translation_value.file_path) if File.exist?(translation_value.file_path)
20
- File.write(translation_value.file_path, YAML.dump(content))
21
- end
22
-
23
- after do
24
- File.unlink(translation_value.file_path) if File.exist?(translation_value.file_path)
25
- end
26
-
27
- it "moves the translation from one file to another and deletes the old file" do
28
- old_path = translation_value.file_path
29
-
30
- expect(old_path).not_to eq nil
31
- expect(translation_value.file_path).not_to eq handler_translation.file_path
32
- expect(translation_value.key).to eq handler_translation.key
33
-
34
- migrator = AwesomeTranslations::TranslationMigrator.new(
35
- translation_value: translation_value,
36
- handler_translation: handler_translation
37
- )
38
- migrator.execute
39
-
40
- expected_path = "#{handler_translation.dir}/en.yml"
41
-
42
- expect(translation_value.file_path).to eq expected_path
43
- expect(YAML.load_file(expected_path)).to eq content
44
- expect(File.exist?(old_path)).to eq false
45
- end
46
- end
@@ -1,8 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handler do
4
- it "lists available handlers" do
5
- handlers = AwesomeTranslations::Handler.all
6
- expect(handlers.length).to be > 0
7
- end
8
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::TranslatedValue do
4
- let(:test_file_path) { "#{Dir.tmpdir}/da.yml" }
5
-
6
- let(:translated_value) do
7
- described_class.new(
8
- file: test_file_path,
9
- key: "activerecord.attributes.test_model.test",
10
- locale: :da,
11
- value: "test"
12
- )
13
- end
14
-
15
- before do
16
- test_translations = {
17
- "da" => {
18
- "activerecord" => {
19
- "attributes" => {
20
- "test_model" => {
21
- "test" => "test",
22
- "other_translation" => "En anden"
23
- }
24
- }
25
- }
26
- }
27
- }
28
-
29
- File.write(test_file_path, YAML.dump(test_translations))
30
- end
31
-
32
- it "#save!" do
33
- translated_value.value = "new test"
34
- translated_value.save!
35
-
36
- translations = YAML.safe_load(File.read(test_file_path))
37
-
38
- expect(translations["da"]["activerecord"]["attributes"]["test_model"]["test"]).to eq "new test"
39
- expect(translations["da"]["activerecord"]["attributes"]["test_model"]["other_translation"]).to eq "En anden"
40
- end
41
- end
@@ -1,54 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Translation do
4
- let(:day_names_monday_translation) do
5
- AwesomeTranslations::Translation.new(
6
- dir: Rails.root.join("config/locales/awesome_translations/date_time"),
7
- key: "date.day_names[1]"
8
- )
9
- end
10
-
11
- let(:am_translation) do
12
- AwesomeTranslations::Translation.new(
13
- dir: Rails.root.join("config/locales/awesome_translations/date_time"),
14
- key: "time.am"
15
- )
16
- end
17
-
18
- it "#array_key" do
19
- expect(day_names_monday_translation.array_key).to eq "date.day_names"
20
- end
21
-
22
- it "#array_translation?" do
23
- expect(day_names_monday_translation.array_translation?).to eq true
24
- end
25
-
26
- it "#array_no" do
27
- expect(day_names_monday_translation.array_no).to eq 1
28
- end
29
-
30
- describe "#value" do
31
- it "returns correct value when it is an array translation" do
32
- expect(day_names_monday_translation.value(locale: "en")).to eq "Monday"
33
- end
34
-
35
- it "returns correct value for normal translations" do
36
- expect(am_translation.value(locale: "en")).to eq "am"
37
- end
38
-
39
- it "doesnt use fallbacks" do
40
- expect(I18n).to receive(:t).with("time.am", default: nil, fallback: false).and_call_original
41
- am_translation.value
42
- end
43
- end
44
-
45
- describe "#value_for?" do
46
- it "returns correct value when it is an array translation" do
47
- expect(day_names_monday_translation.value_for?("en")).to eq true
48
- end
49
-
50
- it "returns correct value for normal translations" do
51
- expect(am_translation.value_for?("en")).to eq true
52
- end
53
- end
54
- end
@@ -1,11 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe TestTranslateService do
4
- it "uses translations" do
5
- expect(TestTranslateService.new.perform).to eq "translation missing: en.services.test_translate_service.hello_world"
6
- end
7
-
8
- it "uses translations in instance methods" do
9
- expect(TestTranslateService.static_method).to eq "translation missing: en.services.test_translate_service.hello_static_method"
10
- end
11
- end
data/spec/spec_helper.rb DELETED
@@ -1,76 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= "test"
3
- require_relative "dummy/config/environment"
4
-
5
- require "rspec/rails"
6
- require "baza_models"
7
- require "database_cleaner"
8
- require "capybara"
9
- require "factory_bot"
10
- require "forgery"
11
- require "globalize"
12
- require "simple_form"
13
-
14
- # Requires supporting ruby files with custom matchers and macros, etc,
15
- # in spec/support/ and its subdirectories.
16
- Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }
17
-
18
- # Checks for pending migrations before tests are run.
19
- # If you are not using ActiveRecord, you can remove this line.
20
- ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
21
-
22
- FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), "factories")
23
- FactoryBot.find_definitions
24
-
25
- AwesomeTranslations.load_object_extensions
26
-
27
- Capybara.app = AwesomeTranslations::Engine
28
-
29
- RSpec.configure do |config|
30
- config.include AwesomeTranslations::Engine.routes.url_helpers
31
- config.include FactoryBot::Syntax::Methods
32
-
33
- config.infer_spec_type_from_file_location!
34
-
35
- config.before(:suite) do
36
- DatabaseCleaner.clean_with(:truncation)
37
-
38
- generator = AwesomeTranslations::CacheDatabaseGenerator.current
39
- generator.cache_translations
40
- end
41
-
42
- config.before do
43
- Capybara.reset_sessions!
44
-
45
- DatabaseCleaner.strategy = :transaction
46
- DatabaseCleaner.start
47
-
48
- AwesomeTranslations::CacheDatabaseGenerator.current.init_database
49
-
50
- BazaModels::TestDatabaseCleaner.clean
51
- end
52
-
53
- config.before(:each, js: true) do
54
- DatabaseCleaner.strategy = :truncation
55
- end
56
-
57
- config.after do
58
- DatabaseCleaner.clean
59
- end
60
-
61
- config.before do
62
- I18n.load_path.delete_if { |path| !File.exist?(path) }
63
- end
64
-
65
- config.after do
66
- generator = AwesomeTranslations::CacheDatabaseGenerator.current
67
- generator.close
68
-
69
- translation_file = Rails.root.join("config/locales/translations.yml").to_s
70
- File.unlink(translation_file) if File.exist?(translation_file)
71
-
72
- at_dir = Rails.root.join("config/locales/awesome_translations").to_s
73
- FileUtils.rm_rf(at_dir) if File.exist?(at_dir)
74
- FileUtils.touch(Rails.root.join("config/locales/.keep").to_s)
75
- end
76
- end