globalize-accessors 0.1.5 → 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.
- checksums.yaml +5 -5
- data/.travis.yml +4 -4
- data/globalize-accessors.gemspec +3 -11
- data/lib/globalize-accessors/version.rb +1 -1
- data/lib/globalize-accessors.rb +2 -1
- data/readme.md +1 -1
- data/test/globalize_accessors_test.rb +10 -26
- data/test/test_helper.rb +2 -1
- metadata +13 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b24dfdcadad659639d275ef9598edd54b74623afcddc067bb3539b9379516d50
|
|
4
|
+
data.tar.gz: b6f234105d5bc9911feba08771b05dd82cd796fc1d767234aec5d1982a0a059b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94a313445016b3967875ac18778e52f80c344936914fe4bbef3083c2e8d596be7013f9ff55c520079ad78351ed445671ca427060957255bab4531cdc0eafd7e0
|
|
7
|
+
data.tar.gz: ad260c54dd05b22081f6c3ac42588c73f634952beeda208f6534584133d07d3b8f686112fd69fb2af68b5c6d401c908858628bf5b58a295baa89a64bfa07fe9d
|
data/.travis.yml
CHANGED
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
|
-
s.add_dependency "globalize", "~> 3.0.0"
|
|
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
|
|
17
|
+
s.add_dependency "globalize", ">= 5.0.0"
|
|
24
18
|
|
|
25
|
-
s.add_development_dependency "bundler", ">= 1.3.5"
|
|
26
|
-
s.add_development_dependency "rake", "~> 0.9.2"
|
|
27
19
|
s.add_development_dependency "sqlite3"
|
|
28
|
-
s.add_development_dependency "
|
|
29
|
-
|
|
20
|
+
s.add_development_dependency "rake"
|
|
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
|
+
attribute_will_change!(localized_attr_name) if value != send(localized_attr_name)
|
|
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}"
|
data/readme.md
CHANGED
|
@@ -70,7 +70,7 @@ If you wish to always define accessors and don't want to call the `globalize_acc
|
|
|
70
70
|
module TranslatesWithAccessors
|
|
71
71
|
|
|
72
72
|
def translates(*params)
|
|
73
|
-
options = params.extract_options!
|
|
73
|
+
options = params.dup.extract_options!
|
|
74
74
|
options.reverse_merge!(:globalize_accessors => true)
|
|
75
75
|
accessors = options.delete(:globalize_accessors)
|
|
76
76
|
super
|
|
@@ -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
|
|
@@ -69,11 +61,6 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
|
69
61
|
assert_equal 0, u.translations.count # count from database
|
|
70
62
|
end
|
|
71
63
|
|
|
72
|
-
test "doesn't build translations without values" do
|
|
73
|
-
u = Unit.new(:name_en => nil, :title_pl => " ")
|
|
74
|
-
assert_equal 0, u.translations.size
|
|
75
|
-
end
|
|
76
|
-
|
|
77
64
|
test "write on new object and read on saved" do
|
|
78
65
|
u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
|
|
79
66
|
|
|
@@ -137,18 +124,6 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
|
137
124
|
assert_equal "Name pl", u.name_pl
|
|
138
125
|
end
|
|
139
126
|
|
|
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
127
|
test "globalize locales on class without locales specified in options" do
|
|
153
128
|
assert_equal [:en, :pl], Unit.globalize_locales
|
|
154
129
|
end
|
|
@@ -212,4 +187,13 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
|
|
|
212
187
|
test "instance without accessors" do
|
|
213
188
|
refute UnitWithoutAccessors.new.respond_to?(:localized_attr_name_for)
|
|
214
189
|
end
|
|
190
|
+
|
|
191
|
+
test "dirty checking" do
|
|
192
|
+
u = Unit.create!(:name_en => "Name en")
|
|
193
|
+
u.name_en = "New name en"
|
|
194
|
+
assert u.changed.include?("name_en")
|
|
195
|
+
assert ["Name en", "New name en"], u.changes["name_en"]
|
|
196
|
+
u.save!
|
|
197
|
+
assert ! u.changed.include?("name_en")
|
|
198
|
+
end
|
|
215
199
|
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.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomasz Stachewicz
|
|
@@ -9,10 +9,10 @@ authors:
|
|
|
9
9
|
- Steve Verlinden
|
|
10
10
|
- Robert Pankowecki
|
|
11
11
|
- Chris Salzberg
|
|
12
|
-
autorequire:
|
|
12
|
+
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date:
|
|
15
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: globalize
|
|
@@ -20,44 +20,30 @@ dependencies:
|
|
|
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
|
-
name:
|
|
32
|
+
name: sqlite3
|
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
|
34
34
|
requirements:
|
|
35
35
|
- - ">="
|
|
36
36
|
- !ruby/object:Gem::Version
|
|
37
|
-
version:
|
|
37
|
+
version: '0'
|
|
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:
|
|
44
|
+
version: '0'
|
|
45
45
|
- !ruby/object:Gem::Dependency
|
|
46
46
|
name: rake
|
|
47
|
-
requirement: !ruby/object:Gem::Requirement
|
|
48
|
-
requirements:
|
|
49
|
-
- - "~>"
|
|
50
|
-
- !ruby/object:Gem::Version
|
|
51
|
-
version: 0.9.2
|
|
52
|
-
type: :development
|
|
53
|
-
prerelease: false
|
|
54
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
55
|
-
requirements:
|
|
56
|
-
- - "~>"
|
|
57
|
-
- !ruby/object:Gem::Version
|
|
58
|
-
version: 0.9.2
|
|
59
|
-
- !ruby/object:Gem::Dependency
|
|
60
|
-
name: sqlite3
|
|
61
47
|
requirement: !ruby/object:Gem::Requirement
|
|
62
48
|
requirements:
|
|
63
49
|
- - ">="
|
|
@@ -76,14 +62,14 @@ dependencies:
|
|
|
76
62
|
requirements:
|
|
77
63
|
- - "~>"
|
|
78
64
|
- !ruby/object:Gem::Version
|
|
79
|
-
version: '
|
|
65
|
+
version: '5.1'
|
|
80
66
|
type: :development
|
|
81
67
|
prerelease: false
|
|
82
68
|
version_requirements: !ruby/object:Gem::Requirement
|
|
83
69
|
requirements:
|
|
84
70
|
- - "~>"
|
|
85
71
|
- !ruby/object:Gem::Version
|
|
86
|
-
version: '
|
|
72
|
+
version: '5.1'
|
|
87
73
|
description: Define methods for accessing translated attributes
|
|
88
74
|
email:
|
|
89
75
|
- tomekrs@o2.pl
|
|
@@ -112,7 +98,7 @@ files:
|
|
|
112
98
|
homepage: http://rubygems.org/gems/globalize-accessors
|
|
113
99
|
licenses: []
|
|
114
100
|
metadata: {}
|
|
115
|
-
post_install_message:
|
|
101
|
+
post_install_message:
|
|
116
102
|
rdoc_options: []
|
|
117
103
|
require_paths:
|
|
118
104
|
- lib
|
|
@@ -127,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
113
|
- !ruby/object:Gem::Version
|
|
128
114
|
version: '1.3'
|
|
129
115
|
requirements: []
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
signing_key:
|
|
116
|
+
rubygems_version: 3.2.3
|
|
117
|
+
signing_key:
|
|
133
118
|
specification_version: 4
|
|
134
119
|
summary: Define methods for accessing translated attributes
|
|
135
120
|
test_files: []
|