translated_attribute_value 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5a4c6cc29831dbf99793f6aaf9f577402b433a6
|
4
|
+
data.tar.gz: 9d450a1543147966ba6471bf2486fb02d6b97def
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49f2db2d0a71bbe080e569b69391cbd73847389bec01a9543d874ff1910c367795180d71446cd658c742429be4e31d479195cf1fdaed855288a816925c0db0d1
|
7
|
+
data.tar.gz: c7aa0566c532f12cf04269712c35c2d593bf7e7831508a53c325397a2e89c8b864e41ef0413b0d34cc62413af99fb52aba4c63d5727505ea39c8e9981ba9b405
|
@@ -28,16 +28,19 @@ module TranslatedAttributeValue
|
|
28
28
|
if defined?(ActiveRecord::Base) && self.ancestors.include?(ActiveRecord::Base)
|
29
29
|
self.send(:define_method, "#{attribute_name}_translated") do
|
30
30
|
attribute_value = self.send(attribute_name)
|
31
|
+
return '' if attribute_value.blank?
|
31
32
|
I18n.t("activerecord.attributes.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
|
32
33
|
end
|
33
34
|
elsif defined?(Mongoid::Document) && self.ancestors.include?(Mongoid::Document)
|
34
35
|
self.send(:define_method, "#{attribute_name}_translated") do
|
35
36
|
attribute_value = self.send(attribute_name)
|
37
|
+
return '' if attribute_value.blank?
|
36
38
|
I18n.t("mongoid.attributes.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
|
37
39
|
end
|
38
40
|
else
|
39
41
|
self.send(:define_method, "#{attribute_name}_translated") do
|
40
42
|
attribute_value = self.send(attribute_name)
|
43
|
+
return '' if attribute_value.blank?
|
41
44
|
I18n.t("translated_attribute_value.#{self.class.to_s.underscore}.#{attribute_name}_translation.#{attribute_value}")
|
42
45
|
end
|
43
46
|
end # of if chain
|
@@ -1,10 +1,45 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
+
shared_examples_for 'class_with_translated_attribute' do |i18n_key_name|
|
5
|
+
|
6
|
+
specify "I can call translated_value_for in the model" do
|
7
|
+
expect(test_model_instance.class).to respond_to(:translated_value_for)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "I can call a attribute with attribute_translated without defining it" do
|
11
|
+
specify "the translation must be called" do
|
12
|
+
expect(I18n).to receive(:t).with(i18n_key_name)
|
13
|
+
test_model_instance.status_translated
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "the method should be defined after the first call" do
|
17
|
+
test_model_instance.status_translated
|
18
|
+
expect(test_model_instance).to respond_to(:status_translated)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'it returns a empty string if the attribute is blank' do
|
23
|
+
specify 'when attribute is a empty string' do
|
24
|
+
def test_model_instance.status
|
25
|
+
""
|
26
|
+
end
|
27
|
+
expect(test_model_instance.status_translated).to eq("")
|
28
|
+
end
|
29
|
+
|
30
|
+
specify 'when attribute is nil' do
|
31
|
+
def test_model_instance.status
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
expect(test_model_instance.status_translated).to eq("")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
4
39
|
describe TranslatedAttributeValue::Base do
|
5
40
|
before(:each) do
|
6
41
|
stub_i18n = Object.new
|
7
|
-
stub_i18n.
|
42
|
+
allow(stub_i18n).to receive("t")
|
8
43
|
stub_const("I18n", stub_i18n)
|
9
44
|
end
|
10
45
|
|
@@ -24,21 +59,7 @@ describe TranslatedAttributeValue::Base do
|
|
24
59
|
end.new
|
25
60
|
}
|
26
61
|
|
27
|
-
|
28
|
-
expect(test_model_instance.class).to respond_to(:translated_value_for)
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "I can call a attribute with attribute_translated without defining it" do
|
32
|
-
specify "the translation must be called" do
|
33
|
-
expect(I18n).to receive(:t).with("activerecord.attributes.nome_classe.status_translation.my_value")
|
34
|
-
test_model_instance.status_translated
|
35
|
-
end
|
36
|
-
|
37
|
-
specify "the method should be defined" do
|
38
|
-
test_model_instance.status_translated
|
39
|
-
expect(test_model_instance).to respond_to(:status_translated)
|
40
|
-
end
|
41
|
-
end
|
62
|
+
it_behaves_like 'class_with_translated_attribute', "activerecord.attributes.nome_classe.status_translation.my_value"
|
42
63
|
|
43
64
|
end
|
44
65
|
|
@@ -58,24 +79,7 @@ describe TranslatedAttributeValue::Base do
|
|
58
79
|
end.new
|
59
80
|
}
|
60
81
|
|
61
|
-
|
62
|
-
expect(test_model_instance.class).to respond_to(:translated_value_for)
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
describe "I can call a attribute with attribute_translated without defining it" do
|
67
|
-
specify "the translation must be called" do
|
68
|
-
expect(I18n).to receive(:t).with("mongoid.attributes.nome_classe.status_translation.my_value")
|
69
|
-
test_model_instance.status_translated
|
70
|
-
end
|
71
|
-
|
72
|
-
specify "the method should be defined" do
|
73
|
-
test_model_instance.status_translated
|
74
|
-
expect(test_model_instance).to respond_to(:status_translated)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
|
82
|
+
it_behaves_like 'class_with_translated_attribute', "mongoid.attributes.nome_classe.status_translation.my_value"
|
79
83
|
end
|
80
84
|
|
81
85
|
describe 'without ActiveRecord or Mongoid' do
|
@@ -94,23 +98,7 @@ describe TranslatedAttributeValue::Base do
|
|
94
98
|
end.new
|
95
99
|
}
|
96
100
|
|
97
|
-
|
98
|
-
expect(test_model_instance.class).to respond_to(:translated_value_for)
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
describe "I can call a attribute with attribute_translated without defining it" do
|
103
|
-
specify "the translation must be called" do
|
104
|
-
expect(I18n).to receive(:t).with("translated_attribute_value.nome_classe.status_translation.my_value")
|
105
|
-
test_model_instance.status_translated
|
106
|
-
end
|
107
|
-
|
108
|
-
specify "the method should be defined" do
|
109
|
-
test_model_instance.status_translated
|
110
|
-
expect(test_model_instance).to respond_to(:status_translated)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
101
|
+
it_behaves_like 'class_with_translated_attribute', "translated_attribute_value.nome_classe.status_translation.my_value"
|
114
102
|
|
115
103
|
end
|
116
104
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translated_attribute_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinícius Oyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|