Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Users now have a simple public profile Closes #2
Browse files Browse the repository at this point in the history
Finished pending scenario, a user is now able to visit his own profile Closes #3
Added link_to_profile helper
  • Loading branch information
Overbryd committed Jun 23, 2011
1 parent e709ffe commit d6d07f8
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 13 deletions.
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -4,4 +4,10 @@ def avatar_url
"http://#{request.domain}#{request.local? ? ":#{request.port}" : ''}#{asset_path('avatar.png')}"
end

def link_to_profile(user)
link_text = image_tag(user.gravatar_url(:size => 20, :default => avatar_url), :class => 'gravatar')
link_text << " " << user.login
link_to link_text, user_path(user)
end

end
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -10,4 +10,6 @@ class User
validates :login, :presence => true

has_gravatar

alias_method :to_param, :login
end
3 changes: 1 addition & 2 deletions app/views/entries/_entry.haml
@@ -1,8 +1,7 @@
%li{ :id => dom_id(entry), :class => entry.contest.closed? ? [%w{gold silver bronze}[entry_counter], 'entry'].join(' ') : 'entry' }
- if entry.contest.closed? || @voted_entries.include?(entry)
.owner
= image_tag entry.user.gravatar_url(:size => 20, :default => avatar_url), :class => 'gravatar'
= entry.user.login
= link_to_profile(entry.user)

- entry.files.each do |name, file|
.filename
Expand Down
7 changes: 2 additions & 5 deletions app/views/layouts/application.haml
Expand Up @@ -19,11 +19,8 @@
#menu
%span
- if current_user
= image_tag current_user.gravatar_url(:size => 20, :default => avatar_url), :class => 'gravatar'
//= link_to current_user.login, user_path(current_user.login)
= current_user.login
:erb
(<%= link_to('log out', [:session], :method => :delete)%>)
= link_to_profile(current_user)
= "(#{link_to('log out', [:session], :method => :delete)})".html_safe
- else
= link_to('log in via Github', '/auth/github')

Expand Down
8 changes: 5 additions & 3 deletions app/views/users/show.haml
Expand Up @@ -2,6 +2,8 @@

= image_tag @user.gravatar_url(:size => 220, :default => avatar_url)

%ul
- @contests.reject{ |contest| contest.open? }.each do |contest|
%li= contest.name
- if @contests.any?
%h3 Contests
%ul
- @contests.each do |contest|
%li= link_to contest.name, contest
2 changes: 1 addition & 1 deletion spec/acceptance/acceptance_helper.rb
Expand Up @@ -12,7 +12,7 @@
'user_info' => {
'nickname' => 'charlie',
'email' => 'charlie@email.com',
'name' => 'Charlie'
'name' => 'Charlie Chaplin'
}
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/contest_index_spec.rb
Expand Up @@ -77,9 +77,9 @@

background { login_via_github }

pending 'visit my profile page' do
scenario 'visit my profile page' do
click_link 'charlie'
page.should have_content 'Alice'
page.should have_content 'Charlie Chaplin'
end

end
Expand Down
29 changes: 29 additions & 0 deletions spec/helpers/application_helper_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper'

describe ApplicationHelper do
describe "link_to_profile" do
before :each do
@user = stub(:login => 'charlie', :to_param => 'charlie', :gravatar_url => 'http://gravatar.org/profile.png')
end

let(:output) { helper.link_to_profile(@user) }

it "should include the gravatar image" do
output.should include('<img')
output.should include('src="http://gravatar.org/profile.png"')
end

it "should include the username" do
output.should include("charlie")
end

it "should html escape the username" do
@user.stubs(:login => '<script>alert("xss")</script>')
output.should_not include('<script>')
end

it "should link to the users profile" do
output.should include('href="/users/charlie"')
end
end
end
6 changes: 6 additions & 0 deletions spec/models/user_spec.rb
Expand Up @@ -18,4 +18,10 @@

end

describe "#to_param" do
it "should use the login field" do
User.new(:login => 'pete').to_param.should eql('pete')
end
end

end

0 comments on commit d6d07f8

Please sign in to comment.