Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ gem 'premailer-rails'
gem "bcrypt", '3.1.16'
gem "json", ">= 2.6", "< 3" # or simply: gem "json", "~> 2.7"
gem 'simple_form'
gem 'country_select'

group :development, :test do
gem 'better_errors'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.3.5)
countries (8.0.4)
unaccent (~> 0.3)
country_select (11.0.0)
countries (> 6.0, < 9.0)
crass (1.0.6)
css_parser (1.17.1)
addressable
Expand Down Expand Up @@ -415,6 +419,7 @@ GEM
concurrent-ruby (~> 1.0)
uglifier (4.2.1)
execjs (>= 0.3.0, < 3)
unaccent (0.4.0)
warden (1.2.9)
rack (>= 2.0.9)
websocket (1.2.11)
Expand Down Expand Up @@ -449,6 +454,7 @@ DEPENDENCIES
ckeditor (~> 4.3.0)
cocoon (~> 1.2.6)
coffee-rails
country_select
debug (~> 1.11)
devise (~> 4.7.3)
dotenv-rails
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/facilitators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
end

def show
@facilitator = Facilitator.find(params[:id])
@facilitator = Facilitator.find(params[:id]).decorate
end

def new
Expand Down Expand Up @@ -61,6 +61,6 @@ def set_facilitator

# Only allow a list of trusted parameters through.
def facilitator_params
params.require(:facilitator).permit(:first_name, :last_name, :email)
params.require(:facilitator).permit(Facilitator::PERMITTED_PARAMS)
end
end
24 changes: 24 additions & 0 deletions app/decorators/facilitator_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class FacilitatorDecorator < Draper::Decorator
delegate_all

DISPLAY_FIELDS = {
"First name" => :first_name,
"Last name" => :last_name,
"Primary email address" => :primary_email_address,
"Primary email type" => :primary_email_address_type,
"Street address" => :street_address,
"City" => :city,
"State" => :state,
"ZIP" => :zip,
"Country" => :country,
"Mailing address type" => :mailing_address_type,
"Phone number" => :phone_number,
"Phone number type" => :phone_number_type
}

def display_fields
DISPLAY_FIELDS.map do |label, method|
{ label: label, value: object.send(method) }
end
end
end
31 changes: 28 additions & 3 deletions app/models/facilitator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
class Facilitator < ApplicationRecord
has_one :user

validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
CONTACT_TYPES = ["Work", "Personal"].freeze
PERMITTED_PARAMS = [
:first_name, :last_name, :primary_email_address, :primary_email_address_type,
:street_address, :city, :state, :zip, :country, :mailing_address_type,
:phone_number, :phone_number_type
].freeze

validates :first_name,
:last_name,
:primary_email_address,
:primary_email_address_type,
:street_address,
:city,
:state,
:zip,
:country,
:mailing_address_type,
:phone_number,
:phone_number_type,
presence: true

validates :primary_email_address_type, inclusion: {in: CONTACT_TYPES}
validates :mailing_address_type, inclusion: {in: CONTACT_TYPES}
validates :phone_number_type, inclusion: {in: CONTACT_TYPES}

# TODO: add validation for zip code containing only numbers
# TODO: add validation on STATE
# TODO: add validation on phone number type
end
38 changes: 23 additions & 15 deletions app/views/facilitators/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<%= form_for(@facilitator) do |f| %>
<%= render 'shared/errors', resource: facilitator if facilitator.errors.any? %>

<div class="form-inputs">
<%= f.label :first_name, class: 'bold' %>
<%= f.text_field :first_name %>
<%= f.label :last_name, class: 'bold' %>
<%= f.text_field :last_name %>
<%= f.label :email, class: 'bold' %>
<%= f.text_field :email %>
</div>

<div class="form-actions">
<%= f.button :submit %>
</div>
<%= simple_form_for @facilitator do |f| %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :primary_email_address %>
<%= f.input :primary_email_address_type,
as: :radio_buttons,
collection: Facilitator::CONTACT_TYPES,
item_wrapper_class: 'form-check' %>
<%= f.input :street_address %>
<%= f.input :city %>
<%= f.input :state %>
<%= f.input :zip %>
<%= f.input :country %>
<%= f.input :mailing_address_type,
as: :radio_buttons,
collection: Facilitator::CONTACT_TYPES,
item_wrapper_class: 'form-check' %>
<%= f.input :phone_number%>
<%= f.input :phone_number_type,
as: :radio_buttons,
collection: Facilitator::CONTACT_TYPES,
item_wrapper_class: 'form-check' %>
<%= f.button :submit %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/facilitators/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tr>
<td><%= facilitator.first_name %></td>
<td><%= facilitator.last_name %></td>
<td><%= facilitator.email %></td>
<td><%= facilitator.primary_email_address %></td>
<td><%= link_to 'Show', facilitator %></td>
<td><%= link_to 'Edit', edit_facilitator_path(facilitator) %></td>
<td><%= link_to 'Destroy', facilitator, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
18 changes: 6 additions & 12 deletions app/views/facilitators/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<p id="notice"><%= notice %></p>

<p>
<strong>First name:</strong>
<%= @facilitator.first_name %>
</p>
<% @facilitator.display_fields.each do |field| %>
<p>
<strong><%= field[:label] %>:</strong>
<%= field[:value].presence || "N/A" %>
</p>
<% end %>

<p>
<strong>Last name:</strong>
<%= @facilitator.last_name %>
</p>

