Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx specs in release 0.27 #14

Merged
merged 8 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ AllCops:
# If a value is specified for TargetRubyVersion then it is used.
# Else if .ruby-version exists and it contains an MRI version it is used.
# Otherwise we fallback to the oldest officially supported Ruby version (2.0).
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0

RSpec:
Patterns:
Expand Down
4 changes: 2 additions & 2 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

SimpleCov.start do
root ENV["ENGINE_ROOT"]
root ENV.fetch("ENGINE_ROOT", nil)

add_filter "lib/decidim/survey_multiple_answers/version.rb"
add_filter "/spec"
end

SimpleCov.command_name ENV["COMMAND_NAME"] || File.basename(Dir.pwd)
SimpleCov.command_name ENV.fetch("COMMAND_NAME", nil) || File.basename(Dir.pwd)

SimpleCov.merge_timeout 1800
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ gem "decidim", "~> 0.27"
gem "decidim-custom_proposal_states", path: "."
gem "decidim-elections", "~> 0.27"

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

group :development, :test do
gem "byebug", "~> 11.0", platform: :mri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module CustomProposalStates
module Admin
class CreateProposalState < Rectify::Command
class CreateProposalState < Decidim::Command
def initialize(form, component)
@form = form
@component = component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module CustomProposalStates
module Admin
class DestroyProposalState < Rectify::Command
class DestroyProposalState < Decidim::Command
# Initializes an UpdateResult Command.
#
# result - The current instance of the result to be destroyed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module CustomProposalStates
module Admin
class UpdateProposalState < Rectify::Command
class UpdateProposalState < Decidim::Command
include TranslatableAttributes

