From a3adf8318dfa681772b191f9e7d7a65ff6e0868d Mon Sep 17 00:00:00 2001 From: James Mason Date: Tue, 13 Nov 2018 13:47:20 -0800 Subject: [PATCH] Add additional social media fields to contacts + YouTube + Blog Simplify logic in the view, and refactor the test #BetterPlace --- app/controllers/admin/contacts_controller.rb | 4 +- app/views/admin/contacts/edit.html.haml | 12 +++--- app/views/conferences/_social_media.haml | 18 +++++--- ...195810_add_youtube_and_blog_to_contacts.rb | 6 +++ db/schema.rb | 4 +- spec/features/contact_spec.rb | 42 +++++++++---------- 6 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 db/migrate/20181113195810_add_youtube_and_blog_to_contacts.rb diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index a0364251..d5f6ddcd 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -24,7 +24,9 @@ module Admin # Only allow a trusted parameter "white list" through. def contact_params - params.require(:contact).permit(:social_tag, :email, :facebook, :googleplus, :twitter, :instagram, :mastodon, :public, :sponsor_email) + params.require(:contact).permit( + :social_tag, :email, :facebook, :googleplus, :twitter, :instagram, + :mastodon, :public, :sponsor_email, :youtube, :blog) end end end diff --git a/app/views/admin/contacts/edit.html.haml b/app/views/admin/contacts/edit.html.haml index 1c48e48a..c242a01f 100644 --- a/app/views/admin/contacts/edit.html.haml +++ b/app/views/admin/contacts/edit.html.haml @@ -12,9 +12,11 @@ = f.input :sponsor_email, hint: 'This will appear in the sponsor segment of the splash for the sponsors to contact to the organizers' = f.inputs name: 'Social Media' do = f.input :social_tag, hint: "The hashtag you'll use on Twitter and Google+. Don't include the '#' sign!'" - = f.input :facebook, hint: 'This will appear in the social media section as link to the Facebook page of your Conference' - = f.input :googleplus, label: 'Google+ Url', hint: 'This will appear in the social media section as the link to the Google+ Page of your Conference' - = f.input :twitter, hint: 'This will appear in the social media section as the link to the Twitter Page of your Conference' - = f.input :instagram, hint: 'This will appear in the social media section as the link to the Instagram Page of your Conference' - = f.input :mastodon, hint: 'This will appear in the social media section as the link to the Mastodon Page of your Conference' + = f.input :blog, hint: 'This will appear in the social media section as a link to your conference blog.' + = f.input :facebook, hint: 'This will appear in the social media section as a link to the Facebook page of your Conference' + = f.input :googleplus, label: 'Google+ Url', hint: 'This will appear in the social media section as a link to the Google+ Page of your Conference' + = f.input :twitter, hint: 'This will appear in the social media section as a link to the Twitter Page of your Conference' + = f.input :instagram, hint: 'This will appear in the social media section as a link to the Instagram Page of your Conference' + = f.input :mastodon, hint: 'This will appear in the social media section as a link to the Mastodon Page of your Conference' + = f.input :youtube, hint: 'This will appear in the social media section as a link to the YouTube channel for your conference.' = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/conferences/_social_media.haml b/app/views/conferences/_social_media.haml index 28a87dbc..ea5c481d 100644 --- a/app/views/conferences/_social_media.haml +++ b/app/views/conferences/_social_media.haml @@ -3,21 +3,27 @@ .container .row .col-md-12.text-center - - unless contact.facebook.blank? + - if contact.blog? + = link_to "#{ contact.blog }" do + %i.fa.fa-rss-square.fa-4x + - if contact.facebook? = link_to "#{ contact.facebook }" do %i.fa.fa-facebook-square.fa-4x - - unless contact.twitter.blank? + - if contact.twitter? = link_to "#{ contact.twitter }" do %i.fa.fa-twitter.fa-4x - - unless contact.instagram.blank? + - if contact.instagram? = link_to "#{ contact.instagram }" do %i.fa.fa-instagram.fa-4x - - unless contact.googleplus.blank? + - if contact.googleplus? = link_to "#{ contact.googleplus }" do %i.fa.fa-google-plus-square.fa-4x - - unless contact.mastodon.blank? + - if contact.mastodon? = link_to "#{ contact.mastodon }" do %i.fa.icon-mastodon.fa-4x - - unless contact.email.blank? + - if contact.youtube? + = link_to "#{ contact.youtube }" do + %i.fa.fa-youtube.fa-4x + - if contact.email? = mail_to "#{ contact.email }" do %i.fa.fa-envelope-o.fa-4x diff --git a/db/migrate/20181113195810_add_youtube_and_blog_to_contacts.rb b/db/migrate/20181113195810_add_youtube_and_blog_to_contacts.rb new file mode 100644 index 00000000..7819b443 --- /dev/null +++ b/db/migrate/20181113195810_add_youtube_and_blog_to_contacts.rb @@ -0,0 +1,6 @@ +class AddYoutubeAndBlogToContacts < ActiveRecord::Migration[5.0] + def change + add_column :contacts, :youtube, :string + add_column :contacts, :blog, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3f55924f..509363e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181009000259) do +ActiveRecord::Schema.define(version: 20181113195810) do create_table "answers", force: :cascade do |t| t.string "title" @@ -123,6 +123,8 @@ ActiveRecord::Schema.define(version: 20181009000259) do t.datetime "updated_at" t.string "sponsor_email" t.string "mastodon" + t.string "youtube" + t.string "blog" end create_table "delayed_jobs", force: :cascade do |t| diff --git a/spec/features/contact_spec.rb b/spec/features/contact_spec.rb index 31ecf51f..f80ceb97 100644 --- a/spec/features/contact_spec.rb +++ b/spec/features/contact_spec.rb @@ -8,41 +8,39 @@ feature Contact do let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organizer) { create(:user, email: 'admin@example.com', role_ids: [organizer_role.id]) } - shared_examples 'update a contact' do - - scenario 'sucessfully', feature: true, js: true do + shared_examples 'contact field' do |field_name, field_value| + it 'updates a contact' do contact = conference.contact expected_count = Contact.count - sign_in organizer visit edit_admin_conference_contact_path(conference.short_title) - - fill_in 'contact_email', with: 'example@example.com' - fill_in 'contact_sponsor_email', with: 'sponsor@example.com' - fill_in 'contact_social_tag', with: 'example' - fill_in 'contact_facebook', with: 'http:\\www.facebook.com' - fill_in 'contact_twitter', with: 'http:\\www.twitter.com' - fill_in 'contact_instagram', with: 'http:\\www.instagram.com' - fill_in 'contact_googleplus', with: 'http:\\www.google.com' - + fill_in 'contact_' + field_name, with: field_value click_button 'Update Contact' expect(flash) .to eq('Contact details were successfully updated.') contact.reload - expect(contact.email).to eq('example@example.com') - expect(contact.sponsor_email).to eq('sponsor@example.com') - expect(contact.social_tag).to eq('example') - expect(contact.facebook).to eq('http:\\www.facebook.com') - expect(contact.twitter).to eq('http:\\www.twitter.com') - expect(contact.instagram).to eq('http:\\www.instagram.com') - expect(contact.googleplus).to eq('http:\\www.google.com') + + expect(contact.send(field_name)).to eq(field_value) expect(Contact.count).to eq(expected_count) end end describe 'organizer' do - it_behaves_like 'update a contact', :organizer - end + before do + sign_in organizer + end + context 'editing', feature: true do + it_behaves_like 'contact field', 'email', 'example@example.com' + it_behaves_like 'contact field', 'sponsor_email', 'sponsor@example.com' + it_behaves_like 'contact field', 'social_tag', 'example' + it_behaves_like 'contact field', 'facebook', 'http://www.facebook.com' + it_behaves_like 'contact field', 'twitter', 'http://www.twitter.com' + it_behaves_like 'contact field', 'instagram', 'http://www.instagram.com' + it_behaves_like 'contact field', 'googleplus', 'http://www.google.com' + it_behaves_like 'contact field', 'blog', 'http://blog.localdomain' + it_behaves_like 'contact field', 'youtube', 'https://youtube.com/osem' + end + end end