From da9f33aa72e79705e2fc467f0bc11ac75c667363 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 16 Jun 2010 17:35:39 -0700 Subject: [PATCH] fixed post stream to ascend by time --- app/controllers/dashboard_controller.rb | 9 +-------- app/models/post.rb | 18 +++++++++++++++--- app/views/dashboard/index.html.haml | 2 ++ config/environments/test.rb | 2 +- config/mongoid.yml | 10 +++++----- spec/spec_helper.rb | 1 + 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index e534252b6..c9d082015 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,13 +2,6 @@ class DashboardController < ApplicationController before_filter :authenticate_user! def index - @posts = Post.all - - @bookmarks = Bookmark.all - @status_messages = StatusMessage.all - @blogs = Blog.all - #@status_messages = @posts.select{ |x| x._type == "StatusMessage"} - #@blogs = @posts.select{ |x| x._type == "Blog"} - #@bookmarks = @posts.select{ |x| x._type == "Bookmarks"} + @posts = Post.recent_ordered_posts end end diff --git a/app/models/post.rb b/app/models/post.rb index 34af94757..e4f4eb175 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -14,10 +14,24 @@ class Post field :source field :snippet - before_create :set_defaults #after_update :notify_friends + + + @@models = ["StatusMessage", "Bookmark", "Blog"] + + def self.recent_ordered_posts + # Need to explicitly name each inherited model for dev environment + query = if Rails.env == "development" + Post.criteria.all(:_type => @@models) + else + Post.criteria.all + end + query.order_by( [:created_at, :desc] ) + end + + protected def set_defaults @@ -33,7 +47,5 @@ class Post #xml = self.to_xml_to_s #friends.each{|friend| ping friend :with => xml } #end - end - diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index 5a63f6b9f..1c60dc8e2 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -1,7 +1,9 @@ - title "Dashboard" + %ul#stream - for post in @posts %li = render "shared/post", :post =>post + /= post.inspect diff --git a/config/environments/test.rb b/config/environments/test.rb index fab2538d4..40d222032 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ Diaspora::Application.configure do # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = false + config.cache_classes = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true diff --git a/config/mongoid.yml b/config/mongoid.yml index 2a97fd67c..e0df0977c 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -19,8 +19,8 @@ test: # set these environment variables on your prod server production: <<: *defaults - host: <%= ENV['MONGOID_HOST'] %> - port: <%= ENV['MONGOID_PORT'] %> - username: <%= ENV['MONGOID_USERNAME'] %> - password: <%= ENV['MONGOID_PASSWORD'] %> - database: <%= ENV['MONGOID_DATABASE'] %> + #host: <%= ENV['MONGOID_HOST'] %> + #port: <%= ENV['MONGOID_PORT'] %> + #username: <%= ENV['MONGOID_USERNAME'] %> + #password: <%= ENV['MONGOID_PASSWORD'] %> + #database: <%= ENV['MONGOID_DATABASE'] %> diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dbfcae118..bc3f0762a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,6 +24,7 @@ Rspec.configure do |config| config.before(:each) do Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop) + end