has_translations 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in has_translations.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -2,6 +2,9 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
+ require 'bundler'
6
+ Bundler::GemHelper.install_tasks
7
+
5
8
  desc 'Default: run unit tests.'
6
9
  task :default => :test
7
10
 
@@ -12,27 +15,3 @@ Rake::TestTask.new(:test) do |t|
12
15
  t.pattern = 'test/**/*_test.rb'
13
16
  t.verbose = true
14
17
  end
15
-
16
- desc 'Generate documentation for the has_translations plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'HasTranslations'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
24
-
25
- begin
26
- require 'jeweler'
27
- Jeweler::Tasks.new do |gemspec|
28
- gemspec.name = "has_translations"
29
- gemspec.summary = "Create translations for your ActiveRecord models."
30
- gemspec.description = "Create translations for your ActiveRecord models. Uses delegate pattern. Fully tested and used in a several production sites."
31
- gemspec.email = "dmitry.polushkin@gmail.com"
32
- gemspec.homepage = "http://github.com/dmitry/has_translations"
33
- gemspec.authors = ["Dmitry Polushkin"]
34
- gemspec.version = '0.3.3'
35
- end
36
- rescue LoadError
37
- puts "Jeweler not available. Install it with: gem install jeweler"
38
- end
@@ -1,56 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "has_translations/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{has_translations}
8
- s.version = "0.3.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dmitry Polushkin"]
12
- s.date = %q{2011-02-21}
6
+ s.name = "has_translations"
7
+ s.version = HasTranslations::VERSION
8
+ s.authors = ["Dmitry Polushkin"]
9
+ s.email = ["dmitry.polushkin@gmail.com"]
10
+ s.homepage = "http://github.com/dmitry/has_translations"
11
+ s.summary = %q{Create translations for your ActiveRecord models.}
13
12
  s.description = %q{Create translations for your ActiveRecord models. Uses delegate pattern. Fully tested and used in a several production sites.}
14
- s.email = %q{dmitry.polushkin@gmail.com}
15
- s.extra_rdoc_files = [
16
- "README.md",
17
- "TODO"
18
- ]
19
- s.files = [
20
- "MIT-LICENSE",
21
- "README.md",
22
- "Rakefile",
23
- "generators/has_translations/USAGE",
24
- "generators/has_translations/has_translations_generator.rb",
25
- "has_translations.gemspec",
26
- "init.rb",
27
- "install.rb",
28
- "lib/has_translations.rb",
29
- "tasks/has_translations_tasks.rake",
30
- "test/.gitignore",
31
- "test/has_translations_test.rb",
32
- "test/schema.rb",
33
- "test/test_helper.rb",
34
- "uninstall.rb"
35
- ]
36
- s.homepage = %q{http://github.com/dmitry/has_translations}
37
- s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.7}
39
- s.summary = %q{Create translations for your ActiveRecord models.}
40
- s.test_files = [
41
- "test/has_translations_test.rb",
42
- "test/schema.rb",
43
- "test/test_helper.rb"
44
- ]
45
13
 
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 3
14
+ s.rubyforge_project = "has_translations"
49
15
 
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- else
52
- end
53
- else
54
- end
55
- end
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
56
20
 
21
+ s.license = 'MIT'
22
+ s.add_dependency "activesupport", "~> 2.3"
23
+ s.add_dependency 'activerecord', '~> 2.3'
24
+ end
@@ -39,7 +39,7 @@ class ActiveRecord::Base
39
39
  # ===
40
40
  #
41
41
  # Configuration options:
42
- #
42
+ #
43
43
  # * <tt>:fallback</tt> - if translation for the current locale not found.
44
44
  # By default false. Set to true if you want to use reader fallback.
45
45
  # Uses algorithm of fallback:
@@ -98,7 +98,7 @@ class ActiveRecord::Base
98
98
  scope_method = if ActiveRecord::VERSION::MAJOR < 3 then :named_scope else :scope end
99
99
 
100
100
  # associations, validations and scope definitions
101
- has_many :translations, :class_name => translation_class_name, :dependent => :destroy
101
+ has_many :translations, :class_name => translation_class_name, :dependent => :destroy, :autosave => true
102
102
  translation_class.belongs_to belongs_to
103
103
  translation_class.validates_presence_of :locale
104
104
  translation_class.validates_uniqueness_of :locale, :scope => :"#{belongs_to}_id"
@@ -140,13 +140,18 @@ class ActiveRecord::Base
140
140
  attrs.each do |name|
141
141
  send :define_method, name do
142
142
  translation = self.translation(I18n.locale)
143
- translation.nil? ? has_translations_options[:nil] : translation.send(name)
143
+ translation.try(name) || has_translations_options[:nil]
144
144
  end
