From 33f590ecc8a010af531489c5d41f24e5499a2abc Mon Sep 17 00:00:00 2001 From: Jess Lee Date: Mon, 6 Aug 2018 13:04:11 -0400 Subject: [PATCH] Jess/mentorship form updates (#653) * add timestamps for mentroship form updates * update placeholder text * Add tests for mentee description change --- app/models/user.rb | 14 ++++++++++++++ app/policies/user_policy.rb | 2 ++ app/views/users/_mentorship.html.erb | 14 +++++++++----- ...180728201801_add_updated_timestamps_to_users.rb | 6 ++++++ db/schema.rb | 2 ++ spec/models/user_spec.rb | 12 ++++++++++++ 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20180728201801_add_updated_timestamps_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index ddaabeb42..10cbb8b85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,6 +103,8 @@ class User < ApplicationRecord after_save :subscribe_to_mailchimp_newsletter after_save :conditionally_resave_articles after_create :estimate_default_language! + before_update :mentor_status_update + before_update :mentee_status_update before_validation :set_username before_validation :downcase_email before_validation :check_for_username_change @@ -497,4 +499,16 @@ class User < ApplicationRecord follower_relationships.destroy_all follows.destroy_all end + + def mentor_status_update + if mentor_description_changed? || offering_mentorship_changed? + self.mentor_form_updated_at = Time.now + end + end + + def mentee_status_update + if mentee_description_changed? || seeking_mentorship_changed? + self.mentee_form_updated_at = Time.now + end + end end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 8fbffecda..ecf011284 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -72,7 +72,9 @@ class UserPolicy < ApplicationPolicy looking_for_work_publicly medium_url mentee_description + mentee_form_updated_at mentor_description + mentor_form_updated_at mostly_work_with name offering_mentorship diff --git a/app/views/users/_mentorship.html.erb b/app/views/users/_mentorship.html.erb index b5a33510b..2f01d53dd 100644 --- a/app/views/users/_mentorship.html.erb +++ b/app/views/users/_mentorship.html.erb @@ -2,23 +2,27 @@

If you're interested in participating as a mentor, mentee, or both, please indicate below and we will be in contact via email.

<%= form_for(@user) do |f| %> -

Offering Help:

+

Offering Help

+

<% if @user.mentor_form_updated_at? %>Last Updated: <%= @user.mentor_form_updated_at.strftime("%b %d, %Y") %><% end %>

<%= f.label :offering_mentorship, "I'd like to be a mentor!"%> <%= f.check_box :offering_mentorship %>
- <%= f.label :mentor_description, "How can you help?" %> - <%= f.text_area :mentor_description, placeholder: "Languages, subject preference, career advice, etc.", maxlength: 500 %> +

Please share the top 3 technologies/concepts you'd be comfortable working on with your mentee, how much experience you currently have (0-10, 10 being super duper expert), and anything else you'd like us to know.

+ <%= f.text_area :mentor_description, placeholder: "For example:\n\n1. Vim - 6, I love teaching people how to use vim because I really believe it increases productivity.\n\nI don't think I'd be comfortable teaching a total beginner. ", maxlength: 500 %>
-

Seeking Help:

+

Seeking Help

+

<% if @user.mentee_form_updated_at? %>Last Updated: + <%= @user.mentor_form_updated_at.strftime("%b %d, %Y") %><% end %>

<%= f.label :seeking_mentorship, "I'm looking for a mentor!"%> <%= f.check_box :seeking_mentorship %>
<%= f.label :mentee_description, "How can we help?" %> - <%= f.text_area :mentee_description, placeholder: "Languages, subject preference, career advice, etc.", maxlength: 500 %> +

Please share the top 3 technologies/concepts you'd like to work on with your mentor, how much experience you currently have (0-10, 0 being no experience at all), and why you're interested in learning more. Please also share your general technical background and career goals.

+ <%= f.text_area :mentee_description, placeholder: "For example:\n\n1. React - 1, I walked through the tutorial on the React website, but I'm feeling lost. I see React listed in lots of job descriptions so I'd like to learn how to utilize the framework.\n\nI graduated from a coding bootcamp 3 months ago and my goal is to land my first developer role. I learned jQuery in the program.", maxlength: 500 %>
diff --git a/db/migrate/20180728201801_add_updated_timestamps_to_users.rb b/db/migrate/20180728201801_add_updated_timestamps_to_users.rb new file mode 100644 index 000000000..1bbee2211 --- /dev/null +++ b/db/migrate/20180728201801_add_updated_timestamps_to_users.rb @@ -0,0 +1,6 @@ +class AddUpdatedTimestampsToUsers < ActiveRecord::Migration[5.1] + def change + add_column :users, :mentee_form_updated_at, :timestamp + add_column :users, :mentor_form_updated_at, :timestamp + end +end diff --git a/db/schema.rb b/db/schema.rb index 08d00898b..6643f8feb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -669,7 +669,9 @@ ActiveRecord::Schema.define(version: 20180806142338) do t.boolean "looking_for_work_publicly", default: false t.datetime "membership_started_at" t.text "mentee_description" + t.datetime "mentee_form_updated_at" t.text "mentor_description" + t.datetime "mentor_form_updated_at" t.integer "monthly_dues", default: 0 t.string "mostly_work_with" t.string "name" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 234acb541..226ad8c13 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -145,6 +145,18 @@ RSpec.describe User, type: :model do expect(user.old_old_username).to eq(old_username) end + it "updates mentor_form_updated_at at appropriate time" do + user.mentor_description = "hello" + user.save + expect(user.mentor_form_updated_at).to_not eq(nil) + end + + it "updates mentee_form_updated_at at appropriate time" do + user.mentee_description = "hello" + user.save + expect(user.mentee_form_updated_at).to_not eq(nil) + end + it "does not allow too short or too long name" do user.name = "" expect(user).not_to be_valid