updateable_views_inheritance 1.5.1 → 1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4134e2e8c505f5ca5c6d53762497a18b168b5cb43027a121f337908d1595d5b
4
- data.tar.gz: 7dc39d94d346f6efef8862c2482afe72d97f745b822b59b313041dcb21fb9ebc
3
+ metadata.gz: 9822cbe06d8820cf3d4dcf96e4bf9c527f130b16d83edc1335858e250e392b55
4
+ data.tar.gz: 32755fb6541e0acb5ee155cb5ceb94021a9c838a28b73c033cc0b8e5c8a60110
5
5
  SHA512:
6
- metadata.gz: e50eeaa1e8e686fe94bd47f02f8109335b7f38efa94e65c108dc5e0c5dcc7509e476ee14ce3de31160673d6bcce0f540dcbf0142f774b1db7f017ed106251b15
7
- data.tar.gz: e2e3e32f9b7e6f77c113c1d80701f6a1345a4352df0779d5cfc3f450bfe11fe04c6b65955ba07de440c4733df71ba84073294f274e6c14e4b80fda1024391208
6
+ metadata.gz: 6fbed4ffbc44f4841eeb0613fe64196f9e38b7e6f01c94aaa3a786d70401b3685a12c7a078d7a2bf26e58e6c615511619abc8b8d4195cf3f0bfddeaafc80ce24
7
+ data.tar.gz: b954e8fc8706faa9e081710292992e1cd60fd3003aa4e7b500f9c52ee71e4c5c5aab944277ab7d48b94f1279f9797dabef61c73cb8b7781dae2a4a2b5178892d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.8.0 (19 April 2026)
2
+
3
+ Upgrade to Rails 8.1
4
+
5
+ ## 1.7.0 (11 March 2025)
6
+
7
+ Upgrade to Rails 7 (tested with 7.0, 7.1, 7.2 and ruby 2.7.3, 3.1.6)
8
+
1
9
  ## 1.5.1 (27 February 2025)
2
10
 
3
11
  Upgrade to Rails 5.1
data/Gemfile CHANGED
@@ -3,9 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in updateable_views_inheritance.gemspec
4
4
  gemspec
5
5
 
6
- if RUBY_VERSION > "2"
7
- gem 'byebug'
8
- else
9
- gem 'debugger'
10
- end
6
+ gem 'byebug'
11
7
 
@@ -9,7 +9,7 @@ module UpdateableViewsInheritance# :nodoc:
9
9
  if object.class.name == self.name || self.disable_inheritance_instantiation
10
10
  object
11
11
  else
12
- object.class.find(attributes.with_indifferent_access[:id])
12
+ object.class.find(attributes.to_h.with_indifferent_access[:id])
13
13
  end
14
14
  end
15
15
  end
@@ -90,19 +90,29 @@ module ActiveRecord #:nodoc:
90
90
  if parent
91
91
  reset_pk_sequence!(parent, pk, sequence)
92
92
  else
93
- unless pk and sequence
93
+ unless pk && sequence
94
94
  default_pk, default_sequence = pk_and_sequence_for(table)
95
+
95
96
  pk ||= default_pk
96
97
  sequence ||= default_sequence
97
98
  end
