Permalink
Browse files

Show the user position on her profile page

  • Loading branch information...
1 parent 4ad4294 commit fd006a4dfe70d0e8e8127501868ebcfd5346acf9 @jeffkreeftmeijer jeffkreeftmeijer committed Jul 26, 2011
Showing with 34 additions and 11 deletions.
  1. +2 −0 app/controllers/users_controller.rb
  2. +1 −0 app/views/users/show.haml
  3. +31 −11 spec/acceptance/users_spec.rb
@@ -6,6 +6,8 @@ def index
end
def show
+ @points = User.only(:points).order_by([:points, :desc]).map(&:points)
+
@user = User.where(:login => params[:id]).first
@entered_contests = Contest.all.where('entries.user_id' => @user.id).select do |contest|
contest.state == 'finished'
@@ -10,6 +10,7 @@
%li= link_to("#{@user.login} on Github", "https://github.com/#{@user.login}")
- @user.urls.reject {|key, value| key == 'GitHub' || value.nil? }.each do |key, url|
%li= link_to url, url
+ %li= "Position: ##{@points.index(@user.points) + 1}"
%li= "Average score: #{sprintf("%.1f", @user.average_score)}/5"
- if @entered_contests.any?
@@ -2,19 +2,25 @@
feature 'Users' do
+ background(:all) do
+
+ %w{ alice bob charlie david }.each_with_index do |login, index|
+ Fabricate(
+ :user,
+ :login => login,
+ :points => index * 100
+ )
+ end
+
+ Fabricate(:user, :login => 'frank')
+ Fabricate(:user, :login => 'gary', :points => 200)
+
+ end
+
context 'on the user index' do
- background(:all) do
- User.any_instance.stubs(:average_score).returns(2.456)
- %w{ alice bob charlie david }.each_with_index do |login, index|
- Fabricate(
- :user,
- :login => login,
- :points => index * 100
- )
- end
- Fabricate(:user, :login => 'frank')
- Fabricate(:user, :login => 'gary', :points => 200)
+ background do
+ User.any_instance.stubs(:average_score).returns(2.456)
visit '/users'
end
@@ -150,4 +156,18 @@
end
+ context 'on user profiles' do
+
+ scenario 'show the user position' do
+
+ {'david' => 1, 'charlie' => 2, 'gary' => 2, 'bob' => 4}.each do |login, position|
+ visit "/users/#{login}"
+ page.should have_content "##{position}"
+ end
+
+
+ end
+
+ end
+
end

0 comments on commit fd006a4

Please sign in to comment.