-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add sharding support to the collection * fix: fixes to the db connection of specs * fix: fix specs for rails older than 6.x * chore: fix rubocop offenses
- Loading branch information
Showing
13 changed files
with
171 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 0.3.7 - 2024-08-05 | ||
* Add `connected_to` to the collection for custom connection handling | ||
|
||
## 0.0.1 | ||
The first release of the esse-active_record plugin | ||
* Added: Initial implementation of the plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Esse | ||
module ActiveRecord | ||
VERSION = '0.3.6' | ||
VERSION = '0.3.7' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Esse::ActiveRecord::Collection, '.connected_to' do | ||
let(:collection_class) { Class.new(described_class) } | ||
|
||
describe '.connected_to' do | ||
it 'sets the connect_with' do | ||
collection_class.connected_to(role: :reading, shard: :default) | ||
expect(collection_class.connect_with).to eq(role: :reading, shard: :default) | ||
end | ||
end | ||
|
||
describe '#each using custom connection', :sharding do | ||
let(:collection_class) do | ||
klass = Class.new(described_class) | ||
klass.base_scope = -> { State } | ||
klass.connected_to(role: :reading) | ||
klass | ||
end | ||
|
||
it 'uses the custom connection' do | ||
expect(ActiveRecord::Base).to receive(:connected_to).with(role: :reading).and_call_original | ||
il_state = State.create!(name: 'Illinois', abbr_name: 'IL') | ||
|
||
instance = collection_class.new | ||
expect { |b| instance.each(&b) }.to yield_successive_args([il_state]) | ||
il_state.destroy | ||
end | ||
end | ||
|
||
describe '#each_batch_ids using custom connection', :sharding do | ||
let(:collection_class) do | ||
klass = Class.new(described_class) | ||
klass.base_scope = -> { State } | ||
klass.connected_to(role: :reading) | ||
klass | ||
end | ||
|
||
it 'uses the custom connection' do | ||
expect(ActiveRecord::Base).to receive(:connected_to).with(role: :reading).and_call_original | ||
il_state = State.create!(name: 'Illinois', abbr_name: 'IL') | ||
|
||
instance = collection_class.new | ||
expect { |b| instance.each_batch_ids(&b) }.to yield_successive_args([il_state.id]) | ||
il_state.destroy | ||
end | ||
end | ||
|
||
describe '#count using custom connection', :sharding do | ||
let(:collection_class) do | ||
klass = Class.new(described_class) | ||
klass.base_scope = -> { State } | ||
klass.connected_to(role: :reading) | ||
klass | ||
end | ||
|
||
it 'uses the custom connection' do | ||
expect(ActiveRecord::Base).to receive(:connected_to).with(role: :reading).and_call_original | ||
il_state = State.create!(name: 'Illinois', abbr_name: 'IL') | ||
|
||
instance = collection_class.new | ||
expect(instance.count).to eq(1) | ||
il_state.destroy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module ShardingHook | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
around do |example| | ||
if example.metadata[:sharding] && | ||
!ActiveRecord::Base.respond_to?(:connected_to) | ||
skip 'ActiveRecord::Base.connected_to is not available in this version of Rails' | ||
return | ||
end | ||
|
||
example.run | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include ShardingHook | ||
end |