Plots2: Match hyphens in node content when scanning for hashtags

Created on 18 Apr 2019  路  9Comments  路  Source: publiclab/plots2

Since #532, when people post new pages, notes, questions, etc, the site scans the body content using this matcher:

https://github.com/publiclab/plots2/blob/b61ca7d0d9415e23659cf3fd93976349fc3488b4/app/models/revision.rb#L53-L58

It matches using this REGEX:

https://github.com/publiclab/plots2/blob/b61ca7d0d9415e23659cf3fd93976349fc3488b4/config/initializers/constants.rb#L4

And it tags the node with all the tags it finds -- stuff in the format #tagname, anywhere in the text.

We don't have tests for this, but we should! We could do a unit test in https://github.com/publiclab/plots2/blob/master/test/unit/revision_test.rb

However, the focus of this issue is to get it to match hyphenated words properly. It currently creates the tag #purple from the string #purple-air. Let's modify the regex to find hyphens too!

Actually the best way to test this would be to write the unit test first. Using node.has_tag('purple-air') to assert that it's done properly. Then to fix the regex and see the tests pass! Test-Driven-Development!!

We'd love help with this!

bug help wanted testing

Most helpful comment

Would love to see this one tackled! In the meantime, i'm editing out tags generated in error that end in a dangling hyphen like simple- purple- because they are adding noise to our tag search results, and our autosuggested tags.

All 9 comments

Would love to see this one tackled! In the meantime, i'm editing out tags generated in error that end in a dangling hyphen like simple- purple- because they are adding noise to our tag search results, and our autosuggested tags.

Hi, I'd love to help with this one.
Working on it

Hi @eplata31, that's great :tada: . Thanks!

Hello, I have made some advance and now I'm wondering if it should also accept low dash, something like purple_air? or just purple-air?

Hi @eplata31, as hyphens are commonly used so solving that is the primary goal but if you can make regex for underscore _ too, that would be great!

Thanks!

l created a PR, asking for a review :D

Hi @gauravano, I know that the refactor made is working correctly because I checked it with a test in the revision_test.rb, when I run the tests on that file everything works fine but I'm getting fails from these two test stest_first-timer_moderated_note_(status=4)_shown_to_author_in_list_view_with_notice and test_first-timer_moderated_note_(status=4)_shown_to_moderator_with_notice_and_approval_prompt_in_list_view, I don't know why since I didn't modify something that interacts with these tests, can you help me?

Hi, I noticed the fixture I created was the problem so I modified it and now all the test are green :+1:
I sent a new PR to be sure that I have the last changes of the project

Oh this is awesome!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

first-timers[bot] picture first-timers[bot]  路  3Comments

jywarren picture jywarren  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments

keshavsethi picture keshavsethi  路  3Comments

first-timers[bot] picture first-timers[bot]  路  3Comments