From 5026af021deeaea79b15bc4830a3c7ca795fe79f Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 16 Aug 2018 13:29:29 -0500 Subject: [PATCH] Fix for nonprofit being weird --- app/api/houdini/v1/nonprofit.rb | 8 +++++++- .../components/registration_page/RegistrationWizard.tsx | 2 +- spec/api/houdini/nonprofit_spec.rb | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/api/houdini/v1/nonprofit.rb b/app/api/houdini/v1/nonprofit.rb index 4d68583f..669a7bbe 100644 --- a/app/api/houdini/v1/nonprofit.rb +++ b/app/api/houdini/v1/nonprofit.rb @@ -30,7 +30,13 @@ class Houdini::V1::Nonprofit < Houdini::V1::BaseAPI requires :nonprofit, type: Hash do requires :name, type:String, desc: 'Organization Name', allow_blank: false, documentation: { param_type: 'body' } - optional :url, type:String, desc: 'Organization website URL', allow_blank:true, regexp: URI::regexp, documentation: { param_type: 'body' } + optional :website, type:String, desc: 'Organization website URL', allow_blank:true, regexp: URI::regexp, documentation: { param_type: 'body' }, coerce_with: ->(url) { + coerced_url = url + unless (url =~ /\Ahttp:\/\/.*/i || url =~ /\Ahttps:\/\/.*/i) + coerced_url = 'http://'+ coerced_url + end + coerced_url + } requires :zip_code, type:String, allow_blank: false, desc: "Organization Address ZIP Code", documentation: { param_type: 'body' } requires :state_code, type:String, allow_blank: false, desc: "Organization Address State Code", documentation: { param_type: 'body' } requires :city, type:String, allow_blank: false, desc: "Organization Address City", documentation: { param_type: 'body' } diff --git a/javascripts/src/components/registration_page/RegistrationWizard.tsx b/javascripts/src/components/registration_page/RegistrationWizard.tsx index d791d858..3cfd88d8 100644 --- a/javascripts/src/components/registration_page/RegistrationWizard.tsx +++ b/javascripts/src/components/registration_page/RegistrationWizard.tsx @@ -59,7 +59,7 @@ export class RegistrationPageForm extends HoudiniForm { inputToForm = { 'nonprofit[name]': 'nonprofitTab.organization_name', - 'nonprofit[url]': 'nonprofitTab.website', + 'nonprofit[website]': 'nonprofitTab.website', 'nonprofit[email]': 'nonprofitTab.org_email', 'nonprofit[phone]': 'nonprofitTab.org_phone', 'nonprofit[city]': 'nonprofitTab.city', diff --git a/spec/api/houdini/nonprofit_spec.rb b/spec/api/houdini/nonprofit_spec.rb index 92fbf15a..56ef886b 100644 --- a/spec/api/houdini/nonprofit_spec.rb +++ b/spec/api/houdini/nonprofit_spec.rb @@ -70,14 +70,14 @@ describe Houdini::V1::Nonprofit, :type => :controller do nonprofit: { email: "noemeila", phone: "notphone", - url: "noturl" + url: "" }} xhr :post, '/api/v1/nonprofit', input expect(response.code).to eq "400" expected = create_errors("user") expected[:errors].push(h(params:["nonprofit[email]"], messages: gr_e("regexp"))) #expected[:errors].push(h(params:["nonprofit[phone]"], messages: gr_e("regexp"))) - expected[:errors].push(h(params:["nonprofit[url]"], messages: gr_e("regexp"))) + #expected[:errors].push(h(params:["nonprofit[url]"], messages: gr_e("regexp"))) expect_validation_errors(JSON.parse(response.body), expected) end @@ -130,7 +130,7 @@ describe Houdini::V1::Nonprofit, :type => :controller do it "succeeds" do force_create(:nonprofit, slug: "n", state_code_slug: "wi", city_slug: "appleton") input = { - nonprofit: {name: "n", state_code: "WI", city: "appleton", zip_code: 54915}, + nonprofit: {name: "n", state_code: "WI", city: "appleton", zip_code: 54915, url: 'www.cs.c'}, user: {name: "Name", email: "em@em.com", password: "12345678", password_confirmation: "12345678"} } @@ -150,7 +150,8 @@ describe Houdini::V1::Nonprofit, :type => :controller do zip_code: "54915", state_code_slug: "wi", city_slug: "appleton", - slug: "n-00" + slug: "n-00", + website: 'http://www.cs.c' }.with_indifferent_access expected_np = our_np.attributes.with_indifferent_access.merge(expected_np)