Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes filtering of active ordergroups #934

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

haraldreingruber
Copy link
Contributor

@haraldreingruber haraldreingruber commented Mar 5, 2022

While working on the first complete version of #716 I realized that the filtering of active ordergroups does not work anymore. At least this was my observation in my development environment.

This change fixes the issue for me.

Thinking about it, I guess an autotest would be nice... Will create this PR as a draft and check if it's easy for me to create a failing test for this bug.

Update:
I've added 2 tests for the Ordergroup.active scope. The helper method probably should be moved to a better location, but wanted to hear your opinion first if this is useful. Also, it contains duplications from seeds_helper.rb...

@haraldreingruber haraldreingruber marked this pull request as ready for review March 6, 2022 19:54
Copy link
Member

@paroga paroga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the test. PR looks good, just a minor few style issues in the tests

@@ -1,5 +1,21 @@
require './db/seeds/seed_helper'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think that testing should depend on seeding helpers. i'd suggest to create helpers for that in the spec directory, if you think code can be shared with other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I totally agree. Luckily, it's not required anymore. Thanks for the hint.

def create_order(starts)
og = user.ordergroup

SupplierCategory.create!(:id => 1, :name => "Other", :financial_transaction_class_id => ftc1.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the <key>: <value> syntax, like you did in line 13, so this line becomes SupplierCategory.create!(id: 1, name: "Other", financial_transaction_class_id: ftc1.id). at the moment there is a mix in the codebase, but it would be great we use the preferred syntax at least in new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. The method is not required anymore but I will watch out to use that syntax in the future.

Do you know if rubocop could fix this automatically?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it could, but it's deactivated ATM to avoid a lot of unrelated code changes when "format on save" is activated.

@@ -8,6 +24,16 @@
let(:ftt3) { create :financial_transaction_type, financial_transaction_class: ftc2 }
let(:user) { create :user, groups: [create(:ordergroup)] }

it 'shows no active ordergroups when all orders are older than 3 months' do
create_order(4.months.ago)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use the let(:<name>) { create :<type> } syntax (like in line 20) here too? if not, you should at least use the factory functions (see spec/factories directory) to create the objects instead of hardcoding all parameters (like the supplier name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yess! Thanks for pointing me to the factories. This is much simpler of course 😊

@paroga paroga merged commit 15e715c into foodcoops:master Mar 7, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants