From d303692bc066c4c36c89fa1ca5b537912f5cf18a Mon Sep 17 00:00:00 2001 From: Monica Powell Date: Mon, 20 Aug 2018 10:20:23 -0400 Subject: [PATCH] #260 increase mentee-mentor description length (#405) * increase mentee-mentor description length and fix linting errors * fix char limit issue and refactor tests --- app/controllers/notifications_controller.rb | 3 ++- app/models/user.rb | 5 ++++- app/policies/admin_policy.rb | 2 +- app/policies/application_policy.rb | 2 +- app/policies/article_policy.rb | 6 +++--- app/policies/block_policy.rb | 14 ++++++------ app/policies/chat_channel_policy.rb | 2 +- app/policies/tag_policy.rb | 2 +- app/policies/user_policy.rb | 2 +- app/views/users/_mentorship.html.erb | 4 ++-- config/initializers/rolify.rb | 2 +- spec/models/user_spec.rb | 24 +++++++++++++++++++++ 12 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 2636d5a88..66543e15c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -41,7 +41,8 @@ end module StreamRails class Enrich def retrieve_objects(references) - Hash[references.map { |model, ids| [model, Hash[construct_query(model, ids).map { |i| [i.id.to_s, i] }]] }] + Hash[references. + map { |model, ids| [model, Hash[construct_query(model, ids).map { |i| [i.id.to_s, i] }]] }] end def construct_query(model, ids) diff --git a/app/models/user.rb b/app/models/user.rb index eb6e22df6..b409a5984 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,8 +94,10 @@ class User < ApplicationRecord :employment_title, :education, :location, length: { maximum: 100 } validates :mostly_work_with, :currently_learning, :currently_hacking_on, - :available_for, :mentee_description, :mentor_description, + :available_for, length: { maximum: 500 } + validates :mentee_description, :mentor_description, + length: { maximum: 1000 } validate :conditionally_validate_summary validate :validate_feed_url validate :unique_including_orgs @@ -202,6 +204,7 @@ class User < ApplicationRecord "user-#{id}-#{updated_at}-#{following_users_count}/following_users_ids", expires_in: 120.hours, ) do + # More efficient query. May not cover future edge cases. # Should probably only return users who have published lately # But this should be okay for most for now. diff --git a/app/policies/admin_policy.rb b/app/policies/admin_policy.rb index 621181143..54edb7950 100644 --- a/app/policies/admin_policy.rb +++ b/app/policies/admin_policy.rb @@ -1,5 +1,5 @@ class AdminPolicy < ApplicationPolicy def show? - user_is_admin? + user_admin? end end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 0a6245c2d..d86158494 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -53,7 +53,7 @@ class ApplicationPolicy end end - def user_is_admin? + def user_admin? user.has_role?(:super_admin) end diff --git a/app/policies/article_policy.rb b/app/policies/article_policy.rb index 9c15c6029..c7d88d156 100644 --- a/app/policies/article_policy.rb +++ b/app/policies/article_policy.rb @@ -1,6 +1,6 @@ class ArticlePolicy < ApplicationPolicy def update? - user_is_author? || user_is_admin? || user_is_org_admin? + user_is_author? || user_admin? || user_org_admin? end def new? @@ -24,7 +24,7 @@ class ArticlePolicy < ApplicationPolicy end def analytics_index? - (user_is_author? && user_can_view_analytics?) || user_is_org_admin? + (user_is_author? && user_can_view_analytics?) || user_org_admin? end def permitted_attributes @@ -39,7 +39,7 @@ class ArticlePolicy < ApplicationPolicy record.user_id == user.id end - def user_is_org_admin? + def user_org_admin? user.org_admin && user.organization_id == record.organization_id end diff --git a/app/policies/block_policy.rb b/app/policies/block_policy.rb index 1d0e6642a..d54196d5b 100644 --- a/app/policies/block_policy.rb +++ b/app/policies/block_policy.rb @@ -1,30 +1,30 @@ class BlockPolicy < ApplicationPolicy def index? - user_is_admin? + user_admin? end def show? - user_is_admin? + user_admin? end def new? - user_is_admin? + user_admin? end def edit? - user_is_admin? + user_admin? end def create? - user_is_admin? + user_admin? end def update? - user_is_admin? + user_admin? end def destroy? - user_is_admin? + user_admin? end def permitted_attributes diff --git a/app/policies/chat_channel_policy.rb b/app/policies/chat_channel_policy.rb index b05284f07..8d378c063 100644 --- a/app/policies/chat_channel_policy.rb +++ b/app/policies/chat_channel_policy.rb @@ -12,7 +12,7 @@ class ChatChannelPolicy < ApplicationPolicy end def moderate? - !user_is_banned? && user_is_admin? + !user_is_banned? && user_admin? end def show? diff --git a/app/policies/tag_policy.rb b/app/policies/tag_policy.rb index c95f6fd1e..322507f80 100644 --- a/app/policies/tag_policy.rb +++ b/app/policies/tag_policy.rb @@ -14,7 +14,7 @@ class TagPolicy < ApplicationPolicy private def has_mod_permission? - user_is_admin? || + user_admin? || user.has_role?(:tag_moderator, record) end end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index ecf011284..fda6cd21f 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -32,7 +32,7 @@ class UserPolicy < ApplicationPolicy end def dashboard_show? - current_user? || user_is_admin? + current_user? || user_admin? end def moderation_routes? diff --git a/app/views/users/_mentorship.html.erb b/app/views/users/_mentorship.html.erb index 06af5da38..f341b41b6 100644 --- a/app/views/users/_mentorship.html.erb +++ b/app/views/users/_mentorship.html.erb @@ -11,7 +11,7 @@

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 %> + <%= 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: 1000 %>

Seeking Help

<% if @user.mentee_form_updated_at? %> @@ -24,7 +24,7 @@

<%= f.label :mentee_description, "How can we help?" %>

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 %> + <%= 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: 1000 %>
diff --git a/config/initializers/rolify.rb b/config/initializers/rolify.rb index 4a17233e3..b175e2c59 100644 --- a/config/initializers/rolify.rb +++ b/config/initializers/rolify.rb @@ -2,6 +2,6 @@ Rolify.configure do |config| # By default ORM adapter is ActiveRecord. uncomment to use mongoid # config.use_mongoid - # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false + # Dynamic shortcuts for User class (user.admin? like methods). Default is: false # config.use_dynamic_shortcuts end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fc2bb6147..0c58e78f9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -184,6 +184,30 @@ RSpec.describe User, type: :model do expect(user.mentee_form_updated_at).not_to eq(nil) end + it "does not allow mentee description to be too long" do + user.mentee_description = Faker::Lorem.paragraph_by_chars(1001) + user.save + expect(user.mentee_form_updated_at).to eq(nil) + end + + it "does not allow mentor description to be too long" do + user.mentor_description = Faker::Lorem.paragraph_by_chars(1001) + user.save + expect(user.mentor_form_updated_at).to eq(nil) + end + + it "allow mentee description to be the max length" do + user.mentee_description = Faker::Lorem.paragraph_by_chars(1000) + user.save + expect(user.mentee_form_updated_at).not_to eq(nil) + end + + it "allow mentor description to be the max length" do + user.mentor_description = Faker::Lorem.paragraph_by_chars(1000) + user.save + expect(user.mentor_form_updated_at).not_to eq(nil) + end + it "does not allow too short or too long name" do user.name = "" expect(user).not_to be_valid