Skip to content

Commit e541099

Browse files
committed
Trasnform site-specific social media columns into bio markdown
1 parent cdf7aad commit e541099

13 files changed

+93
-89
lines changed

app/controllers/participants_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def confirm_email
9393
def participant_params
9494
params.require(controller_name.singularize).permit(
9595
:name, :email, :password,
96-
:bio, :github_profile_username,
97-
:twitter_handle, :code_of_conduct_agreement,
96+
:bio,
97+
:code_of_conduct_agreement,
9898
:contact_details
9999
)
100100
end

app/models/participant.rb

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ def attending_session?(session)
8181
sessions_attending.include?(session)
8282
end
8383

84-
def github_profile_url
85-
"https://github.com/#{self.github_profile_username}"
86-
end
87-
8884
def self.find_by_case_insensitive_email(email)
8985
where(['lower(email) = ?', email.to_s.downcase]).first
9086
end

app/models/sessions_json_builder.rb

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ def to_hash(session)
55
{ id: s.id,
66
participant_id: s.participant.id,
77
presenter_name: s.participant.name,
8-
presenter_twitter_handle: s.participant.twitter_handle,
9-
presenter_github_username: s.participant.github_profile_username,
10-
presenter_github_og_image: s.participant.github_og_image,
118
presenter_bio: s.participant.bio,
129
session_title: s.title,
1310
summary: s.summary,

app/views/participants/edit.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<%= f.inputs do %>
77
<%= f.input :name, :label => 'Your name', :hint => "Please use your real name. This will be used in our printed materials." %>
88
<%= f.input :email, :label => 'Your email', :hint => "Please use a real email address. We need this to contact you about your presentation." %>
9-
<%= f.input :github_profile_username, :label => 'Your GitHub username' %>
10-
<%= f.input :twitter_handle, :label => 'Your Twitter handle' %>
119
<%= f.input :bio, :hint => 'You can use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> syntax here. Examples: <strong>**bold**</strong>, <em>*italic*</em>, [link](http://example.com)'.html_safe %>
1210
<%=
1311
f.input :code_of_conduct_agreement,

app/views/participants/show.html.erb

-16
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
<% end %>
77
<% end %>
88

9-
<div class="row">
10-
<% if @participant.github_profile_username.present? %>
11-
<div class="grid_2 column">
12-
<h4>GitHub:</h4>
13-
<div><%= link_to @participant.github_profile_username, @participant.github_profile_url, target: "blank" %></div>
14-
</div>
15-
<% end %>
16-
17-
<% if @participant.twitter_handle.present? %>
18-
<div class="grid_3 column">
19-
<h4>Twitter:</h4>
20-
<div>@<%= @participant.twitter_handle %></div>
21-
</div>
22-
<% end %>
23-
</div>
24-
259
<div class="row bio">
2610
<h4>Bio</h4>
2711

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class SwitchToFreeformSocialLinks < ActiveRecord::Migration[7.1]
2+
def up
3+
execute("select * from participants").each do |result|
4+
# Replace existing site-specific social media columns with bio markdown
5+
# that mimics the previous formatting of the two supported sites
6+
7+
social_items = []
8+
if slurped = result["github_profile_username"].presence
9+
social_items << "[GitHub](https://github.com/#{extract_username(slurped)})"
10+
end
11+
if cursed = result["twitter_handle"].presence
12+
social_items << "Twitter: @#{extract_username(cursed)}"
13+
end
14+
15+
if social_items.any?
16+
bio = result["bio"]
17+
18+
bio.gsub!(/\s+\Z/, '')
19+
bio << "\n\n**Links:**\n\n"
20+
21+
bio << social_items.map do |item|
22+
"- #{item}"
23+
end.join("\n")
24+
25+
# Data-updating Rails migrations must use raw SQL instead of models to
26+
# ensure migrations continue to work even if models change
27+
28+
update(
29+
"update participants set bio = $1 where id = $2",
30+
"Update social links in bios",
31+
[bio, result["id"]]
32+
)
33+
end
34+
end
35+
36+
remove_column :participants, :github_profile_username
37+
remove_column :participants, :github_og_url # Seems to be 98% redundant with prev col; ignoring
38+
remove_column :participants, :github_og_image # Unused...except in REST API, which is itself probably unused
39+
remove_column :participants, :twitter_handle
40+
end
41+
42+
def down
43+
raise "Migration not reversible, because it would require parsing markdown to recover links"
44+
end
45+
46+
private
47+
48+
def extract_username(username_or_url)
49+
if username_or_url =~ %r{https?://(?:.*)/(\w+)}
50+
$1 # heck with it, last segment of URL path is probably a username…right?
51+
else
52+
username_or_url
53+
end
54+
end
55+
end

db/schema.rb

+32-35
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# of editing this file, please use the migrations feature of Active Record to
33
# incrementally modify your database, and then regenerate this schema definition.
44
#
5-
# Note that this schema.rb definition is the authoritative source for your
6-
# database schema. If you need to create the application database on another
7-
# system, you should be using db:schema:load, not running all the migrations
8-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9-
# you'll amass, the slower it'll run and the greater likelihood for issues).
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2025_02_09_180413) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_03_09_183552) do
14+
create_schema "heroku_ext"
1415

