globalize 5.1.0.beta1 → 5.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a08ebfb553ad5faf8e55d1b120bbafd8571327e2
4
- data.tar.gz: b30cca9abefcb65933dcbff2ace3040f40cbfea7
2
+ SHA256:
3
+ metadata.gz: 93f476f456eba6a50a3bda3d639ae4e4cc7d190d4b846a6534b26b1571dff968
4
+ data.tar.gz: 10d20462ade18061edc4facf99f4e23c58b7855e4121e5f0f2d29ab5eb36eb24
5
5
  SHA512:
6
- metadata.gz: ead976f8983d5477cce5d9e518f48997c7fdedb3abd057a79946fda0828943672069e286c3c9deff5d5ef53f8faebf24a3081f4e4bb323f9e9e5375fe95af5a8
7
- data.tar.gz: 7dd8d873d8492109cffa6561d6a57829f8b7d737f8125dd200a853ac11bcb6f8774c615b5cdd3c024223d81a6841c1c0d9d79481f6a77c11328d4ad363e9c4de
6
+ metadata.gz: 40ca71b7fefb3b4de28f8b6ae08c10fa6c8172cf69e86e18d3ab9166625f41a1ed15c4e4dd53977ff90a7dab4297577ab26a80de130fe58628fb67b0003be54b
7
+ data.tar.gz: 7e5c4637c7f29d92d69ff704fec7d3c71d409c9f27c321df3807055471135877470b37dce6b0daceb68fad96c160e3dd031bf75e1df743acc76156d35f46ccfb
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ RAILS_VERSIONS = %w[
4
+ 4.2.10
5
+ 5.1.6
6
+ 5.2.1
7
+ ]
8
+
9
+ RAILS_VERSIONS.each do |version|
10
+ appraise "rails_#{version}" do
11
+ gem 'activemodel', version
12
+ gem 'activerecord', version
13
+
14
+ platforms :rbx do
15
+ gem "rubysl", "~> 2.0"
16
+ gem "rubinius-developer_tools"
17
+ end
18
+
19
+ platforms :jruby do
20
+ if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
21
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1'
22
+ end
23
+
24
+ if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
25
+ gem 'activerecord-jdbcmysql-adapter', '~> 1'
26
+ end
27
+
28
+ if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
29
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,27 @@
1
1
  # Globalize Changelog
2
2
 
3
- ## 5.1.0 (unreleased)
3
+ ## 5.3.1 (2021-01-11)
4
+
5
+ * Fix foreign keys translation. [#773](https://github.com/globalize/globalize/pull/773) by [Sergey Tokarenko](https://github.com/stokarenko)
6
+
7
+ ## 5.3.0 (2019-05-14)
8
+
9
+ * Prevent 'SystemStackError: stack level too deep' error on attribute reset. [#722](https://github.com/globalize/globalize/pull/722) by [Reinier de Lange](https://github.com/moiristo)
10
+ * Pass the `:limit` option for the FK column. [#721](https://github.com/globalize/globalize/pull/721) by [Denis Demchenko](https://github.com/lancedikson)
11
+ * Add support for Rails 6.0. [#718](https://github.com/globalize/globalize/pull/718) by [Chrıs Seelus](https://github.com/cseelus)
12
+ * FIX: stop registering the attr for Rails 4.2. [#711](https://github.com/globalize/globalize/pull/711) by [Adam Fernung](https://github.com/akfernun)
13
+
14
+ ## 5.2.0 (2018-11-02)
15
+
16
+ * Add support for translated attributes to other QueryMethods and Calculations [#707](https://github.com/globalize/globalize/pull/707) by [kreintjes](https://github.com/kreintjes)
17
+ * Fix `read_attribute` for Rails changes. [#709](https://github.com/globalize/globalize/pull/709) by [ota42y](https://github.com/ota42y) and [nabuchi](https://github.com/nabuchi)
18
+ * Support array as an argument of order. [#675](https://github.com/globalize/globalize/pull/675) by [Maicol Bentancor](https://github.com/MaicolBen)
19
+ * `_reset_attribute` bugfix. [#674](https://github.com/globalize/globalize/pull/674) by [ota42y](https://github.com/ota42y)
20
+ * Add support for Rails 5.2 [#678](https://github.com/globalize/globalize/pull/678) by [kevin-jj](https://github.com/kevin-jj)
21
+ * Fix: wrong number of arguments for ActiveRecord 'attribute' method [#671](https://github.com/globalize/globalize/pull/671) by [Evgeny Danilov](https://github.com/jmelkor)
22
+ * Resolve deprecation warning: attribute is not an attribute known to Active Record. [#629](https://github.com/globalize/globalize/pull/629) by [Michael Rüffer](https://github.com/itschn)
23
+
24
+ ## 5.1.0 (2018-01-15)
4
25
 
5
26
  * Replaced `after_` callbacks with `before_` callbacks and set `autosave: true` by default. [#341](https://github.com/globalize/globalize/pull/341) by [Andrew Volozhanin](https://github.com/scarfacedeb)
6
27
  * Add [RequestStore](https://github.com/steveklabnik/request_store) to make Globalize thread-safe again [#420](https://github.com/globalize/globalize/pull/420)
@@ -35,3 +35,18 @@ Have a bug fix, code improvement or proposed feature? Do the following:
35
35
  For pull requests to Rails/ActiveRecord 4 version of Globalize (v3.x), post to the `master` branch. For pull requests to the Rails/ActiveRecord 3.x version of Globalize (3.x), post to the `3-0-stable` branch.
36
36
 
37
37
  When you submit the pull request, Travis CI will run the [test suite](https://travis-ci.org/globalize/globalize) against your branch and will highlight any failures. Unless there is a good reason for it, we do not generally accept pull requests that take Globalize from green to red.
38
+
39
+ ## Testing
40
+
41
+ ### Requirements
42
+
43
+ - Ruby
44
+ - Bundler
45
+ - SQLite
46
+ - You can switch the database by adding an environment variable. See `test/support/database.rb`.
47
+ - You can also configure your database configurations. See `test/support/database.yml`.
48
+
49
+ ### Run tests on your local machine
50
+
51
+ - `bundle install`
52
+ - `bundle exec rake`
data/Gemfile CHANGED
@@ -1,26 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "pry"
6
-
7
- eval File.read(File.expand_path("../gemfiles/.gemfile.database-config.rb", __FILE__))
8
-
9
- platforms :rbx do
10
- gem "rubysl", "~> 2.0"
11
- gem "rubinius-developer_tools"
12
- end
13
-
14
- platforms :jruby do
15
- if !ENV['TRAVIS'] || ENV['DB'] == 'sqlite3'
16
- gem 'activerecord-jdbcsqlite3-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
17
- end
18
-
19
- if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
20
- gem 'activerecord-jdbcmysql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
21
- end
22
-
23
- if !ENV['TRAVIS'] || %w(postgres postgresql).include?(ENV['DB'])
24
- gem 'activerecord-jdbcpostgresql-adapter', git: "https://github.com/jruby/activerecord-jdbc-adapter"
25
- end
26
- end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ![Globalize](http://globalize.github.io/globalize/images/globalize.png)
2
2
 
3
3
  [![Build Status](https://travis-ci.org/globalize/globalize.svg?branch=master)](https://travis-ci.org/globalize/globalize) [![Code Climate](https://codeclimate.com/github/globalize/globalize.svg)](https://codeclimate.com/github/globalize/globalize)
4
+ [![Open Source Helpers](https://www.codetriage.com/globalize/globalize/badges/users.svg)](https://www.codetriage.com/globalize/globalize)
4
5
 
5
6
  You can chat with us using Gitter:
6
7
 
@@ -27,10 +28,10 @@ gem install globalize
27
28
  When using bundler put this in your Gemfile:
28
29
 
29
30
  ```ruby
30
- gem 'globalize', '~> 5.0.0'
31
+ gem 'globalize', '~> 5.1.0'
31
32
  ```
32
33
 
33
- You have to use branch **master** to work with Rails 5.
34
+ Please help us by letting us know what works, and what doesn't, when using pre-release code.
34
35
 
35
36
  Put in your Gemfile
36
37
 
@@ -239,14 +240,20 @@ Because globalize uses the `:locale` key to specify the locale during
239
240
  mass-assignment, you should avoid having a `locale` attribute on the parent
240
241
  model.
241
242
 
243
+ If you like your translated model to update if a translation changes, use the `touch: true` option together with `translates`:
244
+
245
+ ```ruby
246
+ translates :name, touch: true
247
+ ```
248
+
242
249
  ## Known Issues
243
250
 
244
251
  If you're getting the `ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "column_name" violates not-null constraint` error, the only known way to deal with it as of now is to remove not-null constraint for the globalized columns:
245
252
 
246
253
  ```ruby
247
- class RemoveNullConstraintsFromResources < ActiveRecord::Migration
254
+ class RemoveNullConstraintsFromResourceTranslations < ActiveRecord::Migration
248
255
  def change
249
- change_column_null :resources, :column_name, true
256
+ change_column_null :resource_translations, :column_name, true
250
257
  end
251
258
  end
252
259
  ```
@@ -264,6 +271,9 @@ You can enable them by adding the next line to `config/application.rb` (or only
264
271
  `config/environments/production.rb` if you only want them in production)
265
272
 
266
273
  ```ruby
274
+ # For version 1.1.0 and above of the `i18n` gem:
275
+ config.i18n.fallbacks = [I18n.default_locale]
276
+ # Below version 1.1.0 of the `i18n` gem:
267
277
  config.i18n.fallbacks = true
268
278
  ```
269
279
 
@@ -0,0 +1,22 @@
1
+ version: '3.7'
2
+ services:
3
+ postgres:
4
+ image: postgres:11
5
+ volumes:
6
+ - ./tmp/postgres:/var/lib/postgresql/data
7
+ ports:
8
+ - "5432:5432"
9
+ environment:
10
+ POSTGRES_USER: "postgres"
11
+ POSTGRES_PASSWORD: ""
12
+ mysql:
13
+ image: mysql:8.0
14
+ volumes:
15
+ - ./tmp/mysql:/var/lib/mysql
16
+ ports:
17
+ - "3306:3306"
18
+ environment:
19
+ MYSQL_USER: "root"
20
+ MYSQL_PASSWORD: ""
21
+ MYSQL_ROOT_PASSWORD: ""
22
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../lib/globalize/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'globalize'
5
+ s.version = Globalize::Version
6
+ s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Clemens Kofler', 'John-Paul Bader', 'Tomasz Stachewicz', 'Philip Arndt', 'Chris Salzberg']
7
+ s.email = 'nobody@globalize-rails.org'
8
+ s.homepage = 'http://github.com/globalize/globalize'
9
+ s.summary = 'Rails I18n de-facto standard library for ActiveRecord model/data translation'
10
+ s.description = "#{s.summary}."
11
+ s.license = "MIT"
12
+
13
+ s.files = Dir['{lib/**/*,[A-Z]*}']
14
+ s.platform = Gem::Platform::RUBY
15
+ s.require_path = 'lib'
16
+ s.rubyforge_project = '[none]'
17
+ s.required_ruby_version = '>= 2.4.6'
18
+
19
+ s.add_dependency 'activerecord', '>= 4.2', '< 6.1'
20
+ s.add_dependency 'activemodel', '>= 4.2', '< 6.1'
21
+ s.add_dependency 'request_store', '~> 1.0'
22
+
23
+ s.add_development_dependency 'appraisal'
24
+ s.add_development_dependency 'database_cleaner'
25
+ s.add_development_dependency 'm'
26
+ s.add_development_dependency 'minitest'
27
+ s.add_development_dependency 'minitest-reporters'
28
+ s.add_development_dependency 'pry'
29
+ s.add_development_dependency 'rake'
30
+ s.add_development_dependency 'rdoc'
31
+ s.add_development_dependency 'sqlite3'
32
+ end
@@ -0,0 +1,38 @@
1
+ # Activate the gem you are reporting the issue against.
2
+ gem 'activerecord', '4.2.0'
3
+ gem 'globalize', '5.0.1'
4
+ require 'active_record'
5
+ require 'globalize'
6
+ require 'minitest/autorun'
7
+ require 'logger'
8
+
9
+ # Ensure backward compatibility with Minitest 4
10
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
11
+
12
+ # This connection will do for database-independent bug reports.
13
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
14
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
15
+
16
+ ActiveRecord::Schema.define do
17
+ create_table :posts, force: true do |t|
18
+ end
19
+
20
+ create_table :post_translations, force: true do |t|
21
+ t.references :post
22
+ t.string :title
23
+ t.text :content
24
+ t.string :locale
25
+ end
26
+ end
27
+
28
+ class Post < ActiveRecord::Base
29
+ translates :content, :title
30
+ end
31
+
32
+ class BugTest < Minitest::Test
33
+ def test_association_stuff
34
+ post = Post.create!(title: 'HI')
35
+
36
+ assert_equal 'HI', post.title
37
+ end
38
+ end
@@ -58,6 +58,14 @@ module Globalize
58
58
  RequestStore.store
59
59
  end
60
60
 
61
+ def rails_5?
62
+ ::ActiveRecord.version >= Gem::Version.new('5.1.0')
63
+ end
64
+
65
+ def rails_52?
66
+ ::ActiveRecord.version >= Gem::Version.new('5.2.0')
67
+ end
68
+
61
69
  protected
62
70
 
63
71
  def read_locale
@@ -84,7 +92,7 @@ module Globalize
84
92
  end
85
93
  end
86
94
 
87
- ActiveRecord::Base.mattr_accessor :globalize_serialized_attributes, instance_writer: false
95
+ ActiveRecord::Base.class_attribute :globalize_serialized_attributes, instance_writer: false
88
96
  ActiveRecord::Base.globalize_serialized_attributes = {}
89
97
 
90
98
  ActiveRecord::Base.extend(Globalize::ActiveRecord::ActMacro)
@@ -1,14 +1,14 @@
1
1
  module Globalize
2
2
  module ActiveRecord
3
- autoload :ActMacro, 'globalize/active_record/act_macro'
4
- autoload :Adapter, 'globalize/active_record/adapter'
5
- autoload :AdapterDirty, 'globalize/active_record/adapter_dirty'
6
- autoload :Attributes, 'globalize/active_record/attributes'
7
- autoload :ClassMethods, 'globalize/active_record/class_methods'
8
- autoload :Exceptions, 'globalize/active_record/exceptions'
9
- autoload :InstanceMethods, 'globalize/active_record/instance_methods'
10
- autoload :Migration, 'globalize/active_record/migration'
11
- autoload :Translation, 'globalize/active_record/translation'
12
- autoload :QueryMethods, 'globalize/active_record/query_methods'
3
+ autoload :ActMacro, 'globalize/active_record/act_macro'
4
+ autoload :Adapter, 'globalize/active_record/adapter'
5
+ autoload :AdapterDirty, 'globalize/active_record/adapter_dirty'
6
+ autoload :Attributes, 'globalize/active_record/attributes'
7
+ autoload :ClassMethods, 'globalize/active_record/class_methods'
8
+ autoload :Exceptions, 'globalize/active_record/exceptions'
9
+ autoload :InstanceMethods, 'globalize/active_record/instance_methods'
10
+ autoload :Migration, 'globalize/active_record/migration'
11
+ autoload :Translation, 'globalize/active_record/translation'
12
+ autoload :TranslatedAttributesQuery, 'globalize/active_record/translated_attributes_query'
13
13
  end
14
14
  end
@@ -40,16 +40,19 @@ module Globalize
40
40
  self.translated_attribute_names << attr_name
41
41
  end
42
42
 
43
- if ::ActiveRecord::VERSION::STRING > "5.0" && table_exists? && translation_class.table_exists?
44
- self.ignored_columns += translated_attribute_names.map(&:to_s)
45
- reset_column_information
43
+ begin
44
+ if ::ActiveRecord::VERSION::STRING > "5.0" && table_exists? && translation_class.table_exists?
45
+ self.ignored_columns += translated_attribute_names.map(&:to_s)
46
+ reset_column_information
47
+ end
48
+ rescue ::ActiveRecord::NoDatabaseError
49
+ warn 'Unable to connect to a database. Globalize skipped ignoring columns of translated attributes.'
46
50
  end
47
51
  end
48
52
 
49
53
  def check_columns!(attr_names)
50
- # If tables do not exist, do not warn about conflicting columns
51
- return unless table_exists? && translation_class.table_exists?
52
-
54
+ # If tables do not exist or Rails version is greater than 5, do not warn about conflicting columns
55
+ return unless ::ActiveRecord::VERSION::STRING < "5.0" && table_exists? && translation_class.table_exists?
53
56
  if (overlap = attr_names.map(&:to_s) & column_names).present?
54
57
  ActiveSupport::Deprecation.warn(
55
58
  ["You have defined one or more translated attributes with names that conflict with column(s) on the model table. ",
@@ -58,6 +61,8 @@ module Globalize
58
61
  "Attribute name(s): #{overlap.join(', ')}\n"].join
59
62
  )
60
63
  end
64
+ rescue ::ActiveRecord::NoDatabaseError
65
+ warn 'Unable to connect to a database. Globalize skipped checking attributes with conflicting column names.'
61
66
  end
62
67
 
63
68
  def apply_globalize_options(options)
@@ -94,11 +99,11 @@ module Globalize
94
99
  :foreign_key => options[:foreign_key],
95
100
  :dependent => :destroy,
96
101
  :extend => HasManyExtensions,
97
- :autosave => true,
102
+ :autosave => false,
98
103
  :inverse_of => :globalized_model
99
104
 
100
- before_create :save_translations!
101
- before_update :save_translations!
105
+ after_create :save_translations!
106
+ after_update :save_translations!
102
107
  end
103
108
  end
104
109
 
@@ -43,6 +43,9 @@ module Globalize
43
43
  value = value.val if value.is_a?(Arel::Nodes::Casted)
44
44
  translation[name] = value
45
45
  end
46
+
47
+ ensure_foreign_key_for(translation)
48
+ translation.save!
46
49
  end
47
50
 
48
51
  reset
@@ -54,6 +57,12 @@ module Globalize
54
57
 
55
58
  protected
56
59
 
60
+ # Sometimes the translation is initialised before a foreign key can be set.
61
+ def ensure_foreign_key_for(translation)
62
+ # AR >= 4.1 reflections renamed to _reflections
63
+ translation[translation.class.reflections.stringify_keys["globalized_model"].foreign_key] = record.id
64
+ end
65
+
57
66
  def type_cast(name, value)
58
67
  return value.presence unless column = column_for_attribute(name)
59
68
 
@@ -36,19 +36,23 @@ module Globalize
36
36
  dirty[name][locale] = old
37
37
  end
38
38
  end
39
+
39
40
  def clear_dirty
40
41
  self.dirty = {}
41
42
  end
42
43
 
43
44
  def _reset_attribute name
44
- record.send("#{name}=", record.changed_attributes[name])
45
- record.original_changed_attributes.except!(name)
45
+ original_value = record.changed_attributes[name]
46
+ record.send(:clear_attribute_changes, [name])
47
+ record.send("#{name}=", original_value)
48
+ record.send(:clear_attribute_changes, [name])
46
49
  end
47
50
 
48
51
  def reset
49
52
  clear_dirty
50
53
  super
51
54
  end
55
+
52
56
  end
53
57
  end
54
58
  end
@@ -56,7 +56,11 @@ module Globalize
56
56
  klass = self.const_set(:Translation, Class.new(Globalize::ActiveRecord::Translation))
57
57
  end
58
58
 
59
- klass.belongs_to :globalized_model, :class_name => self.name, :foreign_key => translation_options[:foreign_key], inverse_of: :translations
59
+ klass.belongs_to :globalized_model,
60
+ class_name: self.name,
61
+ foreign_key: translation_options[:foreign_key],
62
+ inverse_of: :translations,
63
+ touch: translation_options.fetch(:touch, false)
60
64
  klass
61
65
  end
62
66
  end
@@ -72,10 +76,10 @@ module Globalize
72
76
  private
73
77
 
74
78
  # Override the default relation method in order to return a subclass
75
- # of ActiveRecord::Relation with custom finder methods for translated
76
- # attributes.
79
+ # of ActiveRecord::Relation with custom finder and calculation methods
80
+ # for translated attributes.
77
81
  def relation
78
- super.extending!(QueryMethods)
82
+ super.extending!(TranslatedAttributesQuery)
79
83
  end
80
84
 
81
85
  protected
@@ -116,6 +120,7 @@ module Globalize
116
120
  end
117
121
 
118
122
  def define_translations_accessor(name)
123
+ attribute(name, ::ActiveRecord::Type::Value.new) if ::ActiveRecord::VERSION::STRING >= "5.0"
119
124
  define_translations_reader(name)
120
125
  define_translations_writer(name)
121
126
  end