98
- if pk
99
- if sequence
100
- select_value <<-SQL, 'Reset sequence'
101
- SELECT setval('#{sequence}', (SELECT COALESCE(MAX(#{pk})+(SELECT increment_by FROM #{sequence}), (SELECT min_value FROM #{sequence})) FROM #{table}), false)
102
- SQL
103
- else
104
- @logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger
99
+
100
+ if @logger && pk && !sequence
101
+ @logger.warn "#{table} has primary key #{pk} with no default sequence."
102
+ end
103
+
104
+ if pk && sequence
105
+ quoted_sequence = quote_table_name(sequence)
106
+ max_pk = query_value("SELECT MAX(#{quote_column_name pk}) FROM #{quote_table_name(table)}", "SCHEMA")
107
+ if max_pk.nil?
108
+ if postgresql_version >= 100000
109
+ minvalue = query_value("SELECT seqmin FROM pg_sequence WHERE seqrelid = #{quote(quoted_sequence)}::regclass", "SCHEMA")
110
+ else
111
+ minvalue = query_value("SELECT min_value FROM #{quoted_sequence}", "SCHEMA")
112
+ end
105
113
  end
114
+
115
+ query_value("SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})", "SCHEMA")
106
116
  end
107
117
  end
108
118
  end
@@ -1,3 +1,3 @@
1
1
  module UpdateableViewsInheritance
2
- VERSION = "1.5.1"
2
+ VERSION = "1.8.0"
3
3
  end
data/test/content_test.rb CHANGED
@@ -2,11 +2,10 @@ require_relative 'test_helper'
2
2
 
3
3
  class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 5)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(5)
6
6
  ActiveRecord::FixtureSet.reset_cache
7
7
  end
8
8
 
9
-
10
9
  def test_find
11
10
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
12
11
  locomotive = Locomotive.find(1)
@@ -33,10 +32,7 @@ class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
33
32
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :electric_locomotives)
34
33
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
35
34
 
36
- binds = [[ElectricLocomotive.columns.find { |c| c.name == 'electricity_consumption'}, 40],
37
- [ElectricLocomotive.columns.find { |c| c.name == 'max_speed'}, 120],
38
- [ElectricLocomotive.columns.find { |c| c.name == 'name'}, 'BoBo'],
39
- [ElectricLocomotive.columns.find { |c| c.name == 'type'}, 'ElectricLocomotive']]
35
+ binds = [40, 120, 'BoBo', 'ElectricLocomotive']
40
36
  res = ActiveRecord::Base.connection.exec_query(<<-SQL, 'Test prepared statement', binds)
41
37
  INSERT INTO electric_locomotives (electricity_consumption, max_speed, name, type) VALUES ($1, $2, $3, $4) RETURNING id
42
38
  SQL
@@ -63,7 +59,7 @@ class UpdateableViewsInheritanceContentTest < ActiveSupport::TestCase
63
59
  def test_update
64
60
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', :steam_locomotives)
65
61
  steam_locomotive = Locomotive.find(1)
66
- steam_locomotive.update_attributes( :name => 'Rocket')
62
+ steam_locomotive.update(name: 'Rocket')
67
63
  steam_locomotive.reload
68
64
  assert_equal 'Rocket', steam_locomotive.name
69
65
  end
@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  class DeepHierarchyTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 8)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(8)
6
6
 
7
7
  ActiveRecord::FixtureSet.reset_cache
8
8
  # order of fixtures is important for the test - last loaded should not be with max(id)
9
- %w(boats electric_trains rack_trains steam_trains cars maglev_trains bicycles).each do |f|
10
- ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
9
+ %w(boats electric_trains rack_trains steam_trains maglev_trains bicycles).each do |f|
10
+ ActiveRecord::FixtureSet.create_fixtures("#{__dir__}/fixtures/", f)
11
11
  end
12
12
  @connection = ActiveRecord::Base.connection
13
13
  end
@@ -41,7 +41,7 @@ class DeepHierarchyTest < ActiveSupport::TestCase
41
41
 
42
42
  def test_single_table_inheritance_deeper_hierarchy_contents
43
43
  mag = MaglevTrain.first
44
- assert_equal [mag.id, mag.name, mag.number_of_rails, mag.max_speed, mag.magnetic_field, (sprintf("%.2f",mag.electricity_consumption))], (@connection.query("SELECT id, name, number_of_rails, max_speed, magnetic_field, electricity_consumption FROM all_vehicles WHERE id=#{mag.id}").first)
44
+ assert_equal [mag.id, mag.name, mag.number_of_rails, mag.max_speed, mag.magnetic_field, mag.electricity_consumption], (@connection.query("SELECT id, name, number_of_rails, max_speed, magnetic_field, electricity_consumption FROM all_vehicles WHERE id=#{mag.id}").first)
45
45
  end
46
46
 
47
47
  class OrderColumnsInAggregateView < ActiveRecord::Migration[4.2]
@@ -7,6 +7,7 @@ require "updateable_views_inheritance"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
10
+ config.load_defaults 8.1
10
11
  # Settings in config/environments/* take precedence over those specified here.
11
12
  # Application configuration should go into files in config/initializers
12
13
  # -- all .rb files in that directory are automatically loaded.
@@ -42,12 +43,6 @@ module Dummy
42
43
  # This is necessary if your schema can't be completely dumped by the schema dumper,
43
44
  # like if you have constraints or database-specific column types
44
45
  # config.active_record.schema_format = :sql
45
-
46
- # Enable the asset pipeline
47
- config.assets.enabled = true
48
-
49
- # Version of your assets, change this if you want to expire all your assets
50
- config.assets.version = '1.0'
51
46
  end
52
47
  end
53
48
 
@@ -2,8 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class InstantiationTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
6
-
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(7)
7
6
  ActiveRecord::FixtureSet.reset_cache
8
7
  # order of fixtures is important for the test - last loaded should not be with max(id)
9
8
  %w[steam_locomotives electric_locomotives maglev_locomotives bicycles].each do |f|
@@ -7,20 +7,20 @@ class UpdateableViewsInheritanceMigrationTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  def test_create_child_default
10
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
10
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(2)
11
11
  assert_equal %w(coal_consumption id max_speed name type water_consumption),
12
12
  @connection.columns(:steam_locomotives).map{ |c| c.name }.sort
13
13
  end
14
14
 
15
15
  def test_create_child_explicit_table
16
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 3)
16
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(3)
17
17
  assert_equal %w(electricity_consumption id max_speed name type),
18
18
  @connection.columns(:electric_locomotives).map{ |c| c.name }.sort
19
19
  end
20
20
 
21
21
  def test_drop_child
22
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 3)
23
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 2)
22
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(3)
23
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(2)
24
24
  assert_equal %w(steam_locomotives), @connection.views.sort
