Skip to content

Commit

Permalink
use format.json in UserRegistrationController#create
Browse files Browse the repository at this point in the history
  • Loading branch information
Yassir4 committed Feb 3, 2025
1 parent ace735b commit 14737a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/user_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create
associate_user

respond_to do |format|
format.js do
format.json do
render json: { email: @user.email }
end
end
Expand All @@ -51,7 +51,7 @@ def spree_user_params
def render_error(errors = {})
clean_up_passwords(resource)
respond_to do |format|
format.js do
format.json do
render json: errors, status: :unauthorized
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/user_registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@request.env["devise.mapping"] = Devise.mappings[:spree_user]
end

describe "via ajax" do
describe "create" do
render_views

let(:user_params) do
Expand All @@ -20,7 +20,7 @@
end

it "returns validation errors" do
post :create, xhr: true, params: { spree_user: {}, use_route: :spree }
post :create, params: { spree_user: {}, use_route: :spree }, as: :json
expect(response.status).to eq(401)
json = JSON.parse(response.body)
expect(json).to eq("email" => ["can't be blank"], "password" => ["can't be blank"])
Expand All @@ -30,7 +30,7 @@
allow(Spree::UserMailer).to receive(:confirmation_instructions).and_raise("Some error")
expect(Alert).to receive(:raise)

post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
post :create, params: { spree_user: user_params, use_route: :spree }, as: :json

expect(response.status).to eq(401)
json = JSON.parse(response.body)
Expand All @@ -41,7 +41,7 @@
end

it "returns 200 when registration succeeds" do
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
post :create, params: { spree_user: user_params, use_route: :spree }, as: :json
expect(response.status).to eq(200)
json = JSON.parse(response.body)
expect(json).to eq("email" => "[email protected]")
Expand All @@ -50,7 +50,7 @@

it "sets user.locale from cookie on create" do
cookies[:locale] = "pt"
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
post :create, params: { spree_user: user_params, use_route: :spree }, as: :json
expect(assigns[:user].locale).to eq("pt")
end
end
Expand Down

0 comments on commit 14737a9

Please sign in to comment.