activerecord-postgresql-cursors 1.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -1,11 +1,10 @@
1
+ # frozen_string_literal: true
1
2
 
2
- if RUBY_VERSION >= '1.9'
3
- require 'simplecov'
3
+ require 'simplecov'
4
4
 
5
- SimpleCov.command_name('Unit Tests')
6
- SimpleCov.start do
7
- add_filter '/test/'
8
- end
5
+ SimpleCov.command_name('Unit Tests')
6
+ SimpleCov.start do
7
+ add_filter '/test/'
9
8
  end
10
9
 
11
10
  require 'rubygems'
@@ -14,60 +13,43 @@ require 'active_support/core_ext/module/aliasing'
14
13
  require 'active_record'
15
14
  require 'logger'
16
15
  require 'minitest/autorun'
17
-
18
- if RUBY_VERSION >= '1.9'
19
- require 'minitest/reporters'
20
- end
16
+ require 'minitest/reporters'
21
17
 
22
18
  require File.join(File.dirname(__FILE__), *%w{ .. lib activerecord-postgresql-cursors })
23
19
 
24
- ActiveRecord::Base.logger = Logger.new("debug.log") if ENV['ENABLE_LOGGER']
25
- ActiveRecord::Base.configurations = {
26
- 'arunit' => {}
27
- }
28
-
29
- %w{
30
- database.yml
31
- local_database.yml
32
- }.each do |file|
33
- file = File.join('test', file)
34
-
35
- next unless File.exists?(file)
20
+ ActiveRecord::Base.logger = Logger.new('debug.log') if ENV['ENABLE_LOGGER']
36
21
 
37
- configuration = YAML.load(File.read(file))
22
+ configurations = {}
38
23
 
39
- if configuration['arunit']
40
- ActiveRecord::Base.configurations['arunit'].merge!(configuration['arunit'])
41
- end
42
-
43
- if defined?(JRUBY_VERSION) && configuration['jdbc']
44
- ActiveRecord::Base.configurations['arunit'].merge!(configuration['jdbc'])
45
- end
46
- end
24
+ file = File.join('test', 'database.yml')
25
+ configuration = YAML.safe_load_file(file)
26
+ configurations['arunit'] = configuration['arunit'] if configuration['arunit']
27
+ configurations['arunit'].merge!(configuration['jdbc']) if defined?(JRUBY_VERSION) && configuration['jdbc']
47
28
 
48
- ActiveRecord::Base.establish_connection 'arunit'
29
+ ActiveRecord::Base.configurations = configurations
30
+ ActiveRecord::Base.establish_connection :arunit
49
31
  ARBC = ActiveRecord::Base.connection
50
32
 
51
33
  puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
52
- puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
53
- if postgresql_version = ARBC.select_rows('SELECT version()').flatten.to_s
54
- puts "PostgreSQL info from version(): #{postgresql_version}"
55
- end
34
+ puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version}"
35
+
36
+ postgresql_version = ARBC.select_rows('SELECT version()').flatten.to_s
56
37
 
57
- if !ARBC.table_exists?('foos')
38
+ puts "PostgreSQL info from version(): #{postgresql_version}" if postgresql_version
39
+
40
+ unless ARBC.data_source_exists?('foos')
58
41
  ActiveRecord::Migration.create_table(:foos) do |t|
59
42
  t.text :name
60
43
  end
61
44
  end
62
45
 
63
- if !ARBC.table_exists?('bars')
46
+ unless ARBC.data_source_exists?('bars')
64
47
  ActiveRecord::Migration.create_table(:bars) do |t|
65
48
  t.text :name
66
49
  t.integer :foo_id
67
50
  end
68
51
  end
69
52
 
70
-
71
53
  class Bar < ActiveRecord::Base
72
54
  belongs_to :foo
73
55
  end
@@ -84,18 +66,25 @@ module PostgreSQLCursorTestHelper
84
66
  ARBC.execute(%{select setval('bars_id_seq', 1, false)})
85
67
 
86
68
  %w{ six seven eight nine ten eleven twelve thirteen fourteen fifteen }.each do |name|
87
- Bar.create(:name => name)
69
+ Bar.create(name: name)
88
70
  end
89
71
 
90
72
  %w{ one two three four five }.each_with_index do |name, i|
91
- foo = Foo.new(:name => name)
92
- foo.bar_ids = [ i + 1, i + 6 ]
73
+ foo = Foo.new(name: name)
74
+ foo.bar_ids = [i + 1, i + 6]
93
75
  foo.save