25
25
  assert_equal %w(ar_internal_metadata
26
26
  locomotives
data/test/schema_test.rb CHANGED
@@ -2,7 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class SchemaTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 5)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(5)
6
6
  @connection = ActiveRecord::Base.connection
7
7
  end
8
8
 
@@ -273,7 +273,7 @@ class SchemaTest < ActiveSupport::TestCase
273
273
  end
274
274
 
275
275
  def test_rebuild_all_parent_and_children_views
276
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 7)
276
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(7)
277
277
  @connection.execute "DROP VIEW all_locomotives" #FIXME: single table inheritance view should be rebuilt as well
278
278
  ChangeTablesInTwoInheritanceChains.new.up
279
279
 
@@ -2,7 +2,7 @@ require_relative 'test_helper'
2
2
 
3
3
  class SingleTableInheritanceAggregateViewTest < ActiveSupport::TestCase
4
4
  def setup
5
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 6)
5
+ ActiveRecord::MigrationContext.new("#{__dir__}/fixtures/migrations").migrate(6)
6
6
  # order of fixtures is important for the test - last loaded should not be with max(id)
7
7
  %w(electric_locomotives maglev_locomotives steam_locomotives).each do |f|
8
8
  ActiveRecord::FixtureSet.create_fixtures(File.dirname(__FILE__) + '/fixtures/', f)
data/test/test_helper.rb CHANGED
@@ -33,9 +33,7 @@ require 'byebug'
33
33
 
34
34
  class ActiveSupport::TestCase #:nodoc:
35
35
  include ActiveRecord::TestFixtures
36
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
37
36
  ActiveRecord::Migration.verbose = false
38
- # self.use_transactional_fixtures = true
39
37
 
40
38
  # def teardown
41
39
  # ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/', 1)
@@ -18,14 +18,13 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency "activerecord", "~> 5.1.7"
21
+ s.add_dependency "activerecord", '>= 8', '< 9'
22
22
  s.add_dependency "pg"
23
23
 
24
- s.add_development_dependency 'bigdecimal', '1.3.5'
25
24
  s.add_development_dependency "bundler"
26
25
  s.add_development_dependency "minitest"
27
26
  s.add_development_dependency "minitest-reporters"
28
- s.add_development_dependency "rails", '~> 5.1.7'
27
+ s.add_development_dependency "rails"
29
28
  s.add_development_dependency "rake"
30
29
  s.add_development_dependency "simplecov"
31
30
  s.add_development_dependency "simplecov_json_formatter"
metadata CHANGED
@@ -1,30 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: updateable_views_inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sava Chankov
8
8
  - Denitsa Belogusheva
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2025-02-27 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '8'
20
+ - - "<"
19
21
  - !ruby/object:Gem::Version
20
- version: 5.1.7
22
+ version: '9'
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - "~>"
27
+ - - ">="
26
28
  - !ruby/object:Gem::Version
27
- version: 5.1.7
29
+ version: '8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '9'
28
33
  - !ruby/object:Gem::Dependency
29
34
  name: pg
30
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,20 +44,6 @@ dependencies:
39
44
  - - ">="
40
45
  - !ruby/object:Gem::Version
41
46
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: bigdecimal
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - '='
47
- - !ruby/object:Gem::Version
48
- version: 1.3.5
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - '='
54
- - !ruby/object:Gem::Version
55
- version: 1.3.5
56
47
  - !ruby/object:Gem::Dependency
57
48
  name: bundler
58
49
  requirement: !ruby/object:Gem::Requirement
@@ -99,16 +90,16 @@ dependencies:
99
90
  name: rails
100
91
  requirement: !ruby/object:Gem::Requirement
101
92
  requirements:
102
- - - "~>"
93
+ - - ">="
103
94
  - !ruby/object:Gem::Version
104
- version: 5.1.7
95
+ version: '0'
105
96
  type: :development
106
97
  prerelease: false
107
98
  version_requirements: !ruby/object:Gem::Requirement
108
99
  requirements:
109
- - - "~>"
100
+ - - ">="
110
101
  - !ruby/object:Gem::Version
111
- version: 5.1.7
102
+ version: '0'
112
103
  - !ruby/object:Gem::Dependency
113
104
  name: rake
114
105
  requirement: !ruby/object:Gem::Requirement
@@ -270,7 +261,6 @@ homepage: http://github.com/tutuf/updateable_views_inheritance
270
261
  licenses:
271
262
  - MIT
272
263
  metadata: {}
273
- post_install_message:
274
264
  rdoc_options: []
275
265
  require_paths:
276
266
  - lib
@@ -285,8 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
275
  - !ruby/object:Gem::Version
286
276
  version: '0'
287
277
  requirements: []
288
- rubygems_version: 3.1.6
289
- signing_key:
278
+ rubygems_version: 3.6.9
290
279
  specification_version: 4
291
280
  summary: Class table inheritance for ActiveRecord
292
281
  test_files: