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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6fd7599f86b6c3962521da63aba9d568360b3a
4
- data.tar.gz: 27afe99b06330d8ef59bd09dfdee4b21571bac25
3
+ metadata.gz: 3229262ee8f633268283f5d27f9530b3ee419d8f
4
+ data.tar.gz: 791ffbdfa8071c57411f9e00f9366a3b242731d9
5
5
  SHA512:
6
- metadata.gz: 81581d05228b6664c5e4e81e32ec1b3b249ab8bc222bcbf2cef6d795ee97e056802a26a49504de10415dc047f559691bec7e1e1a127ec20b59cf8b5fb9019c41
7
- data.tar.gz: 203866ebfd2e76a4753a679f0d5ed6bc339a80cf8d7edcc08c835ceee01e7f53f28bcb9789a7f70da0bcef61ff4c75a9d2ab111519a2333eea6bc4d9acde549f
6
+ metadata.gz: 31cadd05e47d9c3b701527d4e70b551ad542a2594fa0f0c18c6064b9cb669bfc8c473568e286fb68a6784010d9f251f41fe93dbb4d3bd80cd80c44d1d0d9c92a
7
+ data.tar.gz: da7ac8bb04ae0993b630203065750694abd8b372192d6ae706b2daf46b6deec78602443daa2c6ffd0c21c7a4e7d131b07ff6b9744148fd9dfea7e305207f0ed6
@@ -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
- if ENV['RAILS_3']
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
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", "~> 4.2"
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
@@ -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 if value.present?
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}"
@@ -1,5 +1,5 @@
1
1
  module Globalize
2
2
  module Accessors
3
- VERSION = '0.1.5'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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("sqlite3mem")
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.1.5
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: 2014-08-16 00:00:00.000000000 Z
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: '3'
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: '3'
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.3.5
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.3.5
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: '4.2'
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: '4.2'
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.2.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: