Skip to content

Commit

Permalink
refactor: updates with rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-Rousset committed Dec 13, 2024
1 parent bc6cbef commit 990d184
Show file tree
Hide file tree
Showing 24 changed files with 94 additions and 64 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
inherit_gem:
decidim-dev: rubocop-decidim.yml

RSpec/SpecFilePathFormat:
Enabled: true
Exclude:
- spec/services/open_data_exporter_spec.rb
RSpec/DescribeClass:
Enabled: true
Exclude:
- spec/system/phone_authorization_handler/admin_manages_system_authorizations_spec.rb
- spec/system/phone_authorization_handler/user_manages_phone_authorization_spec.rb
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ruby RUBY_VERSION
gem "decidim", "~> 0.29.1"
gem "decidim-additional_authorization_handler", path: "."

gem "puma", ">= 6.3.1"
gem "bootsnap", "~> 1.4"
gem "puma", ">= 6.3.1"

group :development, :test do
gem "byebug", "~> 11.0", platform: :mri
Expand Down
18 changes: 9 additions & 9 deletions app/services/extended_socio_demographic_authorization_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class ExtendedSocioDemographicAuthorizationHandler < Decidim::AuthorizationHandl

def metadata
super.merge(
last_name: last_name,
first_name: first_name,
address: address,
postal_code: postal_code,
city: city,
email: email,
phone_number: phone_number,
resident: resident,
rgpd: rgpd
last_name:,
first_name:,
address:,
postal_code:,
city:,
email:,
phone_number:,
resident:,
rgpd:
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/phone_authorization_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class PhoneAuthorizationHandler < Decidim::AuthorizationHandler
presence: true

def metadata
super.merge(phone_number: phone_number)
super.merge(phone_number:)
end
end
2 changes: 1 addition & 1 deletion config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
decidim_additional_authorization_handler: "#{base_path}/app/packs/entrypoints/decidim_additional_authorization_handler.js",
decidim_additional_authorization_handler_css: "#{base_path}/app/packs/stylesheets/decidim/additional_authorization_handler/additional_authorization_handler.scss"
)
#Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/additional_authorization_handler/additional_authorization_handler")
# Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/additional_authorization_handler/additional_authorization_handler")
4 changes: 2 additions & 2 deletions lib/decidim/additional_authorization_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require "decidim/additional_authorization_handler/workflow"
require "decidim/additional_authorization_handler/engine"
require "decidim/additional_authorization_handler/extends/proposal_serializer_extend"
#require "decidim/additional_authorization_handler/extends/csv_exporter_extend"
# require "decidim/additional_authorization_handler/extends/csv_exporter_extend"
require "decidim/additional_authorization_handler/extends/excel_exporter_extend"
#require "decidim/additional_authorization_handler/extends/json_exporter_extend"
# require "decidim/additional_authorization_handler/extends/json_exporter_extend"

module Decidim
# This namespace holds the logic of the `AdditionalAuthorizationHandler` component. This component
Expand Down
1 change: 0 additions & 1 deletion lib/decidim/additional_authorization_handler/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "rails"
require "decidim/core"


module Decidim
module AdditionalAuthorizationHandler
# This is the engine that runs on the public interface of additional_authorization_handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module CSVExporterExtend
#
# Returns an ExportData instance.
def admin_export(col_sep = Decidim.default_csv_col_sep)
data = ::CSV.generate(headers: admin_headers, write_headers: true, col_sep: col_sep) do |csv|
data = ::CSV.generate(headers: admin_headers, write_headers: true, col_sep:) do |csv|
admin_processed_collection.each do |resource|
csv << admin_headers.map { |header| custom_sanitize(resource[header]) }
end
Expand All @@ -28,7 +28,7 @@ def admin_headers

def admin_processed_collection
@admin_processed_collection ||= collection.map do |resource|
flatten(@serializer.new(resource, false).run).deep_dup
flatten(@serializer.new(resource, public_scope: false).run).deep_dup
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module JSONExporterExtend
# Returns an ExportData with the export.
def admin_export
data = ::JSON.pretty_generate(@collection.map do |resource|
@serializer.new(resource, false).run
@serializer.new(resource, public_scope: false).run
end)

Decidim::Exporters::ExportData.new(data, "json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Extends
module ProposalSerializerExtend
# Public: Initializes the serializer with a proposal.
# public_scope : Bool (default: true) - Allow to add extra information when administrator exports
def initialize(proposal, public_scope = true)
def initialize(proposal, public_scope: true)
@proposal = proposal
@public_scope = public_scope
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def serialize
withdrawn_at: proposal.withdrawn_at
}.merge(options_merge(author: {
**author_fields
}))
}))
end

# options_merge allows to add some objects to merge to the serialize
Expand All @@ -77,16 +77,21 @@ def author_fields
name: resource.authors.map do |author|
author_name(is_author_user_group ? resource.coauthorships.first.user_group : author)
end,
url: resource.authors.map do |author|
author_url(is_author_user_group ? resource.coauthorships.first.user_group : author)
end
}.merge(additional_fields(is_author_user_group))
end

def additional_fields(is_author_user_group)
{
nickname: resource.authors.map do |author|
author_nickname(is_author_user_group ? resource.coauthorships.first.user_group : author)
end,
email: resource.authors.map do |author|
author_email(is_author_user_group ? resource.coauthorships.first.user_group : author)
end,
url: resource.authors.map do |author|
author_url(is_author_user_group ? resource.coauthorships.first.user_group : author)
end,
phone_number: author_phone_number(resource.authors.map { |author| is_author_user_group ? "" : author.id }),
phone_number: author_phone_number(resource.authors.map { |author| is_author_user_group ? "" : author.id })
}
end

Expand Down
16 changes: 16 additions & 0 deletions spec/jobs/export_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ module Admin
ExportJob.perform_now(user, component, "dummies", "JSON")
end
end

describe "Excel" do
it "uses the Excel exporter" do
export_data = double

expect(Decidim::Exporters::Excel)
.to(receive(:new).with(anything, Decidim::Dev::DummySerializer))
.and_return(double(export: export_data))

expect(ExportMailer)
.to(receive(:export).with(user, anything, export_data))
.and_return(double(deliver_now: true))

ExportJob.perform_now(user, component, "dummies", "Excel")
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Decidim
expect(subject.decidim_version).to eq("~> 0.29.0")
end


it "returns module's version" do
expect(described_class.version).to eq("1.0.0")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/decidim/exporters/csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Decidim

let(:serializer) do
Class.new do
def initialize(resource, public_scope = true)
def initialize(resource, public_scope: true)
@resource = resource
@public_scope = public_scope
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/decidim/exporters/excel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Decidim

let(:serializer) do
Class.new do
def initialize(resource, public_scope = true)
def initialize(resource, public_scope: true)
@resource = resource
@public_scope = public_scope
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/decidim/exporters/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Decidim

let(:serializer) do
Class.new do
def initialize(resource, public_scope = true)
def initialize(resource, public_scope: true)
@resource = resource
@public_scope = public_scope
end
Expand Down
4 changes: 2 additions & 2 deletions spec/permissions/admin/permissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Decidim::AdditionalAuthorizationHandler::Admin
let(:permission_action) { Decidim::PermissionAction.new(**action) }

context "when user is admin" do
let(:user) { create :user, :admin, organization: organization }
let(:user) { create :user, :admin, organization: }

it { is_expected.to be_truthy }

Expand All @@ -32,7 +32,7 @@ module Decidim::AdditionalAuthorizationHandler::Admin
end

context "when user is not admin" do
let(:user) { create :user, organization: organization }
let(:user) { create :user, organization: }

it_behaves_like "permission is not set"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
describe ExtendedSocioDemographicAuthorizationHandler do
subject do
described_class.new(
last_name: last_name,
first_name: first_name,
address: address,
postal_code: postal_code,
city: city,
email: email,
phone_number: phone_number,
resident: resident,
rgpd: rgpd
last_name:,
first_name:,
address:,
postal_code:,
city:,
email:,
phone_number:,
resident:,
rgpd:
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/services/open_data_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
end

it "includes the meetings data" do
expect(csv_data).to include(meeting.title["en"].gsub(/"/, '""'))
expect(csv_data).to include(meeting.title["en"].gsub('"', '""'))
end

context "with unpublished components" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
describe "valid?" do
subject { handler.valid? }

let(:extra_params) { { phone_number: phone_number } }
let(:extra_params) { { phone_number: } }

context "when no phone number" do
let(:phone_number) { nil }
Expand Down
6 changes: 3 additions & 3 deletions spec/services/proposals/proposal_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module Proposals

context "when admin exports proposal" do
subject do
described_class.new(proposal, false)
described_class.new(proposal, public_scope: false)
end

let(:serialized) { subject.serialize }
Expand Down Expand Up @@ -317,7 +317,7 @@ module Proposals
end

it "serializes the user email" do
expect(serialized[:author]).to include(email: ["#{proposal.creator_author.email}"])
expect(serialized[:author]).to include(email: [proposal.creator_author.email.to_s])
end

it "serializes the phone number from authorization" do
Expand Down Expand Up @@ -381,7 +381,7 @@ module Proposals
end

it "serializes the email of the user group" do
expect(serialized[:author]).to include(email: ["#{proposal.coauthorships.first.user_group.email}"])
expect(serialized[:author]).to include(email: [proposal.coauthorships.first.user_group.email.to_s])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
switch_to_host(organization.host)
login_as admin, scope: :admin
visit decidim_system.root_path
click_link('Edit', href: "/system/organizations/#{organization.id}/edit")
click_link_or_button "Organizations"
click_link_or_button "Edit"
end

it "allows the system admin to list all available authorization methods" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@

fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

click_on "Send"
click_on "I continue"
expect(page).to have_content("You have been successfully authorized")
end

it "allows the user to skip it" do
click_on "start exploring"
click_on "consult the content of the platform"
expect(page).to have_current_path decidim.account_path

expect(page).to have_content("Participant settings")
Expand All @@ -54,11 +54,11 @@

fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

expect { click_on "Send" }.not_to change(Decidim::Authorization, :count)
expect { click_on "I continue" }.not_to change(Decidim::Authorization, :count)
expect(page).to have_content("There was a problem creating the authorization.")
expect(page).to have_content("A participant is already authorized with the same data. An administrator will contact you to verify your details.")

expect { click_on "Send" }.not_to change(Decidim::AuthorizationTransfer, :count)
expect { click_on "I continue" }.not_to change(Decidim::AuthorizationTransfer, :count)
expect(page).to have_content("There was a problem creating the authorization.")
end
end
Expand All @@ -73,7 +73,7 @@

fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

click_on "Send"
click_on "I continue"
expect(page).to have_content("You have been successfully authorized.")
expect(page).to have_no_content("We have recovered the following participation data based on your authorization:")
end
Expand All @@ -100,7 +100,7 @@

fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

click_on "Send"
click_on "I continue"
expect(page).to have_content("You have been successfully authorized.")
expect(page).to have_content("We have recovered the following participation data based on your authorization:")
expect(page).to have_content("Comments: 10")
Expand Down Expand Up @@ -151,7 +151,7 @@
fill_in "Document number", with: "123456789X"
fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

click_on "Send"
click_on "I continue"

expect(page).to have_content("You have been successfully authorized")

Expand All @@ -170,7 +170,7 @@
fill_in "Document number", with: "12345678"
fill_in_datepicker :authorization_handler_birthday_date, with: Time.current.change(day: 12).strftime("%d/%m/%Y")

click_on "Send"
click_on "I continue"

expect(page).to have_content("There was a problem creating the authorization.")
end
Expand Down Expand Up @@ -241,7 +241,7 @@
end

expect(page).to have_content("Document number")
expect(page).to have_button "Send"
expect(page).to have_button "I continue"
end
end
end
Expand Down Expand Up @@ -280,7 +280,7 @@
end

fill_in "Document number", with: "123456789X"
click_on "Send"
click_on "I continue"

expect(page).to have_content("You have been successfully authorized")
end
Expand Down
Loading

0 comments on commit 990d184

Please sign in to comment.