Skip to content

Commit

Permalink
copy from v0.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Apr 8, 2024
1 parent e39a81c commit dd4eae9
Showing 1 changed file with 34 additions and 43 deletions.
77 changes: 34 additions & 43 deletions spec/shared/proposal_form_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
let(:scope_id) { scope.try(:id) }
let(:latitude) { 40.1234 }
let(:longitude) { 2.1234 }
let(:has_address) { false }
let(:address) { nil }
let(:suggested_hashtags) { [] }
let(:attachment_params) { nil }
Expand All @@ -43,7 +42,6 @@
category_id:,
scope_id:,
address:,
has_address:,
meeting_as_author:,
attachment: attachment_params,
suggested_hashtags:
Expand All @@ -68,10 +66,10 @@
it { is_expected.to be_valid }
end

context "when there's no title" do
context "when there is no title" do
let(:title) { nil }

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }

it "only adds errors to this field" do
subject.valid?
Expand All @@ -92,7 +90,7 @@
end
end

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

context "when the title is the minimum length" do
Expand All @@ -117,14 +115,14 @@
end
end

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end
end

context "when there's no body" do
context "when there is no body" do
let(:body) { nil }

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

context "when no category_id" do
Expand All @@ -142,43 +140,37 @@
context "with invalid category_id" do
let(:category_id) { 987 }

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

context "when geocoding is enabled" do
let(:component) { create(:proposal_component, :with_geocoding_enabled, participatory_space:) }

context "when the has address checkbox is checked" do
let(:has_address) { true }

context "when the address is not present" do
it "does not store the coordinates" do
expect(subject).to be_valid
expect(subject.address).to be_nil
expect(subject.latitude).to be_nil
expect(subject.longitude).to be_nil
end
context "when the address is not present" do
it "does not store the coordinates" do
expect(subject).to be_valid
expect(subject.address).to be_nil
expect(subject.latitude).to be_nil
expect(subject.longitude).to be_nil
end
end

context "when the address is present" do
let(:address) { "Some address" }
context "when the address is present" do
let(:address) { "Some address" }

before do
stub_geocoding(address, [latitude, longitude])
end
before do
stub_geocoding(address, [latitude, longitude])
end

it "validates the address and store its coordinates" do
expect(subject).to be_valid
expect(subject.latitude).to eq(latitude)
expect(subject.longitude).to eq(longitude)
end
it "validates the address and store its coordinates" do
expect(subject).to be_valid
expect(subject.latitude).to eq(latitude)
expect(subject.longitude).to eq(longitude)
end
end

context "when latitude and longitude are manually set" do
context "when the has address checkbox is unchecked" do
let(:has_address) { false }

it "is valid" do
expect(subject).to be_valid
expect(subject.latitude).to be_nil
Expand Down Expand Up @@ -213,7 +205,6 @@
author: previous_proposal.authors.first,
category_id: previous_proposal.try(:category_id),
scope_id: previous_proposal.try(:scope_id),
has_address:,
address:,
attachment: previous_proposal.try(:attachment_params),
latitude:,
Expand Down Expand Up @@ -273,12 +264,12 @@
category_id:,
scope_id:,
address:,
has_address:,
meeting_as_author:,
suggested_hashtags:,
add_photos: [Decidim::Dev.test_file("city.jpeg", "image/jpeg")]
attachments_key => [Decidim::Dev.test_file("city.jpeg", "image/jpeg")]
}
end
let(:attachments_key) { options[:admin] ? :add_photos : :add_documents }

it { is_expected.to be_valid }

Expand All @@ -289,11 +280,11 @@
expect(subject).not_to be_valid

if options[:i18n]
expect(subject.errors.full_messages).to contain_exactly("Title en can't be blank", "Add photos Needs to be reattached")
expect(subject.errors.full_messages).to contain_exactly("Title en cannot be blank", "Add photos Needs to be reattached")
expect(subject.errors.attribute_names).to contain_exactly(:title_en, :add_photos)
else
expect(subject.errors.full_messages).to contain_exactly("Title can't be blank", "Title is too short (under 15 characters)", "Add photos Needs to be reattached")
expect(subject.errors.attribute_names).to contain_exactly(:title, :add_photos)
expect(subject.errors.full_messages).to contain_exactly("Title cannot be blank", "Title is too short (under 15 characters)", "Add documents Needs to be reattached")
expect(subject.errors.attribute_names).to contain_exactly(:title, :add_documents)
end
end
end
Expand Down Expand Up @@ -381,10 +372,10 @@
it { is_expected.to be_valid }
end

context "when there's no title" do
context "when there is no title" do
let(:title) { nil }

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

context "when the title is too long" do
Expand All @@ -396,7 +387,7 @@
end
end

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

unless options[:skip_etiquette_validation]
Expand All @@ -409,14 +400,14 @@
end
end

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end
end

context "when there's no body" do
context "when there is no body" do
let(:body) { nil }

it { is_expected.not_to be_valid }
it { is_expected.to be_invalid }
end

context "when proposals comes from a meeting" do
Expand Down

0 comments on commit dd4eae9

Please sign in to comment.