Skip to content

Commit

Permalink
remove inappropriate status tripping up turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Dec 3, 2024
1 parent 148c6fd commit 7cd9daf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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

0 comments on commit 7cd9daf

Please sign in to comment.