Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #53 from dallasrb/fix_profile_index
Browse files Browse the repository at this point in the history
Fix profile index - update tests to match new sort algorithm
  • Loading branch information
itchy committed Jul 17, 2014
2 parents a8f81ef + 45a4556 commit 5cd643a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
12 changes: 7 additions & 5 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def approve!
self.update_attribute(:approved, true)
end

def save_with_epic_sort(args={})
def save_with_epic_sort(args={})
assign_attributes(args)
epic_sort
save
Expand All @@ -50,9 +50,11 @@ def save_with_epic_sort(args={})
private
def epic_sort
return if organizer?
epic_length = 80 + Random.rand(20)
bio_length = blurb.present? ? blurb.length : 0
score = (epic_length - bio_length).abs
self.sort_order = score
score = Random.rand(20)
score += 100 + Random.rand(20) if name.blank?
score += Random.rand(20) if blurb.blank?
score += Random.rand(20) if twitter.blank?
score += Random.rand(20) if homepage.blank?
self.sort_order = score
end
end
3 changes: 3 additions & 0 deletions app/views/kaminari/_gap.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
per_page: number of items to fetch per page
remote: data-remote
-%>
<!--
Commenting this out because I don't think we need it... plus it has styling issues.
<span class="page gap"><%= raw(t 'views.pagination.truncate') %></span>
-->
8 changes: 4 additions & 4 deletions spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
@member.save_with_epic_sort

@member.reload
@member.sort_order.should be_between(0, 20)
@member.sort_order.should be_between(0, 100)
end

it "should update attributes when saving with epic" do
@member.save_with_epic_sort({blurb: @blurb, name: 'sample'})

@member.reload
@member.sort_order.should be_between(0, 20)
@member.sort_order.should be_between(0, 100)
@member.name.should == 'sample'
end

Expand All @@ -52,8 +52,8 @@
@member.reload
@member_2.reload

@member.sort_order.should be_between(0, 20)
@member_2.sort_order.should be_between(0, 20)
@member.sort_order.should be_between(0, 100)
@member_2.sort_order.should be_between(0, 100)
end

it "should not show non-organizers more than once" do
Expand Down

0 comments on commit 5cd643a

Please sign in to comment.