Skip to content

Improve DatabaseCleaner Configuration API #546

@botandrose

Description

@botandrose

Way back in 2012, 016d66c changed the ::[] API to act as both a command and query, in a decision based on pragmatism. At the time, @bmabey noted his dislike for this, and his desire to deprecate it. Now that we're talking about a v2.0 release, I think this is a good time to talk about improving this situation in a backwards-incompatible way.

I have an alternative API proposal that I've been exploring, which splits the ::[] method into ::[] for queries, and ::[]= for commands. Complex configuration is also simplified to a hash, or array of hashes:

# simple config
DatabaseCleaner[:active_record].strategy = :truncation
# complex config
DatabaseCleaner[:active_record] = {
  connection: :test,
  strategy: :truncation,
  except: %w[goats donkeys],
}
# complex multiple db config
DatabaseCleaner[:active_record] = [
  { connection: :test, strategy: :truncation, except: %w[goats donkeys] },
  { connection: :test_2, strategy: :transaction },
]

I have been working on a document exploring what this API change would look like for DatabaseCleaner's many different use-cases, ranging from the most simplistic all the way up to very complex multiple ORM and database configuration, and this seems like this could work well, while also simplifying internals. I haven't prototyped it yet to confirm, but I even think its possible to add API this to the 1.x series in a backwards-compatible way, which would ease the v2.0 transition.

However, I want to get some feedback on this general direction before going too deep down the rabbit hole. Perhaps there is already an alternative API that you folks have in mind? Or perhaps we don't want to change the API at all at this point? But if this API looks promising, I'll post the document, and we can go from there!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions