Skip to content

Commit

Permalink
fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
antopalidi committed May 22, 2024
1 parent 98abc43 commit fb5913f
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 112 deletions.
29 changes: 0 additions & 29 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
inherit_from:
- .rubocop_ruby.yml
- .rubocop_rails.yml

RSpec/DescribeClass:
Enabled: false

RSpec/IndexedLet:
Enabled: false

RSpecRails/InferredSpecType:
Enabled: false

RSpec/ReceiveMessages:
Enabled: false

Rails/ThreeStateBooleanColumn:
Enabled: false

RSpec/NoExpectationExample:
Enabled: false

FactoryBot/FactoryAssociationWithStrategy:
Enabled: false

RSpec/RepeatedExampleGroupDescription:
Exclude:
- "spec/system/decidim/admin/admin_creates_wallet_spec.rb"

RSpec/RepeatedExampleGroupBody:
Exclude:
- "spec/system/decidim/admin/admin_creates_wallet_spec.rb"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

class AddCensusDataToDecidimVocdoniElections < ActiveRecord::Migration[6.1]
def change
# rubocop:disable Rails/ThreeStateBooleanColumn
add_column :decidim_vocdoni_elections, :internal_census, :boolean, default: false
add_column :decidim_vocdoni_elections, :verification_types, :string, array: true, default: []
add_column :decidim_vocdoni_elections, :census_attributes, :jsonb, default: {}
add_column :decidim_vocdoni_elections, :last_census_update_records_added, :integer
add_column :decidim_vocdoni_elections, :census_last_updated_at, :datetime
add_column :decidim_vocdoni_voters, :in_vocdoni_census, :boolean, default: false
# rubocop:enable Rails/ThreeStateBooleanColumn
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddNotNullConstraintToInVocdoniCensus < ActiveRecord::Migration[6.1]
def change
change_column_null :decidim_vocdoni_voters, :in_vocdoni_census, false
end
end
6 changes: 3 additions & 3 deletions lib/decidim/vocdoni/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
factory :vocdoni_component, parent: :component do
name { Decidim::Components::Namer.new(participatory_space.organization.available_locales, :vocdoni).i18n_name }
manifest_name { :vocdoni }
participatory_space { create(:participatory_process, :with_steps) }
participatory_space { association :participatory_process, :with_steps }
end

factory :vocdoni_election, class: "Decidim::Vocdoni::Election" do
transient do
organization { build(:organization) }
organization { association :organization }
end

upcoming
Expand All @@ -35,7 +35,7 @@
"secret_until_the_end" => true
}
end
component { create(:vocdoni_component, organization:) }
component { association :vocdoni_component, organization: }

trait :configured do
status { "created" }
Expand Down
2 changes: 2 additions & 0 deletions spec/commands/decidim/vocdoni/admin/save_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
describe Decidim::Vocdoni::Admin::SaveResults do
subject { described_class.new(form) }

# rubocop:disable RSpec/IndexedLet
let(:election) { create(:vocdoni_election) }
let(:question1) { create(:vocdoni_question, election:, weight: 1) }
let!(:answer11) { create(:vocdoni_election_answer, question: question1, value: 1) }
let!(:answer12) { create(:vocdoni_election_answer, question: question1, value: 0) }
let(:question2) { create(:vocdoni_question, election:, weight: 0) }
let!(:answer21) { create(:vocdoni_election_answer, question: question2, value: 0) }
let!(:answer22) { create(:vocdoni_election_answer, question: question2, value: 1) }
# rubocop:enable RSpec/IndexedLet

