From 6d1c5b2d27ffdbf6f24ea3a8f230f613e2ce61ed Mon Sep 17 00:00:00 2001 From: Joonas Date: Thu, 20 Jun 2024 11:12:40 +0300 Subject: [PATCH] Fix lint --- Gemfile | 5 ++ Gemfile.lock | 5 ++ .../application_controller_extensions.rb | 4 +- .../privacy/privacy_settings_controller.rb | 4 +- .../action_authorization_helper_extensions.rb | 2 + .../admin/proposal_bulk_actions_helper.rb | 2 + .../privacy/stats_users_count_extensions.rb | 4 +- ...allow_private_messaging_to_decidim_user.rb | 1 + decidim-privacy.gemspec | 5 -- .../api/interfaces/author_interface.rb | 3 +- .../api/interfaces/coauthorable_interface.rb | 2 +- lib/decidim/privacy/test/factories.rb | 2 +- .../impersonatable_users_controller_spec.rb | 12 ++--- .../admin/organization_controller_spec.rb | 26 +++++----- .../assembly_members_controller_spec.rb | 14 +++--- .../comments/comments_controller_spec.rb | 12 ++--- .../debates/debates_controller_spec.rb | 8 +-- .../omniauth_registrations_controller_spec.rb | 2 +- .../meetings/meetings_controller_spec.rb | 10 ++-- .../conversations_controller_spec.rb | 16 +++--- .../own_user_groups_controller_spec.rb | 4 +- .../proposals/proposals_controller_spec.rb | 4 +- .../user_activities_controller_spec.rb | 6 +-- spec/forms/decidim/account_form_spec.rb | 38 +++++++------- .../admin/conference_speaker_form_spec.rb | 16 +++--- .../meeting_registration_invite_form_spec.rb | 16 +++--- .../messaging/conversation_form_spec.rb | 8 +-- .../privacy/privacy_settings_form_spec.rb | 6 +-- .../privacy/publish_account_form_spec.rb | 6 +-- spec/forms/decidim/user_group_form_spec.rb | 20 ++++---- .../endorsable_helper_extensions_spec.rb | 3 +- .../action_authorization_helper_spec.rb | 21 ++++---- spec/models/decidim/action_log_spec.rb | 10 ++-- spec/models/decidim/comments/comment_spec.rb | 4 +- spec/models/decidim/identity_spec.rb | 4 +- spec/models/decidim/initiative_spec.rb | 16 +++--- .../decidim/messaging/conversation_spec.rb | 2 +- spec/models/decidim/organization_spec.rb | 8 +-- .../proposals/collaborative_draft_spec.rb | 12 ++--- spec/models/decidim/user_base_entity_spec.rb | 14 +++--- spec/models/decidim/user_group_spec.rb | 8 +-- spec/models/decidim/user_spec.rb | 6 +-- .../proposals/proposal_presenter_spec.rb | 2 +- .../initiatives/initiative_serializer_spec.rb | 4 +- .../budgets/order_reminder_generator_spec.rb | 18 +++---- spec/system/{ => decidim}/account_spec.rb | 0 .../{ => decidim}/accountability_spec.rb | 0 .../admin_impersonatable_users_spec.rb | 2 +- .../admin_impersonation_logs_spec.rb | 6 +-- spec/system/{ => decidim}/assemblies_spec.rb | 0 spec/system/{ => decidim}/blogs_spec.rb | 6 +-- spec/system/{ => decidim}/comments_spec.rb | 0 .../{ => decidim}/conversations_spec.rb | 26 +++++----- spec/system/{ => decidim}/debates_spec.rb | 6 +-- spec/system/{ => decidim}/initiatives_spec.rb | 0 spec/system/{ => decidim}/meetings_spec.rb | 0 .../{ => decidim}/private_process_spec.rb | 2 +- spec/system/{ => decidim}/proposals_spec.rb | 32 ++++++------ spec/system/{ => decidim}/search_spec.rb | 2 +- spec/system/{ => decidim}/user_group_spec.rb | 2 +- .../core/user_entity_input_filter_spec.rb | 50 +++++++++---------- .../decidim/meetings/meeting_type_spec.rb | 2 +- .../decidim/proposals/proposal_type_spec.rb | 2 +- 63 files changed, 270 insertions(+), 263 deletions(-) rename spec/system/{ => decidim}/account_spec.rb (100%) rename spec/system/{ => decidim}/accountability_spec.rb (100%) rename spec/system/{ => decidim}/admin_impersonatable_users_spec.rb (97%) rename spec/system/{ => decidim}/admin_impersonation_logs_spec.rb (91%) rename spec/system/{ => decidim}/assemblies_spec.rb (100%) rename spec/system/{ => decidim}/blogs_spec.rb (91%) rename spec/system/{ => decidim}/comments_spec.rb (100%) rename spec/system/{ => decidim}/conversations_spec.rb (93%) rename spec/system/{ => decidim}/debates_spec.rb (95%) rename spec/system/{ => decidim}/initiatives_spec.rb (100%) rename spec/system/{ => decidim}/meetings_spec.rb (100%) rename spec/system/{ => decidim}/private_process_spec.rb (97%) rename spec/system/{ => decidim}/proposals_spec.rb (89%) rename spec/system/{ => decidim}/search_spec.rb (99%) rename spec/system/{ => decidim}/user_group_spec.rb (98%) diff --git a/Gemfile b/Gemfile index 48af155..b07610b 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,11 @@ group :development, :test do end group :development do + gem "decidim-admin", DECIDIM_VERSION + gem "decidim-assemblies", DECIDIM_VERSION + gem "decidim-debates", DECIDIM_VERSION + gem "decidim-meetings", DECIDIM_VERSION + gem "decidim-proposals", DECIDIM_VERSION gem "letter_opener_web", "~> 2.0" gem "listen", "~> 3.8" gem "spring", "~> 4.1.3" diff --git a/Gemfile.lock b/Gemfile.lock index d09f7c5..d1d524f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -842,11 +842,16 @@ DEPENDENCIES brakeman (~> 5.2) byebug (~> 11.0) decidim (~> 0.28.0) + decidim-admin (~> 0.28.0) + decidim-assemblies (~> 0.28.0) decidim-conferences (~> 0.28.0) + decidim-debates (~> 0.28.0) decidim-dev (~> 0.28.0) decidim-elections (~> 0.28.0) decidim-initiatives (~> 0.28.0) + decidim-meetings (~> 0.28.0) decidim-privacy! + decidim-proposals (~> 0.28.0) faker (~> 3.2.2) letter_opener_web (~> 2.0) listen (~> 3.8) diff --git a/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb b/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb index f77c8fd..755ac84 100644 --- a/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb +++ b/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb @@ -14,9 +14,7 @@ module ApplicationControllerExtensions def privacy_modal_snippets return unless respond_to?(:snippets) - if current_user && !current_user.public? && user_signed_in? - snippets.add(:foot, helpers.cell("decidim/privacy/publish_account_modal", current_user)) - end + snippets.add(:foot, helpers.cell("decidim/privacy/publish_account_modal", current_user)) if current_user && !current_user.public? && user_signed_in? end end end diff --git a/app/controllers/decidim/privacy/privacy_settings_controller.rb b/app/controllers/decidim/privacy/privacy_settings_controller.rb index ed8e31f..c3b3d05 100644 --- a/app/controllers/decidim/privacy/privacy_settings_controller.rb +++ b/app/controllers/decidim/privacy/privacy_settings_controller.rb @@ -6,12 +6,12 @@ class PrivacySettingsController < ::Decidim::ApplicationController include Decidim::UserProfile def show - enforce_permission_to :read, :user, current_user: current_user + enforce_permission_to(:read, :user, current_user:) @privacy_settings = form(::Decidim::Privacy::PrivacySettingsForm).from_model(current_user) end def update - enforce_permission_to :read, :user, current_user: current_user + enforce_permission_to(:read, :user, current_user:) @privacy_settings = form(::Decidim::Privacy::PrivacySettingsForm).from_params(params) UpdatePrivacySettings.call(current_user, @privacy_settings) do diff --git a/app/helpers/concerns/decidim/privacy/action_authorization_helper_extensions.rb b/app/helpers/concerns/decidim/privacy/action_authorization_helper_extensions.rb index b2e6a09..55650d1 100644 --- a/app/helpers/concerns/decidim/privacy/action_authorization_helper_extensions.rb +++ b/app/helpers/concerns/decidim/privacy/action_authorization_helper_extensions.rb @@ -9,6 +9,7 @@ module ActionAuthorizationHelperExtensions private # rubocop: disable Metrics/PerceivedComplexity + # rubocop: disable Metrics/CyclomaticComplexity def authorized_to(tag, action, arguments, block) if block body = block @@ -56,6 +57,7 @@ def authorized_to(tag, action, arguments, block) end end # rubocop: enable Metrics/PerceivedComplexity + # rubocop: enable Metrics/CyclomaticComplexity end private diff --git a/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb b/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb index 63a12e5..92821d1 100644 --- a/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb +++ b/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb @@ -21,6 +21,7 @@ def bulk_valuators_select(participatory_space, prompt) # Internal: A method to cache to queries to find the valuators for the # current space. + # rubocop:disable Rails/HelperInstanceVariable def find_valuators_for_select(participatory_space) return @valuators_for_select if @valuators_for_select @@ -33,6 +34,7 @@ def find_valuators_for_select(participatory_space) [valuator.name, role.id] end end + # rubocop:enable Rails/HelperInstanceVariable end end end diff --git a/app/queries/concerns/decidim/privacy/stats_users_count_extensions.rb b/app/queries/concerns/decidim/privacy/stats_users_count_extensions.rb index 13975b4..4875da1 100644 --- a/app/queries/concerns/decidim/privacy/stats_users_count_extensions.rb +++ b/app/queries/concerns/decidim/privacy/stats_users_count_extensions.rb @@ -7,8 +7,8 @@ module StatsUsersCountExtensions included do def query users = Decidim::User.entire_collection.where(organization: @organization).not_deleted.not_blocked.confirmed - users = users.where("created_at >= ?", @start_at) if @start_at.present? - users = users.where("created_at <= ?", @end_at) if @end_at.present? + users = users.where(created_at: @start_at..) if @start_at.present? + users = users.where(created_at: ..@end_at) if @end_at.present? users.count end end diff --git a/db/migrate/20230505141624_add_allow_private_messaging_to_decidim_user.rb b/db/migrate/20230505141624_add_allow_private_messaging_to_decidim_user.rb index 9ef268d..2f3b0b7 100644 --- a/db/migrate/20230505141624_add_allow_private_messaging_to_decidim_user.rb +++ b/db/migrate/20230505141624_add_allow_private_messaging_to_decidim_user.rb @@ -3,5 +3,6 @@ class AddAllowPrivateMessagingToDecidimUser < ActiveRecord::Migration[6.1] def change add_column :decidim_users, :allow_private_messaging, :boolean, default: true + change_column_null :decidim_users, :allow_private_messaging, false end end diff --git a/decidim-privacy.gemspec b/decidim-privacy.gemspec index db0465a..0ffdc75 100644 --- a/decidim-privacy.gemspec +++ b/decidim-privacy.gemspec @@ -19,10 +19,5 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,lib}/**/*", "LICENSE-AGPLv3.txt", "Rakefile", "README.md", "db/migrate"] s.add_dependency "decidim-core", Decidim::Privacy.decidim_version - s.add_development_dependency "decidim-admin", Decidim::Privacy.decidim_version - s.add_development_dependency "decidim-assemblies", Decidim::Privacy.decidim_version - s.add_development_dependency "decidim-debates", Decidim::Privacy.decidim_version - s.add_development_dependency "decidim-meetings", Decidim::Privacy.decidim_version - s.add_development_dependency "decidim-proposals", Decidim::Privacy.decidim_version s.metadata["rubygems_mfa_required"] = "true" end diff --git a/lib/decidim/api/interfaces/author_interface.rb b/lib/decidim/api/interfaces/author_interface.rb index dbac69d..a6ea0db 100644 --- a/lib/decidim/api/interfaces/author_interface.rb +++ b/lib/decidim/api/interfaces/author_interface.rb @@ -28,7 +28,8 @@ def organization_name def self.resolve_type(obj, _ctx) return Decidim::Core::UserType if obj.is_a?(Decidim::User) || obj.is_a?(Decidim::Privacy::PrivateUser) - return Decidim::Core::UserGroupType if obj.is_a? Decidim::UserGroup + + Decidim::Core::UserGroupType if obj.is_a? Decidim::UserGroup end end end diff --git a/lib/decidim/api/interfaces/coauthorable_interface.rb b/lib/decidim/api/interfaces/coauthorable_interface.rb index 831b76a..cabf702 100644 --- a/lib/decidim/api/interfaces/coauthorable_interface.rb +++ b/lib/decidim/api/interfaces/coauthorable_interface.rb @@ -42,7 +42,7 @@ def public?(author) end def deleted?(author) - return if author.blank? + return false if author.blank? !author.deleted_at.nil? end diff --git a/lib/decidim/privacy/test/factories.rb b/lib/decidim/privacy/test/factories.rb index c02c355..e3ef064 100644 --- a/lib/decidim/privacy/test/factories.rb +++ b/lib/decidim/privacy/test/factories.rb @@ -6,7 +6,7 @@ factory :privacy_component, parent: :component do name { Decidim::Components::Namer.new(participatory_space.organization.available_locales, :privacy).i18n_name } manifest_name { :privacy } - participatory_space { create(:participatory_process, :with_steps) } + participatory_space { association(:participatory_process, :with_steps) } end FactoryBot.modify do diff --git a/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb b/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb index ed4c05e..45f521d 100644 --- a/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb +++ b/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb @@ -10,14 +10,14 @@ class ImpersonatableUsersController < Decidim::Admin::ApplicationController end end -describe Decidim::Admin::ImpersonatableUsersController, type: :controller do +describe Decidim::Admin::ImpersonatableUsersController do routes { Decidim::Admin::Engine.routes } - let(:organization) { create :organization } - let(:admin_user) { create(:user, :admin, :confirmed, organization: organization) } - let(:private_user) { create(:user, organization: organization) } - let(:public_user) { create(:user, organization: organization, published_at: Time.current) } - let(:another_admin) { create(:user, :admin, :confirmed, organization: organization) } + let(:organization) { create(:organization) } + let(:admin_user) { create(:user, :admin, :confirmed, organization:) } + let(:private_user) { create(:user, organization:) } + let(:public_user) { create(:user, organization:, published_at: Time.current) } + let(:another_admin) { create(:user, :admin, :confirmed, organization:) } describe "#index" do before do diff --git a/spec/controllers/decidim/admin/organization_controller_spec.rb b/spec/controllers/decidim/admin/organization_controller_spec.rb index ce067e9..01e45bb 100644 --- a/spec/controllers/decidim/admin/organization_controller_spec.rb +++ b/spec/controllers/decidim/admin/organization_controller_spec.rb @@ -10,11 +10,11 @@ class OrganizationController < Decidim::Admin::ApplicationController end end -describe Decidim::Admin::OrganizationController, type: :controller do +describe Decidim::Admin::OrganizationController do routes { Decidim::Admin::Engine.routes } - let(:organization) { create :organization } - let(:current_user) { create(:user, :admin, :confirmed, organization: organization) } + let(:organization) { create(:organization) } + let(:current_user) { create(:user, :admin, :confirmed, organization:) } before do request.env["decidim.current_organization"] = organization @@ -22,10 +22,10 @@ class OrganizationController < Decidim::Admin::ApplicationController end describe "GET users and user groups in json format" do - let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } + let(:parsed_response) { response.parsed_body.map(&:symbolize_keys) } context "when user is blocked" do - let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } @@ -34,7 +34,7 @@ class OrganizationController < Decidim::Admin::ApplicationController end context "when user is managed" do - let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } @@ -43,7 +43,7 @@ class OrganizationController < Decidim::Admin::ApplicationController end context "when user is deleted" do - let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } @@ -53,11 +53,11 @@ class OrganizationController < Decidim::Admin::ApplicationController end describe "GET users in json format" do - let!(:user) { create(:user, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - let!(:public_user) { create(:user, name: "Daisy Public", nickname: "daisy_p", organization: organization, published_at: Time.current) } + let!(:user) { create(:user, name: "Daisy Miller", nickname: "daisy_m", organization:) } + let!(:public_user) { create(:user, name: "Daisy Public", nickname: "daisy_p", organization:, published_at: Time.current) } let!(:other_organization_user) { create(:user, name: "Daisy Foo", nickname: "daisy_f", published_at: Time.current) } - let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } + let(:parsed_response) { response.parsed_body.map(&:symbolize_keys) } context "when searching by name" do it "returns the id, name and nickname for filtered users" do @@ -83,7 +83,7 @@ class OrganizationController < Decidim::Admin::ApplicationController end context "when user is blocked" do - let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } @@ -92,7 +92,7 @@ class OrganizationController < Decidim::Admin::ApplicationController end context "when user is managed" do - let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } @@ -101,7 +101,7 @@ class OrganizationController < Decidim::Admin::ApplicationController end context "when user is deleted" do - let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization:) } it "returns an empty json array" do get :users, format: :json, params: { term: "daisy" } diff --git a/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb b/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb index b187bc7..93198e5 100644 --- a/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb +++ b/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb @@ -10,7 +10,7 @@ class AssemblyMembersController end end -describe Decidim::Assemblies::AssemblyMembersController, type: :controller do +describe Decidim::Assemblies::AssemblyMembersController do routes { Decidim::Assemblies::Engine.routes } let(:organization) { create(:organization) } @@ -19,7 +19,7 @@ class AssemblyMembersController create( :assembly, :published, - organization: organization + organization: ) end @@ -32,20 +32,20 @@ class AssemblyMembersController it "displays an empty array of members" do get :index, params: { assembly_slug: assembly.slug } - expect(controller.helpers.collection).to match_array([]) + expect(controller.helpers.collection).to be_empty end end context "when there are members" do - let!(:member1) { create(:assembly_member, :with_user, assembly: assembly) } - let!(:member2) { create(:assembly_member, assembly: assembly) } + let!(:first_member) { create(:assembly_member, :with_user, assembly:) } + let!(:second_member) { create(:assembly_member, assembly:) } let!(:non_member) { create(:assembly_member) } context "when assembly has no public members" do it "displays an empty array of members" do get :index, params: { assembly_slug: assembly.slug } - expect(controller.helpers.collection).to match_array([]) + expect(controller.helpers.collection).to be_empty end end @@ -58,7 +58,7 @@ class AssemblyMembersController it "displays only public members" do get :index, params: { assembly_slug: assembly.slug } - expect(controller.helpers.collection).to match_array([member1]) + expect(controller.helpers.collection).to contain_exactly(member1) end end end diff --git a/spec/controllers/decidim/comments/comments_controller_spec.rb b/spec/controllers/decidim/comments/comments_controller_spec.rb index 3e1524c..1f44dcc 100644 --- a/spec/controllers/decidim/comments/comments_controller_spec.rb +++ b/spec/controllers/decidim/comments/comments_controller_spec.rb @@ -2,20 +2,20 @@ require "spec_helper" -describe Decidim::Comments::CommentsController, type: :controller do +describe Decidim::Comments::CommentsController do routes { Decidim::Comments::Engine.routes } let(:organization) { create(:organization) } - let(:participatory_process) { create :participatory_process, organization: organization } + let(:participatory_process) { create(:participatory_process, organization:) } let(:component) { create(:component, participatory_space: participatory_process) } - let(:commentable) { create(:dummy_resource, component: component) } + let(:commentable) { create(:dummy_resource, component:) } before do request.env["decidim.current_organization"] = organization end describe "POST create" do - let(:user) { create(:user, :confirmed, locale: "en", organization: organization) } + let(:user) { create(:user, :confirmed, locale: "en", organization:) } let(:comment) { Decidim::Comments::Comment.last } let(:params) do { comment: comment_params, xhr: true } @@ -35,7 +35,7 @@ end it "does not permit create action" do - post :create, xhr: true, params: params + post(:create, xhr: true, params:) expect(response).to render_template("decidim/privacy/privacy_block") end end @@ -47,7 +47,7 @@ end it "permits create action" do - post :create, xhr: true, params: params + post(:create, xhr: true, params:) expect(response).to have_http_status(:ok).or have_http_status(:no_content) end end diff --git a/spec/controllers/decidim/debates/debates_controller_spec.rb b/spec/controllers/decidim/debates/debates_controller_spec.rb index e05a00d..e3654b3 100644 --- a/spec/controllers/decidim/debates/debates_controller_spec.rb +++ b/spec/controllers/decidim/debates/debates_controller_spec.rb @@ -2,13 +2,13 @@ require "spec_helper" -describe Decidim::Debates::DebatesController, type: :controller do +describe Decidim::Debates::DebatesController do routes { Decidim::Debates::Engine.routes } let(:organization) { create(:organization) } - let(:component) { create(:debates_component, :with_creation_enabled, organization: organization) } - let!(:debate) { create(:debate, component: component, author: user) } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:component) { create(:debates_component, :with_creation_enabled, organization:) } + let!(:debate) { create(:debate, component:, author: user) } + let(:user) { create(:user, :confirmed, organization:) } let(:params) { { component_id: component.id } } before do diff --git a/spec/controllers/decidim/devise/omniauth_registrations_controller_spec.rb b/spec/controllers/decidim/devise/omniauth_registrations_controller_spec.rb index ac52f98..2ba9f0b 100644 --- a/spec/controllers/decidim/devise/omniauth_registrations_controller_spec.rb +++ b/spec/controllers/decidim/devise/omniauth_registrations_controller_spec.rb @@ -26,7 +26,7 @@ } allow(organization).to receive(:available_authorizations) - .and_return(["facebook"]) + .and_return(["dummy_authorization"]) end context "with successful sign in" do diff --git a/spec/controllers/decidim/meetings/meetings_controller_spec.rb b/spec/controllers/decidim/meetings/meetings_controller_spec.rb index 790dd2e..9ec879a 100644 --- a/spec/controllers/decidim/meetings/meetings_controller_spec.rb +++ b/spec/controllers/decidim/meetings/meetings_controller_spec.rb @@ -2,14 +2,14 @@ require "spec_helper" -describe Decidim::Meetings::MeetingsController, type: :controller do +describe Decidim::Meetings::MeetingsController do routes { Decidim::Meetings::Engine.routes } let(:organization) { create(:organization) } - let(:participatory_process) { create :participatory_process, organization: organization } + let(:participatory_process) { create(:participatory_process, organization:) } let(:meeting_component) { create(:meeting_component, :with_creation_enabled, participatory_space: participatory_process) } - let(:meeting) { create :meeting, :online, :not_official, :published, author: user, component: meeting_component } - let(:user) { create(:user, :confirmed, organization: organization) } + let(:meeting) { create(:meeting, :online, :not_official, :published, author: user, component: meeting_component) } + let(:user) { create(:user, :confirmed, organization:) } let(:params) { { component_id: meeting_component.id } } before do @@ -28,7 +28,7 @@ component_id: meeting_component.id, meeting: { title: generate_localized_title, - description: ::Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title }, + description: Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title }, type_of_meeting: meeting.type_of_meeting, online_meeting_url: meeting.online_meeting_url, start_time: meeting.start_time, diff --git a/spec/controllers/decidim/messaging/conversations_controller_spec.rb b/spec/controllers/decidim/messaging/conversations_controller_spec.rb index 30236a0..95bb61f 100644 --- a/spec/controllers/decidim/messaging/conversations_controller_spec.rb +++ b/spec/controllers/decidim/messaging/conversations_controller_spec.rb @@ -10,12 +10,12 @@ class ConversationsController < Decidim::ApplicationController end end -describe Decidim::Messaging::ConversationsController, type: :controller do +describe Decidim::Messaging::ConversationsController do routes { Decidim::Core::Engine.routes } let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:user1) { create(:user, organization: organization) } + let(:user) { create(:user, :confirmed, organization:) } + let(:user1) { create(:user, organization:) } let!(:conversation2) do Decidim::Messaging::Conversation.start!( originator: user, @@ -39,7 +39,7 @@ class ConversationsController < Decidim::ApplicationController end context "when messaging is disabled" do - let!(:user) { create(:user, :confirmed, organization: organization, allow_private_messaging: false, published_at: Time.current) } + let!(:user) { create(:user, :confirmed, organization:, allow_private_messaging: false, published_at: Time.current) } it "renders 404 error" do expect(subject).to render_template("decidim/privacy/message_block") @@ -47,7 +47,7 @@ class ConversationsController < Decidim::ApplicationController end context "when is public and private messaing is enabled" do - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } + let!(:user) { create(:user, :confirmed, organization:, published_at: Time.current) } context "when is the same user" do it "redirects to previous 2 participant created conversation" do @@ -58,7 +58,7 @@ class ConversationsController < Decidim::ApplicationController context "when conversation with a private user" do subject { get :new, params: { recipient_id: user1.id } } - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } + let!(:user) { create(:user, :confirmed, organization:, published_at: Time.current) } it "redirects to previous 2 participant created conversation" do expect(subject).to redirect_to profile_path(user.nickname) @@ -68,8 +68,8 @@ class ConversationsController < Decidim::ApplicationController context "when conversation with a public user" do subject { get :new, params: { recipient_id: user1.id } } - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } - let!(:user1) { create(:user, organization: organization, published_at: Time.current) } + let!(:user) { create(:user, :confirmed, organization:, published_at: Time.current) } + let!(:user1) { create(:user, organization:, published_at: Time.current) } it "redirects to previous 2 participant created conversation" do expect(subject).to redirect_to conversation_path(conversation2) diff --git a/spec/controllers/decidim/own_user_groups_controller_spec.rb b/spec/controllers/decidim/own_user_groups_controller_spec.rb index cef0b17..6d535cd 100644 --- a/spec/controllers/decidim/own_user_groups_controller_spec.rb +++ b/spec/controllers/decidim/own_user_groups_controller_spec.rb @@ -8,11 +8,11 @@ class OwnUserGroupsController < ApplicationController end end -describe Decidim::OwnUserGroupsController, type: :controller do +describe Decidim::OwnUserGroupsController do routes { Decidim::Core::Engine.routes } let!(:organization) { create(:organization) } - let!(:current_user) { create(:user, :admin, :confirmed, organization: organization) } + let!(:current_user) { create(:user, :admin, :confirmed, organization:) } let!(:private_user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user]) } let!(:user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user], published_at: Time.current) } diff --git a/spec/controllers/decidim/proposals/proposals_controller_spec.rb b/spec/controllers/decidim/proposals/proposals_controller_spec.rb index a3e69c9..f6503da 100644 --- a/spec/controllers/decidim/proposals/proposals_controller_spec.rb +++ b/spec/controllers/decidim/proposals/proposals_controller_spec.rb @@ -10,7 +10,7 @@ class ProposalsController end end -describe Decidim::Proposals::ProposalsController, type: :controller do +describe Decidim::Proposals::ProposalsController do routes { Decidim::Proposals::Engine.routes } let!(:user) { create(:user, :confirmed, organization: component.organization) } @@ -34,7 +34,7 @@ class ProposalsController context "when updating" do let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } - let!(:proposal) { create(:proposal, component: component, users: [user]) } + let!(:proposal) { create(:proposal, component:, users: [user]) } let(:proposal_params) do { title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", diff --git a/spec/controllers/decidim/user_activities_controller_spec.rb b/spec/controllers/decidim/user_activities_controller_spec.rb index 131d5e0..6a4a2f8 100644 --- a/spec/controllers/decidim/user_activities_controller_spec.rb +++ b/spec/controllers/decidim/user_activities_controller_spec.rb @@ -2,11 +2,11 @@ require "spec_helper" -describe Decidim::UserActivitiesController, type: :controller do +describe Decidim::UserActivitiesController do routes { Decidim::Core::Engine.routes } let(:organization) { create(:organization) } - let!(:user) { create(:user, nickname: "Nick", organization: organization, published_at: Time.current) } + let!(:user) { create(:user, nickname: "Nick", organization:, published_at: Time.current) } before do request.env["decidim.current_organization"] = organization @@ -14,7 +14,7 @@ describe "#show" do context "when user is private" do - let!(:user) { create(:user, nickname: "Nick", organization: organization) } + let!(:user) { create(:user, nickname: "Nick", organization:) } it "renders private view" do expect do diff --git a/spec/forms/decidim/account_form_spec.rb b/spec/forms/decidim/account_form_spec.rb index 072645e..73f7f30 100644 --- a/spec/forms/decidim/account_form_spec.rb +++ b/spec/forms/decidim/account_form_spec.rb @@ -5,16 +5,16 @@ describe Decidim::AccountForm do subject do described_class.new( - name: name, - email: email, - nickname: nickname, - old_password: old_password, - password: password, - password_confirmation: password_confirmation, - avatar: avatar, - remove_avatar: remove_avatar, - personal_url: personal_url, - about: about, + name:, + email:, + nickname:, + old_password:, + password:, + password_confirmation:, + avatar:, + remove_avatar:, + personal_url:, + about:, locale: "es" ).with_context( current_organization: organization, @@ -46,7 +46,7 @@ describe "email" do context "when it's already in use in the same organization" do context "and belongs to a private user" do - let!(:existing_user) { create(:user, email: email, organization: organization) } + let!(:existing_user) { create(:user, email:, organization:) } it "is invalid" do expect(subject).not_to be_valid @@ -54,7 +54,7 @@ end context "and belongs to a public user" do - let!(:existing_user) { create(:user, email: email, organization: organization, published_at: Time.current) } + let!(:existing_user) { create(:user, email:, organization:, published_at: Time.current) } it "is invalid" do expect(subject).not_to be_valid @@ -62,7 +62,7 @@ end context "and belongs to a group" do - let!(:existing_group) { create(:user_group, email: email, organization: organization) } + let!(:existing_group) { create(:user_group, email:, organization:) } it "is invalid" do expect(subject).not_to be_valid @@ -71,7 +71,7 @@ end context "when it's already in use in another organization" do - let!(:existing_user) { create(:user, email: email) } + let!(:existing_user) { create(:user, email:) } it "is valid" do expect(subject).to be_valid @@ -82,7 +82,7 @@ describe "nickname" do context "when it's already in use in the same organization" do context "and belongs to a private user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } + let!(:existing_user) { create(:user, nickname:, organization:) } it "is invalid" do expect(subject).not_to be_valid @@ -90,7 +90,7 @@ end context "and belongs to a public user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } + let!(:existing_user) { create(:user, nickname:, organization:, published_at: Time.current) } it "is invalid" do expect(subject).not_to be_valid @@ -98,7 +98,7 @@ end context "and belongs to a group" do - let!(:existing_group) { create(:user_group, nickname: nickname, organization: organization) } + let!(:existing_group) { create(:user_group, nickname:, organization:) } it "is invalid" do expect(subject).not_to be_valid @@ -121,7 +121,7 @@ context "with incorrect old_password" do let(:old_password) { "foobar1234567890" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end end @@ -137,7 +137,7 @@ context "with incorrect old_password" do let(:old_password) { "foobar1234567890" } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end end end diff --git a/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb b/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb index 9150802..f20a84f 100644 --- a/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb +++ b/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb @@ -6,8 +6,8 @@ describe Decidim::Conferences::Admin::ConferenceSpeakerForm do subject(:form) { described_class.from_params(attributes).with_context(context) } - let(:organization) { create :organization } - let(:conference) { create :conference, organization: organization } + let(:organization) { create(:organization) } + let(:conference) { create(:conference, organization:) } let(:current_participatory_space) { conference } let(:meeting_component) do create(:component, manifest_name: :meetings, participatory_space: conference) @@ -70,13 +70,13 @@ let(:existing_user) { true } context "and a private user exists" do - let(:user_id) { create(:user, organization: organization).id } + let(:user_id) { create(:user, organization:).id } it { is_expected.to be_valid } end context "and a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + let(:user_id) { create(:user, organization:, published_at: Time.current).id } it { is_expected.to be_valid } end @@ -86,15 +86,15 @@ subject { form.user } context "when a private user exists" do - let(:user_id) { create(:user, organization: organization).id } + let(:user_id) { create(:user, organization:).id } - it { is_expected.to be_kind_of(Decidim::User) } + it { is_expected.to be_a(Decidim::User) } end context "when a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + let(:user_id) { create(:user, organization:, published_at: Time.current).id } - it { is_expected.to be_kind_of(Decidim::User) } + it { is_expected.to be_a(Decidim::User) } end end end diff --git a/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb b/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb index a2b1a6e..b7c1808 100644 --- a/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb +++ b/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb @@ -5,7 +5,7 @@ describe Decidim::Meetings::Admin::MeetingRegistrationInviteForm do subject(:form) { described_class.from_params(attributes).with_context(context) } - let(:organization) { create :organization } + let(:organization) { create(:organization) } let(:context) do { current_organization: organization @@ -18,26 +18,26 @@ let(:user_id) { nil } let(:attributes) do { - name: name, - email: email, - existing_user: existing_user, - user_id: user_id + name:, + email:, + existing_user:, + user_id: } end context "when existing user is present" do context "and no user is provided" do - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end context "and a private user exists" do - let(:user_id) { create(:user, organization: organization).id } + let(:user_id) { create(:user, organization:).id } it { is_expected.to be_valid } end context "and a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + let(:user_id) { create(:user, organization:, published_at: Time.current).id } it { is_expected.to be_valid } end diff --git a/spec/forms/decidim/messaging/conversation_form_spec.rb b/spec/forms/decidim/messaging/conversation_form_spec.rb index 7f0dc19..14efa13 100644 --- a/spec/forms/decidim/messaging/conversation_form_spec.rb +++ b/spec/forms/decidim/messaging/conversation_form_spec.rb @@ -10,12 +10,12 @@ let(:sender) { create(:user) } let(:params) do { - body: body, - recipient_id: recipient_id + body:, + recipient_id: } end let(:form) do - described_class.from_params(params).with_context(sender: sender) + described_class.from_params(params).with_context(sender:) end context "when everything is OK" do @@ -25,6 +25,6 @@ context "when private recipient" do let!(:recipient_id) { create(:user, organization: sender.organization).id } - it { is_expected.to be_invalid } + it { is_expected.not_to be_valid } end end diff --git a/spec/forms/decidim/privacy/privacy_settings_form_spec.rb b/spec/forms/decidim/privacy/privacy_settings_form_spec.rb index ed11719..6e22695 100644 --- a/spec/forms/decidim/privacy/privacy_settings_form_spec.rb +++ b/spec/forms/decidim/privacy/privacy_settings_form_spec.rb @@ -7,7 +7,7 @@ let(:organization) { create(:organization) } let(:context) { { current_organization: organization } } - let(:user) { create(:user, organization: organization) } + let(:user) { create(:user, organization:) } describe "#map_model" do context "when private user" do @@ -19,7 +19,7 @@ end context "with public user" do - let!(:user) { create(:user, organization: organization, published_at: Time.current) } + let!(:user) { create(:user, organization:, published_at: Time.current) } it "maps the model correctly" do expect(subject.published_at).to be(true) @@ -27,7 +27,7 @@ end context "with no direct message allowed" do - let!(:user) { create(:user, organization: organization, direct_message_types: "followed-only") } + let!(:user) { create(:user, organization:, direct_message_types: "followed-only") } it "maps the model correctly" do expect(subject.published_at).to be(false) diff --git a/spec/forms/decidim/privacy/publish_account_form_spec.rb b/spec/forms/decidim/privacy/publish_account_form_spec.rb index 92d1a47..a7f6bd1 100644 --- a/spec/forms/decidim/privacy/publish_account_form_spec.rb +++ b/spec/forms/decidim/privacy/publish_account_form_spec.rb @@ -6,7 +6,7 @@ subject(:form) { described_class.from_params(attributes) } let(:attributes) do - { agree_public_profile: agree_public_profile } + { agree_public_profile: } end describe "#agree_public_profile" do @@ -22,7 +22,7 @@ let(:agree_public_profile) { nil } it "is invalid" do - expect(subject).to be_invalid + expect(subject).not_to be_valid end end @@ -30,7 +30,7 @@ let(:agree_public_profile) { false } it "is valid" do - expect(subject).to be_invalid + expect(subject).not_to be_valid end end end diff --git a/spec/forms/decidim/user_group_form_spec.rb b/spec/forms/decidim/user_group_form_spec.rb index 9f1cd18..6c27d36 100644 --- a/spec/forms/decidim/user_group_form_spec.rb +++ b/spec/forms/decidim/user_group_form_spec.rb @@ -5,13 +5,13 @@ describe Decidim::UserGroupForm do subject do described_class.new( - name: name, - email: email, - nickname: nickname, - phone: phone, - document_number: document_number, - avatar: avatar, - about: about + name:, + email:, + nickname:, + phone:, + document_number:, + avatar:, + about: ).with_context( current_organization: organization, current_user: user @@ -46,7 +46,7 @@ context "when it's already in use in the same organization" do context "when private user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } + let!(:existing_user) { create(:user, nickname:, organization:) } it "is invalid" do expect(subject).not_to be_valid @@ -54,7 +54,7 @@ end context "when public user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } + let!(:existing_user) { create(:user, nickname:, organization:, published_at: Time.current) } it "is invalid" do expect(subject).not_to be_valid @@ -63,7 +63,7 @@ end context "when it's already in use in another organization" do - let!(:existing_user) { create(:user, nickname: nickname) } + let!(:existing_user) { create(:user, nickname:) } it "is valid" do expect(subject).to be_valid diff --git a/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb b/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb index ebbab15..6b7ef78 100644 --- a/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb +++ b/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb @@ -10,8 +10,7 @@ subject { helper.endorsements_enabled? } before do - allow(helper).to receive(:current_settings).and_return(double(endorsements_enabled: endorsements_enabled)) - allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive_messages(current_settings: double(endorsements_enabled:), current_user: user) end context "when user is private" do diff --git a/spec/helpers/decidim/action_authorization_helper_spec.rb b/spec/helpers/decidim/action_authorization_helper_spec.rb index 0c31480..6a10d8e 100644 --- a/spec/helpers/decidim/action_authorization_helper_spec.rb +++ b/spec/helpers/decidim/action_authorization_helper_spec.rb @@ -15,9 +15,8 @@ let(:path) { "fake_path" } before do - allow(helper).to receive(:current_component).and_return(component) - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:action_authorized_to).with(action, resource: resource, permissions_holder: permissions_holder).and_return(status) + allow(helper).to receive_messages(current_component: component, current_user: user) + allow(helper).to receive(:action_authorized_to).with(action, resource:, permissions_holder:).and_return(status) end shared_examples "an action authorization widget helper" do |params| @@ -119,13 +118,13 @@ describe "action_authorized_link_to" do context "when called with text" do - subject(:rendered) { helper.action_authorized_link_to(action, widget_text, path, resource: resource, permissions_holder: permissions_holder) } + subject(:rendered) { helper.action_authorized_link_to(action, widget_text, path, resource:, permissions_holder:) } it_behaves_like "an action authorization widget helper", has_action: true, widget_parts: %w( user1.name) - expect(response["users"]).not_to include("name" => user2.name) - expect(response["users"]).not_to include("name" => user3.name) - expect(response["users"]).not_to include("name" => user4.name) - expect(response["users"]).to include("name" => user5.name) - expect(response["users"]).to include("name" => user6.name) + expect(response["users"]).to include("name" => first_user.name) + expect(response["users"]).not_to include("name" => second_user.name) + expect(response["users"]).not_to include("name" => third_user.name) + expect(response["users"]).not_to include("name" => fourth_user.name) + expect(response["users"]).to include("name" => fifth_user.name) + expect(response["users"]).to include("name" => sixth_user.name) end context "when user is blocked" do let!(:user1) { create(:user, :blocked, :published, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) + expect(response["users"]).not_to include("name" => first_user.name) end end @@ -106,7 +106,7 @@ let!(:user1) { create(:user, :deleted, :confirmed, :published, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) + expect(response["users"]).not_to include("name" => first_user.name) end end @@ -114,28 +114,28 @@ let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) + expect(response["users"]).not_to include("name" => first_user.name) end end context "when search a user by name" do - let(:query) { %({ users(filter: { name: \"#{term}\" }) { name }}) } + let(:query) { %({ users(filter: { name: "#{term}" }) { name }}) } let(:term) { "FooBar User" } it "returns matching users" do - expect(response["users"]).to include("name" => user1.name) - expect(response["users"]).not_to include("name" => user2.name) - expect(response["users"]).to include("name" => user3.name) - expect(response["users"]).not_to include("name" => user4.name) - expect(response["users"]).to include("name" => user5.name) - expect(response["users"]).to include("name" => user6.name) + expect(response["users"]).to include("name" => first_user.name) + expect(response["users"]).not_to include("name" => second_user.name) + expect(response["users"]).to include("name" => third_user.name) + expect(response["users"]).not_to include("name" => fourth_user.name) + expect(response["users"]).to include("name" => fifth_user.name) + expect(response["users"]).to include("name" => sixth_user.name) end context "when user is blocked" do let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) + expect(response["users"]).not_to include("name" => first_user.name) end end @@ -143,7 +143,7 @@ let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) + expect(response["users"]).not_to include("name" => first_user.name) end end end diff --git a/spec/types/decidim/meetings/meeting_type_spec.rb b/spec/types/decidim/meetings/meeting_type_spec.rb index 800f0ab..d5f1141 100644 --- a/spec/types/decidim/meetings/meeting_type_spec.rb +++ b/spec/types/decidim/meetings/meeting_type_spec.rb @@ -8,7 +8,7 @@ describe Decidim::Meetings::MeetingType, type: :graphql do include_context "with a graphql class type" let(:component) { create(:meeting_component) } - let(:model) { create(:meeting, component: component) } + let(:model) { create(:meeting, component:) } include_examples "authorable interface" end diff --git a/spec/types/decidim/proposals/proposal_type_spec.rb b/spec/types/decidim/proposals/proposal_type_spec.rb index e2006c6..14dc8dc 100644 --- a/spec/types/decidim/proposals/proposal_type_spec.rb +++ b/spec/types/decidim/proposals/proposal_type_spec.rb @@ -7,7 +7,7 @@ describe Decidim::Proposals::ProposalType, type: :graphql do include_context "with a graphql class type" let(:component) { create(:proposal_component) } - let(:model) { create(:proposal, :with_votes, :with_endorsements, :with_amendments, component: component, users: [creator], user_groups: [user_group].compact) } + let(:model) { create(:proposal, :with_votes, :with_endorsements, :with_amendments, component:, users: [creator], user_groups: [user_group].compact) } let(:creator) { create(:user, :confirmed, :published, organization: component.organization) } let(:user_group) { nil }