From 4cd5bb90d475a8e99616609271227428a9ae63d1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 20 Jul 2018 11:53:01 +0200 Subject: [PATCH 1/2] Fix validation error when creating proposals without user verification We were getting a validation error when skipping user verification and creating proposals This was due to the responsible_name being empty for unverified users As skipping user verification is a temporary setting used until Census integration is configured, we can safely skip this validation when this setting is active --- app/models/proposal.rb | 8 ++++++-- spec/features/proposals_spec.rb | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index f47584456..672394c6d 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -36,12 +36,12 @@ class Proposal < ActiveRecord::Base validates :question, presence: true validates :summary, presence: true validates :author, presence: true - validates :responsible_name, presence: true + validates :responsible_name, presence: true, unless: :skip_user_verification? validates :title, length: { in: 4..Proposal.title_max_length } validates :description, length: { maximum: Proposal.description_max_length } validates :question, length: { in: 10..Proposal.question_max_length } - validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length } + validates :responsible_name, length: { in: 6..Proposal.responsible_name_max_length }, unless: :skip_user_verification? validates :retired_reason, inclusion: { in: RETIRE_OPTIONS, allow_nil: true } validates :terms_of_service, acceptance: { allow_nil: false }, on: :create @@ -214,6 +214,10 @@ class Proposal < ActiveRecord::Base return orders end + def skip_user_verification? + Setting["feature.user.skip_verification"].present? + end + protected def set_responsible_name diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index d3d51a96b..7c662df1f 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1804,4 +1804,40 @@ feature 'Successful proposals' do end end + + context "Skip user verification" do + + before do + Setting["feature.user.skip_verification"] = 'true' + end + + after do + Setting["feature.user.skip_verification"] = nil + end + + scenario "Create" do + author = create(:user) + login_as(author) + + visit proposals_path + + within('aside') do + click_link 'Create a proposal' + end + + expect(current_path).to eq(new_proposal_path) + + fill_in 'proposal_title', with: 'Help refugees' + fill_in 'proposal_summary', with: 'In summary what we want is...' + fill_in 'proposal_description', with: 'This is very important because...' + fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' + fill_in 'proposal_video_url', with: 'https://www.youtube.com/watch?v=yPQfcG-eimk' + fill_in 'proposal_tag_list', with: 'Refugees, Solidarity' + check 'proposal_terms_of_service' + + click_button 'Create proposal' + + expect(page).to have_content 'Proposal created successfully.' + end + end end From 2366182689ae2ce87e15e2dd6db4deb16e3a1857 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 20 Jul 2018 12:28:56 +0200 Subject: [PATCH 2/2] Fix specs --- spec/features/proposals_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 7c662df1f..3d567911f 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1829,6 +1829,7 @@ feature 'Successful proposals' do fill_in 'proposal_title', with: 'Help refugees' fill_in 'proposal_summary', with: 'In summary what we want is...' + fill_in 'proposal_question', with: 'Would you like to?' fill_in 'proposal_description', with: 'This is very important because...' fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' fill_in 'proposal_video_url', with: 'https://www.youtube.com/watch?v=yPQfcG-eimk'