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

Remove inappropriate status tripping up turbo #17339

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def update

call.on_failure do |result|
flash[:error] = result.errors.full_messages.join("\n")
render_edit_tab(@type)
render_edit_tab(@type, status: :unprocessable_entity)
end
end
end
Expand Down Expand Up @@ -139,12 +139,12 @@ def redirect_to_type_tab_path(type, notice)
notice:)
end

def render_edit_tab(type)
def render_edit_tab(type, status: :ok)
@tab = params[:tab]
@projects = Project.all
@type = type

render action: :edit, status: :unprocessable_entity
render action: :edit, status:
end

def show_local_breadcrumb
Expand Down
25 changes: 20 additions & 5 deletions spec/controllers/types_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
get "edit", params: { id: type.id, tab: :settings }
end

it { expect(response).to have_http_status(:unprocessable_entity) }
it { expect(response).to have_http_status(:ok) }
it { expect(response).to render_template "edit" }
it { expect(response).to render_template "types/form/_settings" }
it { expect(response.body).to have_css "input[@name='type[name]'][@value='My type']" }
Expand All @@ -233,7 +233,7 @@
get "edit", params: { id: type.id, tab: :projects }
end

it { expect(response).to have_http_status(:unprocessable_entity) }
it { expect(response).to have_http_status(:ok) }
it { expect(response).to render_template "edit" }
it { expect(response).to render_template "types/form/_projects" }

Expand All @@ -242,7 +242,7 @@
}
end

describe "POST update" do
describe "PATCH update" do
let(:project2) { create(:project) }
let(:type) do
create(:type, name: "My type",
Expand All @@ -258,7 +258,7 @@
end

before do
put :update, params:
patch :update, params:
end

it { expect(response).to be_redirect }
Expand All @@ -274,6 +274,21 @@
end
end

describe "WITH the name being erroneously blank" do
let(:params) do
{ "id" => type.id,
"type" => { name: "" },
"tab" => "settings" }
end

before do
patch :update, params:
end

it { expect(response).to have_http_status(:unprocessable_entity) }
it { expect(response).to render_template "edit" }
end

describe "WITH projects removed" do
let(:params) do
{ "id" => type.id,
Expand All @@ -282,7 +297,7 @@
end

before do
put :update, params:
patch :update, params:
end

it { expect(response).to be_redirect }
Expand Down
Loading