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

Not Authorized Error when Testing Admin User Banning #5228

Closed
mstruve opened this issue Dec 23, 2019 · 4 comments
Closed

Not Authorized Error when Testing Admin User Banning #5228

mstruve opened this issue Dec 23, 2019 · 4 comments
Labels
area: tests issues related to tests bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.

Comments

@mstruve
Copy link
Contributor

mstruve commented Dec 23, 2019

Related #4884

1) Admin bans user checks that the user is warned, has a note, and privileges are removed
     Failure/Error: raise Pundit::NotAuthorizedError, "You must be logged in" unless user
     
     Pundit::NotAuthorizedError:
       You must be logged in
     
     # ./app/policies/application_policy.rb:5:in `initialize'
     # ./app/controllers/internal/application_controller.rb:12:in `authorize_admin'
     # ./spec/system/internal/admin_bans_or_warns_user_spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./spec/rails_helper.rb:90:in `block (3 levels) in <top (required)>'
     # ./spec/rails_helper.rb:90:in `block (2 levels) in <top (required)>'
Finished in 7 minutes 17 seconds (files took 8.06 seconds to load)
3180 examples, 1 failure
Failed examples:
rspec ./spec/system/internal/admin_bans_or_warns_user_spec.rb:38 # Admin bans user checks that the user is warned, has a note, and privileges are removed
@mstruve mstruve added good first issue good first issues for anyone new to programming and new to the project. external contributors welcome contribution is welcome! labels Dec 23, 2019
VegaFromLyra added a commit to VegaFromLyra/dev.to that referenced this issue Jan 19, 2020
So it can generate a seed for each test execution which can then
be used to by `rspec --bisect` to repro order dependent flaky specs.

This is one approach to identify the root cause for forem#5228

It appears this is failing because `current_user` is `nil` before this spec is
run.
@icncsx
Copy link
Contributor

icncsx commented May 17, 2020

@mstruve Hi! Could you clarify something for me? I noticed that the entire test suite took more than 7 minutes, so I decided to only run the test which was failing.

I did bundle exec rspec ./spec/system/internal/admin_bans_or_warns_user_spec.rb:41 and it seems like the test passes. Admittedly, I'm very new to Ruby/Rails, so I'm pretty sure I'm doing something wrong. At the same time, I really want to learn and help! I would really appreciate it if you could give me some advice 🙏 on how to tackle this.

@mstruve
Copy link
Contributor Author

mstruve commented May 17, 2020

This is a flaky test which means that it fails intermittently. Usually flaky tests are caused by timing issues or by data issues. You have to either reproduce it or if you cant reproduce it, think creatively about what might cause it to fail.

@rhymes rhymes added area: tests issues related to tests bug always open for contribution labels May 18, 2020
@icncsx
Copy link
Contributor

icncsx commented May 21, 2020

Thanks for the tip!

@mstruve
Copy link
Contributor Author

mstruve commented Jun 10, 2020

Solved: #8379

@mstruve mstruve closed this as completed Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: tests issues related to tests bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.
Projects
None yet
Development

No branches or pull requests

3 participants