mongoid_i18n 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.0.rc)
5
+ activesupport (= 3.0.0.rc)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4.1)
8
+ activesupport (3.0.0.rc)
9
+ bson (1.0.4)
10
+ bson_ext (1.0.4)
11
+ builder (2.1.2)
12
+ diff-lcs (1.1.2)
13
+ gemcutter (0.6.1)
14
+ git (1.2.5)
15
+ i18n (0.4.1)
16
+ jeweler (1.4.0)
17
+ gemcutter (>= 0.1.0)
18
+ git (>= 1.2.5)
19
+ rubyforge (>= 2.0.0)
20
+ json_pure (1.4.6)
21
+ mocha (0.9.8)
22
+ rake
23
+ mongo (1.0.7)
24
+ bson (>= 1.0.4)
25
+ mongoid (2.0.0.beta.16)
26
+ activemodel (= 3.0.0.rc)
27
+ bson (= 1.0.4)
28
+ mongo (= 1.0.7)
29
+ tzinfo (= 0.3.22)
30
+ will_paginate (~> 3.0.pre)
31
+ rake (0.8.7)
32
+ rspec (2.0.0.beta.19)
33
+ rspec-core (= 2.0.0.beta.19)
34
+ rspec-expectations (= 2.0.0.beta.19)
35
+ rspec-mocks (= 2.0.0.beta.19)
36
+ rspec-core (2.0.0.beta.19)
37
+ rspec-expectations (2.0.0.beta.19)
38
+ diff-lcs (>= 1.1.2)
39
+ rspec-mocks (2.0.0.beta.19)
40
+ rubyforge (2.0.4)
41
+ json_pure (>= 1.1.7)
42
+ tzinfo (0.3.22)
43
+ will_paginate (3.0.pre2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bson_ext
50
+ bundler
51
+ jeweler
52
+ mocha
53
+ mongoid (>= 2.0.0.beta.9)
54
+ rspec (>= 2.0.0.beta.8)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/lib/mongoid/i18n.rb CHANGED
@@ -4,21 +4,22 @@ require 'mongoid/i18n/localized_criteria'
4
4
  module Mongoid
5
5
  module I18n
6
6
  extend ActiveSupport::Concern
7
-
7
+
8
8
  module ClassMethods
9
9
  def localized_field(name, options = {})
10
10
  field name, options.merge(:type => LocalizedField)
11
11
  end
12
-
12
+
13
13
  def criteria
14
- I18n::LocalizedCriteria.new(self)
14
+ scope = scope_stack.last rescue nil
15
+ scope || I18n::LocalizedCriteria.new(self)
15
16
  end
16
-
17
+
17
18
  protected
18
19
  def create_accessors(name, meth, options = {})
19
20
  if options[:type] == LocalizedField
20
21
  define_method(meth) { read_attribute(name)[::I18n.locale.to_s] rescue '' }
21
- define_method("#{meth}=") do |value|
22
+ define_method("#{meth}=") do |value|
22
23
  write_attribute(name, (@attributes[name] || {}).merge(::I18n.locale.to_s => value))
23
24
  end
24
25
  define_method("#{meth}_translations") { read_attribute(name) }
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.1.5"
8
+ s.version = "0.1.6"
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{2010-07-29}
12
+ s.date = %q{2010-08-18}
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.
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  ".document",
24
24
  ".gitignore",
25
25
  "Gemfile",
26
+ "Gemfile.lock",
26
27
  "LICENSE",
27
28
  "README.rdoc",
28
29
  "Rakefile",
@@ -40,7 +41,7 @@ Gem::Specification.new do |s|
40
41
  s.homepage = %q{http://github.com/Papipo/mongoid_i18n}
41
42
  s.rdoc_options = ["--charset=UTF-8"]
42
43
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.6}
44
+ s.rubygems_version = %q{1.3.7}
44
45
  s.summary = %q{Mongoid plugin to deal with localizable fields}
45
46
  s.test_files = [
46
47
  "spec/integration/mongoid/i18n_spec.rb",
@@ -53,7 +54,7 @@ Gem::Specification.new do |s|
53
54
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
55
  s.specification_version = 3
55
56
 
56
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
58
  s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0.beta.9"])
58
59
  s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
59
60
  else
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  class Entry
5
5
  include Mongoid::Document
6
6
  include Mongoid::I18n
7
-
7
+
8
8
  localized_field :title
9
9
  field :published, :type => Boolean
10
10
  end
@@ -13,68 +13,68 @@ describe Mongoid::I18n, "localized_field" do
13
13
  before do
14
14
  I18n.locale = :en
15
15
  end
16
-
16
+
17
17
  describe "without an assigned value" do
18
18
  before do
19
19
  @entry = Entry.new
20
20
  end
21
-
21
+
22
22
  it "should return blank" do
23
23
  @entry.title.should be_blank
24
24
  end
25
25
  end
26
-
26
+
27
27
  describe "with an assigned value" do
28
28
  before do
29
29
  @entry = Entry.new(:title => 'Title')
30
30
  end
31
-
31
+
32
32
  describe "and persisted" do
33
33
  before do
34
34
  @entry.save
35
35
  end
36
-
36
+
37
37
  describe "where() criteria" do
38
38
  it "should use the current locale value" do
39
39
  Entry.where(:title => 'Title').first.should == @entry
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe "find(:first) with :conditions" do
44
44
  it "should use the current locale value" do
45
45
  Entry.find(:first, :conditions => {:title => 'Title'}).should == @entry
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  it "should return that value" do
51
51
  @entry.title.should == 'Title'
52
52
  end
53
-
53
+
54
54
  describe "when the locale is changed" do
55
55
  before do
56
56
  I18n.locale = :es
57
57
  end
58
-
58
+
59
59
  it "should return a blank value" do
60
60
  @entry.title.should be_blank
61
61
  end
62
-
62
+
63
63
  describe "a new value is assigned" do
64
64
  before do
65
65
  @entry.title = 'Título'
66
66
  end
67
-
67
+
68
68
  it "should return the new value" do
69
69
  @entry.title.should == 'Título'
70
70
  end
71
-
71
+
72
72
  describe "persisted and retrieved from db" do
73
73
  before do
74
74
  @entry.save
75
75
  @entry = Entry.find(:first, :conditions => {:title => 'Título'})
76
76
  end
77
-
77
+
78
78
  it "the localized field value should be ok" do
79
79
  @entry.title.should == 'Título'
80
80
  I18n.locale = :en
@@ -82,32 +82,32 @@ describe Mongoid::I18n, "localized_field" do
82
82
  @entry.title_translations.should == {'en' => 'Title', 'es' => 'Título'}
83
83
  end
84
84
  end
85
-
85
+
86
86
  describe "getter.translations" do
87
87
  it "should return all translations" do
88
88
  @entry.title_translations.should == {'en' => 'Title', 'es' => 'Título'}
89
89
  end
90
90
  end
91
-
91
+
92
92
  describe "getter.translations=" do
93
93
  before do
94
94
  @entry.title_translations = {'en' => 'New title', 'es' => 'Nuevo título'}
95
95
  end
96
-
96
+
97
97
  it "should accept new translations" do
98
98
  @entry.title_translations.should == {'en' => 'New title', 'es' => 'Nuevo título'}
99
99
  end
100
-
100
+
101
101
  it "the getter should return the new translation" do
102
102
  @entry.title.should == 'Nuevo título'
103
103
  end
104
104
  end
105
-
105
+
106
106
  describe "and we go back to the original locale" do
107
107
  before do
108
108
  I18n.locale = :en
109
109
  end
110
-
110
+
111
111
  it "should return the original value" do
112
112
  @entry.title.should == 'Title'
113
113
  end
@@ -115,4 +115,29 @@ describe Mongoid::I18n, "localized_field" do
115
115
  end
116
116
  end
117
117
  end
118
+ end
119
+
120
+ describe Mongoid::I18n, 'criteria on embeds_many association' do
121
+ before do
122
+ class Entry
123
+ embeds_many :sub_entries
124
+ end
125
+
126
+ class SubEntry
127
+ include Mongoid::Document
128
+ include Mongoid::I18n
129
+ localized_field :title
130
+ embedded_in :entry, :inverse_of => :sub_entries
131
+ end
132
+ @entry = Entry.new
133
+ @sub_entries = (0..2).map { @entry.sub_entries.build }
134
+ end
135
+
136
+ it "should return a LocalizedCriteria" do
137
+ @entry.sub_entries.criteria.should be_a(Mongoid::I18n::LocalizedCriteria)
138
+ end
139
+
140
+ it "should contain the embedded documents" do
141
+ @entry.sub_entries.criteria.instance_variable_get("@documents").should == @sub_entries
142
+ end
118
143
  end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe Mongoid::I18n::LocalizedCriteria do
4
4
  describe "where" do
5
5
  before do
6
- klass = stub(:fields => {'title' => mock(:type => Mongoid::I18n::LocalizedField), 'published' => mock(:type => Boolean)})
6
+ @title = Mongoid::Field.new(:title, :type => Mongoid::I18n::LocalizedField)
7
+ @published = Mongoid::Field.new(:published, :type => Boolean)
8
+ klass = stub(:fields => {'title' => @title, 'published' => @published})
7
9
  @criteria = Mongoid::I18n::LocalizedCriteria.new(klass)
8
10
  @criteria.where(:title.in => ['Title'], :published => true)
9
11
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_i18n
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 5
9
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Rodrigo \xC3\x81lvarez"
@@ -14,14 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-29 00:00:00 +02:00
18
+ date: 2010-08-18 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ name: mongoid
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
22
26
  requirements:
23
27
  - - ">="
24
28
  - !ruby/object:Gem::Version
29
+ hash: 62196465
25
30
  segments:
26
31
  - 2
27
32
  - 0
@@ -29,15 +34,17 @@ dependencies:
29
34
  - beta
30
35
  - 9
31
36
  version: 2.0.0.beta.9
32
- requirement: *id001
33
- prerelease: false
34
37
  type: :runtime
35
- name: mongoid
38
+ version_requirements: *id001
36
39
  - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ name: rspec
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
38
44
  requirements:
39
45
  - - ">="
40
46
  - !ruby/object:Gem::Version
47
+ hash: 62196467
41
48
  segments:
42
49
  - 2
43
50
  - 0
@@ -45,10 +52,8 @@ dependencies:
45
52
  - beta
46
53
  - 8
47
54
  version: 2.0.0.beta.8
48
- requirement: *id002
49
- prerelease: false
50
55
  type: :development
51
- name: rspec
56
+ version_requirements: *id002
52
57
  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 "
53
58
  email: papipo@gmail.com
54
59
  executables: []
@@ -62,6 +67,7 @@ files:
62
67
  - .document
63
68
  - .gitignore
64
69
  - Gemfile
70
+ - Gemfile.lock
65
71
  - LICENSE
66
72
  - README.rdoc
67
73
  - Rakefile
@@ -85,23 +91,27 @@ rdoc_options:
85
91
  require_paths:
86
92
  - lib
87
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
88
95
  requirements:
89
96
  - - ">="
90
97
  - !ruby/object:Gem::Version
98
+ hash: 3
91
99
  segments:
92
100
  - 0
93
101
  version: "0"
94
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
95
104
  requirements:
96
105
  - - ">="
97
106
  - !ruby/object:Gem::Version
107
+ hash: 3
98
108
  segments:
99
109
  - 0
100
110
  version: "0"
101
111
  requirements: []
102
112
 
103
113
  rubyforge_project:
104
- rubygems_version: 1.3.6
114
+ rubygems_version: 1.3.7
105
115
  signing_key:
106
116
  specification_version: 3
107
117
  summary: Mongoid plugin to deal with localizable fields