94
76
  end
95
77
  end
96
78
  end
97
79
 
98
- if RUBY_VERSION >= '1.9'
99
- MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
100
- end
80
+ Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
81
+
82
+ if ENV['CI']
83
+ require 'simplecov_json_formatter'
101
84
 
85
+ SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
86
+ elsif ENV.fetch('COVERAGE', nil) == 'console'
87
+ require_relative 'support/rspec_console'
88
+
89
+ SimpleCov.formatter = SecuricyApp::SimpleCov::Formatter::RSpecConsole
90
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgresql-cursors
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J Smith
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-01 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,40 +16,47 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.3'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.3'
26
+ version: '6.1'
27
27
  description: Provides some support for PostgreSQL cursors in ActiveRecord.
28
28
  email: dark.panda@gmail.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files:
32
- - README.rdoc
32
+ - README.md
33
33
  files:
34
+ - ".github/workflows/main.yml"
34
35
  - ".gitignore"
36
+ - ".rubocop-minitest.yml"
37
+ - ".rubocop.yml"
38
+ - ".rubocop_todo.yml"
39
+ - FUNDING.yml
35
40
  - Gemfile
36
41
  - Guardfile
37
42
  - MIT-LICENSE
38
- - README.rdoc
43
+ - README.md
39
44
  - Rakefile
40
45
  - activerecord-postgresql-cursors.gemspec
41
46
  - lib/active_record/postgresql_cursors/cursors.rb
42
- - lib/active_record/postgresql_cursors/cursors_2.rb
43
47
  - lib/active_record/postgresql_cursors/version.rb
44
48
  - lib/activerecord-postgresql-cursors.rb
45
- - test/cursor_tests.rb
49
+ - sonar-project.properties
50
+ - test/ci/github/database.yml
51
+ - test/cursor_test.rb
46
52
  - test/database.yml
47
53
  - test/test_helper.rb
48
54
  homepage: http://github.com/dark-panda/activerecord-postgresql-cursors
49
55
  licenses:
50
56
  - MIT
51
- metadata: {}
52
- post_install_message:
57
+ metadata:
58
+ rubygems_mfa_required: 'true'
59
+ post_install_message:
53
60
  rdoc_options: []
54
61
  require_paths:
55
62
  - lib
@@ -57,19 +64,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
64
  requirements:
58
65
  - - ">="
59
66
  - !ruby/object:Gem::Version
60
- version: '0'
67
+ version: '3.0'
61
68
  required_rubygems_version: !ruby/object:Gem::Requirement
62
69
  requirements:
63
70
  - - ">="
64
71
  - !ruby/object:Gem::Version
65
72
  version: '0'
66
73
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.5.1
69
- signing_key:
74
+ rubygems_version: 3.5.11
75
+ signing_key:
70
76
  specification_version: 4
71
77
  summary: Provides some support for PostgreSQL cursors in ActiveRecord.
