diff --git a/app/views/account/calculators/edit.html.erb b/app/views/account/calculators/edit.html.erb index 10d648a0a..a52b5cdc4 100644 --- a/app/views/account/calculators/edit.html.erb +++ b/app/views/account/calculators/edit.html.erb @@ -1,83 +1,3 @@ -
- <%= simple_form_for @calculator, url: { action: 'update' }, wrapper: :horizontal_form, html: { novalidate: false } do |f| %> -
-
- <%= f.input :name, class: 'form-control', required: true %> -
-
- <%= f.input :preferable, class: 'form-control' %> -
-
- -

<%= t('.add_new_field_label') %>

- -
-
- <%= select_tag :kind, - options_from_collection_for_select(Field.kinds.keys, :itself, :capitalize), - id: 'calculator_fields_kind', - prompt: t('.form.select_field_kind_label'), - class: 'custom-select', - data: { 'fields-list' => { form: [NamedValue.name, Select.name], - parameter: [Value.name, RangeField.name, Select.name, Calculation.name], - result: [Calculation.name] } } %> -
-
- <%= select_tag :type, '', id: 'calculator_fields_type', - prompt: t('.form.select_field_type_label'), - class: 'custom-select', - disabled: true %> -
-
- <%= link_to t('buttons.create'), '#', - class: 'btn btn-success text-white disabled', - id: 'add-calculator-field', - data: { url: new_account_calculator_field_path(calculator_slug: @calculator) } %> -
-
- -
-

<%= t('.form.form_label') %>

-
- <% if @form_fields.any? %> - <%= f.fields_for :fields, @form_fields do |ff| %> - <%= render 'account/calculators/fields/form', f: ff %> - <% end %> - <% else %> -

<%= t('.form.no_fields_yet_label') %>

- <% end %> -
- -

<%= t('.form.parameters_label') %>

-
- <% if @parameter_fields.any? %> - <%= f.fields_for :fields, @parameter_fields do |ff| %> - <%= render 'account/calculators/fields/form', f: ff %> - <% end %> - <% else %> -

<%= t('.form.no_fields_yet_label') %>

- <% end %> -
- -

<%= t('.form.results_label') %>

-
- <% if @result_fields.any? %> - <%= f.fields_for :fields, @result_fields do |ff| %> - <%= render 'account/calculators/fields/form', f: ff %> - <% end %> - <% else %> -

<%= t('.form.no_fields_yet_label') %>

- <% end %> -
-
- -
-
- <%= f.button :submit, t('.form.update_calculator_button'), class: 'btn btn-green me-2' %> - <%= link_to account_calculators_path, class: 'btn btn-danger d-flex align-items-center justify-content-center' do %> - <%= t('buttons.cancel') %> - <% end %> -
-
- <% end %> +
+ <%= render "account/calculators/partials/form", calculator: @calculator %>
diff --git a/app/views/account/calculators/partials/_form.html.erb b/app/views/account/calculators/partials/_form.html.erb index 4bf810999..651bc6c87 100644 --- a/app/views/account/calculators/partials/_form.html.erb +++ b/app/views/account/calculators/partials/_form.html.erb @@ -1,4 +1,4 @@ -<%= simple_form_for(@calculator, url: account_calculators_path) do |f| %> +<%= simple_form_for(calculator, url: polymorphic_path([:account, calculator], locale: I18n.locale)) do |f| %>
diff --git a/config/locales/en/en.yml b/config/locales/en/en.yml index 1ccf13530..22f6103b6 100644 --- a/config/locales/en/en.yml +++ b/config/locales/en/en.yml @@ -376,7 +376,7 @@ en: no_fields_yet_label: "No fields yet" update_calculator_button: "Update calculator" new: - create_calculator_button: "Create calculator" + create_calculator_button: "Save calculator" cancel_button: "Сancel" prohibited_to_update: " prevent the calculator from updating" prohibited_to_save: " перешкоджають збереженню калькулятора" @@ -473,7 +473,7 @@ en: no_fields_yet_label: "No fields yet" update_calculator_button: "Update calculator" new: - create_calculator_button: "Create calculator" + create_calculator_button: "Save calculator" feature_flags: submit_button: "Save" new_calculator_design: diff --git a/config/locales/uk/uk.yml b/config/locales/uk/uk.yml index 06f683b9e..7f8fa9777 100644 --- a/config/locales/uk/uk.yml +++ b/config/locales/uk/uk.yml @@ -356,7 +356,7 @@ uk: no_fields_yet_label: "Полів поки нема" update_calculator_button: "Оновити калькулятор" new: - create_calculator_button: "Створити калькулятор" + create_calculator_button: "Зберегти калькулятор" cancel_button: "Скасувати" prohibited_to_update: " перешкоджають оновленню калькулятора" prohibited_to_save: " перешкоджають збереженню калькулятора" diff --git a/spec/requests/account/calculators_spec.rb b/spec/requests/account/calculators_spec.rb index 95f57150b..5fb376413 100644 --- a/spec/requests/account/calculators_spec.rb +++ b/spec/requests/account/calculators_spec.rb @@ -7,7 +7,8 @@ include_context :enable_calculators_constructor let!(:calculator) { create(:calculator) } - + let!(:new_attributes) { { calculator: { en_name: "new name" }} } + let!(:invalid_attributes) { { calculator: { en_name: nil }} } let(:user) { create(:user) } let(:locale) { "en" } let(:new_path) { new_account_calculator_path(locale: locale) } @@ -89,6 +90,29 @@ end end + describe "PATCH #update" do + context "with valid parameters" do + it "is successful" do + patch account_calculator_path(calculator), params: new_attributes + calculator.reload + + expect(calculator.en_name).to eq("new name") + expect(flash[:notice]).to eq(I18n.t("notifications.calculator_updated")) + end + end + + context "with invalid parameters" do + it "is not successful" do + expect do + patch account_calculator_path(calculator), params: invalid_attributes + end.not_to change(calculator, :en_name) + + expect(response).to be_unprocessable + expect(response).to render_template(:edit) + end + end + end + describe "GET /account/calculators/:slug" do it "renders the calculator's show page correctly" do get account_calculator_path(calculator.slug, locale: locale)