Skip to content

Commit

Permalink
Merge branch 'main' into seed/inactive-location-and-items
Browse files Browse the repository at this point in the history
  • Loading branch information
lit-poks authored Oct 11, 2024
2 parents 1d4acc6 + 9496887 commit 5035ebf
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Make sure to install **Ubuntu** as your Linux distribution. (This should be defa
Waiting Approval Partner
Email: [email protected]
Password: password!
Another approved partner (with all groups):
Email: [email protected]
Pasword: password!
```
</details>

Expand Down
3 changes: 0 additions & 3 deletions app/models/concerns/provideable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module Provideable
included do
belongs_to :organization # Automatically validates presence as of Rails 5

validates :contact_name, presence: { message: "Must provide a name or a business name" }, if: proc { |ddp| ddp.business_name.blank? }
validates :business_name, presence: { message: "Must provide a name or a business name" }, if: proc { |ddp| ddp.contact_name.blank? }

scope :for_csv_export, ->(organization, *) {
where(organization: organization).order(:business_name)
}
Expand Down
2 changes: 2 additions & 0 deletions app/models/product_drive_participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProductDriveParticipant < ApplicationRecord

validates :phone, presence: { message: "Must provide a phone or an e-mail" }, if: proc { |pdp| pdp.email.blank? }
validates :email, presence: { message: "Must provide a phone or an e-mail" }, if: proc { |pdp| pdp.phone.blank? }
validates :contact_name, presence: { message: "Must provide a name or a business name" }, if: proc { |pdp| pdp.business_name.blank? }
validates :business_name, presence: { message: "Must provide a name or a business name" }, if: proc { |pdp| pdp.contact_name.blank? }
validates :comment, length: { maximum: 500 }

scope :alphabetized, -> { order(:contact_name) }
Expand Down
2 changes: 2 additions & 0 deletions app/models/vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Vendor < ApplicationRecord

has_many :purchases, inverse_of: :vendor, dependent: :destroy

validates :business_name, presence: true

scope :alphabetized, -> { order(:business_name) }

def volume
Expand Down
14 changes: 14 additions & 0 deletions app/views/dashboard/_getting_started_prompt.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</p>

<div id="org-stats-call-to-action-partners">
<%= modal_button_to("#csvImportModal", { text: "Import Partners", icon: "upload", size: "md" }) %>
<% partner_link_text = partner_criteria_met ? "Add More Partners" : "Add a Partner" %>
<%= new_button_to new_partner_path, { text: partner_link_text, size: "md" } %>
</div>
Expand Down Expand Up @@ -135,5 +136,18 @@
</div>
</div>
</div>

<%= render(
layout: "shared/csv_import_modal",
locals: {
import_type: "Partners",
csv_template_url: "/partners_template.csv",
csv_import_url: import_csv_partners_path,
},
) do %>
<li>Open the CSV file with Excel or your favourite spreadsheet program.</li>
<li>Delete the sample data and enter your partner agency names and addresses in the appropriate columns.</li>
<li>Save the file as a CSV file.</li>
<% end %>
<% end %>
<% end %>
9 changes: 4 additions & 5 deletions app/views/users/_organization_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
<ul class="dropdown-menu">
<li>
<%=
edit_button_to(
promote_to_org_admin_organization_path(user_id: user.id),
{text: 'Promote to Admin'},
{method: :post, rel: "nofollow", data: {confirm: 'This will promote the user to admin status. Are you sure that you want to submit this?', size: 'xs'}}
)
edit_button_to(
edit_admin_user_path(user),
{text: 'Edit User'}
)
%>
</li>
<li>
Expand Down
4 changes: 4 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

# Adds comments to rendered views so you know which partials are being rendered
# more easily.
config.action_view.annotate_rendered_view_with_filenames = true

require "socket"
require "ipaddr"
config.web_console.allowed_ips = Socket.ip_address_list.reduce([]) do |res, addrinfo|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class BackfillVendorBusinessNameFromContact < ActiveRecord::Migration[7.1]
def change
Vendor.where(business_name: [nil, ""]).update_all('business_name = contact_name')
end
end
24 changes: 21 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ def random_record_for_org(org, klass)
# ----------------------------------------------------------------------------
Organization.all.each do |org|
# Setup the Partner Group & their item categories
partner_group = FactoryBot.create(:partner_group, organization: org)
partner_group_one = FactoryBot.create(:partner_group, organization: org)

total_item_categories_to_add = Faker::Number.between(from: 1, to: 2)
org.item_categories.sample(total_item_categories_to_add).each do |item_category|
partner_group.item_categories << item_category
partner_group_one.item_categories << item_category
end

next unless org.name == pdx_org.name

partner_group_two = FactoryBot.create(:partner_group, organization: org)
org.item_categories.each do |item_category|
partner_group_two.item_categories << item_category
end
end

Expand Down Expand Up @@ -225,11 +232,22 @@ def random_record_for_org(org, klass)
email: "[email protected]",
status: :awaiting_review,
notes: note.sample
},
{
name: "Second Street Community Outreach",
status: :approved,
email: "[email protected]",
notes: note.sample
}
].each do |partner_option|
p = Partner.find_or_create_by!(partner_option) do |partner|
partner.organization = pdx_org
partner.partner_group = pdx_org.partner_groups.first

if partner_option[:name] == "Second Street Community Outreach"
partner.partner_group = pdx_org.partner_groups.find_by(name: 'Group 2')
else
partner.partner_group = pdx_org.partner_groups.first
end
end

profile = Partners::Profile.create!({
Expand Down
7 changes: 7 additions & 0 deletions spec/models/product_drive_participant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
expect(build(:product_drive_participant, phone: nil)).to be_valid
expect(build(:product_drive_participant, email: nil)).to be_valid
end

it "is invalid unless it has either a contact name or a business name" do
expect(build(:product_drive_participant, contact_name: nil, business_name: nil)).not_to be_valid
expect(build(:product_drive_participant, contact_name: nil, business_name: "George Company").valid?).to eq(true)
expect(build(:product_drive_participant, contact_name: "George Henry", business_name: nil).valid?).to eq(true)
end

it "is invalid if the comment field has more than 500 characters" do
long_comment = "a" * 501
expect(build(:product_drive_participant, comment: long_comment)).not_to be_valid
Expand Down
7 changes: 7 additions & 0 deletions spec/models/vendor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
RSpec.describe Vendor, type: :model do
it_behaves_like "provideable"

context "Validations" do
it "validates that a business name is present" do
expect(build(:vendor, business_name: "Diaper Enterprises")).to be_valid
expect(build(:vendor, business_name: nil)).to_not be_valid
end
end

context "Methods" do
describe "volume" do
it "retrieves the amount of product that has been bought from this vendor" do
Expand Down
11 changes: 11 additions & 0 deletions spec/requests/admin/organizations_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@
get admin_organization_path({ id: organization.id })
expect(response).to be_successful
end

context "with an organization user" do
let!(:user) { create(:user, organization: organization) }

it "provides links to edit the user" do
get admin_organization_path({ id: organization.id })

expect(response.body).to include("Edit User")
expect(response.body).to include(edit_admin_user_path(user.id))
end
end
end

describe "PUT #update" do
Expand Down
20 changes: 19 additions & 1 deletion spec/support/pages/organization_dashboard_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def has_add_inventory_call_to_action?
end

def has_add_partner_call_to_action?
has_selector? "#org-stats-call-to-action-partners"
has_selector? call_to_action_partner_selector
end

def has_add_partner_call_to_action_with_two_links?
has_add_partner_call_to_action? && partner_cta_has_two_links?
end

def has_add_storage_location_call_to_action?
Expand Down Expand Up @@ -153,4 +157,18 @@ def org_logo_selector
def outstanding_selector
"#outstanding"
end

def call_to_action_partner
find call_to_action_partner_selector
end

def call_to_action_partner_selector
"#org-stats-call-to-action-partners"
end

def partner_cta_has_two_links?
within call_to_action_partner do
all("a", count: 2)
end
end
end
6 changes: 0 additions & 6 deletions spec/support/provideable_shared_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
let(:model_f) { described_class.to_s.underscore.to_sym }

context "Validations" do
it "is invalid unless it has either a contact name or a business name" do
expect(build(model_f, contact_name: nil, business_name: nil)).not_to be_valid
expect(build(model_f, contact_name: nil, business_name: "George Company").valid?).to eq(true)
expect(build(model_f, contact_name: "George Henry").valid?).to eq(true)
end

it "is invalid without an organization" do
expect(build(model_f, organization: nil)).not_to be_valid
end
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 @@ -28,7 +28,7 @@
org_dashboard_page.visit

expect(org_dashboard_page).to have_getting_started_guide
expect(org_dashboard_page).to have_add_partner_call_to_action
expect(org_dashboard_page).to have_add_partner_call_to_action_with_two_links
expect(org_dashboard_page).not_to have_add_storage_location_call_to_action
expect(org_dashboard_page).not_to have_add_donation_site_call_to_action
expect(org_dashboard_page).not_to have_add_inventory_call_to_action
Expand Down

0 comments on commit 5035ebf

Please sign in to comment.