Skip to content

Commit

Permalink
Partner social media changes (#3148)
Browse files Browse the repository at this point in the history
* Added instagram field and checkbox to social media section

* Added validation for the checkbox on the social media form

* Small wording change

* Added some tests

* Added some more tests

* Bug fix

* Changed the social media validation error message

* Added a test for the custom error message

* Changed error message

* Partner media info list only renders if partner has social media

* Small refactor

* Updated media info section

* Added social media fields to views for bank admins

* Fixed linting issue

* Added instagram and no_social_media_presence to the other profiles controller
  • Loading branch information
Learningstuff98 authored Oct 29, 2022
1 parent 30ec619 commit a467dcb
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/partners/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def partner_params
:website,
:facebook,
:twitter,
:instagram,
:no_social_media_presence,
:founded,
:form_990,
:proof_of_form_990,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def edit_profile_params
:website,
:facebook,
:twitter,
:instagram,
:no_social_media_presence,
:founded,
:form_990,
:proof_of_form_990,
Expand Down
8 changes: 8 additions & 0 deletions app/models/partners/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
# greater_2_times_fpl :integer
# income_requirement_desc :boolean
# income_verification :boolean
# instagram :string
# more_docs_required :string
# name :string
# new_client_times :string
# no_social_media_presence :boolean
# other_agency_type :string
# partner_status :string default("pending")
# pick_up_email :string
Expand Down Expand Up @@ -92,6 +94,8 @@ class Partner < Base
has_one_attached :proof_of_form_990
has_many_attached :documents

validates :no_social_media_presence, acceptance: {message: "must be checked if you have not provided any of Website, Twitter, Facebook, or Instagram."}, if: :has_no_social_media?

self.ignored_columns = %w[
evidence_based_description
program_client_improvement
Expand Down Expand Up @@ -183,6 +187,10 @@ def impact_metrics

private

def has_no_social_media?
website.blank? && twitter.blank? && facebook.blank? && instagram.blank?
end

def families_served_count
families.count
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/partners/profiles/edit/_media_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<%= form.input :website, label: "Website", class: "form-control", wrapper: :input_group %>
<%= form.input :facebook, label: "Facebook", class: "form-control", wrapper: :input_group %>
<%= form.input :twitter, label: "Twitter", class: "form-control", wrapper: :input_group %>
<%= form.input :instagram, label: "Instagram", class: "form-control", wrapper: :input_group %>
<%= form.input :no_social_media_presence, label: "No Social Media Presence", as: :boolean, class: "form-control", wrapper: :input_group %>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions app/views/partners/profiles/show/_media_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

<dt>Twitter</dt>
<dd><%= partner.twitter %></dd>

<dt>Instagram</dt>
<dd><%= partner.instagram %></dd>

<dt>No Social Media Presence</dt>
<dd><%= humanize_boolean(partner.no_social_media_presence) %></dd>
</dl>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/profiles/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<p>Website: <%= partner_profile.website %></p>
<p>Facebook: <%= partner_profile.facebook %></p>
<p>Twitter: <%= partner_profile.twitter %></p>
<p>Instagram: <%= partner_profile.instagram %></p>
<p>No Social Media Presence: <%= humanize_boolean(partner_profile.no_social_media_presence) %></p>
<br>
<% end %>
<% if partner_profile_fields.include?('agency_stability') || partner_profile_fields.empty? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInstagramToPartnerProfiles < ActiveRecord::Migration[7.0]
def change
add_column :partner_profiles, :instagram, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNoSocialMediaPresenceToPartnerProfiles < ActiveRecord::Migration[7.0]
def change
add_column :partner_profiles, :no_social_media_presence, :boolean
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@
t.string "status_in_diaper_base"
t.boolean "enable_child_based_requests", default: true, null: false
t.boolean "enable_individual_requests", default: true, null: false
t.string "instagram"
t.boolean "no_social_media_presence"
t.index ["essentials_bank_id"], name: "index_partners_on_essentials_bank_id"
end

Expand Down
49 changes: 49 additions & 0 deletions spec/models/partners/partner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
# greater_2_times_fpl :integer
# income_requirement_desc :boolean
# income_verification :boolean
# instagram :string
# more_docs_required :string
# name :string
# new_client_times :string
# no_social_media_presence :boolean
# other_agency_type :string
# partner_status :string default("pending")
# pick_up_email :string
Expand Down Expand Up @@ -104,6 +106,53 @@
end
end

describe "social media info validation for partners" do
context "no social media presence and the checkbox isn't checked" do
let(:partner) { FactoryBot.build(:partners_partner, website: "", twitter: "", facebook: "", instagram: "", no_social_media_presence: false) }

it "should not be valid" do
expect(partner.valid?).to eq(false)
end
end

context "no social media presence and the checkbox is checked" do
let(:partner) { FactoryBot.build(:partners_partner, website: "", twitter: "", facebook: "", instagram: "", no_social_media_presence: true) }

it "should be valid" do
expect(partner.valid?).to eq(true)
end
end

context "has social media presence and the checkbox is unchecked" do
let(:partner) { FactoryBot.build(:partners_partner, no_social_media_presence: false) }

it "with just a website it should be valid" do
partner.update(website: "some website URL", twitter: "", facebook: "", instagram: "")
expect(partner.valid?).to eq(true)
end

it "with just twitter it should be valid" do
partner.update(website: "", twitter: "some twitter URL", facebook: "", instagram: "")
expect(partner.valid?).to eq(true)
end

it "with just facebook it should be valid" do
partner.update(website: "", twitter: "", facebook: "some facebook URL", instagram: "")
expect(partner.valid?).to eq(true)
end

it "with just instagram it should be valid" do
partner.update(website: "", twitter: "", facebook: "", instagram: "some instagram URL")
expect(partner.valid?).to eq(true)
end

it "with every social media option it should be valid" do
partner.update(website: "some website URL", twitter: "some twitter URL", facebook: "some facebook URL", instagram: "some instagram URL")
expect(partner.valid?).to eq(true)
end
end
end

describe '#verified?' do
subject { partner.verified? }
let(:partner) { FactoryBot.build(:partners_partner, partner_status: partner_status) }
Expand Down
2 changes: 1 addition & 1 deletion spec/system/dashboard_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def create_next_product_drive_donation(donation_date:)
drive = @product_drives.sample

create :product_drive_donation, :with_items, product_drive: drive.drive, product_drive_participant: @product_drive_participant, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization,
money_raised: @money_raised_on_each_product_drive
money_raised: @money_raised_on_each_product_drive

OpenStruct.new drive_name: drive.name, quantity: quantity_in_donation, money_raised: @money_raised_on_each_product_drive
end
Expand Down
1 change: 1 addition & 0 deletions spec/system/partners/approval_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
fill_in 'Executive Director Phone', with: '8889990000'
fill_in 'Executive Director Email', with: 'lorem@example.com'
fill_in 'Primary Contact Phone', with: '8889990000'
check 'No Social Media Presence'

click_on 'Update Information'
assert page.has_content? 'Details were successfully updated.'
Expand Down

0 comments on commit a467dcb

Please sign in to comment.