Commit 59704f481e742710fff32c733047eb84478e505e

Authored by Aleksei Kvitinskii
1 parent 9ad444f0

extended user profile with social fields

app/controllers/profile_controller.rb
@@ -3,6 +3,12 @@ class ProfileController < ApplicationController @@ -3,6 +3,12 @@ class ProfileController < ApplicationController
3 @user = current_user 3 @user = current_user
4 end 4 end
5 5
  6 + def social_update
  7 + @user = current_user
  8 + @user.update_attributes(params[:user])
  9 + redirect_to [:profile]
  10 + end
  11 +
6 def password 12 def password
7 @user = current_user 13 @user = current_user
8 end 14 end
app/models/user.rb
@@ -5,7 +5,8 @@ class User < ActiveRecord::Base @@ -5,7 +5,8 @@ class User < ActiveRecord::Base
5 :recoverable, :rememberable, :trackable, :validatable 5 :recoverable, :rememberable, :trackable, :validatable
6 6
7 # Setup accessible (or protected) attributes for your model 7 # Setup accessible (or protected) attributes for your model
8 - attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :projects_limit 8 + attr_accessible :email, :password, :password_confirmation, :remember_me,
  9 + :name, :projects_limit, :skype, :linkedin, :twitter
9 10
10 has_many :users_projects, :dependent => :destroy 11 has_many :users_projects, :dependent => :destroy
11 has_many :projects, :through => :users_projects 12 has_many :projects, :through => :users_projects
@@ -58,5 +59,8 @@ end @@ -58,5 +59,8 @@ end
58 # name :string(255) 59 # name :string(255)
59 # admin :boolean default(FALSE), not null 60 # admin :boolean default(FALSE), not null
60 # projects_limit :integer 61 # projects_limit :integer
  62 +# skype :string
  63 +# linkedin :string
  64 +# twitter :string
61 # 65 #
62 66
app/views/admin/users/_form.html.haml
@@ -25,13 +25,26 @@ @@ -25,13 +25,26 @@
25 = f.label :password_confirmation 25 = f.label :password_confirmation
26 %br 26 %br
27 = f.password_field :password_confirmation 27 = f.password_field :password_confirmation
28 - .span-11  
29 - .field.prepend-top.append-bottom 28 + .field.prepend-top
30 = f.check_box :admin 29 = f.check_box :admin
31 = f.label :admin 30 = f.label :admin
  31 + .span-11
32 .field.prepend-top 32 .field.prepend-top
33 = f.text_field :projects_limit, :class => "small_input" 33 = f.text_field :projects_limit, :class => "small_input"
34 = f.label :projects_limit 34 = f.label :projects_limit
  35 +
  36 + .field
  37 + = f.label :skype
  38 + %br
  39 + = f.text_field :skype
  40 + .field
  41 + = f.label :linkedin
  42 + %br
  43 + = f.text_field :linkedin
  44 + .field
  45 + = f.label :twitter
  46 + %br
  47 + = f.text_field :twitter
35 .clear 48 .clear
36 %br 49 %br
37 .actions 50 .actions
app/views/admin/users/show.html.haml
@@ -14,6 +14,17 @@ @@ -14,6 +14,17 @@
14 %b Projects limit: 14 %b Projects limit:
15 = @admin_user.projects_limit 15 = @admin_user.projects_limit
16 16
  17 + %p
  18 + %b Skype:
  19 + = @admin_user.skype
  20 + %p
  21 + %b LinkedIn:
  22 + = @admin_user.linkedin
  23 + %p
  24 + %b Twitter:
  25 + = @admin_user.twitter
  26 +
  27 +
17 .clear 28 .clear
18 = link_to 'Edit', edit_admin_user_path(@admin_user) 29 = link_to 'Edit', edit_admin_user_path(@admin_user)
19 \| 30 \|
app/views/profile/show.html.haml
@@ -6,3 +6,28 @@ @@ -6,3 +6,28 @@
6 %p 6 %p
7 %b Email: 7 %b Email:
8 = @user.email 8 = @user.email
  9 +
  10 +%br
  11 +
  12 += form_for @user, :url => profile_edit_path, :method => :put do |f|
  13 + -if @user.errors.any?
  14 + #error_explanation
  15 + %ul
  16 + - @user.errors.full_messages.each do |msg|
  17 + %li= msg
  18 +
  19 + .div
  20 + = f.label :skype
  21 + %br
  22 + = f.text_field :skype
  23 + .div
  24 + = f.label :linkedin
  25 + %br
  26 + = f.text_field :linkedin
  27 + .div
  28 + = f.label :twitter
  29 + %br
  30 + = f.text_field :twitter
  31 + .actions
  32 + = f.submit 'Save', :class => "lbutton vm"
  33 +
config/routes.rb
@@ -13,6 +13,7 @@ Gitlab::Application.routes.draw do @@ -13,6 +13,7 @@ Gitlab::Application.routes.draw do
13 get "errors/gitosis" 13 get "errors/gitosis"
14 get "profile/password", :to => "profile#password" 14 get "profile/password", :to => "profile#password"
15 put "profile/password", :to => "profile#password_update" 15 put "profile/password", :to => "profile#password_update"
  16 + put "profile/edit", :to => "profile#social_update"
16 get "profile", :to => "profile#show" 17 get "profile", :to => "profile#show"
17 #get "profile/:id", :to => "profile#show" 18 #get "profile/:id", :to => "profile#show"
18 19
db/migrate/20111019212429_add_social_to_user.rb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +class AddSocialToUser < ActiveRecord::Migration
  2 + def change
  3 + add_column :users, :skype, :string
  4 + add_column :users, :linkedin, :string
  5 + add_column :users, :twitter, :string
  6 + end
  7 +end
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 # 11 #
12 # It's strongly recommended to check this file into your version control system. 12 # It's strongly recommended to check this file into your version control system.
13 13
14 -ActiveRecord::Schema.define(:version => 20111016195506) do 14 +ActiveRecord::Schema.define(:version => 20111019212429) do
15 15
16 create_table "issues", :force => true do |t| 16 create_table "issues", :force => true do |t|
17 t.string "title" 17 t.string "title"
@@ -82,6 +82,9 @@ ActiveRecord::Schema.define(:version =&gt; 20111016195506) do @@ -82,6 +82,9 @@ ActiveRecord::Schema.define(:version =&gt; 20111016195506) do
82 t.string "name" 82 t.string "name"
83 t.boolean "admin", :default => false, :null => false 83 t.boolean "admin", :default => false, :null => false
84 t.integer "projects_limit", :default => 10 84 t.integer "projects_limit", :default => 10
  85 + t.string "skype"
  86 + t.string "linkedin"
  87 + t.string "twitter"
85 end 88 end
86 89
87 add_index "users", ["email"], :name => "index_users_on_email", :unique => true 90 add_index "users", ["email"], :name => "index_users_on_email", :unique => true
spec/models/user_spec.rb
@@ -39,5 +39,8 @@ end @@ -39,5 +39,8 @@ end
39 # name :string(255) 39 # name :string(255)
40 # admin :boolean default(FALSE), not null 40 # admin :boolean default(FALSE), not null
41 # projects_limit :integer 41 # projects_limit :integer
  42 +# skype :string
  43 +# linkedin :string
  44 +# twitter :string
42 # 45 #
43 46
spec/requests/profile_spec.rb
@@ -14,6 +14,22 @@ describe &quot;Profile&quot; do @@ -14,6 +14,22 @@ describe &quot;Profile&quot; do
14 it { page.should have_content(@user.email) } 14 it { page.should have_content(@user.email) }
15 end 15 end
16 16
  17 + describe "Profile update" do
  18 + before do
  19 + visit profile_path
  20 + fill_in "user_skype", :with => "testskype"
  21 + fill_in "user_linkedin", :with => "testlinkedin"
  22 + fill_in "user_twitter", :with => "testtwitter"
  23 + click_button "Save"
  24 + @user.reload
  25 + end
  26 +
  27 + it { @user.skype.should == 'testskype' }
  28 + it { @user.linkedin.should == 'testlinkedin' }
  29 + it { @user.twitter.should == 'testtwitter' }
  30 + end
  31 +
  32 +
17 describe "Password update" do 33 describe "Password update" do
18 before do 34 before do
19 visit profile_password_path 35 visit profile_password_path