-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for creating multiple instances in one DB call #65
Comments
This is what I use in these cases # user_repo.rb
require 'dry/effects'
class UserRepo < ROM::Repository[:users]
include ::Dry::Effects.Reader(:page_size, default: 20)
def list(page: 1)
users.per_page(page_size).page(page).to_a
end
end
# user_repo_spec.rb
require 'dry/effects'
require 'user_repo'
RSpec.describe UserRepo do
include Dry::Effects::Handler.Reader(:page_size)
subject(:repo) { described_class.new }
describe 'pagination' do
around { with_page_size(3, &_1) }
let(:users) { Array.new(4) { Factory[:user] } }
example 'getting second page' do
expect(repo.list(page: 2)).to eql(users[3..])
end
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing features such as pagination requires presence of a number of objects in the repository. Creation of these entities takes more time, since each faked object is created separately. Yet ROM allows for calling commands with multiple instances, which is much more efficient. It would be a nice feature if instead of
we had
which would be executed as a single DB call.
The text was updated successfully, but these errors were encountered: