We now have a new source of truth. You shouldn't use a feature toggle
without adding it to OpenFoodNetwork::FeatureToggle first. All toggles
are added at boot time already.
This makes a clear distinction between the unfiltered and filtered list.
There may also be some gotchas when modifying the array of an
ActiveRecord relation. It also allows us to write shorter code without
storing a separate variable.
The "subject" is usually the code under test. In this spec it would be
the TagRuleApplicator and not the parameter given to it. So I renamed it
to avoid confusion here.
The admin UI shows only features which were added to the database. We
always had to look up a feature's name add it manually before we could
enable it. Now it will appear in the UI after some code asked if it was
enabled.
This only adds a database query once when the feature doesn't exist yet.
The `feature.exist?` call only performs an in-memory lookup in the
memoizer.
For larger queries and especially where filtering and paginating, these simpler product queries are way more efficient. It cuts out some very large subqueries with large lists of product ids.
Before the :scope_to_distributor call was filtering out variants from other distributors anyway via the :exchange_variants table but it is clearer if we filter by distributor on the :variant_overrides left join too.
But let people include out of stock variants by checking a checkbox if they want.
Note, we only apply the variants in stock scope if a distributor is
present. I think this is because this search method is also used when
setting up subscriptions so I don't think we want to change the
behaviour there.
Co-authored-by: Maikel Linke <maikel@email.org.au>
This keeps the `OrderBalance` abstraction but removes the old code now
that the feature is enabled for all users in all instances and there are
no bugs reported. It's become dead code.
Previously we were creating order objects that were not actually complete, and manually setting the `completed_at` field. This meant the order objects being tested were not actually in the correct state, ie: pre-checkout orders that had not been processed properly.