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

refactors suggestion controller out of story controller #1414

Merged
merged 10 commits into from
Jan 9, 2025

Conversation

rahul1990gupta
Copy link
Contributor

@rahul1990gupta rahul1990gupta commented Jan 4, 2025

Overview

The goal is to make story controller light. This tackles part 1.

Testing

lobsters_suggestions-2025-01-04_16.20.01.mp4
3.3.1 :002 > SuggestedTagging.last 
  SuggestedTagging Load (0.6ms)  SELECT `suggested_taggings`.* FROM `suggested_taggings` ORDER BY `suggested_taggings`.`id` DESC LIMIT 1
 => #<SuggestedTagging:0x00007445723c7090 id: 4, story_id: 77, tag_id: 59, user_id: 55> 
3.3.1 :003 > SuggestedTitle.last 
  SuggestedTitle Load (0.3ms)  SELECT `suggested_titles`.* FROM `suggested_titles` ORDER BY `suggested_titles`.`id` DESC LIMIT 1
 => #<SuggestedTitle:0x00007445718b7b50 id: 3, story_id: 77, user_id: 55, title: "Ex veniam vitae 2"> 

@rahul1990gupta rahul1990gupta marked this pull request as ready for review January 4, 2025 10:52
@rahul1990gupta
Copy link
Contributor Author

@pushcx This is ready for review. For some reason, I can't request for review, as the button is disabled for me.

config/routes.rb Outdated

# Mapping old routes to new routes. can be safely removed after the next deployment
get "suggest", to: "suggestions#new"
post "suggest", to: "suggestions#create"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let’s use Rails’ resource routes for the new controllers, and be careful to route old URLs to the new actions so that people who have loaded old pages before the deploy don’t get errors as they submit/vote/hide/save/etc. (Note them with dated comments, we can delete them after a month or so.)

add an explicit note: I don't want to maintain the old URL routes, I want use the Rails routes conventions for these.

I am little confused here. Should I remove these two line ?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I didn't explain that well, I was also misunderstanding what I was looking at.

The resources line is perfect, I want us to use Rails conventions for these routes.

The old routes (your get and post here) should use redirect, so:

get "suggest", to:redirect("/stories/suggestions/new", status: 302)
post "suggest", to:redirect("/stories/suggestions", status: 307)

(The post uses HTTP 307 so that the browser will POST to the new URL instead of switching to GET, it's an old gotcha.)

And then please new route test in spec/routing/stories_spec.rb:

 # 2025-01: Redirects for PR #1414 which moved these routes
 it "is temporary" do
   expect(get("/stories/suggest")).to eq(302)
   expect(Time.zone.today).to be_before(Date.new(2025, 3, 1))
 end

This "time bomb test" will forcibly remind me to delete the redirects after giving people a few weeks to use any tabs they have open. (See 4fd296e for an example of where I did this before. These URLs are unpopular enough that I don't think we need to do the added, slow steps of replacing a 302 redirect with a 301 redirect.)

@rahul1990gupta
Copy link
Contributor Author

Weird error. Does anyone know what's happening ? This branch is passing tests locally

1) Commenting posting a comment
     Failure/Error: <% if Maxmind.uk?(request.remote_ip) || Rails.env.development? %>

     ActionView::Template::Error:
       No such file or directory @ rb_sysopen - /home/runner/dbip.mmdb
     # ./extras/maxmind.rb:4:in 'Maxmind.uk?'
     # ./app/views/layouts/application.html.erb:131:in '_app_views_layouts_application_html_erb___[29](https://github.com/lobsters/lobsters/actions/runs/12645993711/job/35235966409?pr=1414#step:7:30)91631610551038810_22368'
     # ./app/controllers/application_controller.rb:217:in 'ApplicationController#n_plus_one_detection'
     # ./spec/support/authentication_helper.rb:7:in 'AuthenticationHelper::FeatureHelper#stub_login_as'
     # ./spec/features/comment_spec.rb:12:in 'block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Errno::ENOENT:
     #   No such file or directory @ rb_sysopen - /home/runner/dbip.mmdb
     #   ./extras/maxmind.rb:4:in 'Maxmind.uk?'

@pushcx
Copy link
Member

pushcx commented Jan 7, 2025

Sorry, that bug is my fault, from 259b911. I'll have a fix in a minute but I have to wait for Ruby 3.4.1 to install...

@pushcx pushcx merged commit f7738a2 into lobsters:master Jan 9, 2025
4 checks passed
@pushcx
Copy link
Member

pushcx commented Jan 9, 2025

Great! Thanks for refactoring this code, I'm really happy that you've started the process of cleaning up one of the most complicated and error-prone parts of our codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants