Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class TopicsController < ApplicationController | ||
before_filter :require_logined, :except => [:index] | ||
|
||
def index | ||
@topics = Topic.order_by([[:actived_at, :desc]]).page(params[:page]).per(15) | ||
end | ||
|
||
def new | ||
@topic = Topic.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Topic | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
field :title | ||
field :content | ||
field :tags, :type => Array | ||
field :actived_at, :type => DateTime | ||
|
||
belongs_to :user | ||
|
||
validates :title, :content, :user, :presence => true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#main | ||
.container | ||
.row | ||
#mainbar.span12 | ||
#topics.box | ||
%table.item-list | ||
- @topics.each do |topic| | ||
%tr | ||
%td.avatar | ||
= image_tag topic.user.gravatar_url | ||
%td | ||
%h3 | ||
%a{:href => '#'} This is a title | ||
.info | ||
- if topic.tags.present? | ||
%span.tags | ||
- topic.tags.each do |tag| | ||
%a{:href => '#'}= tag | ||
%span.author | ||
by | ||
%a{:href => '#'}= topic.user.name | ||
%span.time | ||
at | ||
= time_ago_in_words topic.created_at | ||
ago. | ||
%td.reply-count | ||
%a{:href => '#'} 0 | ||
#sidebar.span4 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Read about factories at http://github.com/thoughtbot/factory_girl | ||
|
||
FactoryGirl.define do | ||
factory :topic do | ||
title 'title' | ||
content 'content' | ||
tags %w(ruby programing) | ||
association :user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'test_helper' | ||
|
||
class TopicsControllerTest < ActionController::TestCase | ||
def setup | ||
@user = Factory :user | ||
end | ||
|
||
test "should get index" do | ||
get :index | ||
assert_response :success, @response.body | ||
end | ||
|
||
test "should get new topic page" do | ||
get :new | ||
assert_redirected_to login_url | ||
|
||
login_as @user | ||
get :new | ||
assert_response :success, @response.body | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class TopicTest < ActiveSupport::TestCase | ||
end |