Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Controller Tests #970

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yksflip
Copy link
Member

@yksflip yksflip commented Nov 28, 2022

Keeping this atm to track upcoming smaller PR's

  • home_controller.rb Add home controller test #972
  • application_controller.rb
  • articles_controller.rb
  • concerns/auth_concern.rb
  • finance/balancing_controller.rb
  • finance/base_controller.rb
  • login_controller.rb

We found that the articles_controller sync method throws a DoubleRenderError, should we open a new Issue/PR for that?
see spec/controllers/articles_controller_spec.rb:179

Edit: split into seperate PR's

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.

first: once again many thanks for the great work!
i just skimmed the changes and didn't look into detail for now. most of comments apply multiple times, but i didn't mark every single occurrence

the rubucop checks for it are not enforced, since we have a lot of existing code, but it would be great to stick to the Ruby Style Guide for string literals

i know that's it's a hard to split this PR, when all parts would require the Gemfile changes, but it would make the review process easier if the PR would be smaller. maybe start with a single controller test?

@@ -64,7 +64,7 @@ def ordergroup
# cancel personal memberships direct from the myProfile-page
def cancel_membership
if params[:membership_id]
membership = @current_user.memberships.find!(params[:membership_id])
membership = @current_user.memberships.find(params[:membership_id])
Copy link
Member

Choose a reason for hiding this comment

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

why is it ok to remove the ! here and keep it in line 69?

Copy link
Member Author

@yksflip yksflip Dec 5, 2022

Choose a reason for hiding this comment

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

i think a find! method does not exists?

     NoMethodError:
       undefined method `find!' for #<ActiveRecord::Associations::CollectionProxy []>
       Did you mean?  find

find_by! returns a ActiveRecord::RecordNotFound instead of nil compared to find_by
I added another test to check that find also returns a ActiveRecord::RecordNotFound Exception

spec/controllers/articles_controller_spec.rb Outdated Show resolved Hide resolved
Comment on lines +121 to +143
before do
order_article
end
Copy link
Member

Choose a reason for hiding this comment

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

i'd suggest to add a second order at line 15 instead. IMHO there should be no need for a dedicated order_article factory.

spec/controllers/articles_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/articles_controller_spec.rb Outdated Show resolved Hide resolved
spec/support/spec_test_helper.rb Show resolved Hide resolved
spec/support/spec_test_helper.rb Outdated Show resolved Hide resolved
spec/support/spec_test_helper.rb Show resolved Hide resolved
spec/support/spec_test_helper.rb Outdated Show resolved Hide resolved
login user
routes.draw { get "deny_access" => "dummy_auth#call_deny_access" }
get :call_deny_access, params: { foodcoop: FoodsoftConfig[:default_scope] }
expect(response).to redirect_to(root_url)
Copy link
Member

Choose a reason for hiding this comment

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

when do you use _path and when _url?

Copy link
Member Author

Choose a reason for hiding this comment

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

in that specific case the the controller redirects to root_url ... in general not sure, is there a convention?

@yksflip yksflip force-pushed the 8_increase_test_coverage_controllers branch from ad0a138 to e34bf55 Compare November 28, 2022 12:56
@yksflip
Copy link
Member Author

yksflip commented Dec 1, 2022

thanks for your feedback! We'll look into your comments and I'll change the scope of the PR to fit just the Gemfile and one ControllerSpec at first.

@yksflip yksflip marked this pull request as draft December 5, 2022 10:00
@yksflip yksflip force-pushed the 8_increase_test_coverage_controllers branch 3 times, most recently from 433f74d to 78936c3 Compare December 5, 2022 17:11
@kidhab kidhab mentioned this pull request Feb 6, 2023
@yksflip yksflip mentioned this pull request Feb 17, 2023
10 tasks
@yksflip yksflip force-pushed the 8_increase_test_coverage_controllers branch from e5870b5 to d7591d4 Compare March 5, 2023 10:02
yksflip and others added 2 commits March 5, 2023 11:03
Co-authored-by: viehlieb <[email protected]>
Co-authored-by: Tobias Kneuker <[email protected]>
Co-authored-by: viehlieb <[email protected]>
Co-authored-by: Tobias Kneuker <[email protected]>

seperate expects

refactor login user calls

add more articles to test sorting with

fix: fix test for rails upgrade
@yksflip yksflip force-pushed the 8_increase_test_coverage_controllers branch from d7591d4 to d3d7acc Compare March 5, 2023 10:03
@yksflip yksflip mentioned this pull request Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants