globalize-accessors 0.1.3 → 0.1.4

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: fb81591d0892a68040b226ca603d12e538aaa430
4
- data.tar.gz: 4b4e3a579c5eff87286b320b7177f86fa8313b1f
3
+ metadata.gz: e6b68096730b07010773411f39a6765871049ac8
4
+ data.tar.gz: ffe954c351fff999d909f3dd7b06f6cbb316c7b8
5
5
  SHA512:
6
- metadata.gz: 89c74b3362d3fcadeb5999bd19a55ff8695cb421efa1553f08a6dedf2c8375d19956a4cba63cdaf393e4edcf6cd65cf276e9ed9096dd3533498075e74d71fa50
7
- data.tar.gz: 52283201db4341df4b3bb5bef75f77be4d1247a8ccff3f29cd3e79968f9e631b9089e75634f370ef857bbd5fb6ecc442d0b4baf2d1952ad7b4c393ca37c1736e
6
+ metadata.gz: 9bb53008d46631cf26b48442bac3f913c41e0814f9f3659da7bf3aaffa761fb7be2d1eca0069ff27786a3f04c6c42b467210cd99cd1b1d10df22d78b8c967b3f
7
+ data.tar.gz: 86f3612c8aec29e123743e3db869fc243f7918074212a7d31d3f8a4cdf9951c8e00fb68497480561b6ec1886cc1b4698676c84558672af0acddd989bcb62b5b2
@@ -1,4 +1,5 @@
1
- Copyright (c) 2009 [name of plugin creator]
1
+ Copyright (c) 2009, 2010, 2011, 2012, 2013 Tomek "Tomash" Stachewicz,
2
+ Robert Pankowecki, Chris Salzberg
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'rake'
13
13
  desc 'Default: run unit tests.'
14
14
  task :default => :test
15
15
 
16
- desc 'Test the easy_globalize_accessors plugin.'
16
+ desc 'Test globalize-accessors gem.'
17
17
  Rake::TestTask.new(:test) do |t|
18
18
  t.libs << 'lib'
19
19
  t.libs << 'test'
@@ -21,7 +21,7 @@ Rake::TestTask.new(:test) do |t|
21
21
  t.verbose = true
22
22
  end
23
23
 
24
- desc 'Generate documentation for the easy_globalize_accessors plugin.'
24
+ desc 'Generate documentation for globalize-accessors gem.'
25
25
  Rake::RDocTask.new(:rdoc) do |rdoc|
26
26
  rdoc.rdoc_dir = 'rdoc'
27
27
  rdoc.title = 'EasyGlobalizeAccessors'
@@ -3,7 +3,7 @@ require File.expand_path("../lib/globalize-accessors/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "globalize-accessors"
6
- s.version = GlobalizeAccessors::VERSION
6
+ s.version = Globalize::Accessors::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Tomasz Stachewicz", "Wojciech Pietrzak", "Steve Verlinden", "Robert Pankowecki", "Chris Salzberg"]
9
9
  s.email = ["tomekrs@o2.pl", "steve.verlinden@gmail.com", "robert.pankowecki@gmail.com", "rpa@gavdi.com", "chrissalzberg@gmail.com"]
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Define methods for accessing translated attributes"
12
12
  s.description = "Define methods for accessing translated attributes"
13
13
 
14
- s.required_rubygems_version = ">= 1.3.6"
14
+ s.required_rubygems_version = ">= 1.3"
15
15
  s.rubyforge_project = "globalize-accessors"
16
16
 
17
17
  if ENV['RAILS_3']
@@ -22,9 +22,10 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "globalize", ">= 3"
23
23
  end
24
24
 
25
- s.add_development_dependency "bundler", "~> 1.3.5"
25
+ s.add_development_dependency "bundler", ">= 1.3.5"
26
26
  s.add_development_dependency "rake", "~> 0.9.2"
27
27
  s.add_development_dependency "sqlite3"
28
+ s.add_development_dependency "minitest", "~> 4.2"
28
29
 
29
30
 
30
31
  s.files = `git ls-files`.split("\n")
@@ -13,19 +13,16 @@ module Globalize::Accessors
13
13
  end
14
14
  end
15
15
 
16
-
17
16
  private
18
17
 
19
-
20
18
  def define_accessors(attr_name, locale)
21
19
  define_getter(attr_name, locale)
22
20
  define_setter(attr_name, locale)
23
21
  end
24
22
 
25
-
26
23
  def define_getter(attr_name, locale)
27
24
  define_method :"#{attr_name}_#{locale.to_s.underscore}" do
28
- read_attribute(attr_name, :locale => locale)
25
+ globalize.stash.contains?(locale, attr_name) ? globalize.send(:fetch_stash, locale, attr_name) : globalize.send(:fetch_attribute, locale, attr_name)
29
26
  end
30
27
  end
31
28
 
@@ -34,6 +31,7 @@ module Globalize::Accessors
34
31
 
35
32
  define_method :"#{localized_attr_name}=" do |value|
36
33
  write_attribute(attr_name, value, :locale => locale)
34
+ translation_for(locale)[attr_name] = value if value.present?
37
35
  end
38
36
  if respond_to?(:accessible_attributes) && accessible_attributes.include?(attr_name)
39
37
  attr_accessible :"#{localized_attr_name}"
@@ -1,3 +1,5 @@
1
- module GlobalizeAccessors
2
- VERSION = '0.1.3'
1
+ module Globalize
2
+ module Accessors
3
+ VERSION = '0.1.4'
4
+ end
3
5
  end
data/readme.md CHANGED
@@ -26,7 +26,7 @@ class Product
26
26
  end
27
27
  ````
28
28
 
29
- Gives you access to methods: `title_pl`, `title_en`, `title_pl=`, `title_en=` (and a similar set of description_* methods). These work seamlessly with Globalize (not even touching the "core" `title`, `title=` methods used by Globalize itself).
29
+ Gives you access to methods: `title_pl`, `title_en`, `title_pl=`, `title_en=`. These work seamlessly with Globalize (not even touching the "core" `title`, `title=` methods used by Globalize itself).
30
30
 
31
31
  The `:locales` and `:attributes` options are optional. Their default values are:
32
32
 
@@ -82,4 +82,6 @@ end
82
82
 
83
83
  ## Licence
84
84
 
85
- Copyright (c) 2009-2013 Tomek "Tomash" Stachewicz (http://tomash.wrug.eu), Robert Pankowecki (http://robert.pankowecki.pl) released under the MIT license
85
+ Copyright (c) 2009-2013 Tomek "Tomash" Stachewicz (http://tomash.wrug.eu),
86
+ Robert Pankowecki (http://robert.pankowecki.pl), Chris Salzberg (http://dejimata.com)
87
+ released under the MIT license
@@ -51,6 +51,17 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
51
51
  assert_nil u.title_en
52
52
  end
53
53
 
54
+ test "build translations for a new object" do
55
+ u = Unit.new(:name_en => "Name en", :title_pl => "Title pl")
56
+ assert_equal 2, u.translations.size # size of the collection
57
+ assert_equal 0, u.translations.count # count from database
58
+ end
59
+
60
+ test "doesn't build translations without values" do
61
+ u = Unit.new(:name_en => nil, :title_pl => " ")
62
+ assert_equal 0, u.translations.size
63
+ end
64
+
54
65
  test "write on new object and read on saved" do
55
66
  u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
56
67
 
@@ -62,6 +73,14 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
62
73
  assert_nil u.title_en
63
74
  end
64
75
 
76
+ test "updates translations for existing object" do
77
+ u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
78
+ u.name_en = "New name en"
79
+ assert_equal "New name en", u.translations.find {|t| t.locale == :en }.name
80
+ assert_equal "Title pl", u.translations.find {|t| t.locale == :pl }.title
81
+ assert_equal 2, u.translations.count
82
+ end
83
+
65
84
  test "read on existing object" do
66
85
  u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
67
86
  u = Unit.find(u.id)
@@ -144,6 +163,17 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
144
163
  assert_equal "Name en-AU", u.name_en_au
145
164
  end
146
165
 
166
+ test "read when fallbacks present" do
167
+ u = Unit.create!(:name_en => "Name en", :title_pl => "Title pl")
168
+ u = Unit.find(u.id)
169
+ def u.globalize_fallbacks(locale)
170
+ locale == :pl ? [:pl, :en] : [:en, :pl]
171
+ end
172
+
173
+ assert_equal "Name en", u.name
174
+ assert_nil u.title_en
175
+ end
176
+
147
177
  test "globalize attribute names on class without attributes specified in options" do
148
178
  assert_equal [:name_en, :name_pl, :title_en, :title_pl], Unit.globalize_attribute_names
149
179
  end
@@ -1,7 +1,7 @@
1
1
  require 'i18n'
2
2
  I18n.available_locales = [:en, :pl]
3
3
 
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
  require 'active_support'
6
6
  require 'active_support/test_case'
7
7
  require 'logger'
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Stachewicz
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-12-25 00:00:00.000000000 Z
15
+ date: 2014-07-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: globalize
@@ -32,14 +32,14 @@ dependencies:
32
32
  name: bundler
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - ~>
35
+ - - '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: 1.3.5
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
44
  version: 1.3.5
45
45
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,20 @@ dependencies:
70
70
  - - '>='
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: minitest
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: '4.2'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '4.2'
73
87
  description: Define methods for accessing translated attributes
74
88
  email:
75
89
  - tomekrs@o2.pl
@@ -111,11 +125,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  requirements:
112
126
  - - '>='
113
127
  - !ruby/object:Gem::Version
114
- version: 1.3.6
128
+ version: '1.3'
115
129
  requirements: []
116
130
  rubyforge_project: globalize-accessors
117
- rubygems_version: 2.0.3
131
+ rubygems_version: 2.2.0
118
132
  signing_key:
119
133
  specification_version: 4
120
134
  summary: Define methods for accessing translated attributes
121
135
  test_files: []
136
+ has_rdoc: