Skip to content

Commit

Permalink
PostTest running. added Post.recent.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 8, 2010
1 parent 89b0a4d commit ccc847b
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 30 deletions.
17 changes: 9 additions & 8 deletions Gemfile
@@ -1,14 +1,15 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.beta3'
gem 'authlogic', :git => "git://ryanbigg.local/authlogic.git"
gem 'rails', '3.0.1'
gem 'compass'
gem 'haml'

group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'rspec-rails', '2.0.0.beta.6'
gem 'launchy'
end
#group :test do
# gem 'cucumber-rails'
# gem 'capybara'
# gem 'rspec-rails', '2.0.0.beta.6'
# gem 'launchy'
#end

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -7,4 +7,4 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

Rails::Application.load_tasks
Blog::Application.load_tasks
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
@@ -1,5 +1,5 @@
class PostsController < ApplicationController
before_filter :login_required, :except => [:index, :show]
#before_filter :login_required, :except => [:index, :show]

def index
@posts = Post.all
Expand Down
6 changes: 6 additions & 0 deletions app/models/post.rb
Expand Up @@ -3,6 +3,12 @@ class Post < ActiveRecord::Base

has_many :comments

scope :recent, :order => "created_at DESC", :limit => 5
def self.recent_
find(:all, :order => "created_at DESC", :limit => 5)
end


def to_s
title
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base
acts_as_authentic
#acts_as_authentic
end
2 changes: 0 additions & 2 deletions app/models/user_session.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/views/posts/index.html.erb
@@ -1,5 +1,7 @@
We have <%= Post.count %> total posts, isn't that great? During the past days, we blogged about the following bullshit:

<% for post in @posts %>
<h2><%= link_to post, post %></h2>

<%= post.text %>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/posts/show.html.erb
Expand Up @@ -2,6 +2,6 @@

<%= @post.text %>
<% if logged_in? %>
<%# if logged_in? %>
<%= link_to "New Comment", new_post_comment_path(@post) %>
<% end %>
<%# end %>
13 changes: 7 additions & 6 deletions db/schema.rb
@@ -1,10 +1,11 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
Expand Down
37 changes: 37 additions & 0 deletions test/fixtures/posts.yml
@@ -0,0 +1,37 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
title: Post one
text: This is post number one, great!
created_at: 2010-11-08
id: 1

two:
title: Post two
text: This is post number 2, great!
created_at: 2010-11-09
id: 2

three:
title: Post 3
text: This is post number 3, great!
created_at: 2010-11-10
id: 3

four:
title: Post 4
text: This is post number 4, great!
created_at: 2010-11-11
id: 4

five:
title: Post 5
text: This is post number 5, great!
created_at: 2010-11-12
id: 5

six:
title: Post 6
text: This is post number 6, great!
created_at: 2010-11-13
id: 6
8 changes: 0 additions & 8 deletions test/fixtures/users.yml
@@ -1,9 +1 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
username: MyString
crypted_password: MyString

two:
username: MyString
crypted_password: MyString
7 changes: 7 additions & 0 deletions test/unit/post_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class PostTest < ActiveSupport::TestCase
test "should respond to .recent" do
assert_equal [6, 5, 4, 3, 2], Post.recent.collect { |p| p.id }
end
end

0 comments on commit ccc847b

Please sign in to comment.