From a2dd90d355faa6b9bf3dcfcc89982b676c6e3ba0 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Tue, 30 Aug 2016 13:19:29 -0400 Subject: [PATCH 1/2] added user edit, show view info and spec for user profile update --- app/controllers/users_controller.rb | 4 +- app/models/user.rb | 4 +- app/views/users/edit.html.haml | 12 +++ app/views/users/show.html.haml | 77 ++++++++++++++++--- .../20160830122446_add_twitter_to_users.rb | 14 ++++ db/schema.rb | 12 ++- spec/factories/users.rb | 11 +++ spec/features/user_spec.rb | 35 +++++++++ 8 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20160830122446_add_twitter_to_users.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a453c83f..306d740b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -24,6 +24,8 @@ class UsersController < ApplicationController # Only allow a trusted parameter "white list" through. def user_params - params.require(:user).permit(:name, :biography, :nickname, :affiliation) + params.require(:user).permit(:name, :biography, :nickname, :affiliation, + :website_url, :linkedin, :twitter, :googleplus, + :gnu, :diaspora, :github, :gitlab, :gna, :savannah) end end diff --git a/app/models/user.rb b/app/models/user.rb index 29640ab3..1f3baf7e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -54,7 +54,6 @@ class User < ActiveRecord::Base scope :admin, -> { where(is_admin: true) } validates :email, presence: true - validates :username, uniqueness: { case_sensitive: false @@ -62,6 +61,9 @@ class User < ActiveRecord::Base presence: true validate :biography_limit + validates :website_url, :linkedin, :googleplus, :gnu, :twitter, :gitlab, :github, :gna, :savannah, :diaspora, + format: { with: URI.regexp(%w(http https)), message: 'This is an invalid URL. It should start with http or https'}, + allow_blank: true ## # Checkes if the user attended the event diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 825cd9f1..acd046c0 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -14,6 +14,18 @@ = link_to 'Change your avatar here', 'https://gravatar.com' = f.input :affiliation, as: :string, hint: 'This could be a company, a user group, or nothing at all.' + = f.input :website_url, type: :url, label: 'Personal Website' + = f.inputs :name => 'Social Media' do + = f.input :linkedin, type: :url + = f.input :twitter, type: :url + = f.input :googleplus, type: :url, label: 'Google+ Url' + = f.input :gnu, type: :url, label: 'GNU Social' + = f.input :diaspora, type: :url + = f.inputs :name => 'Social Code' do + = f.input :github, type: :url + = f.input :gitlab, type: :url + = f.input :savannah, type: :url + = f.input :gna, type: :url, label: 'Gna!' = f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' }, 'onkeyup' => "word_count(this, 'biography-count', 150)" }, hint: markdown_hint You have used diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 355cda88..14e49c59 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -11,14 +11,69 @@ = markdown(@user.biography) .row .col-md-12 - - if @user.events.confirmed.any? - %h3 - = "#{@user.name} presents #{pluralize(@user.events.confirmed.count, 'Event')}:" - %ul.list-unstyled - - @user.events.confirmed.each do |event| - %li - %h4 - = link_to event.title, conference_program_proposal_path(event.program.conference.short_title, event.id) - %strong - at - = event.program.conference.title + %h3 Social Media and Social Code + %table.table + %tr + %td + %b Website + %td + = @user.website_url.present? ? @user.website_url : '-' + %tr + %td + %b Linkedin + %td + = @user.linkedin.present? ? @user.linkedin : '-' + %tr + %td + %b Twitter + %td + = @user.twitter.present? ? @user.twitter : '-' + %tr + %td + %b GooglePlus + %td + = @user.googleplus.present? ? @user.googleplus : '-' + %tr + %td + %b GNU Social + %td + = @user.gnu.present? ? @user.gnu : '-' + %tr + %td + %b Diaspora + %td + = @user.diaspora.present? ? @user.diaspora : '-' + %tr + %td + %b Savannah + %td + = @user.savannah.present? ? @user.savannah : '-' + %tr + %td + %b Github + %td + = @user.github.present? ? @user.github : '-' + %tr + %td + %b Gitlab + %td + = @user.gitlab.present? ? @user.gitlab : '-' + %tr + %td + %b Gna! + %td + = @user.gna.present? ? @user.gna : '-' + + .row + .col-md-12 + - if @user.events.confirmed.any? + %h3 + = "#{@user.name} presents #{pluralize(@user.events.confirmed.count, 'Event')}:" + %ul.list-unstyled + - @user.events.confirmed.each do |event| + %li + %h4 + = link_to event.title, conference_program_proposal_path(event.program.conference.short_title, event.id) + %strong + at + = event.program.conference.title diff --git a/db/migrate/20160830122446_add_twitter_to_users.rb b/db/migrate/20160830122446_add_twitter_to_users.rb new file mode 100644 index 00000000..25ff1480 --- /dev/null +++ b/db/migrate/20160830122446_add_twitter_to_users.rb @@ -0,0 +1,14 @@ +class AddTwitterToUsers < ActiveRecord::Migration + def change + add_column :users, :twitter, :string + add_column :users, :googleplus, :string + add_column :users, :linkedin, :string + add_column :users, :gnu, :string + add_column :users, :diaspora, :string + add_column :users, :github, :string + add_column :users, :gitlab, :string + add_column :users, :gna, :string + add_column :users, :savannah, :string + add_column :users, :website_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 7da98fe3..8bae41f1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160815140302) do +ActiveRecord::Schema.define(version: 20160830122446) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -489,6 +489,16 @@ ActiveRecord::Schema.define(version: 20160815140302) do t.boolean "is_admin", default: false t.string "username" t.boolean "is_disabled", default: false + t.string "twitter" + t.string "googleplus" + t.string "linkedin" + t.string "gnu" + t.string "diaspora" + t.string "github" + t.string "gitlab" + t.string "gna" + t.string "savannah" + t.string "website_url" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true diff --git a/spec/factories/users.rb b/spec/factories/users.rb index c7ed7ca1..7cab17fc 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -20,6 +20,17 @@ FactoryGirl.define do sequence(:username) { |n| "username#{n}" } password 'changeme' password_confirmation 'changeme' + googleplus { Faker::Internet.url('http://plus.google.com/testosemurl') } + linkedin {Faker::Internet.url('http://linkedin.com/testosemuser')} + website_url { Faker::Internet.url('http://example.com') } + gnu { Faker::Internet.url('http://gnu.io/testosemurl') } + twitter { Faker::Internet.url('http://twitter.com/testosemuser') } + github { Faker::Internet.url('http://github.com/testosemuser') } + gitlab { Faker::Internet.url('http://gitlab.com/testosemuser') } + savannah { Faker::Internet.url('http://savannah.gnu.org/testosemuser') } + diaspora { Faker::Internet.url('http://joindiaspora.com/testosemuser') } + gna { Faker::Internet.url('http://gna.com/testosemuser') } + confirmed_at { Time.now } biography <<-EOS Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus enim diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 7294ec5c..1f9a65d4 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -2,6 +2,40 @@ require 'spec_helper' feature User do + let!(:user) {create(:user)} + + describe 'update user profile' do + scenario 'sucessfully', feature: true do + sign_in user + visit edit_user_path(user.id) + fill_in 'user_website_url', with: 'http://www.example1.com' + fill_in 'user_linkedin', with: 'http://www.linkedin.com/testosemuser1' + fill_in 'user_gnu', with: 'http://gnu.io/testosemuser1' + fill_in 'user_twitter', with: 'http://www.twitter.com/testosemuser1' + fill_in 'user_github', with: 'http://www.github.com/testosemuser1' + fill_in 'user_gitlab', with: 'http://www.gitlab.com/testosemuser1' + fill_in 'user_gna', with: 'http://www.gna.com/testosemuser1' + fill_in 'user_diaspora', with: 'http://joindiaspora.com/testosemuser1' + fill_in 'user_savannah', with: 'http://savannah.gnu.org/testosemuser1' + fill_in 'user_googleplus', with: 'http://plus.google.com/testosemurl1' + + click_button 'Update' + + expect(flash). to eq('User was successfully updated.') + user.reload + expect(user.website_url).to eq('http://www.example1.com') + expect(user.linkedin).to eq('http://www.linkedin.com/testosemuser1') + expect(user.gnu).to eq('http://gnu.io/testosemuser1') + expect(user.twitter).to eq('http://www.twitter.com/testosemuser1') + expect(user.github).to eq('http://www.github.com/testosemuser1') + expect(user.gitlab).to eq('http://www.gitlab.com/testosemuser1') + expect(user.googleplus).to eq('http://plus.google.com/testosemurl1') + expect(user.gna).to eq('http://www.gna.com/testosemuser1') + expect(user.diaspora).to eq('http://joindiaspora.com/testosemuser1') + expect(user.savannah).to eq('http://savannah.gnu.org/testosemuser1') + end + end + shared_examples 'admin ability' do end @@ -9,4 +43,5 @@ feature User do describe 'admin' do it_behaves_like 'admin ability', :admin end + end From 17aa374b990d2224100a59dcba350baacda69352 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Thu, 15 Sep 2016 13:30:58 -0400 Subject: [PATCH 2/2] font awesome gem updated, validation test added and user show page design updated --- Gemfile.lock | 4 +- app/assets/stylesheets/osem.css.scss | 9 ++ app/views/users/edit.html.haml | 27 ++++-- app/views/users/show.html.haml | 119 ++++++++++++++------------- spec/factories/users.rb | 23 +++--- spec/features/user_spec.rb | 3 +- spec/models/user_spec.rb | 31 ++++++- 7 files changed, 136 insertions(+), 80 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2f84aa81..b2288e55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,8 +181,8 @@ GEM fastimage (2.0.0) addressable (~> 2) ffi (1.9.3) - font-awesome-rails (4.1.0.0) - railties (>= 3.2, < 5.0) + font-awesome-rails (4.6.3.1) + railties (>= 3.2, < 5.1) formatador (0.2.4) formtastic (3.1.3) actionpack (>= 3.2.13) diff --git a/app/assets/stylesheets/osem.css.scss b/app/assets/stylesheets/osem.css.scss index d2a2cd10..d15c6a28 100644 --- a/app/assets/stylesheets/osem.css.scss +++ b/app/assets/stylesheets/osem.css.scss @@ -90,3 +90,12 @@ p.comment-body { .changeset{ display: none; } + +.user-profile-icon{ + text-align: center; + display: table; + .concat-text{ + display: block; + font-size: 14px; + } +} diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index acd046c0..e74d4fe1 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -16,16 +16,25 @@ hint: 'This could be a company, a user group, or nothing at all.' = f.input :website_url, type: :url, label: 'Personal Website' = f.inputs :name => 'Social Media' do - = f.input :linkedin, type: :url - = f.input :twitter, type: :url - = f.input :googleplus, type: :url, label: 'Google+ Url' - = f.input :gnu, type: :url, label: 'GNU Social' - = f.input :diaspora, type: :url + = f.input :linkedin, type: :url, as: :string, + hint: 'e.g. https://linkedin.com/osem' + = f.input :twitter, type: :url, as: :string, + hint: 'e.g. https://twitter.com/osem' + = f.input :googleplus, type: :url, label: 'Google+ Url', as: :string, + hint: 'e.g. https://googleplus.com/798239DR45' + = f.input :gnu, type: :url, label: 'GNU Social', as: :string, + hint: 'e.g. https://gnu.io/osem' + = f.input :diaspora, type: :url, as: :string, + hint: 'e.g http://joindiaspora.com/osem' = f.inputs :name => 'Social Code' do - = f.input :github, type: :url - = f.input :gitlab, type: :url - = f.input :savannah, type: :url - = f.input :gna, type: :url, label: 'Gna!' + = f.input :github, type: :url, as: :string, + hint: 'e.g http://github.com/osem' + = f.input :gitlab, type: :url, as: :string, + hint: 'e.g http://gitlab.com/osem' + = f.input :savannah, type: :url, as: :string, + hint: 'e.g http://savannah.gnu.org/osem' + = f.input :gna, type: :url, label: 'Gna!', as: :string, + hint: 'e.g http://gna.com/osem' = f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' }, 'onkeyup' => "word_count(this, 'biography-count', 150)" }, hint: markdown_hint You have used diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 14e49c59..2a9d9669 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -7,63 +7,72 @@ = @user.name %small = @user.nickname + %h3.text-center + Social Media and Social Code + %ul.list-inline.list-unstyled.text-center + - if @user.website_url.present? + %li + = link_to(@user.website_url) do + %div.user-profile-icon + %icon.fa.fa-external-link.fa-3x + %span.concat-text Blog + - if @user.linkedin.present? + %li + = link_to(@user.linkedin) do + %div.user-profile-icon + %icon.fa.fa-linkedin.fa-3x + %span.concat-text Linkedin + - if @user.twitter.present? + %li + = link_to(@user.twitter) do + %div.user-profile-icon + %icon.fa.fa-twitter.fa-3x + %span.concat-text Twitter + - if @user.googleplus.present? + %li + = link_to(@user.googleplus) do + %div.user-profile-icon + %icon.fa.fa-google-plus.fa-3x + %span.concat-text Google+ + - if @user.gnu.present? + %li + = link_to(@user.gnu) do + %div.user-profile-icon + %icon.fa.fa-linux.fa-3x + %span.concat-text Gnu + - if @user.diaspora.present? + %li + = link_to(@user.diaspora) do + %div.user-profile-icon + %icon.fa.fa-asterisk.fa-3x + %span.concat-text Diaspora + - if @user.savannah.present? + %li + = link_to(@user.savannah) do + %div.user-profile-icon + %icon.fa.fa-linux.fa-3x + %span.concat-text Savannah + - if @user.gna.present? + %li + = link_to(@user.gna) do + %div.user-profile-icon + %icon.fa.fa-linux.fa-3x + %span.concat-text Gna! + - if @user.github.present? + %li + = link_to(@user.github) do + %div.user-profile-icon + %icon.fa.fa-github.fa-3x + %span.concat-text Github + - if @user.gitlab.present? + %li + = link_to(@user.gitlab) do + %div.user-profile-icon + %icon.fa.fa-gitlab.fa-3x + %span.concat-text Gitlab + %h3.text-center Bio %p = markdown(@user.biography) - .row - .col-md-12 - %h3 Social Media and Social Code - %table.table - %tr - %td - %b Website - %td - = @user.website_url.present? ? @user.website_url : '-' - %tr - %td - %b Linkedin - %td - = @user.linkedin.present? ? @user.linkedin : '-' - %tr - %td - %b Twitter - %td - = @user.twitter.present? ? @user.twitter : '-' - %tr - %td - %b GooglePlus - %td - = @user.googleplus.present? ? @user.googleplus : '-' - %tr - %td - %b GNU Social - %td - = @user.gnu.present? ? @user.gnu : '-' - %tr - %td - %b Diaspora - %td - = @user.diaspora.present? ? @user.diaspora : '-' - %tr - %td - %b Savannah - %td - = @user.savannah.present? ? @user.savannah : '-' - %tr - %td - %b Github - %td - = @user.github.present? ? @user.github : '-' - %tr - %td - %b Gitlab - %td - = @user.gitlab.present? ? @user.gitlab : '-' - %tr - %td - %b Gna! - %td - = @user.gna.present? ? @user.gna : '-' - .row .col-md-12 - if @user.events.confirmed.any? diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 7cab17fc..c5ce44e6 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -20,16 +20,19 @@ FactoryGirl.define do sequence(:username) { |n| "username#{n}" } password 'changeme' password_confirmation 'changeme' - googleplus { Faker::Internet.url('http://plus.google.com/testosemurl') } - linkedin {Faker::Internet.url('http://linkedin.com/testosemuser')} - website_url { Faker::Internet.url('http://example.com') } - gnu { Faker::Internet.url('http://gnu.io/testosemurl') } - twitter { Faker::Internet.url('http://twitter.com/testosemuser') } - github { Faker::Internet.url('http://github.com/testosemuser') } - gitlab { Faker::Internet.url('http://gitlab.com/testosemuser') } - savannah { Faker::Internet.url('http://savannah.gnu.org/testosemuser') } - diaspora { Faker::Internet.url('http://joindiaspora.com/testosemuser') } - gna { Faker::Internet.url('http://gna.com/testosemuser') } + + trait :with_social_media_and_code_info do + googleplus { Faker::Internet.url('plus.google.com') } + linkedin {Faker::Internet.url('linkedin.com')} + website_url{Faker::Internet.url('example.com')} + gnu{Faker::Internet.url('gnu.io')} + twitter{Faker::Internet.url('twitter.com')} + github{Faker::Internet.url('github.com')} + gitlab{Faker::Internet.url('gitlab')} + savannah{Faker::Internet.url('savannah.gnu.org')} + diaspora{Faker::Internet.url('joindiaspora.com')} + gna{Faker::Internet.url('gna.com')} + end confirmed_at { Time.now } biography <<-EOS diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 1f9a65d4..fea199eb 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' feature User do - - let!(:user) {create(:user)} + let!(:user) {create(:user, :with_social_media_and_code_info)} describe 'update user profile' do scenario 'sucessfully', feature: true do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bf9e4362..c7cb3a93 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -9,8 +9,7 @@ describe User do let(:cfp_role) { Role.find_by(name: 'cfp', resource: conference) } let(:volunteers_coordinator_role) { Role.find_by(name: 'volunteers_coordinator', resource: conference) } let(:organizer) { create(:user, role_ids: [organizer_role.id]) } - let(:user) { create(:user) } - + let!(:user) {create(:user, :with_social_media_and_code_info)} let(:event1) { create(:event, program: conference.program) } let(:another_conference) { create(:conference) } let(:event2) { create(:event, program: another_conference.program) } @@ -48,6 +47,34 @@ describe User do end end + describe 'url format validation' do + context 'with valid url' do + it { should allow_value('http://example.com').for(:website_url) } + it { should allow_value('http://linkedin.com').for(:linkedin) } + it { should allow_value('http://googleplus.com').for(:googleplus) } + it { should allow_value('http://gnu.com').for(:gnu) } + it { should allow_value('http://twitter.com').for(:twitter) } + it { should allow_value('http://github.com').for(:github) } + it { should allow_value('http://gitlab.com').for(:gitlab) } + it { should allow_value('http://joindiaspora.com').for(:diaspora) } + it { should allow_value('http://savannah.gnu.org').for(:savannah) } + it { should allow_value('https://linkedin.com').for(:gna) } + end + + context 'with invalid url' do + it { should_not allow_value('example').for(:website_url) } + it { should_not allow_value('linkedin').for(:linkedin) } + it { should_not allow_value('googleplus').for(:googleplus) } + it { should_not allow_value('gnu').for(:gnu) } + it { should_not allow_value('@twitter').for(:twitter) } + it { should_not allow_value('@github').for(:github) } + it { should_not allow_value('@gitlab').for(:gitlab) } + it { should_not allow_value('diaspora').for(:diaspora) } + it { should_not allow_value('savannah').for(:savannah) } + it { should_not allow_value('gna').for(:gna) } + end + end + describe 'association' do it { is_expected.to have_many(:openids) } it { is_expected.to have_many(:event_users).dependent(:destroy) }