diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index f27f714b2db82..7f288c9d0d6de 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -320,6 +320,7 @@ ignore_unused: - decidim.assemblies.admin.assembly_members.form.explanation - decidim.assemblies.admin.assembly_members.form.image_guide - decidim.assemblies.admin.assembly_members.form.non_user_avatar_help + - decidim.initiatives.create_initiative.select_initiative_type.* - decidim.blogs.admin_log.* - decidim.templates.admin_log.* - decidim.forms.upload_help.explanation diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb new file mode 100644 index 0000000000000..8a722d0ccf190 --- /dev/null +++ b/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Decidim + module Initiatives + class AuthorizationCreateModalsController < Decidim::Initiatives::ApplicationController + helper_method :authorizations, :authorize_action_path + layout false + + def show + @initiative_type = Decidim::InitiativesType.find_by(id: params[:slug]) + render template: "decidim/authorization_modals/show" + end + + private + + def authorize_action_path(handler_name) + authorizations.status_for(handler_name).current_path(redirect_url: URI(request.referer).path) + end + + def authorizations + @authorizations ||= action_authorized_to("create", permissions_holder: @initiative_type) + end + end + end +end diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb index 1804347a681c7..809753fe5b3ef 100644 --- a/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb +++ b/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb @@ -37,12 +37,11 @@ class CreateInitiativeController < Decidim::Initiatives::ApplicationController before_action :ensure_type_exists, only: :show def show - enforce_permission_to :create, :initiative send("#{step}_step", initiative: session_initiative) end def update - enforce_permission_to :create, :initiative + enforce_permission_to :create, :initiative, { initiative_type: initiative_type_from_params } send("#{step}_step", params) end @@ -72,6 +71,9 @@ def select_initiative_type_step(_parameters) def previous_form_step(parameters) @form = build_form(Decidim::Initiatives::PreviousForm, parameters) + + enforce_permission_to :create, :initiative, { initiative_type: initiative_type } + render_wizard end @@ -170,6 +172,10 @@ def initiative_type @initiative_type ||= InitiativesType.where(organization: current_organization).find_by(id: initiative_type_id) end + def initiative_type_from_params + Decidim::InitiativesType.find_by(id: params["initiative"]["type_id"]) + end + def initiative_type_id session_initiative[:type_id] || @form&.type_id end diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb index 230836dae0c37..74cf52a246171 100644 --- a/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb +++ b/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb @@ -30,7 +30,7 @@ class InitiativesController < Decidim::Initiatives::ApplicationController include SingleInitiativeType helper_method :collection, :initiatives, :filter, :stats - helper_method :initiative_type + helper_method :initiative_type, :available_initiative_types # GET /initiatives def index diff --git a/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb b/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb index 75357b1f67e52..805da0cbee3f9 100644 --- a/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb +++ b/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb @@ -85,6 +85,26 @@ def popularity_level5?(initiative) initiative.percentage >= 100 end + def authorized_create_modal_button(type, html_options, &block) + tag = "button" + html_options ||= {} + + if current_user + if action_authorized_to("create", permissions_holder: type).ok? + html_options["data-open"] = "not-authorized-modal" + else + html_options["data-open"] = "authorizationModal" + html_options["data-open-url"] = authorization_create_modal_initiative_path(type) + end + else + html_options["data-open"] = "loginModal" + end + + html_options["onclick"] = "event.preventDefault();" + + send("#{tag}_to", "", html_options, &block) + end + def authorized_vote_modal_button(initiative, html_options, &block) return if current_user && action_authorized_to("vote", resource: initiative, permissions_holder: initiative.type).ok? diff --git a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb index 429c31d06ce69..6c0bc65ab0f6f 100644 --- a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb +++ b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb @@ -88,9 +88,9 @@ def update_public_initiative? def creation_enabled? Decidim::Initiatives.creation_enabled && ( Decidim::Initiatives.do_not_require_authorization || - UserAuthorizations.for(user).any? || - Decidim::UserGroups::ManageableUserGroups.for(user).verified.any? - ) + UserAuthorizations.for(user).any? || + Decidim::UserGroups::ManageableUserGroups.for(user).verified.any?) && + authorized?(:create, permissions_holder: initiative_type) end def request_membership? diff --git a/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb b/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb new file mode 100644 index 0000000000000..d171a48863e65 --- /dev/null +++ b/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb @@ -0,0 +1,19 @@ + diff --git a/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb b/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb index dba0adbb7c5c5..28c47b0350a2c 100644 --- a/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb +++ b/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb @@ -39,9 +39,15 @@ <%= raw translated_attribute type.description %>
- <%= decidim_form_for(@form, url: next_wizard_path, method: :put, html: { id: "new_initiative_#{type.id}", class: "form select-initiative_type-form" }) do |f| %> - <%= f.hidden_field :type_id, value: type.id, id: "initiative_type_id_#{ type.id }" %> - <%= f.submit t(".select"), class: "button" %> + <% if allowed_to?(:create, :initiative, { initiative_type: type }) %> + <%= decidim_form_for(@form, url: next_wizard_path, method: :put, html: { id: "new_initiative_#{type.id}", class: "form select-initiative_type-form" }) do |f| %> + <%= f.hidden_field :type_id, value: type.id, id: "initiative_type_id_#{ type.id }" %> + <%= f.submit t(".select"), class: "button" %> + <% end %> + <% else %> + <%= authorized_create_modal_button(type, remote: true, class: "button") do %> + <%= t(".verification_required") %> + <% end %> <% end %> <% end %> @@ -51,3 +57,4 @@ +<%= render partial: "decidim/initiatives/modal" %> diff --git a/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb b/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb index 13fdcef667b34..6fba4f4c85ef0 100644 --- a/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb +++ b/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb @@ -3,16 +3,23 @@ <%= render partial: "count" %> <% if Decidim::Initiatives.creation_enabled %> - <% if current_user && allowed_to?(:create, :initiative) %> + <% if current_user && available_initiative_types.size > 1 %> <%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small" do %> <%= t(".new_initiative") %> <%= icon "plus", role: "img", "aria-hidden": true %> <% end %> <% elsif current_user %> - + <% if allowed_to?(:create, :initiative, { initiative_type: available_initiative_types.first }) %> + <%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small" do %> + <%= t(".new_initiative") %> + <%= icon "plus", role: "img", "aria-hidden": true %> + <% end %> + <% else %> + <%= authorized_create_modal_button(available_initiative_types.first, remote: true, class: "title-action__action button small") do %> + <%= icon "plus", role: "img", "aria-hidden": true %> + <%= t(".new_initiative") %> + <% end %> + <% end %> <% else %> <% content_for(:redirect_after_login) { create_initiative_url(:select_initiative_type) } %> - -
-
-

