Skip to content

Commit

Permalink
Fix render issues when there were form validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Feb 14, 2025
1 parent cb618d4 commit 4fcf95c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased - [View Diff](https://github.com/westonganger/rails_i18n_manager/compare/v1.1.3...master)
- [#37](https://github.com/westonganger/rails_i18n_manager/pull/37) - Add recommended I18n configuration to the README
- [#36](https://github.com/westonganger/rails_i18n_manager/pull/36) - Many fixes on the Translations#index page
- [#35](https://github.com/westonganger/rails_i18n_manager/pull/35) - Fix render issues when there were form validation errors
- [#34](https://github.com/westonganger/rails_i18n_manager/pull/34) - Fix issue where CSS was missing utility classes for `float: right`
- [#33](https://github.com/westonganger/rails_i18n_manager/pull/33) - Add suggested workflow for teams

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update
redirect_to action: :index
else
flash.now[:error] = "Update failed."
render "rails_i18n_manager/translation_apps/form"
render "form"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update
redirect_to edit_translation_path(@translation_key)
else
flash[:notice] = "Update failed."
render "translations/edit"
render "edit"
end
end

Expand Down
32 changes: 32 additions & 0 deletions spec/request/translation_apps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ module RailsI18nManager
end
end

context "new" do
it "renders" do
get rails_i18n_manager.new_translation_app_path
expect(response).to have_http_status(200)
end
end

context "create" do
it "succeeds" do
assert_changed ->(){ TranslationApp.count } do
post rails_i18n_manager.translation_apps_path, params: {translation_app: {name: "some-new-app-name", default_locale: "en"}}
expect(response).to redirect_to(rails_i18n_manager.edit_translation_app_path(TranslationApp.last))
end
end

it "renders form when there are validation errors" do
assert_not_changed ->(){ TranslationApp.count } do
post rails_i18n_manager.translation_apps_path, params: {translation_app: {name: ""}}
expect(response).to render_template("translation_apps/form")
end
end
end

context "edit" do
it "renders" do
get rails_i18n_manager.edit_translation_app_path(translation_app)
Expand All @@ -43,6 +66,15 @@ module RailsI18nManager
end
expect(response).to redirect_to(rails_i18n_manager.translation_apps_path)
end

it "renders form when there are validation errors" do
assert_not_changed ->(){ translation_app.additional_locales_array } do
patch rails_i18n_manager.translation_app_path(translation_app), params: {translation_app: {additional_locales: ['foobar']}}

expect(response).to render_template("translation_apps/form")
translation_app.reload
end
end
end

end
Expand Down
18 changes: 18 additions & 0 deletions spec/request/translations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ module RailsI18nManager
translation_value.reload
end
end

it "renders edit page when there are validation errors" do
assert_not_changed ->(){ default_translation_value.translation } do
patch rails_i18n_manager.translation_path(translation_key), params: {
translation_key: {
translation_values_attributes: {
"0" => {
id: default_translation_value.id,
translation: "",
}
}
}
}

expect(response).to render_template("translations/edit")
default_translation_value.reload
end
end
end

context "translate_missing" do
Expand Down

0 comments on commit 4fcf95c

Please sign in to comment.