145
145
  end
146
146
  end
147
147
 
148
148
  if options[:writer]
149
149
  attrs.each do |name|
150
+ send :define_method, "#{name}_before_type_cast" do
151
+ translation = self.translation(I18n.locale, false)
152
+ translation.try(name)
153
+ end
154
+
150
155
  send :define_method, "#{name}=" do |value|
151
156
  translation = find_or_build_translation(I18n.locale)
152
157
  translation.send(:"#{name}=", value)
@@ -0,0 +1,3 @@
1
+ module HasTranslations
2
+ VERSION = "0.3.4"
3
+ end
@@ -36,15 +36,22 @@ class HasTranslationsTest < Test::Unit::TestCase
36
36
 
37
37
  def test_writer_text_for_a_given_locale
38
38
  article = Article.create!
39
+ assert_equal '', article.text
40
+ assert_equal nil, article.text_before_type_cast
39
41
  article.text = 'text'
42
+ assert_equal 'text', article.text_before_type_cast
40
43
  assert_equal 0, article.translations.count
41
44
  article.save!
45
+ assert_equal 'text', article.text_before_type_cast
42
46
  assert_equal 1, article.translations.length
43
47
  assert_equal 1, article.translations.count
44
48
  I18n.locale = :en
45
49
  assert_equal '', article.text
46
50
  article.update_attributes!(:text => 'text')
47
51
  assert_equal 2, Article.first.translations.count
52
+ article.text = 'text new'
53
+ article.save!
54
+ assert_equal 'text new', article.text
48
55
  end
49
56
 
50
57
  def test_translations_association_and_translations
data/test/test_helper.rb CHANGED
@@ -1,14 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
 
4
- case ENV['RAILS_VERSION']
5
- when '3.0' then
6
- gem 'activerecord', '~> 3.0.0'
7
- gem 'activesupport', '~> 3.0.0'
8
- else
9
- gem 'activerecord', '~> 2.3.0'
10
- gem 'activesupport', '~> 2.3.0'
11
- end
4
+ rails_version = "~> #{ENV['RAILS_VERSION'] || '3.0.0'}"
5
+
6
+ gem 'activerecord', rails_version
7
+ gem 'activesupport', rails_version
12
8
 
13
9
  require 'active_record'
14
10
  require 'logger'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_translations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmitry Polushkin
@@ -15,20 +15,50 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-21 00:00:00 +00:00
19
- default_executable:
20
- dependencies: []
21
-
18
+ date: 2011-09-09 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 2
31
+ - 3
32
+ version: "2.3"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activerecord
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 2
46
+ - 3
47
+ version: "2.3"
48
+ type: :runtime
49
+ version_requirements: *id002
22
50
  description: Create translations for your ActiveRecord models. Uses delegate pattern. Fully tested and used in a several production sites.
23
- email: dmitry.polushkin@gmail.com
51
+ email:
52
+ - dmitry.polushkin@gmail.com
24
53
  executables: []
25
54
 
26
55
  extensions: []
27
56
 
28
- extra_rdoc_files:
29
- - README.md
30
- - TODO
57
+ extra_rdoc_files: []
58
+
31
59
  files:
60
+ - .gitignore
61
+ - Gemfile
32
62
  - MIT-LICENSE
33
63
  - README.md
34
64
  - Rakefile
@@ -38,17 +68,16 @@ files:
38
68
  - init.rb
39
69
  - install.rb
40
70
  - lib/has_translations.rb
71
+ - lib/has_translations/version.rb
41
72
  - tasks/has_translations_tasks.rake
42
73
  - test/.gitignore
43
74
  - test/has_translations_test.rb
44
75
  - test/schema.rb
45
76
  - test/test_helper.rb
46
77
  - uninstall.rb
47
- - TODO
48
- has_rdoc: true
49
78
  homepage: http://github.com/dmitry/has_translations
50
- licenses: []
51
-
79
+ licenses:
80
+ - MIT
52
81
  post_install_message:
53
82
  rdoc_options: []
54
83
 
@@ -74,12 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
103
  version: "0"
75
104
  requirements: []
76
105
 
77
- rubyforge_project:
78
- rubygems_version: 1.3.7
106
+ rubyforge_project: has_translations
107
+ rubygems_version: 1.8.10
79
108
  signing_key:
80
109
  specification_version: 3
81
110
  summary: Create translations for your ActiveRecord models.
82
- test_files:
83
- - test/has_translations_test.rb
84
- - test/schema.rb
85
- - test/test_helper.rb
111
+ test_files: []
112
+
data/TODO DELETED
@@ -1,2 +0,0 @@
1
- http://github.com/technicalpickles/jeweler
2
- http://wiki.github.com/qrush/gemcutter/create