diff --git a/app/assets/images/medium_icon.svg b/app/assets/images/medium_icon.svg new file mode 100644 index 000000000..432404621 --- /dev/null +++ b/app/assets/images/medium_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index 610e431fb..ad2d176a2 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -122,6 +122,7 @@ class Internal::UsersController < Internal::ApplicationController user.email_public = false user.facebook_url = nil user.dribbble_url = nil + user.medium_url = nil user.stackoverflow_url = nil user.behance_url = nil user.linkedin_url = nil diff --git a/app/models/user.rb b/app/models/user.rb index c834e36be..4fbdf7d31 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -83,6 +83,9 @@ class User < ApplicationRecord validates :dribbble_url, allow_blank: true, format: /\Ahttps:\/\/(www.dribbble.com|dribbble.com)\/([a-zA-Z0-9\-\_]{2,20})\/?\Z/ + validates :medium_url, + allow_blank: true, + format: /\Ahttps:\/\/(www.medium.com|medium.com)\/([a-zA-Z0-9\-\_\@\.]{2,32})\/?\Z/ # rubocop:enable Metrics/LineLength validates :employer_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] } validates :shirt_gender, diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index 4e9ced7a7..2de506a2e 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -11,7 +11,7 @@ - + @@ -159,6 +159,11 @@ <%= inline_svg("dribbble_icon.svg", class:"icon-img") %> <% end %> + <% if @user.medium_url.present? %> + + <%= inline_svg("medium_icon.svg", class:"icon-img") %> + + <% end %> <% if @user.website_url.present? %> <%= inline_svg("external-link-logo.svg", class:"icon-img") %> @@ -177,14 +182,14 @@ border: 2px solid <%= HexComparer.new([@tag_model.bg_color_hex || "#0000000",@tag_model.text_color_hex || "#ffffff"]).brightness(0.88) %>; box-shadow: 5px 6px 0px <%= HexComparer.new([@tag_model.bg_color_hex || "#0000000",@tag_model.text_color_hex || "#ffffff"]).brightness(0.88) %>; } - +

<% if @tag_model && @tag_model.pretty_name.present? %> <%= @tag_model.pretty_name %> <% else %> - <%= @tag %> + <%= @tag %> <% end %> <% if @tag_model %>

<% end %>

- + Add the DEV badge to your personal site. Click here for the code

<%= form_for(@user) do |f| %> @@ -125,7 +125,7 @@
<%= f.label :linkedin_url %> <%= f.url_field :linkedin_url %> -
+
<%= f.label :behance_url %> <%= f.url_field :behance_url %> @@ -133,7 +133,11 @@
<%= f.label :dribbble_url %> <%= f.url_field :dribbble_url %> -
+
+
+ <%= f.label :medium_url %> + <%= f.url_field :medium_url %> +
<%= f.hidden_field :tab, value: @tab %> diff --git a/db/migrate/20181016181008_add_medium_url_to_users.rb b/db/migrate/20181016181008_add_medium_url_to_users.rb new file mode 100644 index 000000000..e53b534f9 --- /dev/null +++ b/db/migrate/20181016181008_add_medium_url_to_users.rb @@ -0,0 +1,5 @@ +class AddMediumUrlToUsers < ActiveRecord::Migration[5.1] + def change + add_column :users, :medium_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e1f85117..51495dcd2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -10,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181008174839) do +ActiveRecord::Schema.define(version: 20181016181008) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -693,6 +695,7 @@ ActiveRecord::Schema.define(version: 20181008174839) do t.string "location" t.boolean "looking_for_work", default: false t.boolean "looking_for_work_publicly", default: false + t.string "medium_url" t.datetime "membership_started_at" t.text "mentee_description" t.datetime "mentee_form_updated_at" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fb0ca2153..5758376f6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -142,6 +142,18 @@ RSpec.describe User, type: :model do expect(user).not_to be_valid end + it "accepts valid https medium url" do + %w(jess jess/ je-ss je_ss).each do |username| + user.medium_url = "https://medium.com/#{username}" + expect(user).to be_valid + end + end + + it "does not accept invalid medium url" do + user.medium_url = "ben.com" + expect(user).not_to be_valid + end + it "changes old_username if old_old_username properly if username changes" do old_username = user.username random_new_username = "username_#{rand(100000000)}"