From 404445f3afc28ddb149ba0ba72f09aa4509fdd99 Mon Sep 17 00:00:00 2001 From: yafei Lee Date: Mon, 25 Jun 2012 08:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E6=8E=92=E5=BA=8F=E9=87=87?= =?UTF-8?q?=E7=94=A8=E5=88=9B=E5=BB=BA=E6=97=B6=E5=80=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 2 +- app/controllers/blogs_controller.rb | 6 +++--- app/models/post.rb | 1 + spec/controllers/admin/posts_controller_spec.rb | 2 +- spec/controllers/blogs_controller_spec.rb | 9 +++++++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2a301c7..7c924a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://ruby.taobao.org/ + remote: http://rubygems.org/ specs: actionmailer (3.2.6) actionpack (= 3.2.6) diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 4cc9505..dd9e363 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -3,14 +3,14 @@ class BlogsController < ApplicationController def index type = params[:type] if type or type == "" - @posts = Post.where(type: map[type]) + @posts = Post.where(type: map[type]).order(:created_at => :desc ) else - @posts = Post.all + @posts = Post.all.order(:created_at => :desc ) end end def rss - @posts = Post.all.limit(10) + @posts = Post.all.order(:created_at => :desc).limit(10) render :layout=>false response.headers["Content-Type"] = "application/xml; charset=utf-8" end diff --git a/app/models/post.rb b/app/models/post.rb index 09325a6..9889dd6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,6 +4,7 @@ class Post LIFE = "生活" CREATOR = "创业" include Mongoid::Document + include Mongoid::Timestamps field :title, :type => String field :content, :type => String field :type, :type=> String diff --git a/spec/controllers/admin/posts_controller_spec.rb b/spec/controllers/admin/posts_controller_spec.rb index 74d739d..5ac2f06 100644 --- a/spec/controllers/admin/posts_controller_spec.rb +++ b/spec/controllers/admin/posts_controller_spec.rb @@ -11,6 +11,6 @@ describe Admin::PostsController do puts 'hello world' ``` EOF - response.body.should == "

ruby\nputs 'hello world'\n

\n" + response.body.should == "

ruby
\nputs 'hello world'
\n

\n" end end diff --git a/spec/controllers/blogs_controller_spec.rb b/spec/controllers/blogs_controller_spec.rb index d6944c9..cfb17ff 100644 --- a/spec/controllers/blogs_controller_spec.rb +++ b/spec/controllers/blogs_controller_spec.rb @@ -2,4 +2,13 @@ require 'spec_helper' describe BlogsController do + it 'index should get by order desc' do + a = Post.new(title: '123', content: '123'*20, type: Post::TECH) + a.save! + sleep 1 + b = Post.new(title: '1234', content: '123'*20,type: Post::TECH) + b.save! + get :index + assigns[:posts][1].title.should == a.title + end end