awesome_translations 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+
3
+ describe AwesomeTranslations::Handlers::FileHandler do
4
+ let(:handler) { AwesomeTranslations::Handlers::FileHandler.new }
5
+
6
+ describe "erb stuff" do
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.haml" }.translations }
10
+ let(:layout_group) { handler.groups.find { |group| group.name == "app/views/layouts/application.html.haml" } }
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}/config/locales/awesome_translations/app/views/layouts/application"
40
+ end
41
+ end
42
+
43
+ describe "library stuff" do
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).to_not 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/app/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).to_not eq nil
68
+ expect(user_translation).to_not 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).to_not 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/app/controllers/users_controller"
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 3
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}/config/locales/awesome_translations"
97
+ end
98
+
99
+ it "doesn't detect absolute existing direct translations" do
100
+ expect(translations.map(&:key)).to_not include "activerecord.attributes.users.email"
101
+ end
102
+ end
103
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -507,9 +507,7 @@ files:
507
507
  - lib/awesome_translations/handlers.rb
508
508
  - lib/awesome_translations/handlers/base_handler.rb
509
509
  - lib/awesome_translations/handlers/devise_handler.rb
510
- - lib/awesome_translations/handlers/erb_handler.rb
511
- - lib/awesome_translations/handlers/global_handler.rb
512
- - lib/awesome_translations/handlers/library_handler.rb
510
+ - lib/awesome_translations/handlers/file_handler.rb
513
511
  - lib/awesome_translations/handlers/model_handler.rb
514
512
  - lib/awesome_translations/handlers/rails_handler.rb
515
513
  - lib/awesome_translations/handlers/validations_handler.rb
@@ -1400,9 +1398,7 @@ files:
1400
1398
  - spec/factories/translation_value.rb
1401
1399
  - spec/factories/user.rb
1402
1400
  - spec/features/clean_ups_spec.rb
1403
- - spec/handlers/erb_handler_spec.rb
1404
- - spec/handlers/global_handler_spec.rb
1405
- - spec/handlers/library_handler_spec.rb
1401
+ - spec/handlers/file_handler_spec.rb
1406
1402
  - spec/handlers/model_handler_spec.rb
1407
1403
  - spec/handlers/validations_handler_spec.rb
1408
1404
  - spec/handlers_spec.rb
@@ -2321,9 +2317,7 @@ test_files:
2321
2317
  - spec/factories/translation_value.rb
2322
2318
  - spec/factories/user.rb
2323
2319
  - spec/features/clean_ups_spec.rb
2324
- - spec/handlers/erb_handler_spec.rb
2325
- - spec/handlers/global_handler_spec.rb
2326
- - spec/handlers/library_handler_spec.rb
2320
+ - spec/handlers/file_handler_spec.rb
2327
2321
  - spec/handlers/model_handler_spec.rb
2328
2322
  - spec/handlers/validations_handler_spec.rb
2329
2323
  - spec/handlers_spec.rb
@@ -1,31 +0,0 @@
1
- class AwesomeTranslations::Handlers::GlobalHandler < AwesomeTranslations::Handlers::BaseHandler
2
- def groups
3
- ArrayEnumerator.new do |yielder|
4
- yielder << AwesomeTranslations::Group.new(
5
- id: "global",
6
- handler: self,
7
- data: {
8
- name: "Global translations"
9
- }
10
- )
11
- end
12
- end
13
-
14
- def translations_for_group(_group)
15
- ArrayEnumerator.new do |yielder|
16
- translations_found = {}
17
-
18
- erb_inspector = AwesomeTranslations::ErbInspector.new
19
- erb_inspector.files.each do |file|
20
- file.translations.each do |translation|
21
- next unless translation.global?
22
-
23
- unless translations_found.key?(translation.full_key)
24
- translations_found[translation.full_key] = true
25
- yielder << translation.model
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,41 +0,0 @@
1
- class AwesomeTranslations::Handlers::LibraryHandler < AwesomeTranslations::Handlers::BaseHandler
2
- def groups
3
- ArrayEnumerator.new do |yielder|
4
- erb_inspector.files.each do |file|
5
- id = file.file_path.gsub(/[^A-z0-9]/, "_")
6
-
7
- group = AwesomeTranslations::Group.new(
8
- id: id,
9
- handler: self,
10
- data: {
11
- name: file.file_path,
12
- root_path: file.root_path,
13
- full_path: file.full_path,
14
- file_path: file.file_path
15
- }
16
- )
17
-
18
- yielder << group if translations_for_group(group).any?
19
- end
20
- end
21
- end
22
-
23
- def translations_for_group(group)
24
- ArrayEnumerator.new do |yielder|
25
- file = erb_inspector.file(group.data[:root_path], group.data[:file_path])
26
-
27
- file.translations.each do |translation|
28
- next unless translation.relative?
29
- yielder << translation.model
30
- end
31
- end
32
- end
33
-
34
- private
35
-
36
- def erb_inspector
37
- @erb_inspector ||= AwesomeTranslations::ErbInspector.new(
38
- exts: [".rb", ".rake"]
39
- )
40
- end
41
- end
@@ -1,39 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::ErbHandler do
4
- let(:handler) { AwesomeTranslations::Handlers::ErbHandler.new }
5
- let(:users_index_group) { handler.groups.find { |group| group.name == "app/views/users/index.html.haml" } }
6
- let(:users_index_translations) { users_index_group.translations }
7
- let(:users_partial_test_translations) { handler.groups.find { |group| group.name == "app/views/users/_partial_test.html.haml" }.translations }
8
- let(:layout_group) { handler.groups.find { |group| group.name == "app/views/layouts/application.html.haml" } }
9
- let(:layout_translations) { layout_group.translations }
10
-
11
- it "finds translations made with the t method" do
12
- hello_world_translations = users_index_translations.select { |t| t.key == "users.index.hello_world" }.to_a
13
- expect(hello_world_translations.length).to eq 1
14
- end
15
-
16
- it "finds translations in the layout" do
17
- danish_translations = layout_translations.select { |t| t.key == "layouts.application.danish" }.to_a
18
- expect(danish_translations.length).to eq 1
19
- end
20
-
21
- it "doesnt include _ in partial keys" do
22
- partial_test = users_partial_test_translations.select { |t| t.key == "users.partial_test.partial_test" }.to_a
23
- expect(partial_test.length).to eq 1
24
- end
25
-
26
- it "removes special characters when using the custom method" do
27
- current_language_translation = layout_translations.select { |t| t.key == "layouts.application.the_current_language_is" }.to_a
28
- expect(current_language_translation.length).to eq 1
29
- end
30
-
31
- it "has unique translations" do
32
- expect(layout_translations.select { |t| t.key == "layouts.application.hello_world" }.to_a.length).to eq 1
33
- end
34
-
35
- it "sets the correct translation path" do
36
- danish_translation = layout_translations.find { |t| t.key == "layouts.application.danish" }
37
- expect(danish_translation.dir).to eq "#{Rails.root}/config/locales/awesome_translations/app/views/layouts/application"
38
- end
39
- end
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::GlobalHandler do
4
- let(:global_handler) { AwesomeTranslations::Handlers::GlobalHandler.new }
5
- let(:translations) { global_handler.groups.first.translations.to_a }
6
- let(:yes_translation) { translations.find { |translation| translation.key == "yes" } }
7
-
8
- it "finds the right translations" do
9
- expect(translations.length).to eq 2
10
- end
11
-
12
- it "reads the keys right" do
13
- expect(yes_translation.key).to eq "yes"
14
- end
15
-
16
- it "sets the correct translation path" do
17
- expect(yes_translation.dir).to eq "#{Rails.root}/config/locales/awesome_translations"
18
- end
19
-
20
- it "doesn't detect absolute existing direct translations" do
21
- expect(translations.map(&:key)).to_not include "activerecord.attributes.users.email"
22
- end
23
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AwesomeTranslations::Handlers::LibraryHandler do
4
- let(:handler) { AwesomeTranslations::Handlers::LibraryHandler.new }
5
- let(:group) { handler.groups.find { |group| group.name == "app/models/role.rb" } }
6
- let(:mailer_group) { handler.groups.find { |group| group.name == "app/mailers/my_mailer.rb" } }
7
- let(:subject_translation) { mailer_group.translations.find { |translation| translation.key == "my_mailer.mailer_action.custom_subject" } }
8
- let(:admin_translation) { group.translations.find { |translation| translation.key == "models.role.administrator" } }
9
- let(:application_helper_group) { handler.groups.find { |group| group.name == "app/helpers/application_helper.rb" } }
10
- let(:hello_world_translation) { application_helper_group.translations.find { |translation| translation.key == "helpers.application_helper.hello_world" } }
11
- let(:users_controller_handler) { handler.groups.find { |group| group.name == "app/controllers/users_controller.rb" } }
12
- let(:update_saved_translation) { users_controller_handler.translations.find { |translation| translation.key == "users.user_was_updated" } }
13
-
14
- it "finds translations made with the t method" do
15
- expect(admin_translation).to_not eq nil
16
- expect(admin_translation.key).to eq "models.role.administrator"
17
- expect(admin_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/app/models/role"
18
- end
19
-
20
- it "generates keys with method-name for mailers" do
21
- expect(subject_translation.key).to eq "my_mailer.mailer_action.custom_subject"
22
- end
23
-
24
- it "finds translations in arrays" do
25
- moderator_translation = group.translations.find { |translation| translation.key == "models.role.moderator" }
26
- user_translation = group.translations.find { |translation| translation.key == "models.role.user" }
27
-
28
- expect(moderator_translation).to_not eq nil
29
- expect(user_translation).to_not eq nil
30
- end
31
-
32
- it "finds helpers translations using helper_t" do
33
- expect(hello_world_translation.key).to eq "helpers.application_helper.hello_world"
34
- end
35
-
36
- it "finds translations with the controller_t-method" do
37
- expect(update_saved_translation).to_not eq nil
38
- expect(update_saved_translation.key).to eq "users.user_was_updated"
39
- expect(update_saved_translation.dir).to end_with "spec/dummy/config/locales/awesome_translations/app/controllers/users_controller"
40
- end
41
- end