From f685020fd0fe1cf70bcbb963c3fe51cf214a828c Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 17 Mar 2020 13:12:09 +0100 Subject: [PATCH] Show results and stats settings only in budget edit view --- app/views/admin/budgets/_form.html.erb | 4 +++- spec/system/admin/budgets_spec.rb | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/views/admin/budgets/_form.html.erb b/app/views/admin/budgets/_form.html.erb index d3cc652e6..4702a7ae2 100644 --- a/app/views/admin/budgets/_form.html.erb +++ b/app/views/admin/budgets/_form.html.erb @@ -88,7 +88,9 @@ <% end %> - <%= render "admin/shared/show_results_fields", form: f %> + <% if @budget.persisted? %> + <%= render "admin/shared/show_results_fields", form: f %> + <% end %>
diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index b7a9d90fe..ad0bfe854 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -144,6 +144,15 @@ describe "Admin budgets", :admin do expect(page).to have_css(".is-invalid-label", text: "Name") expect(page).to have_css("small.form-error", text: "has already been taken") end + + scenario "Do not show results and stats settings on new budget", :js do + visit new_admin_budget_path + + expect(page).not_to have_content "Show results and stats" + expect(page).not_to have_field "Show results" + expect(page).not_to have_field "Show stats" + expect(page).not_to have_field "Show advanced stats" + end end context "Destroy" do @@ -216,6 +225,16 @@ describe "Admin budgets", :admin do end end + scenario "Show results and stats settings", :js do + visit edit_admin_budget_path(budget) + + within_fieldset "Show results and stats" do + expect(page).to have_field "Show results" + expect(page).to have_field "Show stats" + expect(page).to have_field "Show advanced stats" + end + end + scenario "Changing name for current locale will update the slug if budget is in draft phase", :js do budget.update!(phase: "drafting") old_slug = budget.slug