Skip to content

Commit

Permalink
feat: add connect_with option to the collection definition
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Aug 5, 2024
1 parent d581849 commit b3c0d3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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.8 - 2024-?
* Add `connect_with:` option to the collection definition.

## 0.3.7 - 2024-08-05
* Add `connected_to` to the collection for custom connection handling

Expand Down
1 change: 1 addition & 0 deletions lib/esse/plugins/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def collection(*args, **kwargs, &block)
repo = Class.new(Esse::ActiveRecord::Collection)
repo.base_scope = -> { model_class }
repo.batch_size = kwargs.delete(:batch_size) if kwargs.key?(:batch_size)
repo.connect_with = kwargs.delete(:connect_with) if kwargs.key?(:connect_with)
repo.class_eval(&block) if block

super(repo, *args, **kwargs)
Expand Down
14 changes: 14 additions & 0 deletions spec/esse/plugin/active_record/collection_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
expect(col.batch_size).to eq(10)
end

it 'define a collection with custom connect_with' do
expect {
stub_esse_index(:animals) do
plugin :active_record

repository :animal do
collection(Animal, connect_with: { role: :reading })
end
end
}.not_to raise_error
expect(col = AnimalsIndex.repo.instance_variable_get(:@collection_proc)).to be < Esse::ActiveRecord::Collection
expect(col.connect_with).to eq(role: :reading)
end

it 'evaluates the block in the Esse::ActiveRecord::Collection' do
expect {
stub_esse_index(:animals) do
Expand Down

0 comments on commit b3c0d3e

Please sign in to comment.