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

Stories Controller: create separate controller and views for articles by search #14377

Merged

Conversation

squarebat
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Refactor

Description

As discussed in #2914 , the Stories controller has a lot of responsibilities which need to be divided for ease of debugging and testing. This PR divides the task for displaying articles by search in separate controller stories/articles_search_controller, views, specs and routes for the same have been updated. No changes have been made to the URL for searching articles.

Related Tickets & Documents

Added/updated tests?

  • Yes - the test for search has been moved to spec/requests/stories/articles_search_spec from spec/requests/stories_index_spec.rb

@squarebat squarebat requested a review from a team as a code owner July 28, 2021 17:36
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Jul 28, 2021
@github-actions
Copy link
Contributor

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

rescue_from ArgumentError, with: :bad_request

def index
@query = "...searching"
Copy link
Contributor

@citizen428 citizen428 Jul 29, 2021

Choose a reason for hiding this comment

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

I know you moved over this code but now is probably a good time to review it. Why are we assigning a static string to an instance variable? It also doesn't seem to be used in the view.

There may be a legitimate reason for this, I'd like to know myself. Same for @article_index which gets assigned in 3 different controllers but doesn't seem to appear elsewhere in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those variables bothered me as well. I could not find out why they exist but removing them does not seem to affect the search function and tests do not fail either. However, it did not seem like a good idea to remove variables without knowing how they are used so I let them be 😅

@@ -0,0 +1,22 @@
module Stories
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fully convinced by the naming here. This is in no way your fault but it was always confusing that the model was called Article while the corresponding controller was named StoriesController. On top of that, we're planning to rename the model to Post eventually. 😅 I'd be tempted to have this in Articles::SearchController instead because it's articles we're searching for.

Copy link
Contributor Author

@squarebat squarebat Jul 29, 2021

Choose a reason for hiding this comment

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

My first though was to move it to a new controller/articles folder, however there are three controllers dealing with articles in the controller/stories folder. I assume "stories" to be a set of activities dealing with different types of content (posts, podcasts, pages, organizations etc). There's also find_featured_story in app/services/articles/feeds/large_forem_experimental.rb that deals with featuring articles on users home feed according to user preferences and activity. I found it rather difficult to interpret what the term "stories" stand for. As you say, creating controllers in modules that correspond to the model name seems correct. However, I would like to have some more clarity on what stories is 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a problem we had in several areas of our codebase, names didn't agree in several places. For example, what is called Listings in the front end was backed by a model called ClassifiedListing which I eventually ended up renaming. "Stories" is not really a word we use in internal discussions, so it's not really a domain concept. Hence the pending rename to Post. In the meantime, I think Articles::Search would make more sense but I am aware that there are already several article-related controllers in the Stories namespace. I guess we might as well just leave it here.

Copy link
Contributor

@maestromac maestromac left a comment

Choose a reason for hiding this comment

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

Pending @citizen428 's request, everything else LGTM!

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Jul 29, 2021
@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Jul 30, 2021
@rhymes
Copy link
Contributor

rhymes commented Jul 30, 2021

@maestromac I'll let you merge this in case we missed something :D

@maestromac maestromac merged commit 7567e77 into forem:main Jul 30, 2021
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants