Fixes an issue where the LineItem :sorted_by_name_and_unit_value scope was not working with removal of the default scopes on line item and variant, which meant that the join in the scope was excluding soft-deleted items that should not have been excluded.
Without syncing the two threads with a lock, the spec could accidentally
pass even if the code is broken. It was accidentally removed during
refactoring in b0fa1464f.
This (should) considerably improve traces like
https://app.datadoghq.com/apm/trace/917632173599137280?spanID=3163385094622710144&env=production&sort=time&colorBy=service&spanViewType=metadata&graphType=flamegraph&shouldShowLegend=true
by fixing the following 3 N+1s
```
user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
Customer => [:enterprise]
Add to your query: .includes([:enterprise])
Call stack
/usr/src/app/app/serializers/api/admin/customer_with_calculated_balance_serializer.rb:24:in `balance_value'
/usr/src/app/app/serializers/api/admin/customer_with_calculated_balance_serializer.rb:9:in `balance'
/usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
/usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'
user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
Spree::Address => [:state]
Add to your query: .includes([:state])
Call stack
/usr/src/app/app/serializers/api/address_serializer.rb:14:in `state_name'
/usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
/usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'
user: root
GET /admin/customers.json?enterprise_id=4
USE eager loading detected
Spree::Address => [:country]
Add to your query: .includes([:country])
Call stack
/usr/src/app/app/serializers/api/address_serializer.rb:10:in `country_name'
/usr/src/app/app/controllers/admin/customers_controller.rb:20:in `block (2 levels) in index'
/usr/src/app/app/controllers/admin/customers_controller.rb:17:in `index'
```
This popped up after improving the balances calculation. Now, that it's
fast, it's clear that are more performance problems on that endpoint.
We'll see if there are any left after this.
Where the presence of an object is being validated and that object comes from an *association*, we should use `validates :object, presence: true` instead of `validates :object_id, presence: true`.
This does not apply in the same way to validations on uniqueness of certain attributes, such as `validates :object_id, uniqueness...`
Enumerable#uniq is fine (eg calling #uniq on an Array object), but now using #uniq on an ActiveRecord::Relation is deprecated in favour of #distinct (which modifies the query itself, as opposed to iterating over the results of the query).
DEPRECATION WARNING: ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1. Use model.errors.add(:preferred_discount_amount, ["has an invalid format. Please enter a number."]) instead. (called from block (2 levels) in localize_number at /home/runner/work/openfoodnetwork/openfoodnetwork/lib/spree/localized_number.rb:38)
This fixes the error UK's is experiencing:
```
PG::AmbiguousColumn: ERROR: column reference "state" is ambiguous LINE
1: SELECT DISTINCT spree_orders.*, CASE WHEN state IN ('cancele...
^ : SELECT DISTINCT spree_orders.*, CASE WHEN state IN ('canceled',
'returned') THEN payment_total WHEN state IS NOT NULL THEN payment_total
- total ELSE 0 END AS balance_value, spree_orders.* FROM "spree_orders"
INNER JOIN "spree_shipments"
```
See
https://app.bugsnag.com/yaycode/openfoodnetwork-uk/errors/6058c45989d37300079e8312?event_id=6058ccd30075af73bcb20000&i=sk&m=nw.
We observed invalid payment states in Bugsnag but we don't actually know
in which state the payment intent was in. From the context we can guess
that it was "succeeded" but it would be good to validate this. And in
the future it would be good to know if there are other invalid states we
can end up in.
The notification to Bugsnag happens in another part of the code.
Fixes:
384) Spree::OrderMailer basic behaviour doesn't aggressively escape double quotes in confirmation body
Failure/Error: adjustments = adjustments.to_a + order.shipment_adjustments.to_a
ActionView::Template::Error:
Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined.
# ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for'
# ./app/views/spree/order_mailer/_order_summary.html.haml:43:in `_app_views_spree_order_mailer__order_summary_html_haml__2911251238692323485_70331958934800'
# ./app/views/spree/order_mailer/confirm_email_for_customer.html.haml:23:in `_app_views_spree_order_mailer_confirm_email_for_customer_html_haml__3734564010704881256_70331959518520'
# ./app/mailers/spree/order_mailer.rb:35:in `block in confirm_email_for_customer'
# ./app/mailers/spree/order_mailer.rb:33:in `confirm_email_for_customer'
# ./spec/mailers/order_mailer_spec.rb:20:in `block (3 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ActiveRecord::HasManyThroughOrderError:
# Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined.
# ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for'
Fixes:
259) Spree::ShippingMethod#shipments can gather all the related shipments
Failure/Error: expect(shipping_method.shipments).to include(shipment)
ActiveRecord::HasManyThroughOrderError:
Cannot have a has_many :through association 'Spree::ShippingMethod#shipments' which goes through 'Spree::ShippingMethod#shipping_rates' before the through association is defined.
# ./spec/models/spree/shipping_method_spec.rb:190:in `block (3 levels) in <module:Spree>'
Fixes:
292) OrderManagement::Subscriptions::ProxyOrderSyncer#sync! when the subscription is not persisted and the schedule includes upcoming oc that closes after ends_at does not create a new proxy order for that oc
Failure/Error: order_cycle.schedules << schedule
ActiveRecord::HasManyThroughOrderError:
Cannot have a has_many :through association 'OrderCycle#schedules' which goes through 'OrderCycle#order_cycle_schedules' before the through association is defined.
# ./spec/factories.rb:29:in `block (4 levels) in <top (required)>'
# ./spec/factories.rb:28:in `each'
# ./spec/factories.rb:28:in `block (3 levels) in <top (required)>'
# ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:59:in `block (4 levels) in <module:Subscriptions>'
# ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:65:in `block (4 levels) in <module:Subscriptions>'
# ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (6 levels) in <module:Subscriptions>'
# ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (5 levels) in <module:Subscriptions>'
Failure/Error: enterprise.andand.touch
ActiveRecord::ActiveRecordError:
cannot touch on a new or destroyed record object. Consider using persisted?, new_record?, or destroyed? before touching
# ./app/models/spree/address.rb:155:in `touch_enterprise'
# ./spec/factories/product_factory.rb:12:in `block (3 levels) in <top (required)>'
# ./spec/factories/variant_factory.rb:26:in `block (4 levels) in <top (required)>'
# ./spec/models/spree/variant_spec.rb:9:in `block (2 levels) in <module:Spree>'
- This method is already translated thanks to rails-i18n, but it is missing few langages such as 'fr_BE'. Adding those keys makes it possible to have the translation.
- Adding translations to `en.yml` could be seen as useless (since is already correctly handled by rails-i18n) but this is the way we process i18n issues.
This was being triggered by a callback in Spree::Adjustments before, but now that the adjustable is not the order, it does not get triggered by fees being added to line items...
We get the same value here, but without the three additional database hits to adjustments (both of these values are already present on the order object itself).
- Code is at a single place
- No need to import `localizeCurrencyFilter` into Controllers that required unit_prices
- Add `currencyconfig` into unit_prices_spec as it's now dependant to localizeCurrencyFilter
- Only needs to watch `unit_value_human` and `variant.price` the only two editable field for this form that is related to unit price
- Add hidden_field_tag to retrieve values into the controller
- Add method `processUnitPrice` which is responsible for computing the right unit price, that depends on `price`, `variant_unit_scale`, `variant_unit`, `unit_value` and `variant_unit_name`
- Watch the needed model to compute the unit price: `product.price` and `product.variant_unit_name`
- Add dependencies : UnitPrices and localizeCurrencyFilter
- Add currencyconfig to spec, as it's needed by localizeCurrencyFilter
- Put `'ng-controller' => 'unitsCtrl'` to the relevant node.
- Add new ng-model, as it's needed to watch it in order to compute unit price : `product.price`
- Finally display the needed information: `product.unit_price_value` and `product.unit_price_unit`
- Arguments were misordered and `scale` is needed to compute the denominator.
- Reorder "state machine" if-else as variant_unit_name is priority and "item" is too.
- @andrewpbrett I need your review here ;)
- Still need to test imperial system
- Add a new i18n key for the content of the tooltip: js.shopfront.unit_price_tooltip.admin
- Display unit price readonly field near the price field
- Still fake values, needs to be updated
- As this directive is now used by Darkswarm and admin, move files in shared/ folders
- Needs some css variable in admin part : as question-mark-with-tooltip is used in admin part, it needs some css variable
- Add own scss variables file with all needed variables for question-mark-icon. Some duplication, but now really independant and shared between both darkswarm and admin.
- Remove strange border around the button, rendered by chrome when button is focused.
- Test that the unit price wrapper is here
- Click on the question mark icon and display the tooltip
- Click outside the question mark icon and hide the toolip
This moves them to a more unit-like style where the mailer methods are
the subjects. However, I did so only for the methods that show order
balance and thus we want to be extra sure of their coverage.
If these are unit tests, it's much easier to find a `describe` with the
method under test and putting all the tests exercising that method
together.
It turns out that `#update_payment_state` is by far the method that we
test the most which leads me to think:
a) this class might be doing too many things.
b) other methods might not be that well covered.
Fixes:
Spree::Preferences::Preferable persisted preferables requires a valid id but returns default values
Failure/Error:
class CreatePrefTest < ActiveRecord::Migration
def self.up
create_table :pref_tests do |t|
t.string :col
end
end
def self.down
drop_table :pref_tests
end
StandardError:
Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:
class CreatePrefTest < ActiveRecord::Migration[4.2]
# ./spec/models/spree/preferences/preferable_spec.rb:225:in `block (3 levels) in <top (required)>'
This fixes the following deprecation warnings
```
DEPRECATION WARNING: `config.serve_static_files` is deprecated and will be removed in Rails 5.1.
Please use `config.public_file_server.enabled = true` instead.
(called from block in <top (required)> at /home/runner/work/openfoodnetwork/openfoodnetwork/config/environments/test.rb:13)
DEPRECATION WARNING: `config.static_cache_control` is deprecated and will be removed in Rails 5.1.
Please use
`config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }`
instead.
(called from block in <top (required)> at /home/runner/work/openfoodnetwork/openfoodnetwork/config/environments/test.rb:14)
```
This moves them to a more unit-like style where the mailer methods are
the subjects. However, I did so only for the methods that show order
balance and thus we want to be extra sure of their coverage.
This fixes:
```
DEPRECATION WARNING: Passing an argument to force an association to
reload is now deprecated and will be removed in Rails 5.1. Please call
`reload` on the result collection proxy instead. (called from
can_own_more_enterprises? at /usr/src/app/app/models/spree/user.rb:112)
```
This method in particular gets called a lot of times so it'll have it's
cost in performance.
As is, we're seeing builds almost only on merge commits and not on
others. Also, the build status is not displayed at the bottom of the
PR.
Once we see this fixed and have a better understanding, we can decide
whether or not we remove the `push` event. I guess both we'll be needed.
The `Spree::Admin::OrdersController`'s test file quite long (as well as
the controller itself) but it'll grow more in the upcoming commits.
That's just a symptom of that controller having too many
responsibilities. It does much more than CRUD on `Spree::Order` (the
Rails convention).
Things like invoices are an entity on their own and would better fit
into a `InvoicesController`. Hopefully, splitting up the tests is hint
for the next dev to do that.
The user should need to tick only one box to agree.
We don't remember yet if someone agreed to the platform TOS and
therefore the box is always unticked to start with.
Remembering the agreement is another issue:
https://github.com/openfoodfoundation/openfoodnetwork/issues/6328
Checking for `false` instead of a falsey value allows us to distinguish
from an unset variable and disable the checkout button only when a
checkbox is present and unticked.
This was working with the seller's terms but now it includes the
platform's terms as well.
Pending:
- Simplify Ansible code
- Unify the two terms checkboxes if both required
The checkout page shows a checkbox to accept the platform's Terms of
Service. Ticking the box doesn't have any effect yet but at least people
are aware and are presented with a link to the terms.
This removes the deprecation warning:
```
[WARNING] The default currency will change from `USD` to `nil` in the
next major release. Make sure to set it explicitly using
`Money.default_currency=` to avoid potential issues
```
This removes the deprecation warning:
```
[WARNING] The default rounding mode will change from `ROUND_HALF_EVEN`
to `ROUND_HALF_UP` in the next major release. Set it explicitly using
`Money.rounding_mode=` to avoid potential problems.
```
by specifying the default rounding mode at boot time so that it's only
set once for the whole app. See
https://github.com/RubyMoney/money#rounding for details.
This fixes the following deprecation warning
```
[DEPRECATION] `html` is deprecated - use `html_wrap` instead. Please
note that `html_wrap` will wrap all parts of currency and if you use
`with_currency` option, currency element class changes from `currency`
to `money-currency`.
```
This removes millions of deprecation warnings like the following
```
[DEPRECATION] `symbol_position: :before` is deprecated - you can replace it with `format: %u %n`
```
from the build. It gets printed every time a `Spree::Money` is instantiated.
This should result in a non-negligible speed up of the test suite.
This is already tested by the top-most before block and besides, we
there's no OFN in Japan. We don't need to test all supported currencies
but ensure that the various arguments work as intended.
We set this value to `true` unconditionally in an initializer, and then check the value in various places via Spree::Config. It's never false, and it's not configurable, so we can just drop it and remove the related conditionals. 🔥
This was triggering two separate updates, and each of those updates could trigger callbacks, and those could trigger other callbacks. Here we're doing the same thing, but with one update.
It's a code smell to have a boolean control argument.
`Permissions::Order` goes too far and assumes we want to filter out
canceled orders when using report's search params and this is not the
case.
This almost removes the responsibility of fetching orders from this
class, that has too many. Ideally, I'd go on and leave this up to the
caller of this class making `Reports::LineItems` rely completely on the
passed in `orders_relation`. Not today.
This model concerns helps us put together this related methods. Although
it doesn't provide any encapsulation yet, it makes a bit easier to
consider them all next time we need to change this implementation
somehow. It's a bit of an illusion but it feels like we are making this
God object model a bit smaller.
It also gives more room for documentation that will aid future devs.
This is quite hard and tedious due to its tight coupling with
Permissions::Order but sets the path to adding more of these and
eventually refactoring this class in the future.
This was initially intended to cache the result of the `#map` and
`#uniq` calls but we're not confident enough and don't want to
scopecreep this. It's still worth to point out that this is what we
need, line items' `unique orders`. Hopefully, next time we find a way to
optimize it.
@@ -6,12 +6,13 @@ This is a general guide to setting up an Open Food Network **development environ
The fastest way to make it work locally is to use Docker, you only need to setup git, see the [Docker setup guide](docker/README.md).
Otherwise, for a local setup you will need:
* Ruby 2.3.7 and bundler
* Ruby 2.4.4 and bundler (check current Ruby version in [.ruby-version](https://github.com/openfoodfoundation/openfoodnetwork/blob/master/.ruby-version) file)
* PostgreSQL database
* Chrome (for testing)
The following guides will provide OS-specific step-by-step instructions to get these requirements installed:
- [Ubuntu Setup Guide][ubuntu]
- [Debian Setup Guide][debian]
- [OSX Setup Guide][osx]
If you are likely to need to manage multiple version of ruby on your local machine, we recommend version managers such as [rbenv](https://github.com/rbenv/rbenv) or [RVM](https://rvm.io/).
@@ -20,7 +21,7 @@ For those new to Rails, the following tutorial will help get you up to speed wit
### Get it
If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), it is a good idea to begin by forking this repo using the `Fork` button in the top-right corner of this screen. You should then be able to use `git clone` to copy your fork onto your local machine.
So you have set up your local environment according to the requirements listed above. If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), it is a good idea to begin by forking this repo using the `Fork` button in the top-right corner of this screen. You should then be able to use `git clone` to copy your fork onto your local machine:
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.