def initialize(form, state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def change
t.string :css_class
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def down
remove_foreign_key :decidim_proposals_proposals, column: :decidim_proposals_proposal_state_id
remove_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id
end
end
end
4 changes: 2 additions & 2 deletions db/migrate/20231102234909_create_default_proposal_states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def up
return unless Decidim.version.to_s.include?("0.26")

states = {
"0" => :not_answered,
"0" => :not_answered,
"10" => :evaluating,
"20" => :accepted,
"-10" => :rejected,
Expand All @@ -37,4 +37,4 @@ def up
end

def down; end
end
end
1 change: 1 addition & 0 deletions decidim-custom_proposal_states.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "decidim-dev", "~> 0.27"
s.add_development_dependency "decidim-elections", "~> 0.27"
s.add_development_dependency "decidim-sortitions", "~> 0.27"
s.metadata["rubygems_mfa_required"] = "true"
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def state_classes
case state
when "accepted"
["success"]
when "rejected"
when "rejected", "withdrawn"
["alert"]
when "evaluating"
["warning"]
when "withdrawn"
["alert"]
else
["muted"]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def self.prepended(base)
base.class_eval do
def default_filter_params
{
search_text: "",
state: default_states,
origin: default_filter_origin_params,
search_text_cont: "",
with_any_state: default_states,
with_any_origin: default_filter_origin_params,
activity: "all",
category_id: default_filter_category_params,
scope_id: default_filter_scope_params,
with_any_category: default_filter_category_params,
with_any_scope: default_filter_scope_params,
related_to: "",
type: "all"
}
Expand Down
6 changes: 3 additions & 3 deletions spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ENV["ENFORCED_LOCALES"].presence || "en"
end

let(:i18n) { I18n::Tasks::BaseTask.new({ locales: locales.split(",") }) }
let(:i18n) { I18n::Tasks::BaseTask.new(locales: locales.split(",")) }
let(:missing_keys) { i18n.missing_keys }
let(:unused_keys) { i18n.unused_keys }
let(:non_normalized_paths) { i18n.non_normalized_paths }
Expand All @@ -23,8 +23,8 @@
unless ENV["SKIP_NORMALIZATION"]
it "is normalized" do
error_message = "The following files need to be normalized:\n" \
"#{non_normalized_paths.map { |path| " #{path}" }.join("\n")}\n" \
"Please run `bundle exec i18n-tasks normalize --locales #{locales}` to fix them"
"#{non_normalized_paths.map { |path| " #{path}" }.join("\n")}\n" \
"Please run `bundle exec i18n-tasks normalize --locales #{locales}` to fix them"

expect(non_normalized_paths).to be_empty, error_message
end
Expand Down
23 changes: 12 additions & 11 deletions spec/proposals/cells/decidim/proposals/proposal_m_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Decidim::Proposals

let(:my_cell) { cell("decidim/proposals/proposal_m", proposal, context: { show_space: show_space }) }
let(:cell_html) { my_cell.call }
let(:created_at) { Time.current - 1.month }
let(:created_at) { 1.month.ago }
let(:published_at) { Time.current }
let(:component) { create(:extended_proposal_component, :with_attachments_allowed) }
let!(:proposal) { create(:extended_proposal, component: component, created_at: created_at, published_at: published_at) }
Expand Down Expand Up @@ -80,6 +80,7 @@ module Decidim::Proposals
let!(:attachment_3_pdf) { create(:attachment, :with_pdf, attached_to: proposal) }

it "renders the first image in the card whatever the order between attachments" do
attachment_2_img.reload
expect(subject).to have_css(".card__image")
expect(subject.find(".card__image")[:src]).to eq(attachment_2_img.thumbnail_url)
end
Expand Down Expand Up @@ -230,19 +231,19 @@ module Decidim::Proposals
end

context "when the active participatory space step change" do
let(:step_1) { create(:participatory_process_step, participatory_process: participatory_process, active: step_1_active) }
let(:step1) { create(:participatory_process_step, participatory_process: participatory_process, active: step_1_active) }
let(:step_1_active) { true }
let(:step_2) { create(:participatory_process_step, participatory_process: participatory_process, active: step_2_active) }
let(:step2) { create(:participatory_process_step, participatory_process: participatory_process, active: step_2_active) }
let(:step_2_active) { false }
let(:step_3) { create(:participatory_process_step, participatory_process: participatory_process, active: step_3_active) }
let(:step3) { create(:participatory_process_step, participatory_process: participatory_process, active: step_3_active) }
let(:step_3_active) { false }
let(:component) do
create(:extended_proposal_component,
participatory_space: participatory_process,
step_settings: {
step_1.id => { votes_enabled: false },
step_2.id => { votes_enabled: true },
step_3.id => { votes_enabled: false }
step1.id => { votes_enabled: false },
step2.id => { votes_enabled: true },
step3.id => { votes_enabled: false }
})
end
let(:participatory_process) { create(:participatory_process) }
Expand All @@ -251,8 +252,8 @@ module Decidim::Proposals
it "generates a different hash" do
old_hash = my_cell.send(:cache_hash)

step_1.update!(active: false)
step_2.update!(active: true)
step1.update!(active: false)
step2.update!(active: true)
proposal.reload

expect(my_cell.send(:cache_hash)).not_to eq(old_hash)
Expand All @@ -266,8 +267,8 @@ module Decidim::Proposals
it "generates a different hash" do
old_hash = my_cell.send(:cache_hash)

step_2.update!(active: false)
step_3.update!(active: true)
step2.update!(active: false)
step3.update!(active: true)
proposal.reload

expect(my_cell.send(:cache_hash)).not_to eq(old_hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Admin

context "when the form is not valid" do
before do
expect(form).to receive(:invalid?).and_return(true)
allow(form).to receive(:invalid?).and_return(true)
end

it "broadcasts invalid" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Admin

describe "when the form is not valid" do
before do
expect(form).to receive(:invalid?).and_return(true)
allow(form).to receive(:invalid?).and_return(true)
end

it "broadcasts invalid" do
Expand Down Expand Up @@ -197,10 +197,17 @@ module Admin

context "when attachments are allowed" do
let(:component) { create(:extended_proposal_component, :with_attachments_allowed) }
let(:blob) do
ActiveStorage::Blob.create_and_upload!(
io: File.open(Decidim::Dev.test_file("city.jpeg", "image/jpeg"), "rb"),
filename: "city.jpeg",
content_type: "image/jpeg" # Or figure it out from `name` if you have non-JPEGs
)
end
let(:attachment_params) do
{
title: "My attachment",
file: Decidim::Dev.test_file("city.jpeg", "image/jpeg")
file: blob.signed_id
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Proposals
module Admin
describe ImportParticipatoryText do
describe "call" do
let!(:document_file) { IO.read(Decidim::Dev.asset(document_name)) }
let!(:document_file) { File.read(Decidim::Dev.asset(document_name)) }
let(:current_component) do
create(
:extended_proposal_component,
Expand Down Expand Up @@ -70,7 +70,7 @@ module Admin
it "doesn't create any proposal" do
expect do
command.call
end.to change(Proposal, :count).by(0)
end.not_to change(Proposal, :count)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Admin
it "doesn't create the proposal" do
expect do
command.call
end.to change(Proposal, :count).by(0)
end.not_to change(Proposal, :count)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

describe "when the form is not valid" do
before do
expect(form).to receive(:invalid?).and_return(true)
allow(form).to receive(:invalid?).and_return(true)
end

it "broadcasts invalid" do
Expand Down Expand Up @@ -112,10 +112,18 @@

context "when attachments are allowed" do
let(:component) { create(:extended_proposal_component, :with_attachments_allowed) }
let(:blob) do
ActiveStorage::Blob.create_and_upload!(
io: File.open(Decidim::Dev.test_file("city.jpeg", "image/jpeg"), "rb"),
filename: "city.jpeg",
content_type: "image/jpeg" # Or figure it out from `name` if you have non-JPEGs
)
end

let(:attachment_params) do
{
title: "My attachment",
file: Decidim::Dev.test_file("city.jpeg", "image/jpeg")
file: blob.signed_id
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Proposals

describe "when the form is not valid" do
before do
expect(form).to receive(:invalid?).and_return(true)
allow(form).to receive(:invalid?).and_return(true)
end

it "broadcasts invalid" do
Expand Down Expand Up @@ -104,7 +104,7 @@ module Proposals
creator = proposal.creator

expect(creator.author).to eq(author)
expect(creator.user_group).to eq(nil)
expect(creator.user_group).to be_nil
end

it "adds the author as a follower" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Proposals
let(:current_user) { create(:user, organization: component.organization) }

it "broadcasts invalid" do
expect(collaborative_draft.authored_by?(current_user)).to eq(false)
expect(collaborative_draft.authored_by?(current_user)).to be(false)
expect { command.call }.to broadcast(:invalid)
end
end
Expand Down
Loading
Loading