Is there a way to mock data for all inserts and fetches implicitly using a mock database adapter? #2095
nelsnelson
started this conversation in
General
Replies: 1 comment 1 reply
-
The mock adapter is as the name says, a mock. The main purpose of it is testing Sequel itself. It is not an in-memory database. You may want to use an SQLite memory database if you want an in-memory database. Note that you can pass options when creating the mock Database (such as :fetch as :autoid). If you are looking for examples of how to use the mock adapter, you probably want to look at Sequel's tests. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Greetings,-
I've mistakenly opened an issue in an attempt to resolve the issue I had been experiencing trying to configure a mock database adapter for use in a spec test suite which will support automatically incremented primary key id values for row fetches (and inserts).
It now seems clear that I had a fundamental misunderstanding of how the mock database adapter is intended to be operated within the context of an rspec test suite.
I may still not have the right picture here. I've been hoping to use the mock adapter in a testing configuration (
ENV['APP_ENV'] = 'test'
) which would seamlessly support existing code which set up database connection for model classes.Is there a way to configure the mock adapter to always generate an automatically incremented id for fetches and inserts?
One example of an error I'm trying to avoid:
My thoughts were that this was happening because the mock database adapter wasn't correctly assigning an
:id=>value
wherevalue
was an automatically incremented counter internal to the adapter. But it is beginning to dawn on me that it is instead because I'm not explicitly invoking theDatabase#autoid=
andDatabase#fetch=
methods for the database following its initialization.Is there an alternative to explicit invocation? Perhaps it can be accomplished at a configuration level using a connection string parameter?
I'm guessing such functionality for returning generated mock data for fetches and inserts based on the schema of the individual model for a particular class inherited from
Sequel::Model
is not a feature of the mock adapter. The challenges for such a feature would probably involve some prohibitive and perhaps even unnecessary complexity.Beta Was this translation helpful? Give feedback.
All reactions