1516
# These are extensions that must be enabled in order to support this database
1617
enable_extension "pg_stat_statements"
@@ -19,8 +20,8 @@
1920
create_table "attendances", id: :serial, force: :cascade do |t|
2021
t.integer "session_id", null: false
2122
t.integer "participant_id", null: false
22-
t.datetime "created_at", null: false
23-
t.datetime "updated_at", null: false
23+
t.datetime "created_at", precision: nil, null: false
24+
t.datetime "updated_at", precision: nil, null: false
2425
t.index ["session_id", "participant_id"], name: "index_attendances_on_session_id_and_participant_id", unique: true
2526
end
2627

@@ -32,25 +33,25 @@
3233
create_table "categorizations", id: :serial, force: :cascade do |t|
3334
t.integer "category_id", null: false
3435
t.integer "session_id", null: false
35-
t.datetime "created_at", null: false
36-
t.datetime "updated_at", null: false
36+
t.datetime "created_at", precision: nil, null: false
37+
t.datetime "updated_at", precision: nil, null: false
3738
t.index ["category_id", "session_id"], name: "index_categorizations_on_category_id_and_session_id", unique: true
3839
end
3940

4041
create_table "code_of_conduct_agreements", force: :cascade do |t|
4142
t.bigint "participant_id", null: false
4243
t.bigint "event_id", null: false
43-
t.datetime "created_at", null: false
44-
t.datetime "updated_at", null: false
44+
t.datetime "created_at", precision: nil, null: false
45+
t.datetime "updated_at", precision: nil, null: false
4546
t.index ["event_id"], name: "index_code_of_conduct_agreements_on_event_id"
4647
t.index ["participant_id"], name: "index_code_of_conduct_agreements_on_participant_id"
4748
end
4849

4950
create_table "events", id: :serial, force: :cascade do |t|
5051
t.string "name", limit: 255, null: false
5152
t.date "date", null: false
52-
t.datetime "created_at", null: false
53-
t.datetime "updated_at", null: false
53+
t.datetime "created_at", precision: nil, null: false
54+
t.datetime "updated_at", precision: nil, null: false
5455
end
5556

5657
create_table "levels", id: :serial, force: :cascade do |t|
@@ -61,51 +62,47 @@
6162
t.string "name", null: false
6263
t.string "slug", null: false
6364
t.string "markdown", null: false
64-
t.datetime "created_at", null: false
65-
t.datetime "updated_at", null: false
65+
t.datetime "created_at", precision: nil, null: false
66+
t.datetime "updated_at", precision: nil, null: false
6667
t.index ["slug"], name: "index_markdown_contents_on_slug", unique: true
6768
end
6869

6970
create_table "participants", id: :serial, force: :cascade do |t|
7071
t.string "name", limit: 255
7172
t.string "email", limit: 255
7273
t.text "bio"
73-
t.datetime "created_at", null: false
74-
t.datetime "updated_at", null: false
74+
t.datetime "created_at", precision: nil, null: false
75+
t.datetime "updated_at", precision: nil, null: false
7576
t.string "crypted_password", limit: 255
7677
t.string "persistence_token", limit: 255
7778
t.string "perishable_token", limit: 255, default: "", null: false
78-
t.string "github_profile_username"
79-
t.string "github_og_image"
80-
t.string "github_og_url"
81-
t.string "twitter_handle"
82-
t.datetime "email_confirmed_at"
79+
t.datetime "email_confirmed_at", precision: nil
8380
t.index ["email"], name: "index_participants_on_email", unique: true
8481
t.index ["perishable_token"], name: "index_participants_on_perishable_token"
8582
end
8683

8784
create_table "presentations", id: :serial, force: :cascade do |t|
8885
t.integer "session_id"
8986
t.integer "participant_id"
90-
t.datetime "created_at", null: false
91-
t.datetime "updated_at", null: false
87+
t.datetime "created_at", precision: nil, null: false
88+
t.datetime "updated_at", precision: nil, null: false
9289
end
9390

9491
create_table "presenter_timeslot_restrictions", id: :serial, force: :cascade do |t|
9592
t.integer "participant_id"
9693
t.integer "timeslot_id"
9794
t.float "weight"
98-
t.datetime "created_at", null: false
99-
t.datetime "updated_at", null: false
95+
t.datetime "created_at", precision: nil, null: false
96+
t.datetime "updated_at", precision: nil, null: false
10097
t.index ["timeslot_id", "participant_id"], name: "present_timeslot_participant_unique", unique: true
10198
end
10299

103100
create_table "rooms", id: :serial, force: :cascade do |t|
104101
t.integer "event_id", null: false
105102
t.string "name", limit: 255, null: false
106103
t.integer "capacity"
107-
t.datetime "created_at", null: false
108-
t.datetime "updated_at", null: false
104+
t.datetime "created_at", precision: nil, null: false
105+
t.datetime "updated_at", precision: nil, null: false
109106
t.boolean "schedulable", default: true
110107
end
111108

@@ -115,8 +112,8 @@
115112
t.text "description", null: false
116113
t.boolean "panel", default: false, null: false
117114
t.boolean "projector", default: false, null: false
118-
t.datetime "created_at", null: false
119-
t.datetime "updated_at", null: false
115+
t.datetime "created_at", precision: nil, null: false
116+
t.datetime "updated_at", precision: nil, null: false
120117
t.integer "event_id"
121118
t.integer "timeslot_id"
122119
t.integer "room_id"
@@ -136,10 +133,10 @@
136133

137134
create_table "timeslots", id: :serial, force: :cascade do |t|
138135
t.integer "event_id", null: false
139-
t.datetime "created_at", null: false
140-
t.datetime "updated_at", null: false
141-
t.datetime "starts_at"
142-
t.datetime "ends_at"
136+
t.datetime "created_at", precision: nil, null: false
137+
t.datetime "updated_at", precision: nil, null: false
138+
t.datetime "starts_at", precision: nil
139+
t.datetime "ends_at", precision: nil
143140
t.boolean "schedulable", default: true
144141
t.string "title"
145142
end

lib/tasks/app.rake

-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ namespace :app do
621621
participant.email = FFaker::Internet.safe_email
622622
participant.password = 'standard'
623623
participant.bio = FFaker::Lorem.paragraph if [true, false].sample
624-
participant.twitter_handle = FFaker::Internet.user_name(participant.name) if [true, false].sample
625624
participant.save!
626625
progress.increment
627626
end

spec/controllers/participants_controller_spec.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,11 @@
102102

103103
describe "more attributes are not required" do
104104
it "should be successful" do
105-
put :update, params: {id: joe, participant: {
106-
twitter_handle: 'schmoe',
107-
github_profile_username: 'jschmoe'}
108-
}
105+
put :update, params: {
106+
id: joe, participant: { bio: 'schmoe' }
107+
}
109108
expect(response).to be_redirect
110-
expect(joe.reload.twitter_handle).to eq 'schmoe'
111-
expect(joe.github_profile_username).to eq 'jschmoe'
109+
expect(joe.reload.bio).to eq 'schmoe'
112110
end
113111
end
114112

spec/factories/participant.rb

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
factory :luke do
1717
email { "[email protected]" }
1818
name { "Luke Francl" }
19-
github_profile_username { "look" }
20-
github_og_image { "https://avatars1.githubusercontent.com/u/10186?v=3&s=400" }
21-
github_og_url { "https://github.com/look" }
22-
twitter_handle { "lof" }
2319
bio { "the man with the master plan" }
2420
end
2521
end

spec/features/manage_your_profile_spec.rb

-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212

1313
scenario "I can update my profile attributes" do
1414
click_link "Welcome Joe Schmoe"
15-
fill_in 'Your GitHub username', with: "JoeSchmoeGithubUsername"
16-
fill_in 'Your Twitter handle', with: "JoeSchmoeTwitterHandle"
1715
bio = FFaker::HipsterIpsum.paragraph(3)
1816
fill_in 'Bio', with: bio
1917
click_button "Update Profile"
2018

21-
expect(page).to have_content "JoeSchmoeGithubUsername"
22-
expect(page).to have_content "JoeSchmoeTwitterHandle"
2319
expect(page).to have_content bio
2420
end
2521
end

spec/models/participant_spec.rb

-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
require 'spec_helper'
22

33
describe Participant do
4-
5-
describe "github profile url" do
6-
let(:luke) { create(:luke) }
7-
8-
it "can be constructed with a github username" do
9-
expect(luke.github_profile_url).to eq "https://github.com/look"
10-
end
11-
end
12-
134
describe "timeslot restrictions" do
145
let(:event) { create(:event) }
156
let!(:time1) { create(:timeslot_1, event: event) }

spec/models/sessions_json_builder_spec.rb

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
expect(h[:participant_id]).to be session.participant_id
1414

1515
expect(h[:presenter_name]).to be session.participant.name
16-
expect(h[:presenter_twitter_handle]).to be session.participant.twitter_handle
17-
expect(h[:presenter_github_username]).to be session.participant.github_profile_username
18-
expect(h[:presenter_github_og_image]).to be session.participant.github_og_image
1916
expect(session.participant.bio).to_not be_nil
2017
expect(h[:presenter_bio]).to be session.participant.bio
2118
expect(h[:session_title]).to be session.title

0 commit comments

Comments
 (0)