docbrown/spec
Daniel Uber 68867e7c68
Ensure we have current user information before deciding how to handle the "flag user" button (#13279)
* Make test fail again

Minimal reproduction via `rspec
spec/system/user/trusted_user_flags_user_spec.rb --order=random
--seed=9374` which runs in this order:

- when signed in as a trusted user
- when not logged in
- when signed in as the non-trusted user
- when signed in as the user

Because "not logged in" immediately precedes "non-trusted user" in this
order, the browser store cache is cleared and there is no user. Since
there's no user, the flag is not removed.

* Wait for current user promise before processing current user

* Extract button callback registration to function

This addresses a code climate concern (function exceeded 50 lines) by
extracting the button behavior to a function of (button, id, name),
and calls that within the exported initFlag function.

* Prefer request to fetch

Addresses feedback to use @utilities/http's request method in  place
of fetch (which automatically adds the needed csrf headers)

* Reorder imports

Satisfies code climate report that imports are out of order

* Add honeybadger notify to error handling

Do more than just notify that something went wrong. Notify honeybadger
on failure to flag/unflag a user.

* Remove temp variable

This makes the notify code look more like the suggestion

* Reduce function arglist

Since the user id and name are properties of the flagButton's dataset,
we can efficiently extract them from the flagButton.

Only pull user id from dataset to check if current user = profile
user, and extract id and name from dataset after passing the
flagButton.

* reorder imports

Not sure how I managed to reverse this in 18aeb675b but here we go again

* Test button behavior

The original tests only asserted that the link to reactions was
present and labeled correctly. Add additional check that we can use
the button and that the label toggling occurs (this adds a request to
the test case, but adds a test for user facing behavior).

* Tame eslint check

I was getting conflicting feedback on import ordering from code
climate and eslint. Since telling eslint to ignore its rules was
immediately clear to me (there's an example on the line before this)
that's the direction I headed, but I can revisit if it matters

https://github.com/forem/forem/pull/13279#issuecomment-814411401
captures the conflict (code climate wants @utilities/http first,
eslint wants ../chat/util first, one or the other fails regardless of
the ordering.

* Use multiple rules in one ignore comment

https://eslint.org/docs/user-guide/configuring/rules#disabling-rules
supports multiple warnings separated by commas

* Remove stray comment

* Move documentation comment to the code it describes

* Replace invalid name

I had copied from the suggested code snippet the
userData.profileUserID name, but userData in this context is a global
function, and `profileUserId` (capitalization) is the bound variable
in this context.

Fix it before we throw an error trying to report an error (ironically,
before the window alert telling the user an error occurred, I think
this would have been visible only in console).

* Actually call the remove button function
2021-04-07 16:28:21 -05:00
..
black_box Routine rubocop fixes (#10237) 2020-09-08 12:06:47 -04:00
decorators Make definition of new user configurable (#12999) 2021-03-23 14:13:06 +07:00
factories Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
fixtures ✂️ Remove the approvals gem ✂️ (#12978) 2021-03-19 13:28:06 -07:00
generator Add service generator (#11265) 2020-11-10 09:09:35 +07:00
helpers Re-Add Reporter Email Form to /admin/reports (#13011) [deploy] 2021-03-22 08:19:05 -06:00
initializers Fix regression in Honeybadger.config.exceptions.ignore (#12796) 2021-02-23 19:08:29 +01:00
lib Added credits_awarded to badges (#13073) 2021-03-24 11:33:58 +03:00
liquid_tags ✂️ Remove the approvals gem ✂️ (#12978) 2021-03-19 13:28:06 -07:00
mailers Add email type as utm_campaign column (#13297) 2021-04-07 12:54:51 -04:00
models [15 Min Fix]: Extract a post's followers out of service and onto Article model (#13229) 2021-04-07 06:46:32 -07:00
policies Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
queries Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
refinements Update data exporter to handle admin send (#10274) 2020-10-26 18:00:56 -04:00
requests Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
routing Add mobile push notifications to Forem (#12419) 2021-03-12 14:08:18 -06:00
serializers/search [deploy] Refactor:Remove Reaction Search Code (#10377) 2020-09-23 12:27:50 -05:00
services [15-minute fix] Don't allow markdown to use CSS classes (#13282) 2021-04-07 11:40:39 -04:00
support Remove pro role + expose analytics to all users via dashboard (#13156) 2021-03-30 15:02:18 -07:00
system Ensure we have current user information before deciding how to handle the "flag user" button (#13279) 2021-04-07 16:28:21 -05:00
tasks [15 Min Fix]: Fix incorrect scope used by metrics:overview rake task (#13138) 2021-03-25 17:31:10 -07:00
uploaders Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
view_objects Enable Rubocop 0.89 cops and fix Lint/ violations (#9709) 2020-08-10 16:57:12 +02:00
views ✂️ Remove the approvals gem ✂️ (#12978) 2021-03-19 13:28:06 -07:00
workers Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
rails_helper.rb Remove buffer gem and related code: step 1 (#12993) 2021-03-24 09:58:38 +07:00
spec_helper.rb [15-minute fix] Don't allow markdown to use CSS classes (#13282) 2021-04-07 11:40:39 -04:00