Permalink
Browse files

Order user log entries by most to least recent

Also update log_entries fixtures to use fixed IDs
  • Loading branch information...
1 parent c5359cd commit f36d95af9ea3631a4210c3ed09c0f61d0dd22d62 @nickh committed Aug 29, 2008
Showing with 15 additions and 2 deletions.
  1. +1 −1 app/models/user.rb
  2. +7 −0 spec/fixtures/log_entries.yml
  3. +7 −1 spec/models/user_spec.rb
View
@@ -10,5 +10,5 @@
class User < ActiveRecord::Base
validates_uniqueness_of :openid_identifier
- has_many :log_entries
+ has_many :log_entries, :order => 'id DESC'
end
@@ -1,4 +1,6 @@
+<% id = 0 %>
valid_entry:
+ id: <% id += 1 %>
user_id: 1
departed_at: "2008-08-10 12:00:00"
arrived_at: "2008-08-10 16:00:00"
@@ -10,21 +12,26 @@ valid_entry:
# Pretend these two users went sailing together every day for a month
<% (1..31).each do |i| %>
user1_entry<%= i %>:
+ id: <%= id += 1 %>
user_id: 1
departed_at: <%= sprintf "2008-09-%02d 12:30:00", i %>
arrived_at: <%= sprintf "2008-09-%02d 16:30:00", i %>
user2_entry<%= i %>:
+ id: <%= id += 1 %>
user_id: 2
departed_at: <%= sprintf "2008-09-%02d 12:30:00", i %>
arrived_at: <%= sprintf "2008-09-%02d 16:30:00", i %>
<% end %>
# Also give each user a more recent incomplete entry
user1_incomplete_entry:
+ id: <%= id += 1 %>
user_id: 1
departed_at: '2008-10-01 12:30:00'
user2_incomplete_entry:
+ id: <%= id += 1 %>
user_id: 2
departed_at: '2008-10-01 12:30:00'
+
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe User do
- fixtures :users
+ fixtures :users, :log_entries
it 'should respond to user attributes' do
user = User.new
@@ -15,6 +15,12 @@
User.new.should have_many(:log_entries)
end
+ it 'should order log_entries by most to least recent' do
+ entries = User.find(:first).log_entries
+ entry_ids = entries.collect{|e| e.id}
+ entry_ids.should == entry_ids.sort.reverse
+ end
+
it "should not be valid with a duplicate OpenID identifier" do
existing_user = User.find(:first)
new_user = User.new(:openid_identifier => existing_user.openid_identifier)

0 comments on commit f36d95a

Please sign in to comment.