let(:organization) { election.component.organization }
let(:user) { create(:user, :admin, :confirmed, organization:) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Vocdoni
module Admin
describe AnswersController, type: :controller do
describe AnswersController do
routes { Decidim::Vocdoni::AdminEngine.routes }

let(:user) { create(:user, :confirmed, :admin, organization: component.organization) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Vocdoni::Admin::ElectionCalendarController, type: :controller do
describe Decidim::Vocdoni::Admin::ElectionCalendarController do
routes { Decidim::Vocdoni::AdminEngine.routes }

let(:user) { create(:user, :confirmed, :admin, organization: component.organization) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Vocdoni::Admin::ElectionsController, type: :controller do
describe Decidim::Vocdoni::Admin::ElectionsController do
routes { Decidim::Vocdoni::AdminEngine.routes }

let(:user) { create(:user, :confirmed, :admin, organization: component.organization) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Vocdoni::Admin::WalletsController, type: :controller do
describe Decidim::Vocdoni::Admin::WalletsController do
routes { Decidim::Vocdoni::AdminEngine.routes }

let(:user) { create(:user, :confirmed, :admin) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Vocdoni::ElectionsController, type: :controller do
describe Decidim::Vocdoni::ElectionsController do
routes { Decidim::Vocdoni::Engine.routes }

let(:component) { create(:vocdoni_component) }
Expand Down
8 changes: 3 additions & 5 deletions spec/controllers/decidim/vocdoni/votes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe Decidim::Vocdoni::VotesController, type: :controller do
describe Decidim::Vocdoni::VotesController do
routes { Decidim::Vocdoni::Engine.routes }

let(:component) { create(:vocdoni_component) }
Expand Down Expand Up @@ -40,8 +40,7 @@

context "when user is verified and is in the Vocdoni census" do
before do
allow(controller).to receive(:voter_verified?).and_return(true)
allow(controller).to receive(:voter).and_return(voter)
allow(controller).to receive_messages(voter_verified?: true, voter:)
end

it "returns verification status" do
Expand All @@ -53,8 +52,7 @@

context "when user is verified and is not in the Vocdoni census" do
before do
allow(controller).to receive(:voter_verified?).and_return(false)
allow(controller).to receive(:voter).and_return(voter)
allow(controller).to receive_messages(voter_verified?: false, voter:)
end

it "returns verification status" do
Expand Down
10 changes: 6 additions & 4 deletions spec/helpers/decidim/vocdoni/admin/steps_wizard_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

describe "#tab_link_class" do
before do
allow(election).to receive(:ready_for_questions_form?).and_return(true)
allow(election).to receive(:ready_for_census_form?).and_return(true)
allow(election).to receive(:ready_for_calendar_form?).and_return(true)
allow(election).to receive(:ready_for_publish_form?).and_return(true)
allow(election).to receive_messages(
ready_for_questions_form?: true,
ready_for_census_form?: true,
ready_for_calendar_form?: true,
ready_for_publish_form?: true
)
end

it 'returns an empty string for the "questions" tab with a present election' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe Decidim::Vocdoni::Admin::CreateVoterWalletsJob, type: :job do
RSpec.describe Decidim::Vocdoni::Admin::CreateVoterWalletsJob do
let!(:election) { create(:vocdoni_election, :upcoming, :with_internal_census) }
let!(:voters) { create_list(:vocdoni_voter, 2, election:, wallet_address: nil) }
let(:election_id) { election.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe Decidim::Vocdoni::Admin::UpdateElectionCensusJob, type: :job do
RSpec.describe Decidim::Vocdoni::Admin::UpdateElectionCensusJob do
subject { described_class.perform_later(election.id, non_voter_ids, user.id) }

let!(:election) { create(:vocdoni_election, :upcoming, :with_internal_census) }
Expand Down
14 changes: 10 additions & 4 deletions spec/models/decidim/vocdoni/answer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
end

context "when there are multiple answers" do
let!(:answer3) { create(:vocdoni_election_answer, question:, votes: 11) }
let!(:answer4) { create(:vocdoni_election_answer, question:, votes: 22) }
let!(:answer5) { create(:vocdoni_election_answer, question:, votes: 33) }
let!(:answer6) { create(:vocdoni_election_answer, question:, votes: 1) }
let!(:answers) do
[
{ question:, votes: 11 },
{ question:, votes: 22 },
{ question:, votes: 33 },
{ question:, votes: 1 }
].map do |attrs|
create(:vocdoni_election_answer, attrs)
end
end

it "sums to 100" do
expect(subject.question.answers.map(&:votes_percentage).sum).to eq(100)
Expand Down
6 changes: 3 additions & 3 deletions spec/models/decidim/vocdoni/election_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@
subject { election.answers_have_values? }

let(:question) { create(:vocdoni_question, election:) }
let!(:answer1) { create(:vocdoni_election_answer, question:, value: 0) }
let!(:answer2) { create(:vocdoni_election_answer, question:, value: 1) }
let!(:first_answer) { create(:vocdoni_election_answer, question:, value: 0) }
let!(:second_answer) { create(:vocdoni_election_answer, question:, value: 1) }

it { is_expected.to be_truthy }

context "when there answers have no values" do
let!(:answer1) { create(:vocdoni_election_answer, question:, value: nil) }
let!(:first_answer) { create(:vocdoni_election_answer, question:, value: nil) }

it { is_expected.to be_falsey }
end
Expand Down
60 changes: 30 additions & 30 deletions spec/models/decidim/vocdoni/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@
end

describe "#to_vocdoni" do
let(:question1) { create(:vocdoni_question, :complete) }
let(:question2) { create(:vocdoni_question, :complete) }
let(:vocdoni1) { question1.to_vocdoni }
let(:vocdoni2) { question2.to_vocdoni }
let(:first_question) { create(:vocdoni_question, :complete) }
let(:second_question) { create(:vocdoni_question, :complete) }
let(:first_vocdoni) { first_question.to_vocdoni }
let(:second_vocdoni) { second_question.to_vocdoni }

it "returns the question in the Vocdoni format" do
question1.build_answer_values!
expect(vocdoni1[0]["en"]).to eq(question1.title["en"])
expect(vocdoni1[0]["ca"]).to eq(question1.title["ca"])
expect(vocdoni1[0]["default"]).to eq(question1.title["en"])
expect(vocdoni1[1]["en"]).to eq(question1.description["en"])
expect(vocdoni1[1]["ca"]).to eq(question1.description["ca"])
expect(vocdoni1[1]["default"]).to eq(question1.description["en"])
expect(vocdoni1[2][0]["title"]["en"]).to eq(question1.answers[0].title["en"])
expect(vocdoni1[2][0]["value"]).to eq(0)
expect(vocdoni1[2][1]["title"]["en"]).to eq(question1.answers[1].title["en"])
expect(vocdoni1[2][1]["value"]).to eq(1)
expect(vocdoni1[2][2]["title"]["en"]).to eq(question1.answers[2].title["en"])
expect(vocdoni1[2][2]["value"]).to eq(2)
first_question.build_answer_values!
expect(first_vocdoni[0]["en"]).to eq(first_question.title["en"])
expect(first_vocdoni[0]["ca"]).to eq(first_question.title["ca"])
expect(first_vocdoni[0]["default"]).to eq(first_question.title["en"])
expect(first_vocdoni[1]["en"]).to eq(first_question.description["en"])
expect(first_vocdoni[1]["ca"]).to eq(first_question.description["ca"])
expect(first_vocdoni[1]["default"]).to eq(first_question.description["en"])
expect(first_vocdoni[2][0]["title"]["en"]).to eq(first_question.answers[0].title["en"])
expect(first_vocdoni[2][0]["value"]).to eq(0)
expect(first_vocdoni[2][1]["title"]["en"]).to eq(first_question.answers[1].title["en"])
expect(first_vocdoni[2][1]["value"]).to eq(1)
expect(first_vocdoni[2][2]["title"]["en"]).to eq(first_question.answers[2].title["en"])
expect(first_vocdoni[2][2]["value"]).to eq(2)

question2.build_answer_values!
expect(vocdoni2[0]["en"]).to eq(question2.title["en"])
expect(vocdoni2[0]["ca"]).to eq(question2.title["ca"])
expect(vocdoni2[0]["default"]).to eq(question2.title["en"])
expect(vocdoni2[1]["en"]).to eq(question2.description["en"])
expect(vocdoni2[1]["ca"]).to eq(question2.description["ca"])
expect(vocdoni2[1]["default"]).to eq(question2.description["en"])
expect(vocdoni2[2][0]["title"]["en"]).to eq(question2.answers[0].title["en"])
expect(vocdoni2[2][0]["value"]).to eq(0)
expect(vocdoni2[2][1]["title"]["en"]).to eq(question2.answers[1].title["en"])
expect(vocdoni2[2][1]["value"]).to eq(1)
expect(vocdoni2[2][2]["title"]["en"]).to eq(question2.answers[2].title["en"])
expect(vocdoni2[2][2]["value"]).to eq(2)
second_question.build_answer_values!
expect(second_vocdoni[0]["en"]).to eq(second_question.title["en"])
expect(second_vocdoni[0]["ca"]).to eq(second_question.title["ca"])
expect(second_vocdoni[0]["default"]).to eq(second_question.title["en"])
expect(second_vocdoni[1]["en"]).to eq(second_question.description["en"])
expect(second_vocdoni[1]["ca"]).to eq(second_question.description["ca"])
expect(second_vocdoni[1]["default"]).to eq(second_question.description["en"])
expect(second_vocdoni[2][0]["title"]["en"]).to eq(second_question.answers[0].title["en"])
expect(second_vocdoni[2][0]["value"]).to eq(0)
expect(second_vocdoni[2][1]["title"]["en"]).to eq(second_question.answers[1].title["en"])
expect(second_vocdoni[2][1]["value"]).to eq(1)
expect(second_vocdoni[2][2]["title"]["en"]).to eq(second_question.answers[2].title["en"])
expect(second_vocdoni[2][2]["value"]).to eq(2)
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/shared/vote_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
click_link_or_button "Preview"
end

# rubocop:disable RSpec/NoExpectationExample
it { uses_the_voting_booth({ email: user.email, token: "123456" }) }
# rubocop:enable RSpec/NoExpectationExample

it "shows the preview alert" do
expect(page).to have_content("This is a preview of the voting booth.")
Expand Down
10 changes: 6 additions & 4 deletions spec/system/decidim/admin/admin_creates_wallet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe "Admin creates wallet", :slow, type: :system do
describe "Admin creates wallet", :slow do # rubocop:disable RSpec/DescribeClass
let(:manifest_name) { :vocdoni }
let(:current_component) { create(:vocdoni_component) }
let!(:election) { create(:vocdoni_election, :ready_for_setup, component: current_component, title: { en: "English title" }) }
Expand Down Expand Up @@ -40,9 +40,11 @@

shared_context "with environment settings" do |env|
before do
allow(Decidim::Vocdoni).to receive(:api_endpoint_env).and_return(env)
allow(Decidim::Vocdoni).to receive(:vocdoni_reseller_name).and_return("Test reseller")
allow(Decidim::Vocdoni).to receive(:vocdoni_reseller_email).and_return("[email protected]")
allow(Decidim::Vocdoni).to receive_messages(
api_endpoint_env: env,
vocdoni_reseller_name: "Test reseller",
vocdoni_reseller_email: "[email protected]"
)
end
end

Expand Down
Loading

0 comments on commit fb5913f

Please sign in to comment.