globalize-accessors 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/globalize-accessors.gemspec +3 -11
- data/lib/globalize-accessors.rb +2 -1
- data/lib/globalize-accessors/version.rb +1 -1
- data/test/globalize_accessors_test.rb +24 -21
- data/test/test_helper.rb +2 -1
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3229262ee8f633268283f5d27f9530b3ee419d8f
|
4
|
+
data.tar.gz: 791ffbdfa8071c57411f9e00f9366a3b242731d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31cadd05e47d9c3b701527d4e70b551ad542a2594fa0f0c18c6064b9cb669bfc8c473568e286fb68a6784010d9f251f41fe93dbb4d3bd80cd80c44d1d0d9c92a
|
7
|
+
data.tar.gz: da7ac8bb04ae0993b630203065750694abd8b372192d6ae706b2daf46b6deec78602443daa2c6ffd0c21c7a4e7d131b07ff6b9744148fd9dfea7e305207f0ed6
|
data/globalize-accessors.gemspec
CHANGED
@@ -14,19 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.required_rubygems_version = ">= 1.3"
|
15
15
|
s.rubyforge_project = "globalize-accessors"
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
elsif ENV['RAILS_4']
|
20
|
-
s.add_dependency "globalize", "~> 4.0.0.alpha.1"
|
21
|
-
else
|
22
|
-
s.add_dependency "globalize", ">= 3"
|
23
|
-
end
|
24
|
-
|
25
|
-
s.add_development_dependency "bundler", ">= 1.3.5"
|
17
|
+
s.add_dependency "globalize", "~> 5.0.0"
|
18
|
+
s.add_development_dependency "bundler", "~> 1.7.2"
|
26
19
|
s.add_development_dependency "rake", "~> 0.9.2"
|
27
20
|
s.add_development_dependency "sqlite3"
|
28
|
-
s.add_development_dependency "minitest", "~>
|
29
|
-
|
21
|
+
s.add_development_dependency "minitest", "~> 5.1"
|
30
22
|
|
31
23
|
s.files = `git ls-files`.split("\n")
|
32
24
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
data/lib/globalize-accessors.rb
CHANGED
@@ -36,8 +36,9 @@ module Globalize::Accessors
|
|
36
36
|
localized_attr_name = localized_attr_name_for(attr_name, locale)
|
37
37
|
|
38
38
|
define_method :"#{localized_attr_name}=" do |value|
|
39
|
+
return if !translation_caches[locale] && value.blank?
|
39
40
|
write_attribute(attr_name, value, :locale => locale)
|
40
|
-
translation_for(locale)[attr_name] = value
|
41
|
+
translation_for(locale)[attr_name] = value
|
41
42
|
end
|
42
43
|
if respond_to?(:accessible_attributes) && accessible_attributes.include?(attr_name)
|
43
44
|
attr_accessible :"#{localized_attr_name}"
|
@@ -17,19 +17,11 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class UnitInheritedWithOptions < ActiveRecord::Base
|
20
|
+
self.table_name = :units
|
20
21
|
translates :color
|
21
22
|
globalize_accessors :locales => [:de], :attributes => [:color]
|
22
23
|
end
|
23
24
|
|
24
|
-
if ENV['RAILS_3']
|
25
|
-
class UnitWithAttrAccessible < ActiveRecord::Base
|
26
|
-
self.table_name = :units
|
27
|
-
attr_accessible :name
|
28
|
-
translates :name, :title
|
29
|
-
globalize_accessors
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
25
|
class UnitWithDashedLocales < ActiveRecord::Base
|
34
26
|
self.table_name = :units
|
35
27
|
translates :name
|
@@ -74,6 +66,29 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
74
66
|
assert_equal 0, u.translations.size
|
75
67
|
end
|
76
68
|
|
69
|
+
test "doesn't build translations without values even after saving" do
|
70
|
+
u = Unit.new(:name_en => nil, :title_pl => " ")
|
71
|
+
u.save
|
72
|
+
|
73
|
+
# On Rails 4, Globalize will always create an empty translation for
|
74
|
+
# the default locale
|
75
|
+
# On Rails 3, Globalize will never create a translation
|
76
|
+
assert u.translated_locales.exclude?(:pl)
|
77
|
+
end
|
78
|
+
|
79
|
+
test "persisted translations can be set to empty values" do
|
80
|
+
u = Unit.new(:name_en => "test")
|
81
|
+
u.save
|
82
|
+
u.name_en = ""
|
83
|
+
assert_equal "", u.translations.first.name
|
84
|
+
end
|
85
|
+
|
86
|
+
test "not persisted translations can be set to empty values" do
|
87
|
+
u = Unit.new(:name_en => "test")
|
88
|
+
u.name_en = ""
|
89
|
+
assert_equal "", u.translations.first.name
|
90
|
+
end
|
91
|
+
|
77
92
|
test "write on new object and read on saved" do
|
78
93
|
u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
|
79
94
|
|
@@ -137,18 +152,6 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
137
152
|
assert_equal "Name pl", u.name_pl
|
138
153
|
end
|
139
154
|
|
140
|
-
if ENV['RAILS_3']
|
141
|
-
test "whitelist locale accessors if the original attribute is whitelisted" do
|
142
|
-
u = UnitWithAttrAccessible.new()
|
143
|
-
u.update_attributes(:name => "Name en", :name_pl => "Name pl", :title => "Title en", :title_pl => "Title pl")
|
144
|
-
|
145
|
-
assert_equal "Name en", u.name
|
146
|
-
assert_equal "Name pl", u.name_pl
|
147
|
-
assert_nil u.title
|
148
|
-
assert_nil u.title_pl
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
155
|
test "globalize locales on class without locales specified in options" do
|
153
156
|
assert_equal [:en, :pl], Unit.globalize_locales
|
154
157
|
end
|
data/test/test_helper.rb
CHANGED
@@ -12,6 +12,7 @@ plugin_test_dir = File.dirname(__FILE__)
|
|
12
12
|
|
13
13
|
ActiveRecord::Base.logger = Logger.new(File.join(plugin_test_dir, "debug.log"))
|
14
14
|
ActiveRecord::Base.configurations = YAML::load( IO.read( File.join(plugin_test_dir, 'db', 'database.yml') ) )
|
15
|
-
ActiveRecord::Base.establish_connection(
|
15
|
+
ActiveRecord::Base.establish_connection(:sqlite3mem)
|
16
16
|
ActiveRecord::Migration.verbose = false
|
17
|
+
ActiveSupport::TestCase.test_order = :sorted
|
17
18
|
load(File.join(plugin_test_dir, "db", "schema.rb"))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globalize-accessors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Stachewicz
|
@@ -12,36 +12,36 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: globalize
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - "~>"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 5.0.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - "
|
28
|
+
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
30
|
+
version: 5.0.0
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: bundler
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- - "
|
35
|
+
- - "~>"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
37
|
+
version: 1.7.2
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - "
|
42
|
+
- - "~>"
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.
|
44
|
+
version: 1.7.2
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: rake
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,14 +76,14 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
79
|
+
version: '5.1'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '
|
86
|
+
version: '5.1'
|
87
87
|
description: Define methods for accessing translated attributes
|
88
88
|
email:
|
89
89
|
- tomekrs@o2.pl
|
@@ -128,8 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '1.3'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project: globalize-accessors
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.4.5
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Define methods for accessing translated attributes
|
135
135
|
test_files: []
|
136
|
+
has_rdoc:
|