72
- test_files:
73
- - test/cursor_tests.rb
74
- - test/database.yml
75
- - test/test_helper.rb
78
+ test_files: []
@@ -1,75 +0,0 @@
1
-
2
- module ActiveRecord
3
- class Base
4
- class << self
5
- # Override ActiveRecord::Base#find to allow for cursors in
6
- # PostgreSQL. To use a cursor, set the first argument of
7
- # find to :cursor. A PostgreSQLCursor object will be returned,
8
- # which can then be used as an Enumerable to loop through the
9
- # results.
10
- #
11
- # By default, cursor names are generated automatically using
12
- # "cursor_#{rand}", where rand is a big ol' random number that
13
- # is pretty unlikely to clash if you're using nested cursors.
14
- # Alternatively, you can supply a specific cursor name by
15
- # supplying a :cursor_name option.
16
- def find_with_cursors *args
17
- if args.first.to_s == 'cursor'
18
- options = args.extract_options!
19
- cursor_name = options.delete(:cursor_name)
20
- validate_find_options(options)
21
- set_readonly_option!(options)
22
- find_cursor(cursor_name, options)
23
- else
24
- find_without_cursors(*args)
25
- end
26
- end
27
- alias_method_chain :find, :cursors
28
-
29
- def cursor(*args)
30
- find(:cursor, *args)
31
- end
32
- end
33
-
34
- private
35
- # Find method for using cursors. This works just like the regular
36
- # ActiveRecord::Base#find_every method, except it returns a
37
- # PostgreSQLCursor object that can be used to loop through records.
38
- def self.find_cursor(cursor_name, options)
39
- unless connection.is_a? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
40
- raise CursorsNotSupported, "#{connection.class} doesn't support cursors"
41
- end
42
-
43
- catch :invalid_query do
44
- if options[:include]
45
- join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merge_includes(scope(:find, :include), options[:include]), options[:joins])
46
- return ActiveRecord::PostgreSQLCursor.new(
47
- self,
48
- cursor_name,
49
- construct_finder_sql_with_included_associations(
50
- options,
51
- join_dependency
52
- ),
53
- join_dependency
54
- )
55
- else
56
- return ActiveRecord::PostgreSQLCursor.new(
57
- self,
58
- cursor_name,
59
- construct_finder_sql(
60
- options
61
- )
62
- )
63
- end
64
- end
65
- nil
66
- end
67
- end
68
-
69
- class PostgreSQLCursor
70
- def initialize_with_rails_2(model, cursor_name, query, join_dependency = nil)
71
- initialize_without_rails_2(model, cursor_name, query, join_dependency)
72
- end
73
- alias_method_chain :initialize, :rails_2
74
- end
75
- end
data/test/cursor_tests.rb DELETED
@@ -1,97 +0,0 @@
1
-
2
- $: << File.dirname(__FILE__)
3
- require 'test_helper'
4
-
5
- class PostgreSQLCursorTests < MiniTest::Unit::TestCase
6
- include PostgreSQLCursorTestHelper
7
-
8
- def test_find_cursor
9
- cursor = Foo.find(:cursor, :order => 'id')
10
-
11
- assert(cursor.is_a?(ActiveRecord::PostgreSQLCursor))
12
-
13
- assert_equal(%w{ one two three four five }, cursor.collect(&:name))
14
- end
15
-
16
- def test_cursor_scoped
17
- cursor = Foo.cursor(:order => 'id')
18
-
19
- assert(cursor.is_a?(ActiveRecord::PostgreSQLCursor))
20
-
21
- assert_equal(%w{ one two three four five }, cursor.collect(&:name))
22
- end
23
-
24
- def test_cursor_while_updating
25
- cursor = Foo.cursor(:order => 'id')
26
-
27
- cursor.each do |row|
28
- row.name = "#{row.name}_updated"
29
- assert(row.save)
30
- end
31
-
32
- assert_equal(%w{ one_updated two_updated three_updated four_updated five_updated }, cursor.collect(&:name))
33
- end
34
-
35
- def test_with_associations
36
- cursor = Foo.cursor(:order => 'id')
37
-
38
- cursor.each do |row|
39
- assert(row.is_a?(Foo))
40
- row.bars.each do |bar|
41
- assert(bar.is_a?(Bar))
42
- end
43
- end
44
- end
45
-
46
- def test_with_associations_eager_loading
47
- cursor = Foo.cursor(:order => 'foos.id', :include => :bars)
48
-
49
- cursor.each do |row|
50
- assert(row.is_a?(Foo))
51
- row.bars.each do |bar|
52
- assert(bar.is_a?(Bar))
53
- end
54
- end
55
- end
56
-
57
- def test_nested_cursors
58
- cursor = Foo.cursor(:order => 'foos.id')
59
-
60
- cursor.each do |row|
61
- bars_cursor = row.bars.cursor
62
- assert(bars_cursor.is_a?(ActiveRecord::PostgreSQLCursor))
63
-
64
- bars_cursor.each do |bar|
65
- assert(bar.is_a?(Bar))
66
- end
67
- end
68
- end
69
-
70
- if ActiveRecord::VERSION::MAJOR >= 3
71
- def test_as_relation
72
- cursor = Foo.order('foos.id').where('foos.id >= 3').cursor
73
- assert_equal(3, cursor.to_a.length)
74
-
75
- cursor.each do |row|
76
- assert(row.is_a?(Foo))
77
- assert_equal(2, row.bars.length)
78
- row.bars.each do |bar|
79
- assert(bar.is_a?(Bar))
80
- end
81
- end
82
- end
83
-
84
- def test_as_relation_with_associations
85
- cursor = Foo.includes(:bars).order('foos.id').where('foos.id >= 3').cursor
86
- assert_equal(3, cursor.to_a.length)
87
-
88
- cursor.each do |row|
89
- assert(row.is_a?(Foo))
90
- assert_equal(2, row.bars.length)
91
- row.bars.each do |bar|
92
- assert(bar.is_a?(Bar))
93
- end
94
- end
95
- end
96
- end
97
- end