tr8n 3.1.8 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data/.gitignore +2 -1
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -1
  4. data/.watchr +18 -0
  5. data/Gemfile.lock +16 -10
  6. data/app/assets/images/tr8n/minus_node.png +0 -0
  7. data/app/assets/images/tr8n/pixel.gif +0 -0
  8. data/app/assets/images/tr8n/plus_node.png +0 -0
  9. data/app/assets/javascripts/tr8n/tr8n.js +1 -0
  10. data/app/assets/javascripts/tr8n/tr8n_client_sdk.js +581 -425
  11. data/app/assets/stylesheets/tr8n/layout.css.scss +1 -1
  12. data/app/assets/stylesheets/tr8n/tr8n.css.scss +20 -0
  13. data/app/controllers/tr8n/admin/base_controller.rb +4 -1
  14. data/app/controllers/tr8n/admin/clientsdk_controller.rb +1 -1
  15. data/app/controllers/tr8n/admin/metrics_controller.rb +30 -0
  16. data/app/controllers/tr8n/api/v1/base_controller.rb +12 -0
  17. data/app/controllers/tr8n/api/v1/language_controller.rb +7 -5
  18. data/app/controllers/tr8n/awards_controller.rb +1 -1
  19. data/app/controllers/tr8n/base_controller.rb +12 -6
  20. data/app/controllers/tr8n/dashboard_controller.rb +1 -1
  21. data/app/controllers/tr8n/forum_controller.rb +1 -1
  22. data/app/controllers/tr8n/glossary_controller.rb +1 -1
  23. data/app/controllers/tr8n/help_controller.rb +1 -1
  24. data/app/controllers/tr8n/phrases_controller.rb +1 -1
  25. data/app/controllers/tr8n/translator_controller.rb +8 -0
  26. data/app/helpers/tr8n/admin/base_helper.rb +1 -1
  27. data/app/helpers/tr8n/base_helper.rb +1 -1
  28. data/app/helpers/tr8n/dashboard_helper.rb +1 -1
  29. data/app/models/tr8n/base_filter.rb +1 -1
  30. data/app/models/tr8n/daily_language_metric.rb +1 -1
  31. data/app/models/tr8n/date_rule.rb +1 -1
  32. data/app/models/tr8n/gender_list_rule.rb +1 -1
  33. data/app/models/tr8n/gender_rule.rb +1 -1
  34. data/app/models/tr8n/glossary.rb +1 -1
  35. data/app/models/tr8n/glossary_filter.rb +1 -1
  36. data/app/models/tr8n/integration/ru/russian_gender_list_rule.rb +1 -1
  37. data/app/models/tr8n/integration/ru/russian_numeric_rule.rb +1 -1
  38. data/app/models/tr8n/ip_location.rb +1 -1
  39. data/app/models/tr8n/ip_location_filter.rb +1 -1
  40. data/app/models/tr8n/language.rb +19 -7
  41. data/app/models/tr8n/language_case.rb +1 -1
  42. data/app/models/tr8n/language_case_filter.rb +1 -1
  43. data/app/models/tr8n/language_case_rule.rb +1 -1
  44. data/app/models/tr8n/language_case_rule_filter.rb +1 -1
  45. data/app/models/tr8n/language_case_value_map.rb +1 -1
  46. data/app/models/tr8n/language_case_value_map_filter.rb +1 -1
  47. data/app/models/tr8n/language_filter.rb +1 -1
  48. data/app/models/tr8n/language_forum_abuse_report.rb +1 -1
  49. data/app/models/tr8n/language_forum_abuse_report_filter.rb +1 -1
  50. data/app/models/tr8n/language_forum_message.rb +1 -1
  51. data/app/models/tr8n/language_forum_message_filter.rb +1 -1
  52. data/app/models/tr8n/language_forum_topic.rb +1 -1
  53. data/app/models/tr8n/language_forum_topic_filter.rb +1 -1
  54. data/app/models/tr8n/language_metric.rb +1 -1
  55. data/app/models/tr8n/language_metric_filter.rb +1 -1
  56. data/app/models/tr8n/language_rule.rb +1 -1
  57. data/app/models/tr8n/language_rule_filter.rb +1 -1
  58. data/app/models/tr8n/language_user.rb +1 -1
  59. data/app/models/tr8n/language_user_filter.rb +1 -1
  60. data/app/models/tr8n/list_rule.rb +1 -1
  61. data/app/models/tr8n/monthly_language_metric.rb +1 -1
  62. data/app/models/tr8n/numeric_rule.rb +35 -28
  63. data/app/models/tr8n/sync_log.rb +1 -1
  64. data/app/models/tr8n/sync_log_filter.rb +1 -1
  65. data/app/models/tr8n/total_language_metric.rb +1 -1
  66. data/app/models/tr8n/translation.rb +4 -3
  67. data/app/models/tr8n/translation_domain.rb +11 -3
  68. data/app/models/tr8n/translation_domain_filter.rb +1 -1
  69. data/app/models/tr8n/translation_filter.rb +1 -1
  70. data/app/models/tr8n/translation_key.rb +73 -36
  71. data/app/models/tr8n/translation_key_comment.rb +1 -1
  72. data/app/models/tr8n/translation_key_comment_filter.rb +1 -1
  73. data/app/models/tr8n/translation_key_filter.rb +1 -1
  74. data/app/models/tr8n/translation_key_lock.rb +1 -1
  75. data/app/models/tr8n/translation_key_lock_filter.rb +1 -1
  76. data/app/models/tr8n/translation_key_source.rb +16 -5
  77. data/app/models/tr8n/translation_key_source_filter.rb +1 -1
  78. data/app/models/tr8n/translation_source.rb +12 -4
  79. data/app/models/tr8n/translation_source_filter.rb +1 -1
  80. data/app/models/tr8n/translation_source_language.rb +1 -1
  81. data/app/models/tr8n/translation_vote.rb +1 -1
  82. data/app/models/tr8n/translation_vote_filter.rb +1 -1
  83. data/app/models/tr8n/translator.rb +21 -5
  84. data/app/models/tr8n/translator_filter.rb +1 -1
  85. data/app/models/tr8n/translator_following.rb +1 -1
  86. data/app/models/tr8n/translator_following_filter.rb +1 -1
  87. data/app/models/tr8n/translator_log.rb +3 -3
  88. data/app/models/tr8n/translator_log_filter.rb +1 -1
  89. data/app/models/tr8n/translator_metric.rb +1 -1
  90. data/app/models/tr8n/translator_metric_filter.rb +1 -1
  91. data/app/models/tr8n/translator_report.rb +1 -1
  92. data/app/models/tr8n/translator_report_filter.rb +1 -1
  93. data/app/models/tr8n/value_rule.rb +1 -1
  94. data/app/views/tr8n/admin/clientsdk/index.html.erb +29 -29
  95. data/app/views/tr8n/admin/clientsdk/lb_samples.html.erb +1 -1
  96. data/app/views/tr8n/admin/metrics/_tabs.html.erb +22 -0
  97. data/app/views/tr8n/admin/metrics/index.html.erb +60 -0
  98. data/app/views/tr8n/common/_header.html.erb +3 -1
  99. data/app/views/tr8n/common/_language_selector.html.erb +4 -2
  100. data/app/views/tr8n/common/_scripts.html.erb +5 -0
  101. data/app/views/tr8n/common/_terms_of_service.html.erb +53 -0
  102. data/app/views/tr8n/help/credits.html.erb +4 -0
  103. data/app/views/tr8n/language/_select.html.erb +5 -1
  104. data/app/views/tr8n/translator/registration.html.erb +21 -0
  105. data/config/routes.rb +3 -1
  106. data/doc/classes.graffle +356 -7194
  107. data/lib/generators/tr8n/templates/config/tr8n/config.yml +9 -1
  108. data/lib/generators/tr8n/templates/config/tr8n/site/shortcuts.yml +1 -1
  109. data/lib/generators/tr8n/templates/config/tr8n/tokens/decorations.yml +4 -1
  110. data/lib/generators/tr8n/tr8n_generator.rb +1 -1
  111. data/lib/tasks/tr8n.rake +1 -1
  112. data/lib/tr8n.rb +23 -0
  113. data/lib/tr8n/active_dumper.rb +1 -1
  114. data/lib/tr8n/cache.rb +1 -8
  115. data/lib/tr8n/cache_adapters/memcached.rb +1 -1
  116. data/lib/tr8n/config.rb +37 -1
  117. data/lib/tr8n/dictionary.rb +1 -1
  118. data/lib/tr8n/engine.rb +4 -1
  119. data/lib/tr8n/exception.rb +1 -1
  120. data/lib/tr8n/extender.rb +1 -1
  121. data/lib/tr8n/extensions/action_controller_extension.rb +5 -4
  122. data/lib/tr8n/extensions/action_view_extension.rb +71 -20
  123. data/lib/tr8n/extensions/array_extension.rb +14 -1
  124. data/lib/tr8n/extensions/date_extension.rb +1 -1
  125. data/lib/tr8n/extensions/fixnum_extension.rb +1 -1
  126. data/lib/tr8n/extensions/hash_extension.rb +1 -1
  127. data/lib/tr8n/extensions/string_extension.rb +1 -1
  128. data/lib/tr8n/extensions/time_extension.rb +1 -1
  129. data/lib/tr8n/ip_address.rb +1 -1
  130. data/lib/tr8n/key_registration_exception.rb +1 -1
  131. data/lib/tr8n/keyboard_mapping.rb +1 -1
  132. data/lib/tr8n/logger.rb +1 -1
  133. data/lib/tr8n/railtie.rb +1 -1
  134. data/lib/tr8n/site_map.rb +1 -1
  135. data/lib/tr8n/site_map_section.rb +1 -1
  136. data/lib/tr8n/token.rb +1 -1
  137. data/lib/tr8n/token_exception.rb +1 -1
  138. data/lib/tr8n/tokenized_label.rb +2 -12
  139. data/lib/tr8n/tokens/data_token.rb +1 -1
  140. data/lib/tr8n/tokens/decoration_token.rb +1 -1
  141. data/lib/tr8n/tokens/hidden_token.rb +1 -1
  142. data/lib/tr8n/tokens/method_token.rb +1 -1
  143. data/lib/tr8n/tokens/transform_token.rb +1 -1
  144. data/lib/tr8n/version.rb +25 -1
  145. data/local/tr8n_server/app/models/user.rb +1 -0
  146. data/local/tr8n_server/config/environments/test.rb +1 -1
  147. data/local/tr8n_server/config/tr8n/config.yml +45 -39
  148. data/local/tr8n_server/config/tr8n/site/shortcuts.yml +1 -1
  149. data/local/tr8n_server/db/schema.rb +2 -0
  150. data/spec/controllers/awards_controller_spec.rb +22 -0
  151. data/spec/controllers/base_controller_spec.rb +6 -0
  152. data/spec/controllers/dashboard_controller_spec.rb +23 -0
  153. data/spec/controllers/forum_controller_spec.rb +23 -0
  154. data/spec/controllers/glossary_controller_spec.rb +22 -0
  155. data/spec/controllers/help_controller_spec.rb +22 -0
  156. data/spec/controllers/language_cases_controller_spec.rb +13 -0
  157. data/spec/controllers/language_controller_spec.rb +10 -0
  158. data/spec/controllers/phrases_controller_spec.rb +22 -0
  159. data/spec/controllers/translations_controller_spec.rb +23 -0
  160. data/spec/controllers/translator_controller_spec.rb +22 -0
  161. data/spec/lib/tokenized_label_spec.rb +42 -0
  162. data/spec/lib/tokens/data_token_spec.rb +49 -0
  163. data/spec/lib/tokens/decoration_token_spec.rb +49 -0
  164. data/spec/lib/tokens/hidden_token_spec.rb +53 -0
  165. data/spec/lib/tokens/method_token_spec.rb +61 -0
  166. data/spec/lib/tokens/transform_token_spec.rb +51 -0
  167. data/spec/models/tr8n/daily_language_metric_spec.rb +5 -0
  168. data/spec/models/tr8n/date_rule_spec.rb +5 -0
  169. data/spec/models/tr8n/gender_list_rule_spec.rb +5 -0
  170. data/spec/models/tr8n/gender_rule_spec.rb +141 -0
  171. data/spec/models/tr8n/glossary_spec.rb +5 -0
  172. data/spec/models/tr8n/ip_location_spec.rb +5 -0
  173. data/spec/models/tr8n/language_case_rule_spec.rb +5 -0
  174. data/spec/models/tr8n/language_case_spec.rb +5 -0
  175. data/spec/models/tr8n/language_case_value_map_spec.rb +5 -0
  176. data/spec/models/tr8n/language_forum_abuse_report_spec.rb +5 -0
  177. data/spec/models/tr8n/language_forum_message_spec.rb +5 -0
  178. data/spec/models/tr8n/language_forum_topic_spec.rb +5 -0
  179. data/spec/models/tr8n/language_metric_spec.rb +5 -0
  180. data/spec/models/tr8n/language_rule_spec.rb +5 -0
  181. data/spec/models/tr8n/language_spec.rb +79 -0
  182. data/spec/models/tr8n/language_user_spec.rb +5 -0
  183. data/spec/models/tr8n/list_rule_spec.rb +5 -0
  184. data/spec/models/tr8n/monthly_language_metric_spec.rb +5 -0
  185. data/spec/models/tr8n/numeric_rule_spec.rb +162 -0
  186. data/spec/models/tr8n/sync_log_spec.rb +5 -0
  187. data/spec/models/tr8n/total_language_metric_spec.rb +5 -0
  188. data/spec/models/tr8n/translation_domain_spec.rb +5 -0
  189. data/spec/models/tr8n/translation_key_comment_spec.rb +5 -0
  190. data/spec/models/tr8n/translation_key_lock_spec.rb +5 -0
  191. data/spec/models/tr8n/translation_key_source_spec.rb +5 -0
  192. data/spec/models/tr8n/translation_key_spec.rb +118 -0
  193. data/spec/models/tr8n/translation_source_language_spec.rb +5 -0
  194. data/spec/models/tr8n/translation_source_spec.rb +5 -0
  195. data/spec/models/tr8n/translation_spec.rb +5 -0
  196. data/spec/models/tr8n/translation_vote_spec.rb +5 -0
  197. data/spec/models/tr8n/translator_following_spec.rb +5 -0
  198. data/spec/models/tr8n/translator_log_spec.rb +5 -0
  199. data/spec/models/tr8n/translator_metric_spec.rb +5 -0
  200. data/spec/models/tr8n/translator_report_spec.rb +5 -0
  201. data/spec/models/tr8n/translator_spec.rb +140 -0
  202. data/spec/spec_helper.rb +26 -27
  203. data/tr8n.gemspec +3 -1
  204. metadata +173 -50
  205. data/local/tr8n_server/db/migrate/20110930041150_create_tr8n_tables.rb +0 -372
  206. data/spec/fake_app.rb +0 -50
  207. data/spec/lib/data_token_spec.rb +0 -26
  208. data/spec/lib/transform_token_spec.rb +0 -22
  209. data/spec/models/translation_key_spec.rb +0 -63
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::DailyLanguageMetric do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::DateRule do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::GenderListRule do
4
+
5
+ end
@@ -0,0 +1,141 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::GenderRule do
4
+ before :all do
5
+ @lang = Tr8n::Language.create(:locale => "elb", :english_name => "Elbonian")
6
+ end
7
+
8
+ after :all do
9
+ @lang.destroy
10
+ end
11
+
12
+ describe 'class methods' do
13
+ it 'should respec configuration settings' do
14
+ Tr8n::Config.stub!(:rules_engine).and_return({
15
+ :gender_rule => {
16
+ token_suffixes: ["user", "actor", "target"],
17
+ object_method: "gender",
18
+ method_values: {
19
+ female: "f",
20
+ male: "m",
21
+ neutral: "n",
22
+ unknown: "u"
23
+ }
24
+ }
25
+ })
26
+
27
+ Tr8n::GenderRule.dependency.should eq("gender")
28
+ Tr8n::GenderRule.suffixes.should eq(["user", "actor", "target"])
29
+
30
+ Tr8n::GenderRule.gender_object_value_for(:female).should eq("f")
31
+ Tr8n::GenderRule.gender_object_value_for(:male).should eq("m")
32
+ Tr8n::GenderRule.gender_object_value_for(:neutral).should eq("n")
33
+ Tr8n::GenderRule.gender_object_value_for(:unknown).should eq("u")
34
+
35
+ obj = mock("object_with_gender")
36
+ obj.should_receive(:gender).and_return("m")
37
+ Tr8n::GenderRule.gender_token_value(obj).should eq("m")
38
+ end
39
+
40
+ describe 'default transform without token value' do
41
+ it 'should always use a musculine form' do
42
+ Tr8n::GenderRule.default_transform("he").should eq("he")
43
+ Tr8n::GenderRule.default_transform("he", "she").should eq("he")
44
+ Tr8n::GenderRule.default_transform("his", "her").should eq("his")
45
+ end
46
+ end
47
+
48
+ describe 'transform with a token value' do
49
+ it 'should return the form based on the token value' do
50
+ male = mock("male")
51
+ male.stub!(:gender).and_return("male")
52
+ female = mock("male")
53
+ female.stub!(:gender).and_return("female")
54
+ unknwon = mock("unknwon")
55
+ unknwon.stub!(:gender).and_return("unknwon")
56
+
57
+ Tr8n::GenderRule.transform(male, "registered on").should eq("registered on")
58
+ Tr8n::GenderRule.transform(male, "he", "she").should eq("he")
59
+ Tr8n::GenderRule.transform(male, "his", "her").should eq("his")
60
+ Tr8n::GenderRule.transform(male, "he", "she", "he/she").should eq("he")
61
+
62
+ Tr8n::GenderRule.transform(female, "registered on").should eq("registered on")
63
+ Tr8n::GenderRule.transform(female, "he", "she").should eq("she")
64
+ Tr8n::GenderRule.transform(female, "his", "her").should eq("her")
65
+ Tr8n::GenderRule.transform(female, "he", "she", "he/she").should eq("she")
66
+
67
+ Tr8n::GenderRule.transform(unknwon, "registered on").should eq("registered on")
68
+ Tr8n::GenderRule.transform(unknwon, "he", "she").should eq("he/she")
69
+ Tr8n::GenderRule.transform(unknwon, "his", "her").should eq("his/her")
70
+ Tr8n::GenderRule.transform(unknwon, "he", "she", "he/she").should eq("he/she")
71
+ end
72
+ end
73
+ end
74
+
75
+ describe 'instance methods' do
76
+ describe 'evaluate rule' do
77
+ it 'should return results based on gender' do
78
+ male = mock("male")
79
+ male.stub!(:gender).and_return("male")
80
+ female = mock("male")
81
+ female.stub!(:gender).and_return("female")
82
+ unknwon = mock("unknwon")
83
+ unknwon.stub!(:gender).and_return("unknwon")
84
+
85
+ definition = {operator: "is", value: "male"}
86
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
87
+ rule.evaluate(male).should be_true
88
+ rule.evaluate(female).should be_false
89
+ rule.evaluate(unknwon).should be_false
90
+
91
+ definition = {operator: "is_not", value: "male"}
92
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
93
+ rule.evaluate(male).should be_false
94
+ rule.evaluate(female).should be_true
95
+ rule.evaluate(unknwon).should be_true
96
+
97
+ definition = {operator: "is", value: "female"}
98
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
99
+ rule.evaluate(male).should be_false
100
+ rule.evaluate(female).should be_true
101
+ rule.evaluate(unknwon).should be_false
102
+
103
+ definition = {operator: "is_not", value: "female"}
104
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
105
+ rule.evaluate(male).should be_true
106
+ rule.evaluate(female).should be_false
107
+ rule.evaluate(unknwon).should be_true
108
+ end
109
+ end
110
+
111
+ describe 'hashing a rule' do
112
+ it 'should produce a correct hash' do
113
+ definition = {operator: "is", value: "male"}
114
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
115
+ rule.to_hash.should eq({:type=>"gender", :operator=>"is", :value=>"male"})
116
+ end
117
+ end
118
+
119
+ describe 'describing a rule' do
120
+ it 'should produce a correct description' do
121
+ definition = {operator: "is", value: "male"}
122
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
123
+ rule.description.should eq("is a male")
124
+
125
+ definition = {operator: "is", value: "unknown"}
126
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
127
+ rule.description.should eq("has an unknown gender")
128
+
129
+ definition = {operator: "is_not", value: "female"}
130
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
131
+ rule.description.should eq("is not a female")
132
+
133
+ definition = {operator: "is_not", value: "unknown"}
134
+ rule = Tr8n::GenderRule.create(:language => @lang, :definition => definition)
135
+ rule.description.should eq("does not have an unknown gender")
136
+ end
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::Glossary do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::IpLocation do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageCaseRule do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageCase do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageCaseValueMap do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageForumAbuseReport do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageForumMessage do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageForumTopic do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageMetric do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageRule do
4
+
5
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::Language do
4
+ describe 'cache key' do
5
+ it 'shold use locale' do
6
+ lang = Tr8n::Language.find_or_create('test', 'Test Language')
7
+ lang.cache_key.should eq("language_test")
8
+ end
9
+ end
10
+
11
+ describe 'finding or creating a new language' do
12
+ context 'none existing language' do
13
+ it 'should not be found' do
14
+ lang = Tr8n::Language.for('test')
15
+ lang.should be_nil
16
+ end
17
+
18
+ it 'should be created' do
19
+ lang = Tr8n::Language.for('test')
20
+ lang.should be_nil
21
+
22
+ lang = Tr8n::Language.find_or_create('test', 'Test Language')
23
+ lang.locale.should eql('test')
24
+ lang.english_name.should eql('Test Language')
25
+
26
+ lang = Tr8n::Language.for('test')
27
+ lang.should be_a(Tr8n::Language)
28
+ lang.english_name.should eql('Test Language')
29
+ end
30
+ end
31
+
32
+ context 'existing language' do
33
+ it 'should be found' do
34
+ Tr8n::Language.create(:locale => 'test123', :english_name => 'Test Language 123')
35
+ lang = Tr8n::Language.for('test123')
36
+ lang.should be_a(Tr8n::Language)
37
+ lang.english_name.should eql('Test Language 123')
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'current language' do
43
+ before :all do
44
+ @lang = Tr8n::Language.find_or_create('test', 'Test Language')
45
+ Tr8n::Config.init(@lang.locale)
46
+ end
47
+
48
+ after :all do
49
+ @lang.destroy
50
+ end
51
+
52
+ it 'must be set' do
53
+ lang = Tr8n::Language.for('test')
54
+ lang.should be_a(Tr8n::Language)
55
+ lang.current?.should be_true
56
+ end
57
+ end
58
+
59
+ describe 'default language' do
60
+ before :all do
61
+ @lang = Tr8n::Language.find_or_create('test', 'Test Language')
62
+ Tr8n::Config.init(@lang.locale)
63
+ end
64
+
65
+ after :all do
66
+ @lang.destroy
67
+ end
68
+
69
+ it 'must be set' do
70
+ Tr8n::Config.stub(:default_locale).and_return(@lang.locale)
71
+ lang = Tr8n::Language.for('test')
72
+ lang.should be_a(Tr8n::Language)
73
+ lang.default?.should be_true
74
+ end
75
+ end
76
+
77
+
78
+
79
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::LanguageUser do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::ListRule do
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::MonthlyLanguageMetric do
4
+
5
+ end
@@ -0,0 +1,162 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Tr8n::NumericRule do
4
+ before :all do
5
+ @lang = Tr8n::Language.create(:locale => "elb", :english_name => "Elbonian")
6
+ end
7
+
8
+ after :all do
9
+ @lang.destroy
10
+ end
11
+
12
+ describe 'class methods' do
13
+ it 'should respec configuration settings' do
14
+ Tr8n::Config.stub!(:rules_engine).and_return({
15
+ :numeric_rule => {
16
+ token_suffixes: ["count", "num"],
17
+ object_method: "to_i"
18
+ }
19
+ })
20
+
21
+ Tr8n::NumericRule.dependency.should eq("number")
22
+ Tr8n::NumericRule.suffixes.should eq(["count", "num"])
23
+ Tr8n::NumericRule.number_token_value(5).should eq(5)
24
+
25
+ obj = mock("numeric_object")
26
+ obj.should_receive(:to_i).and_return(42)
27
+ Tr8n::NumericRule.number_token_value(obj).should eq(42)
28
+ end
29
+
30
+ describe 'default transform without token value' do
31
+ it 'should return the pluralized form of the noun' do
32
+ Tr8n::NumericRule.default_transform("car", "cars").should eq("cars")
33
+ Tr8n::NumericRule.default_transform("car").should eq("cars")
34
+ end
35
+ end
36
+
37
+ describe 'transform with a token value' do
38
+ it 'should return the form based on the token value' do
39
+ Tr8n::NumericRule.transform(1, "person", "people").should eq("person")
40
+ Tr8n::NumericRule.transform(2, "person", "people").should eq("people")
41
+ Tr8n::NumericRule.transform(2, "car").should eq("cars")
42
+ end
43
+ end
44
+
45
+ describe 'sanitize values' do
46
+ it 'should strip values' do
47
+ Tr8n::NumericRule.sanitize_values("1, 2, 3 , 4 ").should eq(["1","2","3","4"])
48
+ Tr8n::NumericRule.sanitize_values("1,2,3,4").should eq(["1","2","3","4"])
49
+ end
50
+ end
51
+
52
+ describe 'humanize values' do
53
+ it 'should strip values' do
54
+ Tr8n::NumericRule.humanize_values("1, 2, 3 , 4 ").should eq("1, 2, 3, 4")
55
+ Tr8n::NumericRule.humanize_values("1,2,3,4").should eq("1, 2, 3, 4")
56
+ end
57
+ end
58
+
59
+ describe 'evaluating a rule fragment' do
60
+ it 'should return correct results' do
61
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is, [5]).should be_true
62
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is, [2,3,5]).should be_true
63
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is, [4]).should be_false
64
+
65
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is_not, [4]).should be_true
66
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is_not, [4,2,3]).should be_true
67
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :is_not, [5]).should be_false
68
+
69
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :ends_in, [5]).should be_true
70
+ Tr8n::NumericRule.evaluate_rule_fragment(25, :ends_in, [5]).should be_true
71
+ Tr8n::NumericRule.evaluate_rule_fragment(25, :ends_in, [2,3,4,5]).should be_true
72
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :ends_in, [2]).should be_false
73
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :ends_in, [2,3,4]).should be_false
74
+
75
+ Tr8n::NumericRule.evaluate_rule_fragment(5, :does_not_end_in, [2,3,4]).should be_true
76
+ Tr8n::NumericRule.evaluate_rule_fragment(25, :does_not_end_in, [2,4]).should be_true
77
+ Tr8n::NumericRule.evaluate_rule_fragment(25, :does_not_end_in, [2,5]).should be_false
78
+ Tr8n::NumericRule.evaluate_rule_fragment(25, :does_not_end_in, [5]).should be_false
79
+ end
80
+ end
81
+ end
82
+
83
+ describe 'instance methods' do
84
+ describe 'creating a rule' do
85
+ it 'should create a rule object' do
86
+ definition = {multipart: false, part1: "is", value1: "1"}
87
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
88
+ rule.should be_a(Tr8n::NumericRule)
89
+ end
90
+ end
91
+
92
+ describe 'evaluating a simple rule' do
93
+ it 'should return correct results' do
94
+ definition = {multipart: false, part1: "is", value1: "1,2,3,4"}
95
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
96
+ rule.evaluate(5).should be_false
97
+ rule.evaluate(1).should be_true
98
+
99
+ definition = {multipart: false, part1: "is_not", value1: "2,3,4,5"}
100
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
101
+ rule.evaluate(5).should be_false
102
+ rule.evaluate(1).should be_true
103
+
104
+ definition = {multipart: false, part1: "ends_in", value1: "2,3,4,5"}
105
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
106
+ rule.evaluate(25).should be_true
107
+ rule.evaluate(1).should be_false
108
+
109
+ definition = {multipart: false, part1: "does_not_end_in", value1: "2,3,4,5"}
110
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
111
+ rule.evaluate(25).should be_false
112
+ rule.evaluate(1).should be_true
113
+ end
114
+ end
115
+
116
+ describe 'evaluating multipart rule' do
117
+ it 'should return correct results' do
118
+ definition = {multipart: true, part1: "ends_in", value1: "1", operator: "and", part2: "does_not_end_in", value2: "11"}
119
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
120
+ rule.evaluate(1).should be_true
121
+ rule.evaluate(21).should be_true
122
+ rule.evaluate(231).should be_true
123
+ rule.evaluate(1021).should be_true
124
+ rule.evaluate(2).should be_false
125
+ rule.evaluate(11).should be_false
126
+ rule.evaluate(211).should be_false
127
+ rule.evaluate(1011).should be_false
128
+
129
+ definition = {multipart: true, part1: "ends_in", value1: "2,3,4", operator: "and", part2: "does_not_end_in", value2: "12,13,14"}
130
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
131
+ rule.evaluate(2).should be_true
132
+ rule.evaluate(1023).should be_true
133
+ rule.evaluate(34).should be_true
134
+ rule.evaluate(1013).should be_false
135
+ rule.evaluate(14).should be_false
136
+ end
137
+ end
138
+
139
+ describe 'hashing a rule' do
140
+ it 'should produce a correct hash' do
141
+ definition = {multipart: true, part1: "ends_in", value1: "2,3,4", operator: "and", part2: "does_not_end_in", value2: "12,13,14"}
142
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
143
+ rule.to_hash.should eq({:type=>"number", :multipart=>true, :operator=>"and", :part1=>"ends_in",
144
+ :value1=>"2,3,4", :part2=>"does_not_end_in", :value2=>"12,13,14"})
145
+ end
146
+ end
147
+
148
+ describe 'describing a rule' do
149
+ it 'should produce a correct description' do
150
+ definition = {multipart: true, part1: "ends_in", value1: "2,3,4", operator: "and", part2: "does_not_end_in", value2: "12,13,14"}
151
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
152
+ rule.description.should eq("ends in 2, 3, 4, but not in 12, 13, 14")
153
+
154
+ definition = {multipart: false, part1: "does_not_end_in", value1: "2,3,4,5"}
155
+ rule = Tr8n::NumericRule.create(:language => @lang, :definition => definition)
156
+ rule.description.should eq("does not end in 2, 3, 4, 5")
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+ end