diff --git a/Gemfile b/Gemfile index 158d206b..7e30fc06 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem "decidim-cache_cleaner" gem "decidim-decidim_awesome" gem "decidim-extended_socio_demographic_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module-extended_socio_demographic_authorization_handler.git", branch: DECIDIM_BRANCH -gem "decidim-extra_user_fields", git: "https://github.com/PopulateTools/decidim-module-extra_user_fields.git", branch: "release/0.27-stable" +gem "decidim-extra_user_fields", git: "https://github.com/OpenSourcePolitics/decidim-module-extra_user_fields.git", branch: "feat/notifications_sending_frequency" gem "decidim-friendly_signup", git: "https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git" gem "decidim-gallery", git: "https://github.com/OpenSourcePolitics/decidim-module-gallery.git", branch: "fix/nokogiri_deps" gem "decidim-homepage_interactive_map", git: "https://github.com/OpenSourcePolitics/decidim-module-homepage_interactive_map.git", branch: DECIDIM_BRANCH diff --git a/Gemfile.lock b/Gemfile.lock index 11e11dce..2f06dead 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,16 @@ GIT decidim-extended_socio_demographic_authorization_handler (0.27.0) decidim-core (~> 0.27) +GIT + remote: https://github.com/OpenSourcePolitics/decidim-module-extra_user_fields.git + revision: 9517905551332c4145796bc21ef5e035f99176b4 + branch: feat/notifications_sending_frequency + specs: + decidim-extra_user_fields (0.27.2) + country_select (~> 4.0) + decidim-core (>= 0.27.0, < 0.28) + deface (~> 1.5) + GIT remote: https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git revision: 1a054faf964cc6ed07f1bec47cb92f0083a5bcb4 @@ -74,16 +84,6 @@ GIT omniauth (~> 2.0) omniauth-oauth2 (>= 1.7.2, < 2.0) -GIT - remote: https://github.com/PopulateTools/decidim-module-extra_user_fields.git - revision: ef262d6619ef254de1379278f56c4c6af789e54c - branch: release/0.27-stable - specs: - decidim-extra_user_fields (0.27.2) - country_select (~> 4.0) - decidim-core (>= 0.27.0, < 0.28) - deface (~> 1.5) - GIT remote: https://github.com/alecslupu-pfa/decidim-module-survey_multiple_answers revision: 65ea83227f99d0f3d6237f98334ecc914a2a5597 diff --git a/config/initializers/friendly_signup.rb b/config/initializers/friendly_signup.rb index 460c5890..a22291a4 100644 --- a/config/initializers/friendly_signup.rb +++ b/config/initializers/friendly_signup.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +return unless defined?(Decidim::FriendlySignup) + Decidim::FriendlySignup.configure do |config| # Override password views or leave the originals (default is true): config.override_passwords = ENV.fetch("FRIENDLY_SIGNUP_OVERRIDE_PASSWORDS", "1") == "1" diff --git a/spec/commands/decidim/create_registration_spec.rb b/spec/commands/decidim/create_registration_spec.rb index cc17492a..3a56327a 100644 --- a/spec/commands/decidim/create_registration_spec.rb +++ b/spec/commands/decidim/create_registration_spec.rb @@ -3,120 +3,124 @@ require "spec_helper" module Decidim - module Comments - describe CreateRegistration do - describe "call" do - let(:organization) { create(:organization) } - - let(:name) { "Username" } - let(:nickname) { "nickname" } - let(:email) { "user@example.org" } - let(:password) { "Y1fERVzL2F" } - let(:password_confirmation) { password } - let(:tos_agreement) { "1" } - let(:newsletter) { "1" } - let(:current_locale) { "fr" } - - let(:form_params) do - { - "user" => { - "name" => name, - "nickname" => nickname, - "email" => email, - "password" => password, - "password_confirmation" => password_confirmation, - "tos_agreement" => tos_agreement, - "newsletter_at" => newsletter - } + describe CreateRegistration do + describe "call" do + let(:organization) { create(:organization) } + + let(:name) { "Username" } + let(:nickname) { "nickname" } + let(:email) { "user@example.org" } + let(:password) { "Y1fERVzL2F" } + let(:password_confirmation) { password } + let(:tos_agreement) { "1" } + let(:newsletter) { "1" } + let(:current_locale) { "fr" } + let(:notifications_sending_frequency) { "none" } + + let(:form_params) do + { + "user" => { + "name" => name, + "nickname" => nickname, + "email" => email, + "password" => password, + "password_confirmation" => password_confirmation, + "tos_agreement" => tos_agreement, + "newsletter_at" => newsletter } + } + end + let(:form) do + RegistrationForm.from_params( + form_params, + current_locale: current_locale + ).with_context( + current_organization: organization + ) + end + let(:command) { described_class.new(form) } + + describe "when the form is not valid" do + before do + allow(form).to receive(:invalid?).and_return(true) end - let(:form) do - RegistrationForm.from_params( - form_params, - current_locale: current_locale - ).with_context( - current_organization: organization - ) + + it "broadcasts invalid" do + expect { command.call }.to broadcast(:invalid) end - let(:command) { described_class.new(form) } - describe "when the form is not valid" do - before do - allow(form).to receive(:invalid?).and_return(true) - end + it "doesn't create a user" do + expect do + command.call + end.not_to change(User, :count) + end + + context "when the user was already invited" do + let(:user) { build(:user, email: email, organization: organization) } - it "broadcasts invalid" do - expect { command.call }.to broadcast(:invalid) + before do + user.invite! + clear_enqueued_jobs end - it "doesn't create a user" do + # rubocop:disable RSpec/ChangeByZero + it "receives the invitation email again" do expect do command.call - end.not_to change(User, :count) + user.reload + end.to change(User, :count).by(0) + .and broadcast(:invalid) + .and change(user.reload, :invitation_token) + expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.on_queue("mailers") end + # rubocop:enable RSpec/ChangeByZero + end + end - context "when the user was already invited" do - let(:user) { build(:user, email: email, organization: organization) } - - before do - user.invite! - clear_enqueued_jobs - end - - # rubocop:disable RSpec/ChangeByZero - it "receives the invitation email again" do - expect do - command.call - user.reload - end.to change(User, :count).by(0) - .and broadcast(:invalid) - .and change(user.reload, :invitation_token) - expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.on_queue("mailers") - end - # rubocop:enable RSpec/ChangeByZero - end + describe "when the form is valid" do + before do + Decidim::ExtraUserFields.notifications_sending_frequency = "none" end - describe "when the form is valid" do - it "broadcasts ok" do - expect { command.call }.to broadcast(:ok) - end + it "broadcasts ok" do + expect { command.call }.to broadcast(:ok) + end - it "creates a new user" do - expect(User).to receive(:create!).with( - name: form.name, - nickname: form.nickname, - email: form.email, - password: form.password, - password_confirmation: form.password_confirmation, - tos_agreement: form.tos_agreement, - newsletter_notifications_at: form.newsletter_at, - organization: organization, - accepted_tos_version: organization.tos_version, - locale: form.current_locale, - password_updated_at: an_instance_of(ActiveSupport::TimeWithZone), - extended_data: { - country: nil, - date_of_birth: nil, - gender: nil, - location: nil, - phone_number: nil, - postal_code: nil - } - ).and_call_original - - expect { command.call }.to change(User, :count).by(1) - end + it "creates a new user" do + expect(User).to receive(:create!).with( + name: form.name, + nickname: form.nickname, + email: form.email, + password: form.password, + password_confirmation: form.password_confirmation, + tos_agreement: form.tos_agreement, + newsletter_notifications_at: form.newsletter_at, + organization: organization, + accepted_tos_version: organization.tos_version, + locale: form.current_locale, + password_updated_at: an_instance_of(ActiveSupport::TimeWithZone), + notifications_sending_frequency: "none", + extended_data: { + country: nil, + date_of_birth: nil, + gender: nil, + location: nil, + phone_number: nil, + postal_code: nil + } + ).and_call_original + + expect { command.call }.to change(User, :count).by(1) + end - describe "when user keeps the newsletter unchecked" do - let(:newsletter) { "0" } + describe "when user keeps the newsletter unchecked" do + let(:newsletter) { "0" } - it "creates a user with no newsletter notifications" do - expect do - command.call - expect(User.last.newsletter_notifications_at).to be_nil - end.to change(User, :count).by(1) - end + it "creates a user with no newsletter notifications" do + expect do + command.call + expect(User.last.newsletter_notifications_at).to be_nil + end.to change(User, :count).by(1) end end end