Code Monkey home page Code Monkey logo

Comments (9)

etagwerker avatar etagwerker commented on June 13, 2024 1

@swiknaba Not sure about Micah's preference, but I would prefer the options-hash way.

So instead of doing this:

    def strategy=(args)
      strategy, *strategy_args = args

I would be interested in it doing this:

    def strategy=(strategy, strategy_args = {})
      ...

I think that would be the least disruptive change and it wouldn't require people using database_cleaner to change their implementations.

from database_cleaner.

botandrose avatar botandrose commented on June 13, 2024 1

@swiknaba @etagwerker Yes, options-hash sounds good to me!

from database_cleaner.

zedtux avatar zedtux commented on June 13, 2024 1

In the case that helps, here is the deprecation warning from Ruby 2.7 :

/usr/local/bundle/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaner.rb:85: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

from database_cleaner.

swiknaba avatar swiknaba commented on June 13, 2024

@botandrose in case one would start working on this, any preference from the maintainers for either kwargs or options-hashes? I think, using hashes gives more flexibility regarding the DSL, since the gem is broken into multiple gems, and each gem might want to add or omit certain options/key-words. On the other hand, being explicit makes it easier to follow the codebase if you are not familiar with it. From my short look at two of the gems (Redis, active-record), there are not that many options, thus being explicit could be the way to go.

from database_cleaner.

botandrose avatar botandrose commented on June 13, 2024

@swiknaba @etagwerker I took a look at this today, and I learned something new about Ruby! It looks like the way Ruby handles multiple arguments to setter methods ending in = is a bit of syntax sugar magic. Specifically, it will always first convert the multiple arguments to an array, and then passes that array as a single argument to the method. The only way I could find to bypass this magic is by using send:

DatabaseCleaner.send(:strategy=, :truncation, { only: "users" })

Therefore, in order to keep the same API, we appear to be stuck with the def strategy=(args); strategy, *strategy_args = args; ... pattern. @swiknaba You say in your original post that this won't work on Ruby 3.0, but the tests are all passing, and I wasn't able to reproduce the failure locally. Can you explain what you mean? At present, this implementation doesn't seem to be a problem.

I do agree that we should normalize options hashes vs kwargs across the DatabaseCleaner gem family.

from database_cleaner.

zedtux avatar zedtux commented on June 13, 2024

Ruby 3.0 is out since almost 2 years now, when could we expect this gem to be adapted for Ruby 3 ?

@botandrose which branch has that fix ? If I can help by testing it, I would be very happy to do so.

from database_cleaner.

swiknaba avatar swiknaba commented on June 13, 2024

@botandrose indeed, tests are all passing, however when I used

DatabaseCleaner.strategy = :deletion, { except: %i[not_you also_not_you blubb] }

in my codebase, then RSpec failed with a syntax error.

It seems there was a workaround found: DatabaseCleaner/database_cleaner-mongoid#16 (comment)

I haven't tested that yet, though.

from database_cleaner.

niborg avatar niborg commented on June 13, 2024

Even though CI seems to pass, for me running Ruby 3.0.3 against v2.01 locally raises two errors:

Screenshot 2023-01-09 at 4 27 06 PM

In any event, I ran into the same issue as others, and circumvented it by specifying the strategy object explicitly:

DatabaseCleaner[:redis].strategy = DatabaseCleaner::Redis::Deletion.new(only: ["something:*"])

This approach is documented in the ActiveRecord adapter, but isn't present on this specific repository and other adapter repositories.

Is an easy solution to this problem adjusting the documentation to recommend the above approach? Anyone upgrading who runs into this issue will likely revisit the docs and can correct the problem easily. Downside is that it smells like a bit of an abstraction leak. If there is a desire to keep using primitive values to set a strategy, then I think the strategy= should be deprecated in favor of something like set_strategy(strategy, strategy_args = {}), similar to how @etagwerker suggested.

from database_cleaner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.