diff --git a/decidim-conferences/app/controllers/decidim/conferences/registration_types_controller.rb b/decidim-conferences/app/controllers/decidim/conferences/registration_types_controller.rb index ba86d4e85a44..a12c4ecaa1ab 100644 --- a/decidim-conferences/app/controllers/decidim/conferences/registration_types_controller.rb +++ b/decidim-conferences/app/controllers/decidim/conferences/registration_types_controller.rb @@ -8,7 +8,7 @@ class RegistrationTypesController < Decidim::Conferences::ApplicationController helper_method :collection, :conference def index - raise ActionController::RoutingError, "No registration types for this conference " if registration_types.empty? && current_participatory_space.registrations_enabled.empty? + raise ActionController::RoutingError, "No registration types for this conference " if registration_types.empty? && current_participatory_space.registrations_enabled enforce_permission_to :list, :registration_types end diff --git a/decidim-conferences/app/models/decidim/conference.rb b/decidim-conferences/app/models/decidim/conference.rb index 1133c5c18dc7..936ceefa7262 100644 --- a/decidim-conferences/app/models/decidim/conference.rb +++ b/decidim-conferences/app/models/decidim/conference.rb @@ -113,6 +113,12 @@ def has_available_slots? available_slots > conference_registrations.count end + def has_published_registration_types? + return false if registration_types.empty? + + registration_types.any?(&:published_at?) + end + def remaining_slots available_slots - conference_registrations.count end diff --git a/decidim-conferences/app/views/decidim/conferences/conferences/_conference_hero.html.erb b/decidim-conferences/app/views/decidim/conferences/conferences/_conference_hero.html.erb index e939ee53bad1..a974d508e2ee 100644 --- a/decidim-conferences/app/views/decidim/conferences/conferences/_conference_hero.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conferences/_conference_hero.html.erb @@ -19,7 +19,7 @@ <% if current_participatory_space.registrations_enabled? %> <% if current_participatory_space.has_registration_for?(current_user) %> <%= link_to t("layouts.decidim.conference_hero.manage_registration"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__primary" %> - <% else %> + <% elsif current_participatory_space.has_published_registration_types? %> <%= link_to t("layouts.decidim.conference_hero.register"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__secondary" %> <% end %> <% end %> diff --git a/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb b/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb index bf297f427de7..b84671c8a8e3 100644 --- a/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb +++ b/decidim-conferences/app/views/decidim/conferences/conferences/show.html.erb @@ -58,7 +58,7 @@ edit_link( <% if current_participatory_space.registrations_enabled? %> <% if current_participatory_space.has_registration_for?(current_user) %> <%= link_to t("decidim.conferences.conferences.show.manage_registration"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__primary" %> - <% else %> + <% elsif current_participatory_space.has_published_registration_types? %> <%= link_to t("decidim.conferences.conferences.show.register"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__secondary" %> <% end %> <% end %> @@ -85,7 +85,9 @@ edit_link( <% if current_participatory_space.registrations_enabled? %>
-

<%= t("decidim.conferences.conferences.show.register") %>

+ <% if current_participatory_space.has_published_registration_types? %> +

<%= t("decidim.conferences.conferences.show.register") %>

+ <% end %> <% if current_user.present? %>
@@ -96,7 +98,7 @@ edit_link(
<% if current_participatory_space.has_registration_for?(current_user) %> <%= link_to t("decidim.conferences.conferences.show.manage_registration"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__primary" %> - <% else %> + <% elsif current_participatory_space.has_published_registration_types? %> <%= link_to t("decidim.conferences.conferences.show.register"), decidim_conferences.conference_registration_types_path(current_participatory_space), class: "button button__lg button__secondary" %> <% end %>
diff --git a/decidim-conferences/spec/controllers/registration_types_controller_spec.rb b/decidim-conferences/spec/controllers/registration_types_controller_spec.rb new file mode 100644 index 000000000000..c2c5bdd3d7c2 --- /dev/null +++ b/decidim-conferences/spec/controllers/registration_types_controller_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Conferences + describe RegistrationTypesController do + routes { Decidim::Conferences::Engine.routes } + + let(:organization) { create(:organization) } + let!(:conference) do + create( + :conference, + :published, + registrations_enabled:, + organization: + ) + end + let(:registrations_enabled) { true } + let(:registration_types_count) { 5 } + let!(:registration_types) do + create_list(:registration_type, registration_types_count, conference:) + end + + before do + request.env["decidim.current_organization"] = organization + end + + describe "index" do + context "when registration_types is present" do + it "does not raise an error" do + get :index, params: { conference_slug: conference.slug } + assert_response :success + end + end + + context "when registration_types is empty" do + let(:registration_types) { [] } + + context "and current_participatory_space registrations is enabled" do + it "does raise an error" do + expect { get :index, params: { conference_slug: conference.slug } } + .to raise_error(ActionController::RoutingError) + end + end + + context "and current_participatory_space registrations is disabled" do + let(:registrations_enabled) { false } + + it "does not raise an error" do + get :index, params: { conference_slug: conference.slug } + assert_response :success + end + end + end + end + end + end +end diff --git a/decidim-conferences/spec/models/decidim/conference_spec.rb b/decidim-conferences/spec/models/decidim/conference_spec.rb index a72a0c06678c..f3797a4748b4 100644 --- a/decidim-conferences/spec/models/decidim/conference_spec.rb +++ b/decidim-conferences/spec/models/decidim/conference_spec.rb @@ -28,5 +28,29 @@ module Decidim it { is_expected.to be_valid } end + + describe "#has_published_registration_types?" do + subject { conference.has_published_registration_types? } + + context "when conference has no registration type" do + it { is_expected.to be_falsey } + end + + context "when conference has registration types" do + let!(:registration_types) do + create_list(:registration_type, 5, conference:) + end + + it { is_expected.to be_truthy } + + context "and the registration types are unpublished" do + let!(:registration_types) do + create_list(:registration_type, 5, :unpublished, conference:) + end + + it { is_expected.to be_falsey } + end + end + end end end diff --git a/decidim-conferences/spec/system/conference_registrations_spec.rb b/decidim-conferences/spec/system/conference_registrations_spec.rb index 04e6cddd372b..1cf9cee023d2 100644 --- a/decidim-conferences/spec/system/conference_registrations_spec.rb +++ b/decidim-conferences/spec/system/conference_registrations_spec.rb @@ -127,6 +127,50 @@ def visit_conference_registration_type expect(page).to have_css("button[disabled]", text: "Registration", count: 4) end end + + context "and there are published registrations types" do + it "allows to register" do + visit_conference + within ".conference__hero" do + expect(page).to have_content "Register" + end + within ".conference__content-block" do + expect(page).to have_content "Register" + click_on "Register" + end + expect(page).to have_content "CHOOSE YOUR REGISTRATION OPTION:" + end + end + + context "and there are unpublished registrations types" do + let!(:registration_types) do + create_list(:registration_type, 5, :unpublished, conference:) + end + + it "does not show the register button" do + visit_conference + within ".conference__hero" do + expect(page).to have_no_content "Register" + end + within ".conference__content-block" do + expect(page).to have_no_content "Register" + end + end + end + + context "and there are no registrations types" do + let(:registration_types) { [] } + + it "does not show the register button" do + visit_conference + within ".conference__hero" do + expect(page).to have_no_content "Register" + end + within ".conference__content-block" do + expect(page).to have_no_content "Register" + end + end + end end context "and the user is going to the conference" do