- <%= t(".not_authorized.explanation") %> -

-
-
- - +<%= render partial: "decidim/initiatives/modal" %> diff --git a/decidim-initiatives/config/locales/en.yml b/decidim-initiatives/config/locales/en.yml index 23c4682bfcd3d..10cc29a12ae5b 100644 --- a/decidim-initiatives/config/locales/en.yml +++ b/decidim-initiatives/config/locales/en.yml @@ -395,6 +395,7 @@ en: more_information: "(More information)" select: I want to promote this initiative select_initiative_type_help: Initiatives are a means by which the participants can intervene so that the organization can undertake actions in defence of the general interest. Which initiative do you want to launch? + verification_required: Verify your account to promote this initiative share_committee_link: continue: Continue invite_to_committee_help: Link to invite people that will be part of the promoter committee @@ -505,11 +506,6 @@ en: unfold: Unfold index_header: new_initiative: New initiative - not_authorized: - authorizations_page: View authorizations - close: Close - explanation: You need to be verified in order to create a new initiative. - title: Authorization required initiatives: closed_initiatives_warning: Currently, there are no open initiatives, but here you can find all the closed initiatives listed. no_initiatives_warning: No initiatives match your search criteria. @@ -586,6 +582,12 @@ en: status_change_for: The initiative %{title} has changed its status last_activity: new_initiative: New initiative + modal: + not_authorized: + authorizations_page: View authorizations + close: Close + explanation: You need to be verified in order to create a new initiative. + title: Authorization required pages: home: highlighted_initiatives: @@ -619,6 +621,7 @@ en: comment: Comment initiatives_type: actions: + create: Create title: Actions vote: Sign layouts: diff --git a/decidim-initiatives/lib/decidim/initiatives/engine.rb b/decidim-initiatives/lib/decidim/initiatives/engine.rb index 17a87edca55e6..2c77478413280 100644 --- a/decidim-initiatives/lib/decidim/initiatives/engine.rb +++ b/decidim-initiatives/lib/decidim/initiatives/engine.rb @@ -36,6 +36,7 @@ class Engine < ::Rails::Engine member do get :authorization_sign_modal, to: "authorization_sign_modals#show" + get :authorization_create_modal, to: "authorization_create_modals#show" get :print, to: "initiatives#print", as: "print" get :send_to_technical_validation, to: "initiatives#send_to_technical_validation" end diff --git a/decidim-initiatives/lib/decidim/initiatives/participatory_space.rb b/decidim-initiatives/lib/decidim/initiatives/participatory_space.rb index fddd2191034e0..b0991fe588868 100644 --- a/decidim-initiatives/lib/decidim/initiatives/participatory_space.rb +++ b/decidim-initiatives/lib/decidim/initiatives/participatory_space.rb @@ -30,7 +30,7 @@ participatory_space.register_resource(:initiatives_type) do |resource| resource.model_class_name = "Decidim::InitiativesType" - resource.actions = %w(vote) + resource.actions = %w(vote create) end participatory_space.model_class_name = "Decidim::Initiative" diff --git a/decidim-initiatives/spec/permissions/decidim/initiatives/permissions_spec.rb b/decidim-initiatives/spec/permissions/decidim/initiatives/permissions_spec.rb index a7200a62559d5..1a955d5879f63 100644 --- a/decidim-initiatives/spec/permissions/decidim/initiatives/permissions_spec.rb +++ b/decidim-initiatives/spec/permissions/decidim/initiatives/permissions_spec.rb @@ -201,6 +201,9 @@ let(:action) do { scope: :public, action: :create, subject: :initiative } end + let(:context) do + { initiative_type: initiative.type } + end context "when creation is enabled" do before do @@ -236,6 +239,34 @@ it { is_expected.to be true } end + + context "when the initiative type has permissions to create" do + before do + initiative.type.create_resource_permission( + permissions: { + "create" => { + "authorization_handlers" => { + "dummy_authorization_handler" => { "options" => {} }, + "another_dummy_authorization_handler" => { "options" => {} } + } + } + } + ) + end + + context "when user is not verified" do + it { is_expected.to be false } + end + + context "when user is fully verified" do + before do + create(:authorization, name: "dummy_authorization_handler", user: user, granted_at: 2.seconds.ago) + create(:authorization, name: "another_dummy_authorization_handler", user: user, granted_at: 2.seconds.ago) + end + + it { is_expected.to be true } + end + end end context "when creation is not enabled" do diff --git a/decidim-initiatives/spec/system/create_initiative_spec.rb b/decidim-initiatives/spec/system/create_initiative_spec.rb index e65a1e9628916..1499404c75283 100644 --- a/decidim-initiatives/spec/system/create_initiative_spec.rb +++ b/decidim-initiatives/spec/system/create_initiative_spec.rb @@ -20,9 +20,11 @@ promoting_committee_enabled: initiative_type_promoting_committee_enabled, signature_type: signature_type) end - let!(:other_initiative_type) { create(:initiatives_type, organization: organization) } let!(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } - let!(:other_initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } + let!(:initiative_type_scope2) { create(:initiatives_type_scope, type: initiative_type) } + let!(:other_initiative_type) { create(:initiatives_type, organization: organization) } + let!(:other_initiative_type_scope) { create(:initiatives_type_scope, type: other_initiative_type) } + let(:third_initiative_type) { create(:initiatives_type, organization: organization) } shared_examples "initiatives path redirection" do it "redirects to initiatives path" do @@ -126,83 +128,315 @@ end describe "create initiative verification" do - context "when the user is logged in" do - context "and they're verified" do - it "they are taken to the initiative form" do - click_link "New initiative" - expect(page).to have_content("Which initiative do you want to launch") + context "when there is just one initiative type" do + let!(:other_initiative_type) { nil } + let!(:other_initiative_type_scope) { nil } + + context "when the user is logged in" do + context "and they do not need to be verified" do + it "they are taken to the initiative form" do + click_link "New initiative" + expect(page).to have_content("What does the initiative consist of") + end + end + + context "and creation require a verification" do + before do + allow(Decidim::Initiatives.config).to receive(:do_not_require_authorization).and_return(false) + visit decidim_initiatives.initiatives_path + end + + context "and they are verified" do + it "they are taken to the initiative form" do + click_link "New initiative" + expect(page).to have_content("What does the initiative consist of?") + end + end + + context "and they are not verified" do + let(:authorization) { nil } + + it "they need to verify" do + click_button "New initiative" + expect(page).to have_content("Authorization required") + end + + it "they are redirected to the initiative form after verifying" do + click_button "New initiative" + click_link "View authorizations" + click_link "Example authorization" + fill_in "Document number", with: "123456789X" + click_button "Send" + expect(page).to have_content("What does the initiative consist of?") + end + end + end + + context "and an authorization handler has been activated" do + before do + initiative_type.create_resource_permission( + permissions: { + "create" => { + "authorization_handlers" => { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + ) + visit decidim_initiatives.initiatives_path + end + + let(:authorization) { nil } + + it "they need to verify" do + click_button "New initiative" + expect(page).to have_content("Authorization required") + end + + it "they are authorized to create after verifying" do + click_button "New initiative" + click_link 'Authorize with "Example authorization"' + fill_in "Document number", with: "123456789X" + click_button "Send" + click_link "New initiative" + expect(page).to have_content("What does the initiative consist of?") + end end end - context "and they aren't verified" do - let(:authorization) { nil } + context "when they are not logged in" do + let(:login) { false } - it "they need to verify" do + it "they need to login in" do click_button "New initiative" - expect(page).to have_content("Authorization required") + expect(page).to have_content("Please sign in") end - it "they are redirected to the initiative form after verifying" do - click_button "New initiative" - click_link "View authorizations" - click_link "Example authorization" - fill_in "Document number", with: "123456789X" - click_button "Send" - expect(page).to have_content("Which initiative do you want to launch") + context "when they do not need to be verified" do + it "they are redirected to the initiative form after log in" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("What does the initiative consist of") + end + end + + context "and creation require a verification" do + before do + allow(Decidim::Initiatives.config).to receive(:do_not_require_authorization).and_return(false) + end + + context "and they are verified" do + it "they are redirected to the initiative form after log in" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("What does the initiative consist of") + end + end + + context "and they are not verified" do + let(:authorization) { nil } + + it "they are shown an error" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("You are not authorized to perform this action") + end + end + end + + context "and an authorization handler has been activated" do + before do + initiative_type.create_resource_permission( + permissions: { + "create" => { + "authorization_handlers" => { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + ) + visit decidim_initiatives.initiatives_path + end + + let(:authorization) { nil } + + it "they are shown an error" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("You are not authorized to perform this action") + end end end end - context "when they aren't logged in" do - let(:login) { false } + context "when there are multiples initiative type" do + context "when the user is logged in" do + context "and they do not need to be verified" do + it "they are taken to the initiative form" do + click_link "New initiative" + expect(page).to have_content("Which initiative do you want to launch") + end + end - it "they need to login in" do - click_button "New initiative" - expect(page).to have_content("Please sign in") - end + context "and creation require a verification" do + before do + allow(Decidim::Initiatives.config).to receive(:do_not_require_authorization).and_return(false) + end - context "when they are verified" do - it "they are redirected to the initiative form after log in" do - click_button "New initiative" - fill_in "Email", with: authorized_user.email - fill_in "Password", with: "decidim123456789" - click_button "Log in" + context "and they are verified" do + it "they are taken to the initiative form" do + click_link "New initiative" + expect(page).to have_content("Which initiative do you want to launch") + end + end + + context "and they are not verified" do + let(:authorization) { nil } + + it "they need to verify" do + click_link "New initiative" + expect(page).to have_css("button[data-open=not-authorized-modal]", visible: :all, count: 2) + end + + it "they are redirected to the initiative form after verifying" do + click_link "New initiative" + click_button "Verify your account to promote this initiative" + click_link "View authorizations" + click_link "Example authorization" + fill_in "Document number", with: "123456789X" + click_button "Send" + expect(page).to have_content("Which initiative do you want to launch") + end + end + end + + context "and an authorization handler has been activated on the first initiative type" do + before do + initiative_type.create_resource_permission( + permissions: { + "create" => { + "authorization_handlers" => { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + ) + visit decidim_initiatives.initiatives_path + end + + let(:authorization) { nil } - expect(page).to have_content("Which initiative do you want to launch") + it "they need to verify" do + click_link "New initiative" + click_button "Verify your account to promote this initiative" + expect(page).to have_content("Authorization required") + end + + it "they are authorized to create after verifying" do + click_link "New initiative" + click_button "Verify your account to promote this initiative" + click_link 'Authorize with "Example authorization"' + fill_in "Document number", with: "123456789X" + click_button "Send" + click_button "I want to promote this initiative" + expect(page).to have_content("What does the initiative consist of?") + end end end - context "when they aren't verified" do - let(:do_not_require_authorization) { false } - let(:authorization) { nil } + context "when they are not logged in" do + let(:login) { false } - it "they are shown an error" do + it "they need to login in" do click_button "New initiative" - fill_in "Email", with: authorized_user.email - fill_in "Password", with: "decidim123456789" - click_button "Log in" + expect(page).to have_content("Please sign in") + end + + context "when they do not need to be verified" do + it "they are redirected to the initiative form after log in" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" - expect(page).to have_content("You are not authorized to perform this action") + expect(page).to have_content("Which initiative do you want to launch") + end + end + + context "and creation require a verification" do + before do + allow(Decidim::Initiatives.config).to receive(:do_not_require_authorization).and_return(false) + end + + context "and they are verified" do + it "they are redirected to the initiative form after log in" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("Which initiative do you want to launch") + end + end + + context "and they are not verified" do + let(:authorization) { nil } + + it "they are shown an error" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_css("button[data-open=not-authorized-modal]", visible: :all, count: 2) + end + end + end + + context "and an authorization handler has been activated" do + before do + initiative_type.create_resource_permission( + permissions: { + "create" => { + "authorization_handlers" => { + "dummy_authorization_handler" => { "options" => {} } + } + } + } + ) + visit decidim_initiatives.initiatives_path + end + + let(:authorization) { nil } + + it "they are redirected to the initiative form after log in but need to verify" do + click_button "New initiative" + fill_in "Email", with: authorized_user.email + fill_in "Password", with: "decidim123456789" + click_button "Log in" + + expect(page).to have_content("Which initiative do you want to launch") + click_button "Verify your account to promote this initiative" + expect(page).to have_content("Authorization required") + end end end end end context "when rich text editor is enabled for participants" do - let(:initiative_type_minimum_committee_members) { 2 } - let(:signature_type) { "any" } - let(:initiative_type_promoting_committee_enabled) { true } - let(:initiative_type) do - create(:initiatives_type, - organization: organization, - minimum_committee_members: initiative_type_minimum_committee_members, - promoting_committee_enabled: initiative_type_promoting_committee_enabled, - signature_type: signature_type) - end - let!(:other_initiative_type) { create(:initiatives_type, organization: organization) } - let!(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } - let!(:other_initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } - before do organization.update(rich_text_editor_in_public_views: true) click_link "New initiative" @@ -214,20 +448,6 @@ describe "creating an initiative" do context "without validation" do - let(:initiative_type_minimum_committee_members) { 2 } - let(:signature_type) { "any" } - let(:initiative_type_promoting_committee_enabled) { true } - let(:initiative_type) do - create(:initiatives_type, - organization: organization, - minimum_committee_members: initiative_type_minimum_committee_members, - promoting_committee_enabled: initiative_type_promoting_committee_enabled, - signature_type: signature_type) - end - let!(:other_initiative_type) { create(:initiatives_type, organization: organization) } - let!(:initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } - let!(:other_initiative_type_scope) { create(:initiatives_type_scope, type: initiative_type) } - before do click_link "New initiative" end @@ -248,8 +468,8 @@ it "do not show initiative types without related scopes" do within "main" do - expect(page).not_to have_content(translated(other_initiative_type.title, locale: :en)) - expect(page).not_to have_content(ActionView::Base.full_sanitizer.sanitize(translated(other_initiative_type.description, locale: :en), tags: [])) + expect(page).not_to have_content(translated(third_initiative_type.title, locale: :en)) + expect(page).not_to have_content(ActionView::Base.full_sanitizer.sanitize(translated(third_initiative_type.description, locale: :en), tags: [])) end end end @@ -278,12 +498,13 @@ context "when there is only one initiative type" do let!(:other_initiative_type) { nil } + let!(:other_initiative_type_scope) { nil } - it "doesn't displays initiative types" do + it "does not displays initiative types" do expect(page).not_to have_current_path(decidim_initiatives.create_initiative_path(id: :select_initiative_type)) end - it "doesn't display the 'choose' step" do + it "does not display the 'choose' step" do within ".wizard__steps" do expect(page).not_to have_content("Choose") end @@ -340,6 +561,7 @@ context "when there is only one initiative type" do let!(:other_initiative_type) { nil } + let!(:other_initiative_type_scope) { nil } before do fill_in "Title", with: translated(initiative.title, locale: :en) @@ -358,7 +580,7 @@ end end - context "when there are several initiatives type" do + context "when there are several initiative types" do before do find_button("I want to promote this initiative").click fill_in "Title", with: translated(initiative.title, locale: :en) @@ -399,7 +621,7 @@ end context "when only one signature collection and scope are available" do - let(:other_initiative_type_scope) { nil } + let(:initiative_type_scope2) { nil } let(:initiative_type) { create(:initiatives_type, organization: organization, minimum_committee_members: initiative_type_minimum_committee_members, signature_type: "offline") } it "hides and automatically selects the values" do @@ -410,7 +632,7 @@ end end - context "when the scope isn't selected" do + context "when the scope is not selected" do it "shows an error" do select("Online", from: "Signature collection type") find_button("Continue").click