pecorino 0.7.2 → 0.7.4

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.
@@ -23,7 +23,7 @@ class PostgresAdapterTest < ActiveSupport::TestCase
23
23
 
24
24
  def create_postgres_database_if_none
25
25
  self.class.establish_connection(encoding: "unicode", database: SEED_DB_NAME.call)
26
- ActiveRecord::Base.connection.execute("SELECT 1 FROM pecorino_leaky_buckets")
26
+ ActiveRecord::Base.connection_pool.with_connection { |connection| connection.execute("SELECT 1 FROM pecorino_leaky_buckets") }
27
27
  rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
28
28
  create_postgres_database
29
29
  retry
@@ -38,20 +38,24 @@ class PostgresAdapterTest < ActiveSupport::TestCase
38
38
  def create_postgres_database
39
39
  ActiveRecord::Migration.verbose = false
40
40
  self.class.establish_connection(database: "postgres")
41
- ActiveRecord::Base.connection.create_database(SEED_DB_NAME.call, charset: :unicode)
41
+ ActiveRecord::Base.connection_pool.with_connection { |connection| connection.create_database(SEED_DB_NAME.call, charset: :unicode) }
42
42
  ActiveRecord::Base.connection.close
43
43
  self.class.establish_connection(encoding: "unicode", database: SEED_DB_NAME.call)
44
44
  end
45
45
 
46
46
  def truncate_test_tables
47
- ActiveRecord::Base.connection.execute("TRUNCATE TABLE pecorino_leaky_buckets")
48
- ActiveRecord::Base.connection.execute("TRUNCATE TABLE pecorino_blocks")
47
+ ActiveRecord::Base.connection_pool.with_connection do |connection|
48
+ connection.execute("TRUNCATE TABLE pecorino_leaky_buckets")
49
+ connection.execute("TRUNCATE TABLE pecorino_blocks")
50
+ end
49
51
  end
50
52
 
51
53
  def test_create_tables
52
54
  ActiveRecord::Base.transaction do
53
- ActiveRecord::Base.connection.execute("DROP TABLE pecorino_leaky_buckets")
54
- ActiveRecord::Base.connection.execute("DROP TABLE pecorino_blocks")
55
+ ActiveRecord::Base.connection_pool.with_connection do |connection|
56
+ connection.execute("DROP TABLE pecorino_leaky_buckets")
57
+ connection.execute("DROP TABLE pecorino_blocks")
58
+ end
55
59
  # The adapter has to be in a variable as the schema definition is scoped to the migrator, not self
56
60
  retained_adapter = create_adapter # the schema define block is run via instance_exec so it does not retain scope
57
61
  ActiveRecord::Schema.define(version: 1) do |via_definer|
@@ -64,6 +68,6 @@ class PostgresAdapterTest < ActiveSupport::TestCase
64
68
  Minitest.after_run do
65
69
  ActiveRecord::Base.connection.close
66
70
  establish_connection(database: "postgres")
67
- ActiveRecord::Base.connection.drop_database(SEED_DB_NAME.call)
71
+ ActiveRecord::Base.connection_pool.with_connection { |connection| connection.drop_database(SEED_DB_NAME.call) }
68
72
  end
69
73
  end
@@ -33,8 +33,10 @@ class SqliteAdapterTest < ActiveSupport::TestCase
33
33
 
34
34
  def test_create_tables
35
35
  ActiveRecord::Base.transaction do
36
- ActiveRecord::Base.connection.execute("DROP TABLE pecorino_leaky_buckets")
37
- ActiveRecord::Base.connection.execute("DROP TABLE pecorino_blocks")
36
+ ActiveRecord::Base.connection_pool.with_connection do |connection|
37
+ connection.execute("DROP TABLE pecorino_leaky_buckets")
38
+ connection.execute("DROP TABLE pecorino_blocks")
39
+ end
38
40
  # The adapter has to be in a variable as the schema definition is scoped to the migrator, not self
39
41
  retained_adapter = create_adapter # the schema define block is run via instance_exec so it does not retain scope
40
42
  ActiveRecord::Schema.define(version: 1) do |via_definer|
data/test/block_test.rb CHANGED
@@ -4,20 +4,24 @@ require "test_helper"
4
4
  require "base64"
5
5
 
6
6
  class BlockTest < ActiveSupport::TestCase
7
+ def setup
8
+ @adapter = Pecorino::Adapters::MemoryAdapter.new
9
+ end
10
+
7
11
  test "sets a block" do
8
12
  k = Base64.strict_encode64(Random.bytes(4))
9
- assert_nil Pecorino::Block.blocked_until(key: k)
10
- assert Pecorino::Block.set!(key: k, block_for: 30.minutes)
13
+ assert_nil Pecorino::Block.blocked_until(key: k, adapter: @adapter)
14
+ assert Pecorino::Block.set!(key: k, block_for: 30.minutes, adapter: @adapter)
11
15
 
12
- blocked_until = Pecorino::Block.blocked_until(key: k)
16
+ blocked_until = Pecorino::Block.blocked_until(key: k, adapter: @adapter)
13
17
  assert_in_delta Time.now + 30.minutes, blocked_until, 10
14
18
  end
15
19
 
16
20
  test "does not return a block which has lapsed" do
17
21
  k = Base64.strict_encode64(Random.bytes(4))
18
- assert_nil Pecorino::Block.blocked_until(key: k)
19
- Pecorino::Block.set!(key: k, block_for: -30.minutes)
20
- blocked_until = Pecorino::Block.blocked_until(key: k)
22
+ assert_nil Pecorino::Block.blocked_until(key: k, adapter: @adapter)
23
+ Pecorino::Block.set!(key: k, block_for: -30.minutes, adapter: @adapter)
24
+ blocked_until = Pecorino::Block.blocked_until(key: k, adapter: @adapter)
21
25
  assert_nil blocked_until
22
26
  end
23
27
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pecorino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 2025-08-07 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -35,8 +34,10 @@ files:
35
34
  - ".github/workflows/ci.yml"
36
35
  - ".gitignore"
37
36
  - ".standard.yml"
37
+ - ".yardopts"
38
38
  - CHANGELOG.md
39
39
  - CODE_OF_CONDUCT.md
40
+ - Gemfile
40
41
  - LICENSE.txt
41
42
  - README.md
42
43
  - Rakefile
@@ -59,6 +60,7 @@ files:
59
60
  - lib/pecorino/version.rb
60
61
  - pecorino.gemspec
61
62
  - rbi/pecorino.rbi
63
+ - rbi/pecorino.rbs
62
64
  - test/adapters/adapter_test_methods.rb
63
65
  - test/adapters/memory_adapter_test.rb
64
66
  - test/adapters/postgres_adapter_test.rb
@@ -77,7 +79,6 @@ metadata:
77
79
  homepage_uri: https://github.com/cheddar-me/pecorino
78
80
  source_code_uri: https://github.com/cheddar-me/pecorino
79
81
  changelog_uri: https://github.com/cheddar-me/pecorino/CHANGELOG.md
80
- post_install_message:
81
82
  rdoc_options: []
82
83
  require_paths:
83
84
  - lib
@@ -92,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubygems_version: 3.1.6
96
- signing_key:
96
+ rubygems_version: 3.6.2
97
97
  specification_version: 4
98
98
  summary: Database-based rate limiter using leaky buckets
99
99
  test_files: []