counter_culture 3.7.0 → 3.8.1

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
  SHA256:
3
- metadata.gz: 88687e8c584a1643026e8e09d9f64484110fd7a19ebf1faa6cb311361e8c35ca
4
- data.tar.gz: a81ac645489129472e265f3bfefa0573f11a9e8419a40ba7f4c687c692367177
3
+ metadata.gz: 4355ba12c0a0ecf776641647648a3422d5aafc76c48a5db418d381f51f0890de
4
+ data.tar.gz: 8b1dd8e1de14b7b5377deaa9143c0ffbc8e6f4418524931dcd494417de49d1ca
5
5
  SHA512:
6
- metadata.gz: 82ffa1af6e6ad80f68a56b77cdae1f68dd30aa63535281f4ee19ee3ad1e5f88cc7053ae4cab6f1786db7038baeb81cf5c434b1b657f886b62862d79b0d99d7dc
7
- data.tar.gz: 83e5c626c97583727a5cbef6c824dd5eb25625d169a53e65e73bd1d2ab633121bb2a1a2de430a2d522caa92382b5852d731e0f954818fa906ab2b0060986119a
6
+ metadata.gz: d3c7ec219454d12a50d79815da7fa920cd1644ca268fceea089d9eac28438b7a28df3949f969bc9c63ee60a56c0d6d4e8f56e42f0e2218cb9e42e9a157ca1420
7
+ data.tar.gz: 63c4cd5958f0a3a2fa9eb6b6018cc0891ced1f2ad2708d02ea49f9cce8416ffc42a62ae01eb7b2cf2dad5334e16061eac517c7f8be40b35068694b63a238c748
data/.circleci/config.yml CHANGED
@@ -49,7 +49,7 @@ workflows:
49
49
  matrix:
50
50
  parameters:
51
51
  ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3"]
52
- rails-version: ["5.2", "6.0", "6.1", "7.0", "7.1"]
52
+ rails-version: ["5.2", "6.0", "6.1", "7.0", "7.1", "7.2"]
53
53
  database: ["postgresql", "sqlite3", "mysql2"]
54
54
  exclude:
55
55
  - ruby-version: "3.0"
@@ -106,3 +106,30 @@ workflows:
106
106
  - ruby-version: "2.6"
107
107
  rails-version: "7.1"
108
108
  database: "mysql2"
109
+ - ruby-version: "2.6"
110
+ rails-version: "7.2"
111
+ database: "postgresql"
112
+ - ruby-version: "2.6"
113
+ rails-version: "7.2"
114
+ database: "sqlite3"
115
+ - ruby-version: "2.6"
116
+ rails-version: "7.2"
117
+ database: "mysql2"
118
+ - ruby-version: "2.7"
119
+ rails-version: "7.2"
120
+ database: "postgresql"
121
+ - ruby-version: "2.7"
122
+ rails-version: "7.2"
123
+ database: "sqlite3"
124
+ - ruby-version: "2.7"
125
+ rails-version: "7.2"
126
+ database: "mysql2"
127
+ - ruby-version: "3.0"
128
+ rails-version: "7.2"
129
+ database: "postgresql"
130
+ - ruby-version: "3.0"
131
+ rails-version: "7.2"
132
+ database: "sqlite3"
133
+ - ruby-version: "3.0"
134
+ rails-version: "7.2"
135
+ database: "mysql2"
data/Appraisals CHANGED
@@ -4,6 +4,7 @@
4
4
  6.1
5
5
  7.0
6
6
  7.1
7
+ 7.2
7
8
  ].each do |rails_version|
8
9
  appraise "rails-#{rails_version}" do
9
10
  gem 'rails', "~> #{rails_version}.0"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 3.8.1 (October 18, 2024)
2
+
3
+ Bugfixes:
4
+ - Fix compatibility with `mobility` gem by skipping attributes that don't exist in the database but show up in `saved_changes` (#401)
5
+
6
+ ## 3.8.0 (October 4, 2024)
7
+
8
+ New features:
9
+ - Prefer using `with_connection` where possible (#398)
10
+
1
11
  ## 3.7.0 (June 20, 2024)
2
12
 
3
13
  New features:
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.2.0"
6
+
7
+ gemspec path: "../"
@@ -1,3 +1,5 @@
1
+ require_relative './with_connection'
2
+
1
3
  module CounterCulture
2
4
  class Counter
3
5
  CONFIG_OPTIONS = [ :column_names, :counter_cache_name, :delta_column, :foreign_key_values, :touch, :delta_magnitude, :execute_after_commit ]
@@ -65,11 +67,13 @@ module CounterCulture
65
67
  # MySQL throws an ambiguous column error if any joins are present and we don't include the
66
68
  # table name. We isolate this change to MySQL because sqlite has the opposite behavior and
67
69
  # throws an exception if the table name is present after UPDATE.
68
- quoted_column = if klass.connection.adapter_name == 'Mysql2'
69
- "#{klass.quoted_table_name}.#{model.connection.quote_column_name(change_counter_column)}"
70
- else
71
- "#{model.connection.quote_column_name(change_counter_column)}"
72
- end
70
+ quoted_column = WithConnection.new(klass).call do |connection|
71
+ if connection.adapter_name == 'Mysql2'
72
+ "#{klass.quoted_table_name}.#{connection.quote_column_name(change_counter_column)}"
73
+ else
74
+ "#{connection.quote_column_name(change_counter_column)}"
75
+ end
76
+ end
73
77
 
74
78
  column_type = klass.type_for_attribute(change_counter_column).type
75
79
 
@@ -328,6 +332,8 @@ module CounterCulture
328
332
 
329
333
  changes_method = ACTIVE_RECORD_VERSION >= Gem::Version.new("5.1.0") ? :saved_changes : :changed_attributes
330
334
  obj.public_send(changes_method).each do |key, value|
335
+ next unless obj.has_attribute?(key.to_s)
336
+
331
337
  old_value = ACTIVE_RECORD_VERSION >= Gem::Version.new("5.1.0") ? value.first : value
332
338
  # We set old values straight to AR @attributes variable to avoid
333
339
  # write_attribute callbacks from other gems (e.g. ArTransactionChanges)
@@ -1,6 +1,8 @@
1
1
  require 'active_support/core_ext/module/delegation'
2
2
  require 'active_support/core_ext/module/attribute_accessors'
3
3
 
4
+ require_relative './with_connection'
5
+
4
6
  module CounterCulture
5
7
  class Reconciler
6
8
  ACTIVE_RECORD_VERSION = Gem.loaded_specs["activerecord"].version
@@ -312,7 +314,9 @@ module CounterCulture
312
314
  # using Postgres with schema-namespaced tables. But then it's required,
313
315
  # and otherwise it's just a no-op, so why not do it?
314
316
  def quote_table_name(table_name)
315
- relation_class.connection.quote_table_name(table_name)
317
+ WithConnection.new(relation_class).call do |connection|
318
+ connection.quote_table_name(table_name)
319
+ end
316
320
  end
317
321
 
318
322
  def parameterize(string)
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.7.0'.freeze
2
+ VERSION = '3.8.1'.freeze
3
3
  end
@@ -0,0 +1,33 @@
1
+ module CounterCulture
2
+ class WithConnection
3
+ def initialize(recipient)
4
+ @recipient = recipient
5
+ end
6
+
7
+ attr_reader :recipient
8
+
9
+ def call
10
+ if rails_7_2_or_greater?
11
+ recipient.with_connection do |connection|
12
+ yield connection
13
+ end
14
+ elsif rails_7_1?
15
+ recipient.connection_pool.with_connection do |connection|
16
+ yield connection
17
+ end
18
+ else
19
+ yield recipient.connection
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def rails_7_1?
26
+ Gem::Requirement.new('~> 7.1.0').satisfied_by?(Gem::Version.new(Rails.version))
27
+ end
28
+
29
+ def rails_7_2_or_greater?
30
+ Gem::Requirement.new('>= 7.2.0').satisfied_by?(Gem::Version.new(Rails.version))
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-20 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -318,12 +318,14 @@ files:
318
318
  - gemfiles/rails_6.1.gemfile
319
319
  - gemfiles/rails_7.0.gemfile
320
320
  - gemfiles/rails_7.1.gemfile
321
+ - gemfiles/rails_7.2.gemfile
321
322
  - lib/counter_culture.rb
322
323
  - lib/counter_culture/counter.rb
323
324
  - lib/counter_culture/extensions.rb
324
325
  - lib/counter_culture/reconciler.rb
325
326
  - lib/counter_culture/skip_updates.rb
326
327
  - lib/counter_culture/version.rb
328
+ - lib/counter_culture/with_connection.rb
327
329
  - lib/generators/counter_culture_generator.rb
328
330
  - lib/generators/templates/counter_culture_migration.rb.erb
329
331
  homepage: https://github.com/magnusvk/counter_culture