diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index ef76162ea..da39f8428 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -1,7 +1,6 @@ class Officing::ResidenceController < Officing::BaseController - before_action :load_officer_assignment - before_action :validate_officer_assignment, only: :create + before_action :validate_officer_assignment def new @residence = Officing::Residence.new @@ -23,13 +22,14 @@ class Officing::ResidenceController < Officing::BaseController end def load_officer_assignment - @officer_assignments = current_user.poll_officer. + @officer_assignments ||= current_user.poll_officer. officer_assignments. voting_days. where(date: Date.current) end def validate_officer_assignment + load_officer_assignment if @officer_assignments.blank? redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") end diff --git a/app/views/officing/residence/new.html.erb b/app/views/officing/residence/new.html.erb index a508fae52..c736b1f23 100644 --- a/app/views/officing/residence/new.html.erb +++ b/app/views/officing/residence/new.html.erb @@ -1,32 +1,25 @@

<%= t("officing.residence.new.title") %>

-<% if @officer_assignments.present? %> -
-
- <%= form_for @residence, as: "residence", url: officing_residence_path do |f| %> - <%= render "errors" %> + -<% else %> -
- <%= t("officing.residence.new.no_assignments") %> -
-<% end %> +
diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 3eb0e70d7..568c0e146 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -51,7 +51,6 @@ en: submit: Validate document error_verifying_census: "The Census was unable to verify this document." form_errors: prevented the verification of this document - no_assignments: "You don't have officing shifts today" voters: new: title: Polls diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index c1d1fa837..1314713b1 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -51,7 +51,6 @@ es: submit: Validar documento error_verifying_census: "El PadrĂ³n no pudo verificar este documento." form_errors: evitaron verificar este documento - no_assignments: "Hoy no tienes turno de presidente de mesa" voters: new: title: Votaciones diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 4972d215e..587932ebe 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -21,4 +21,9 @@ module CommonActions check "user_terms_of_service" end + def validate_officer + allow_any_instance_of(Officing::ResidenceController). + to receive(:validate_officer_assignment).and_return(true) + end + end