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

Fix obscure bug #518

Merged
merged 1 commit into from
Nov 10, 2023
Merged

Fix obscure bug #518

merged 1 commit into from
Nov 10, 2023

Conversation

santib
Copy link
Member

@santib santib commented Nov 10, 2023

Having the status action defined in ApiController which is then inherited by other controllers, was causing a very strange bug related to the wrap_parameters Rails feature.

In order to reproduce go to the main branch, perform the following changes to force the execution of the wrap_parameters feature:

+++ spec/requests/api/v1/users/update_spec.rb
@@ -9,14 +9,14 @@ describe 'PUT api/v1/user/' do
   before { subject }

   context 'with valid params' do
-    let(:params) { { user: { username: 'new username' } } }
+    let(:params) { { username: 'new username' } }

     it 'returns success' do
       expect(response).to have_http_status(:success)
     end

     it 'updates the user' do
-      expect(user.reload.username).to eq(params[:user][:username])
+      expect(user.reload.username).to eq(params[:username])
     end

and run:

bundle exec rspec spec/requests/api/v1/status_spec.rb spec/requests/api/v1/users/update_spec.rb --order defined

as you can see it fails. The reason is that Rails is wrapping the parameters for the projects/update endpoint in a key named "api" instead of the correct one "user"

@santib santib requested a review from a team November 10, 2023 15:59
Copy link
Contributor

@JulianPasquale JulianPasquale left a comment

Choose a reason for hiding this comment

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

👀

@santib santib merged commit 956e2ee into main Nov 10, 2023
3 checks passed
@santib santib deleted the fix-obscure-bug branch November 10, 2023 18:00
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.

4 participants