mongoid_i18n 0.2.1 → 0.3.0
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.
- data/Gemfile +1 -7
- data/Gemfile.lock +15 -8
- data/README.rdoc +18 -1
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/config/locales/en.yml +8 -0
- data/lib/mongoid/i18n.rb +28 -3
- data/lib/mongoid/i18n/criterion/selector.rb +1 -1
- data/lib/mongoid/i18n/localized_validator.rb +27 -0
- data/mongoid_i18n.gemspec +26 -16
- data/spec/integration/mongoid/i18n_spec.rb +209 -2
- metadata +81 -26
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongoid_i18n (0.2.1)
|
5
|
+
bson_ext (~> 1.2)
|
6
|
+
mongoid (>= 2.0.0)
|
7
|
+
mongoid_i18n
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: http://rubygems.org/
|
3
11
|
specs:
|
4
|
-
activemodel (3.0.
|
5
|
-
activesupport (= 3.0.
|
12
|
+
activemodel (3.0.7)
|
13
|
+
activesupport (= 3.0.7)
|
6
14
|
builder (~> 2.1.2)
|
7
15
|
i18n (~> 0.5.0)
|
8
|
-
activesupport (3.0.
|
16
|
+
activesupport (3.0.7)
|
9
17
|
bson (1.3.0)
|
10
18
|
bson_ext (1.3.0)
|
11
19
|
builder (2.1.2)
|
12
20
|
diff-lcs (1.1.2)
|
13
21
|
git (1.2.5)
|
14
22
|
i18n (0.5.0)
|
15
|
-
jeweler (1.
|
23
|
+
jeweler (1.6.0)
|
16
24
|
bundler (~> 1.0.0)
|
17
25
|
git (>= 1.2.5)
|
18
26
|
rake
|
@@ -29,20 +37,19 @@ GEM
|
|
29
37
|
rspec-core (~> 2.5.0)
|
30
38
|
rspec-expectations (~> 2.5.0)
|
31
39
|
rspec-mocks (~> 2.5.0)
|
32
|
-
rspec-core (2.5.
|
40
|
+
rspec-core (2.5.2)
|
33
41
|
rspec-expectations (2.5.0)
|
34
42
|
diff-lcs (~> 1.1.2)
|
35
43
|
rspec-mocks (2.5.0)
|
36
|
-
tzinfo (0.3.
|
44
|
+
tzinfo (0.3.27)
|
37
45
|
will_paginate (3.0.pre2)
|
38
46
|
|
39
47
|
PLATFORMS
|
40
48
|
ruby
|
41
49
|
|
42
50
|
DEPENDENCIES
|
43
|
-
bson_ext (~> 1.2)
|
44
51
|
bundler
|
45
52
|
jeweler
|
46
53
|
mocha
|
47
|
-
|
54
|
+
mongoid_i18n!
|
48
55
|
rspec
|
data/README.rdoc
CHANGED
@@ -28,7 +28,24 @@ This will allow you to do stuff like this:
|
|
28
28
|
|
29
29
|
@entry.title_translations # this returns a hash: {'en' => 'Title', 'es' => 'Title'}
|
30
30
|
@entry.title_translations = {'en' => 'New title', 'es' => 'Nuevo título} # You can always mass-assign.
|
31
|
-
|
31
|
+
|
32
|
+
The localized_field helper has two options (set to false as default):
|
33
|
+
-- credits to @nicolaracco & @ogeidix
|
34
|
+
localized_field :title, :clear_empty_values => true # This will remove all blank values when you do a mass assignment
|
35
|
+
localized_field :title, :use_default_if_empty => true # This will return the value assigned to the default locale, if there isn't a value for the current locale
|
36
|
+
|
37
|
+
localized_field :title, :clear_empty_values => true, :use_default_if_empty => true # When you do mass assignment, empty values are removed. If you try to get a 'removed' value, it will return the default value
|
38
|
+
|
39
|
+
With the last case:
|
40
|
+
@entry.title_translations = { 'en' => 'New title', 'es' => '' } # It will store only the 'en' value
|
41
|
+
@entry.title_translations[:es] # => New title
|
42
|
+
|
43
|
+
There are validation helper to manage locale fields:
|
44
|
+
-- credits to @nicolaracco & @ogeidix
|
45
|
+
validates_default_locale :title # The field has to contain at least the default translation
|
46
|
+
validates_one_locale :title # The field has to contain at least one translation
|
47
|
+
validates_all_locales :title # The field has to contain a translation for each available locale
|
48
|
+
|
32
49
|
Criteria is handled for you:
|
33
50
|
|
34
51
|
I18n.locale = :en
|
data/Rakefile
CHANGED
@@ -17,7 +17,12 @@ begin
|
|
17
17
|
gem.homepage = "http://github.com/Papipo/mongoid_i18n"
|
18
18
|
gem.authors = ["Rodrigo Álvarez"]
|
19
19
|
gem.add_dependency "mongoid", '>= 2.0.0'
|
20
|
+
gem.add_dependency "bson_ext", "~> 1.2"
|
20
21
|
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "mocha"
|
23
|
+
gem.add_development_dependency "jeweler"
|
24
|
+
gem.add_development_dependency "bundler"
|
25
|
+
|
21
26
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
27
|
end
|
23
28
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/mongoid/i18n.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'mongoid/i18n/localized_field'
|
2
2
|
require 'mongoid/i18n/criterion/selector'
|
3
|
+
require 'mongoid/i18n/localized_validator'
|
4
|
+
|
5
|
+
# add english load path by default
|
6
|
+
I18n.load_path << File.join(File.dirname(__FILE__), "..", "..", "config", "locales", "en.yml")
|
3
7
|
|
4
8
|
module Mongoid
|
5
9
|
module I18n
|
@@ -7,23 +11,44 @@ module Mongoid
|
|
7
11
|
|
8
12
|
module ClassMethods
|
9
13
|
def localized_field(name, options = {})
|
10
|
-
field name, options.merge(:type => LocalizedField)
|
14
|
+
field name, options.merge(:type => LocalizedField, :default => LocalizedField.new)
|
15
|
+
end
|
16
|
+
|
17
|
+
def validates_default_locale(names, options = {})
|
18
|
+
validates_with LocalizedValidator, options.merge(:mode => :only_default, :attributes => names)
|
19
|
+
end
|
20
|
+
|
21
|
+
def validates_one_locale(names, options = {})
|
22
|
+
validates_with LocalizedValidator, options.merge(:mode => :one_locale, :attributes => names)
|
23
|
+
end
|
24
|
+
|
25
|
+
def validates_all_locales(names, options = {})
|
26
|
+
validates_with LocalizedValidator, options.merge(:mode => :all_locales, :attributes => names)
|
11
27
|
end
|
12
28
|
|
13
29
|
protected
|
14
30
|
def create_accessors(name, meth, options = {})
|
15
31
|
if options[:type] == LocalizedField
|
16
|
-
|
32
|
+
if options[:use_default_if_empty]
|
33
|
+
define_method(meth) { read_attribute(name)[::I18n.locale.to_s] || read_attribute(name)[::I18n.default_locale.to_s] rescue ''}
|
34
|
+
else
|
35
|
+
define_method(meth) { read_attribute(name)[::I18n.locale.to_s] rescue '' }
|
36
|
+
end
|
17
37
|
define_method("#{meth}=") do |value|
|
18
38
|
value = if value.is_a?(Hash)
|
19
39
|
(@attributes[name] || {}).merge(value)
|
20
40
|
else
|
21
41
|
(@attributes[name] || {}).merge(::I18n.locale.to_s => value)
|
22
42
|
end
|
43
|
+
value = value.delete_if { |key, value| value.blank? } if options[:clear_empty_values]
|
23
44
|
write_attribute(name, value)
|
24
45
|
end
|
25
46
|
define_method("#{meth}_translations") { read_attribute(name) }
|
26
|
-
|
47
|
+
if options[:clear_empty_values]
|
48
|
+
define_method("#{meth}_translations=") { |value| write_attribute(name, value.delete_if { |key, value| value.blank? }) }
|
49
|
+
else
|
50
|
+
define_method("#{meth}_translations=") { |value| write_attribute(name, value) }
|
51
|
+
end
|
27
52
|
else
|
28
53
|
super
|
29
54
|
end
|
@@ -2,7 +2,7 @@ module Mongoid
|
|
2
2
|
module Criterion
|
3
3
|
class Selector< Hash
|
4
4
|
def []=(key, value)
|
5
|
-
key = "#{key}.#{::I18n.locale}" if fields[key.to_s].type == Mongoid::I18n::LocalizedField
|
5
|
+
key = "#{key}.#{::I18n.locale}" if fields[key.to_s].try(:type) == Mongoid::I18n::LocalizedField
|
6
6
|
super
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module I18n
|
3
|
+
class LocalizedValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each record, attribute, value
|
5
|
+
if options[:mode] == :only_default
|
6
|
+
if record.send("#{attribute}_translations")[::I18n.default_locale.to_s].blank?
|
7
|
+
record.errors.add(attribute, :locale_blank, options.except(:mode).merge(
|
8
|
+
:cur_locale => ::I18n.t(:"locales.#{::I18n.default_locale}", :default => ::I18n.default_locale.to_s)
|
9
|
+
))
|
10
|
+
end
|
11
|
+
elsif options[:mode] == :one_locale
|
12
|
+
record.errors.add(attribute, :all_locales_blank, options.except(:mode)) if record.send("#{attribute}_translations").empty?
|
13
|
+
elsif options[:mode] == :all_locales
|
14
|
+
#difference between available locales and stored locales
|
15
|
+
diffloc = ::I18n.available_locales - record.send("#{attribute}_translations").keys.collect { |key| key.to_sym }
|
16
|
+
|
17
|
+
#print an error for each missing locale
|
18
|
+
diffloc.each do |locale|
|
19
|
+
record.errors.add(attribute, :locale_blank, options.except(:mode).merge(
|
20
|
+
:cur_locale => ::I18n.t(:"locales.#{locale}", :default => locale.to_s)
|
21
|
+
))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/mongoid_i18n.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid_i18n}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rodrigo \303\201lvarez"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-05-08}
|
13
13
|
s.description = %q{This gem aims to be a transparent way to deal with localizable fields.
|
14
14
|
Basically use localized_field() instead of field() and that's it.
|
15
15
|
It will take care of locales for you when using find or criteria.
|
@@ -28,9 +28,11 @@ Gem::Specification.new do |s|
|
|
28
28
|
"README.rdoc",
|
29
29
|
"Rakefile",
|
30
30
|
"VERSION",
|
31
|
+
"config/locales/en.yml",
|
31
32
|
"lib/mongoid/i18n.rb",
|
32
33
|
"lib/mongoid/i18n/criterion/selector.rb",
|
33
34
|
"lib/mongoid/i18n/localized_field.rb",
|
35
|
+
"lib/mongoid/i18n/localized_validator.rb",
|
34
36
|
"mongoid_i18n.gemspec",
|
35
37
|
"spec/.rspec",
|
36
38
|
"spec/integration/mongoid/i18n_spec.rb",
|
@@ -40,42 +42,50 @@ Gem::Specification.new do |s|
|
|
40
42
|
s.require_paths = ["lib"]
|
41
43
|
s.rubygems_version = %q{1.6.2}
|
42
44
|
s.summary = %q{Mongoid plugin to deal with localizable fields}
|
43
|
-
s.test_files = [
|
44
|
-
"spec/integration/mongoid/i18n_spec.rb",
|
45
|
-
"spec/spec_helper.rb"
|
46
|
-
]
|
47
45
|
|
48
46
|
if s.respond_to? :specification_version then
|
49
47
|
s.specification_version = 3
|
50
48
|
|
51
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_runtime_dependency(%q<
|
53
|
-
s.
|
54
|
-
s.
|
55
|
-
s.
|
56
|
-
s.
|
57
|
-
s.
|
50
|
+
s.add_runtime_dependency(%q<mongoid_i18n>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
58
56
|
s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0"])
|
57
|
+
s.add_runtime_dependency(%q<bson_ext>, ["~> 1.2"])
|
59
58
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
60
62
|
else
|
61
|
-
s.add_dependency(%q<
|
62
|
-
s.add_dependency(%q<
|
63
|
+
s.add_dependency(%q<mongoid_i18n>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
63
65
|
s.add_dependency(%q<rspec>, [">= 0"])
|
64
66
|
s.add_dependency(%q<mocha>, [">= 0"])
|
65
67
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
68
|
s.add_dependency(%q<bundler>, [">= 0"])
|
67
69
|
s.add_dependency(%q<mongoid>, [">= 2.0.0"])
|
70
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.2"])
|
68
71
|
s.add_dependency(%q<rspec>, [">= 0"])
|
72
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
73
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
69
75
|
end
|
70
76
|
else
|
71
|
-
s.add_dependency(%q<
|
72
|
-
s.add_dependency(%q<
|
77
|
+
s.add_dependency(%q<mongoid_i18n>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
73
79
|
s.add_dependency(%q<rspec>, [">= 0"])
|
74
80
|
s.add_dependency(%q<mocha>, [">= 0"])
|
75
81
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
76
82
|
s.add_dependency(%q<bundler>, [">= 0"])
|
77
83
|
s.add_dependency(%q<mongoid>, [">= 2.0.0"])
|
84
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.2"])
|
78
85
|
s.add_dependency(%q<rspec>, [">= 0"])
|
86
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
87
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
88
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
79
89
|
end
|
80
90
|
end
|
81
91
|
|
@@ -6,6 +6,21 @@ class Entry
|
|
6
6
|
include Mongoid::I18n
|
7
7
|
|
8
8
|
localized_field :title
|
9
|
+
localized_field :title_with_default, :use_default_if_empty => true
|
10
|
+
localized_field :title_without_empty_values, :clear_empty_values => true
|
11
|
+
end
|
12
|
+
|
13
|
+
class EntryWithValidations
|
14
|
+
include Mongoid::Document
|
15
|
+
include Mongoid::I18n
|
16
|
+
|
17
|
+
localized_field :title_validated_with_default_locale
|
18
|
+
localized_field :title_validated_with_one_locale
|
19
|
+
localized_field :title_validated_with_all_locales
|
20
|
+
|
21
|
+
validates_default_locale :title_validated_with_default_locale
|
22
|
+
validates_one_locale :title_validated_with_one_locale
|
23
|
+
validates_all_locales :title_validated_with_all_locales
|
9
24
|
end
|
10
25
|
|
11
26
|
describe Mongoid::I18n, "localized_field" do
|
@@ -27,7 +42,7 @@ describe Mongoid::I18n, "localized_field" do
|
|
27
42
|
before do
|
28
43
|
@entry = Entry.new(:title => 'Title')
|
29
44
|
end
|
30
|
-
|
45
|
+
|
31
46
|
it "should return that value" do
|
32
47
|
@entry.title.should == 'Title'
|
33
48
|
end
|
@@ -37,6 +52,12 @@ describe Mongoid::I18n, "localized_field" do
|
|
37
52
|
@entry.save
|
38
53
|
end
|
39
54
|
|
55
|
+
describe "find by id" do
|
56
|
+
it "should find the document" do
|
57
|
+
Entry.find(@entry.id).should == @entry
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
40
61
|
describe "where() criteria" do
|
41
62
|
it "should use the current locale value" do
|
42
63
|
Entry.where(:title => 'Title').first.should == @entry
|
@@ -156,4 +177,190 @@ describe Mongoid::I18n, 'localized field in embedded document' do
|
|
156
177
|
it "should store the title in the right locale" do
|
157
178
|
@entry.reload.sub_entry.subtitle.should == 'Oxford Street'
|
158
179
|
end
|
159
|
-
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe Mongoid::I18n, "localized_field with :use_default_if_empty => true" do
|
183
|
+
before do
|
184
|
+
I18n.default_locale = :en
|
185
|
+
I18n.locale = :en
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "without an assigned value" do
|
189
|
+
before do
|
190
|
+
@entry = Entry.new
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should return blank" do
|
194
|
+
@entry.title_with_default.should be_blank
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "with an assigned value in the default locale" do
|
199
|
+
before do
|
200
|
+
@entry = Entry.new(:title_with_default => 'Title with default')
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return that value with the default locale" do
|
204
|
+
@entry.title_with_default.should == 'Title with default'
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "when the locale is changed" do
|
208
|
+
before do
|
209
|
+
I18n.locale = :it
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return the value of the default locale" do
|
213
|
+
@entry.title_with_default.should == 'Title with default'
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "when a new value is assigned" do
|
217
|
+
before do
|
218
|
+
@entry.title_with_default = 'Titolo con default'
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should return the new value" do
|
222
|
+
@entry.title_with_default.should == 'Titolo con default'
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "if we go back to the original locale" do
|
226
|
+
before do
|
227
|
+
I18n.locale = :en
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should return the original value" do
|
231
|
+
@entry.title_with_default.should == 'Title with default'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe Mongoid::I18n, "localized_field with :clear_empty_values => true" do
|
240
|
+
describe "when are assigned two translations" do
|
241
|
+
before do
|
242
|
+
I18n.locale = :en
|
243
|
+
@entry = Entry.new
|
244
|
+
@entry.title_without_empty_values_translations = {"en" => "Title en", "it" => "Title it"}
|
245
|
+
end
|
246
|
+
|
247
|
+
it "has those translations" do
|
248
|
+
@entry.title_without_empty_values_translations.should == {"en" => "Title en", "it" => "Title it"}
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "when is set to a blank value" do
|
252
|
+
before do
|
253
|
+
@entry.title_without_empty_values = ''
|
254
|
+
end
|
255
|
+
|
256
|
+
it "lose current locale translation" do
|
257
|
+
@entry.title_without_empty_values_translations.should == {"it" => "Title it"}
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "when is assigned a blank translation" do
|
262
|
+
before do
|
263
|
+
@entry.title_without_empty_values_translations = {"it" => "", "en" => "Title en"}
|
264
|
+
end
|
265
|
+
|
266
|
+
it "lose that translation" do
|
267
|
+
@entry.title_without_empty_values_translations.should == {"en" => "Title en"}
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe Mongoid::I18n, "localized_field with validation 'validates_default_locale'" do
|
274
|
+
before do
|
275
|
+
I18n.default_locale = :en
|
276
|
+
I18n.locale = :it
|
277
|
+
@entry = EntryWithValidations.new
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "when run entry validations and default locale translation wasn't set" do
|
281
|
+
before do
|
282
|
+
@entry.title_validated_with_default_locale="Titolo"
|
283
|
+
@entry.valid?
|
284
|
+
end
|
285
|
+
|
286
|
+
it "is added a 'locale_blank' error for that field to entry errors list" do
|
287
|
+
@entry.errors.include?(:title_validated_with_default_locale).should be_true
|
288
|
+
@entry.errors[:title_validated_with_default_locale][0].split('.').last.should == 'locale_blank'
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "when run entry validations and default locale translation was set" do
|
293
|
+
before do
|
294
|
+
@entry.title_validated_with_default_locale_translations={'en'=>'Title'}
|
295
|
+
@entry.valid?
|
296
|
+
end
|
297
|
+
|
298
|
+
it "no error for that field is added to entry errors list" do
|
299
|
+
@entry.errors.include?(:title_validated_with_default_locale).should be_false
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe Mongoid::I18n, "localized_field with validation 'validates_one_locale'" do
|
305
|
+
before do
|
306
|
+
I18n.default_locale = :en
|
307
|
+
I18n.locale = :it
|
308
|
+
@entry = EntryWithValidations.new
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "when run entry validations and no translation was set" do
|
312
|
+
before do
|
313
|
+
@entry.valid?
|
314
|
+
end
|
315
|
+
|
316
|
+
it "is added a 'locale_blank' error for that field to entry errors list" do
|
317
|
+
@entry.errors.include?(:title_validated_with_one_locale).should be_true
|
318
|
+
@entry.errors[:title_validated_with_one_locale][0].split('.').last.should == 'all_locales_blank'
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "when run entry validations and a locale translation was set" do
|
323
|
+
before do
|
324
|
+
@entry.title_validated_with_one_locale_translations={'it'=>'Titolo'}
|
325
|
+
@entry.valid?
|
326
|
+
end
|
327
|
+
|
328
|
+
it "no error for that field is added to entry errors list" do
|
329
|
+
@entry.errors.include?(:title_validated_with_one_locale).should be_false
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe Mongoid::I18n, "localized_field with validation 'validates_all_locales'" do
|
335
|
+
before do
|
336
|
+
I18n.default_locale = :en
|
337
|
+
I18n.available_locales = [:en, :it, :de, :fr]
|
338
|
+
I18n.locale = :it
|
339
|
+
@entry = EntryWithValidations.new
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "when run entry validations and not all translations were set" do
|
343
|
+
before do
|
344
|
+
@entry.title_validated_with_all_locales_translations={'it'=>'Titolo', 'en'=>'Title'}
|
345
|
+
@entry.valid?
|
346
|
+
end
|
347
|
+
|
348
|
+
it "is added a 'locale_blank' error for that field for each missing locale" do
|
349
|
+
@entry.errors.include?(:title_validated_with_all_locales).should be_true
|
350
|
+
@entry.errors[:title_validated_with_all_locales].count.should == 2
|
351
|
+
@entry.errors[:title_validated_with_all_locales][0].split('.').last.should == 'locale_blank'
|
352
|
+
@entry.errors[:title_validated_with_all_locales][1].split('.').last.should == 'locale_blank'
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "when run entry validations and all available locales translation were set" do
|
357
|
+
before do
|
358
|
+
@entry.title_validated_with_all_locales_translations={'it'=>'Titolo', 'en'=>'Title', 'fr'=>'Titre', 'de'=>'Titel'}
|
359
|
+
@entry.valid?
|
360
|
+
end
|
361
|
+
|
362
|
+
it "no error for that field is added to entry errors list" do
|
363
|
+
@entry.errors.include?(:title_validated_with_all_locales).should be_false
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Rodrigo \xC3\x81lvarez"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,34 +24,31 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 3
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
|
34
|
-
name: bson_ext
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
name: mongoid_i18n
|
35
34
|
version_requirements: *id001
|
36
35
|
- !ruby/object:Gem::Dependency
|
37
36
|
prerelease: false
|
38
|
-
type: :
|
37
|
+
type: :development
|
39
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ">="
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
43
|
+
hash: 3
|
45
44
|
segments:
|
46
|
-
- 2
|
47
|
-
- 0
|
48
45
|
- 0
|
49
|
-
version:
|
50
|
-
name:
|
46
|
+
version: "0"
|
47
|
+
name: rspec
|
51
48
|
version_requirements: *id002
|
52
49
|
- !ruby/object:Gem::Dependency
|
53
50
|
prerelease: false
|
54
|
-
type: :
|
51
|
+
type: :development
|
55
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
53
|
none: false
|
57
54
|
requirements:
|
@@ -65,7 +62,7 @@ dependencies:
|
|
65
62
|
version_requirements: *id003
|
66
63
|
- !ruby/object:Gem::Dependency
|
67
64
|
prerelease: false
|
68
|
-
type: :
|
65
|
+
type: :development
|
69
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
67
|
none: false
|
71
68
|
requirements:
|
@@ -79,7 +76,7 @@ dependencies:
|
|
79
76
|
version_requirements: *id004
|
80
77
|
- !ruby/object:Gem::Dependency
|
81
78
|
prerelease: false
|
82
|
-
type: :
|
79
|
+
type: :development
|
83
80
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
81
|
none: false
|
85
82
|
requirements:
|
@@ -93,7 +90,7 @@ dependencies:
|
|
93
90
|
version_requirements: *id005
|
94
91
|
- !ruby/object:Gem::Dependency
|
95
92
|
prerelease: false
|
96
|
-
type: :
|
93
|
+
type: :development
|
97
94
|
requirement: &id006 !ruby/object:Gem::Requirement
|
98
95
|
none: false
|
99
96
|
requirements:
|
@@ -123,8 +120,23 @@ dependencies:
|
|
123
120
|
version_requirements: *id007
|
124
121
|
- !ruby/object:Gem::Dependency
|
125
122
|
prerelease: false
|
126
|
-
type: :
|
123
|
+
type: :runtime
|
127
124
|
requirement: &id008 !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ~>
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 11
|
130
|
+
segments:
|
131
|
+
- 1
|
132
|
+
- 2
|
133
|
+
version: "1.2"
|
134
|
+
name: bson_ext
|
135
|
+
version_requirements: *id008
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
prerelease: false
|
138
|
+
type: :development
|
139
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
128
140
|
none: false
|
129
141
|
requirements:
|
130
142
|
- - ">="
|
@@ -134,7 +146,49 @@ dependencies:
|
|
134
146
|
- 0
|
135
147
|
version: "0"
|
136
148
|
name: rspec
|
137
|
-
version_requirements: *
|
149
|
+
version_requirements: *id009
|
150
|
+
- !ruby/object:Gem::Dependency
|
151
|
+
prerelease: false
|
152
|
+
type: :development
|
153
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
name: mocha
|
163
|
+
version_requirements: *id010
|
164
|
+
- !ruby/object:Gem::Dependency
|
165
|
+
prerelease: false
|
166
|
+
type: :development
|
167
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 3
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
name: jeweler
|
177
|
+
version_requirements: *id011
|
178
|
+
- !ruby/object:Gem::Dependency
|
179
|
+
prerelease: false
|
180
|
+
type: :development
|
181
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
hash: 3
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
version: "0"
|
190
|
+
name: bundler
|
191
|
+
version_requirements: *id012
|
138
192
|
description: "This gem aims to be a transparent way to deal with localizable fields.\n Basically use localized_field() instead of field() and that's it.\n It will take care of locales for you when using find or criteria.\n "
|
139
193
|
email: papipo@gmail.com
|
140
194
|
executables: []
|
@@ -153,9 +207,11 @@ files:
|
|
153
207
|
- README.rdoc
|
154
208
|
- Rakefile
|
155
209
|
- VERSION
|
210
|
+
- config/locales/en.yml
|
156
211
|
- lib/mongoid/i18n.rb
|
157
212
|
- lib/mongoid/i18n/criterion/selector.rb
|
158
213
|
- lib/mongoid/i18n/localized_field.rb
|
214
|
+
- lib/mongoid/i18n/localized_validator.rb
|
159
215
|
- mongoid_i18n.gemspec
|
160
216
|
- spec/.rspec
|
161
217
|
- spec/integration/mongoid/i18n_spec.rb
|
@@ -194,6 +250,5 @@ rubygems_version: 1.6.2
|
|
194
250
|
signing_key:
|
195
251
|
specification_version: 3
|
196
252
|
summary: Mongoid plugin to deal with localizable fields
|
197
|
-
test_files:
|
198
|
-
|
199
|
-
- spec/spec_helper.rb
|
253
|
+
test_files: []
|
254
|
+
|