<p>
<strong>Email:</strong>
<%= @facilitator.email %>
</p>

<%= link_to 'Edit', edit_facilitator_path(@facilitator) %> |
<%= link_to 'Back', facilitators_path %>
14 changes: 14 additions & 0 deletions db/migrate/20250913164451_add_contact_info_to_facilitators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AddContactInfoToFacilitators < ActiveRecord::Migration[6.1]
def change
add_column :facilitators, :primary_email_address, :string, null: false
add_column :facilitators, :primary_email_address_type, :string, null: false
add_column :facilitators, :street_address, :string, null: false
add_column :facilitators, :city, :string, null: false
add_column :facilitators, :state, :string, null: false
add_column :facilitators, :zip, :string, null: false
add_column :facilitators, :country, :string, null: false
add_column :facilitators, :mailing_address_type, :string, null: false
add_column :facilitators, :phone_number, :string, null: false
add_column :facilitators, :phone_number_type, :string, null: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20250913171135_remove_email_from_facilitators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveEmailFromFacilitators < ActiveRecord::Migration[6.1]
def change
remove_column :facilitators, :email, :string
end
end
13 changes: 11 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2025_09_12_173152) do
ActiveRecord::Schema.define(version: 2025_09_13_171135) do

create_table "admins", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.string "email", default: "", null: false
Expand Down Expand Up @@ -142,9 +142,18 @@
create_table "facilitators", charset: "utf8mb3", force: :cascade do |t|
t.string "first_name", null: false
t.string "last_name", null: false
t.string "email", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "primary_email_address", null: false
t.string "primary_email_address_type", null: false
t.string "street_address", null: false
t.string "city", null: false
t.string "state", null: false
t.string "zip", null: false
t.string "country", null: false
t.string "mailing_address_type", null: false
t.string "phone_number", null: false
t.string "phone_number_type", null: false
end

create_table "faqs", id: :integer, charset: "utf8mb3", force: :cascade do |t|
Expand Down
4 changes: 4 additions & 0 deletions spec/decorators/facilitator_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'rails_helper'

RSpec.describe FacilitatorDecorator do
end
11 changes: 10 additions & 1 deletion spec/factories/facilitators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
factory :facilitator do
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.unique.email }
primary_email_address { Faker::Internet.unique.email }
primary_email_address_type { 'Personal' }
street_address { Faker::Address.street_address }
city { Faker::Address.city }
state { Faker::Address.state }
zip { Faker::Address.postcode }
country { Faker::Address.country}
mailing_address_type { 'Personal' }
phone_number { Faker::PhoneNumber.phone_number }
phone_number_type { 'Personal' }
end
end
14 changes: 13 additions & 1 deletion spec/models/facilitator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
describe 'validations' do
it { should validate_presence_of(:first_name) }
it { should validate_presence_of(:last_name) }
it { should validate_presence_of(:email) }
it { should validate_presence_of(:primary_email_address) }
it { should validate_presence_of(:primary_email_address_type) }
it { should validate_presence_of(:street_address) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are requiring all of these fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The collaboration agreement has * by all these fields so I'm assuming they are all required. I can confirm with the AWBW team this afternoon! If they're not required I'll change these

it { should validate_presence_of(:city) }
it { should validate_presence_of(:state) }
it { should validate_presence_of(:zip) }
it { should validate_presence_of(:country) }
it { should validate_presence_of(:mailing_address_type) }
it { should validate_presence_of(:phone_number) }
it { should validate_presence_of(:phone_number_type) }
it { should validate_inclusion_of(:primary_email_address_type).in_array(%w[Work Personal]) }
it { should validate_inclusion_of(:mailing_address_type).in_array(%w[Work Personal]) }
it { should validate_inclusion_of(:phone_number_type).in_array(%w[Work Personal]) }
end
end
2 changes: 1 addition & 1 deletion spec/views/facilitators/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it "has a form with the facilitator fields" do
expect(rendered).to have_field('First name', with: facilitator.first_name)
expect(rendered).to have_field('Last name', with: facilitator.last_name)
expect(rendered).to have_field('Email', with: facilitator.email)
expect(rendered).to have_field('Primary email address', with: facilitator.primary_email_address)
end

it "has a link to the show page" do
Expand Down
4 changes: 2 additions & 2 deletions spec/views/facilitators/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

it "renders a list of facilitators" do
expect(rendered).to match(facilitator.email)
expect(rendered).to match(facilitator_2.email)
expect(rendered).to match(facilitator.primary_email_address)
expect(rendered).to match(facilitator_2.primary_email_address)
end
end
2 changes: 1 addition & 1 deletion spec/views/facilitators/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it "has a form with the facilitator fields" do
expect(rendered).to have_field('First name')
expect(rendered).to have_field('Last name')
expect(rendered).to have_field('Email')
expect(rendered).to have_field('Primary email address')
end

it "has a link back to the index page" do
Expand Down
4 changes: 2 additions & 2 deletions spec/views/facilitators/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
let(:facilitator) { create(:facilitator)}

before do
assign(:facilitator, facilitator)
assign(:facilitator, facilitator.decorate)
render
end

it "renders attributes in <p>" do
expect(rendered).to match(facilitator.first_name)
expect(rendered).to match(facilitator.last_name)
expect(rendered).to match(facilitator.email)
expect(rendered).to match(facilitator.primary_email_address)
end
end