globalize 5.3.1 → 7.0.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 +4 -4
- data/Appraisals +14 -9
- data/CHANGELOG.md +34 -0
- data/CONTRIBUTING.md +5 -7
- data/Gemfile +25 -0
- data/Gemfile.lock +102 -0
- data/README.md +43 -48
- data/Rakefile +22 -17
- data/lib/globalize/active_record/act_macro.rb +22 -22
- data/lib/globalize/active_record/adapter_dirty.rb +24 -3
- data/lib/globalize/active_record/class_methods.rb +20 -7
- data/lib/globalize/active_record/instance_methods.rb +38 -30
- data/lib/globalize/active_record/migration.rb +4 -3
- data/lib/globalize/active_record/translated_attributes_query.rb +0 -17
- data/lib/globalize/version.rb +1 -1
- data/lib/globalize.rb +18 -8
- data/lib/patches/active_record/{rails5_1 → rails6_1}/serialization.rb +2 -2
- data/lib/patches/active_record/{rails5_1 → rails6_1}/uniqueness_validator.rb +1 -1
- data/lib/patches/active_record/rails7_1/serialization.rb +28 -0
- data/lib/patches/active_record/rails7_2/serialization.rb +15 -0
- data/lib/patches/active_record/relation.rb +12 -9
- data/lib/patches/active_record/serialization.rb +6 -4
- data/lib/patches/active_record/uniqueness_validator.rb +1 -7
- data/lib/patches/active_support/inflections.rb +12 -0
- metadata +41 -39
- data/docker-compose.yml +0 -22
- data/globalize.gemspec +0 -32
- data/issue_template.rb +0 -38
- data/lib/patches/active_record/query_method.rb +0 -3
- data/lib/patches/active_record/rails4/query_method.rb +0 -35
- data/lib/patches/active_record/rails4/serialization.rb +0 -22
- data/lib/patches/active_record/rails4/uniqueness_validator.rb +0 -42
- data/lib/patches/active_record/rails5/uniqueness_validator.rb +0 -47
data/issue_template.rb
DELETED
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'active_record/attribute_methods/query'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module AttributeMethods
|
5
|
-
module Query
|
6
|
-
def query_attribute(attr_name)
|
7
|
-
unless value = read_attribute(attr_name)
|
8
|
-
false
|
9
|
-
else
|
10
|
-
column = self.class.columns_hash[attr_name]
|
11
|
-
if column.nil?
|
12
|
-
|
13
|
-
# TODO submit a rails patch
|
14
|
-
|
15
|
-
# not sure what active_record tests say but i guess this should mean:
|
16
|
-
# call to_i and check zero? if the value is a Numeric or starts with
|
17
|
-
# a digit, so it can meaningfully be typecasted by to_i
|
18
|
-
|
19
|
-
# if Numeric === value || value !~ /[^0-9]/
|
20
|
-
if Numeric === value || value.to_s =~ /^[0-9]/
|
21
|
-
!value.to_i.zero?
|
22
|
-
else
|
23
|
-
return false if ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(value)
|
24
|
-
!value.blank?
|
25
|
-
end
|
26
|
-
elsif column.number?
|
27
|
-
!value.zero?
|
28
|
-
else
|
29
|
-
!value.blank?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Globalize
|
2
|
-
module AttributeMethods
|
3
|
-
module Serialization
|
4
|
-
def serialize(attr_name, class_name_or_coder = Object)
|
5
|
-
super(attr_name, class_name_or_coder)
|
6
|
-
|
7
|
-
coder = if class_name_or_coder == ::JSON
|
8
|
-
::ActiveRecord::Coders::JSON
|
9
|
-
elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
|
10
|
-
class_name_or_coder
|
11
|
-
else
|
12
|
-
::ActiveRecord::Coders::YAMLColumn.new(class_name_or_coder)
|
13
|
-
end
|
14
|
-
|
15
|
-
self.globalize_serialized_attributes = globalize_serialized_attributes.dup
|
16
|
-
self.globalize_serialized_attributes[attr_name] = coder
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
ActiveRecord::AttributeMethods::Serialization::ClassMethods.send(:prepend, Globalize::AttributeMethods::Serialization)
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'active_record/validations/uniqueness.rb'
|
2
|
-
|
3
|
-
module Globalize
|
4
|
-
module UniquenessValidatorOverride
|
5
|
-
def validate_each(record, attribute, value)
|
6
|
-
klass = record.class
|
7
|
-
if klass.translates? && klass.translated?(attribute)
|
8
|
-
finder_class = klass.translation_class
|
9
|
-
table = finder_class.arel_table
|
10
|
-
|
11
|
-
relation = build_relation(finder_class, table, attribute, value).and(table[:locale].eq(Globalize.locale))
|
12
|
-
relation = relation.and(table[klass.reflect_on_association(:translations).foreign_key].not_eq(record.send(:id))) if record.persisted?
|
13
|
-
|
14
|
-
translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
|
15
|
-
untranslated_scopes = Array(options[:scope]) - translated_scopes
|
16
|
-
|
17
|
-
untranslated_scopes.each do |scope_item|
|
18
|
-
scope_value = record.send(scope_item)
|
19
|
-
reflection = klass.reflect_on_association(scope_item)
|
20
|
-
if reflection
|
21
|
-
scope_value = record.send(reflection.foreign_key)
|
22
|
-
scope_item = reflection.foreign_key
|
23
|
-
end
|
24
|
-
relation = relation.and(find_finder_class_for(record).arel_table[scope_item].eq(scope_value))
|
25
|
-
end
|
26
|
-
|
27
|
-
translated_scopes.each do |scope_item|
|
28
|
-
scope_value = record.send(scope_item)
|
29
|
-
relation = relation.and(table[scope_item].eq(scope_value))
|
30
|
-
end
|
31
|
-
|
32
|
-
if klass.unscoped.with_translations.where(relation).exists?
|
33
|
-
record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
|
34
|
-
end
|
35
|
-
else
|
36
|
-
super
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
ActiveRecord::Validations::UniquenessValidator.send :prepend, Globalize::UniquenessValidatorOverride
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Globalize
|
2
|
-
module Validations
|
3
|
-
module UniquenessValidator
|
4
|
-
def validate_each(record, attribute, value)
|
5
|
-
klass = record.class
|
6
|
-
if klass.translates? && klass.translated?(attribute)
|
7
|
-
finder_class = klass.translation_class
|
8
|
-
finder_table = finder_class.arel_table
|
9
|
-
relation = build_relation(finder_class, finder_table, attribute, value).where(locale: Globalize.locale)
|
10
|
-
relation = relation.where.not(klass.reflect_on_association(:translations).foreign_key => record.send(:id)) if record.persisted?
|
11
|
-
|
12
|
-
|
13
|
-
translated_scopes = Array(options[:scope]) & klass.translated_attribute_names
|
14
|
-
untranslated_scopes = Array(options[:scope]) - translated_scopes
|
15
|
-
|
16
|
-
relation = relation.joins(:globalized_model) if untranslated_scopes.present?
|
17
|
-
untranslated_scopes.each do |scope_item|
|
18
|
-
scope_value = record.send(scope_item)
|
19
|
-
reflection = klass.reflect_on_association(scope_item)
|
20
|
-
if reflection
|
21
|
-
scope_value = record.send(reflection.foreign_key)
|
22
|
-
scope_item = reflection.foreign_key
|
23
|
-
end
|
24
|
-
relation = relation.where(find_finder_class_for(record).table_name => { scope_item => scope_value })
|
25
|
-
end
|
26
|
-
|
27
|
-
translated_scopes.each do |scope_item|
|
28
|
-
scope_value = record.send(scope_item)
|
29
|
-
relation = relation.where(scope_item => scope_value)
|
30
|
-
end
|
31
|
-
relation = relation.merge(options[:conditions]) if options[:conditions]
|
32
|
-
|
33
|
-
# if klass.unscoped.with_translations.where(relation).exists?
|
34
|
-
if relation.exists?
|
35
|
-
error_options = options.except(:case_sensitive, :scope, :conditions)
|
36
|
-
error_options[:value] = value
|
37
|
-
record.errors.add(attribute, :taken, error_options)
|
38
|
-
end
|
39
|
-
else
|
40
|
-
super(record, attribute, value)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
ActiveRecord::Validations::UniquenessValidator.prepend Globalize::Validations::UniquenessValidator
|