Commit 7c401621 by tady

Merge commit 'f1da4188' into feat/fix_notify

parents 906b44e5 f1da4188
......@@ -8,6 +8,9 @@ class PostsController < ApplicationController
# GET /posts/1
# GET /posts/1.json
def show
current_user.visit_post!(@post)
@post.tags.each do |_tag|
add_breadcrumb("##{_tag.name}", _tag.decorate.show_path)
end
......
......@@ -27,6 +27,14 @@ class PostDecorator < Draper::Decorator
end
end
def created_date
model.created_at.strftime('%Y-%m-%d')
end
def updated_date
model.updated_at.strftime('%Y-%m-%d')
end
def display_specified_date
if model.specified_date
model.specified_date.strftime('%Y-%m-%d')
......
class Footprint < ActiveRecord::Base
belongs_to :user
belongs_to :post
end
......@@ -20,6 +20,7 @@ class Post < ActiveRecord::Base
has_many :tags, through: :post_tags
belongs_to :author, class_name: 'User'
has_many :comments
has_many :footprints
# default_scope { where(is_draft: false).order(:updated_at => :desc) }
......@@ -68,6 +69,10 @@ class Post < ActiveRecord::Base
order(updated_at: :desc).limit(limit)
}
######################################################################
# Instance method
######################################################################
# generate forked post (not saved)
def generate_fork(user)
......@@ -91,4 +96,8 @@ class Post < ActiveRecord::Base
def body_for_slideshow
self.body.gsub(/^#/, "---\n\n#")
end
def visited_user_count
footprints.select(:user_id).uniq.count
end
end
......@@ -38,6 +38,7 @@ class User < ActiveRecord::Base
has_many :posts, foreign_key: 'author_id'
has_many :comments, foreign_key: 'author_id'
has_many :notifications
has_many :footprints
######################################################################
# scope
......@@ -80,6 +81,9 @@ class User < ActiveRecord::Base
user
end
######################################################################
# instance methods
######################################################################
# check if google oauth token is expired
def google_oauth_token_expired?
......@@ -111,5 +115,8 @@ class User < ActiveRecord::Base
notifications.create(detail_path: detail_path, body: body, is_read: false)
end
# record footprint
def visit_post!(post)
footprints.create!(post: post)
end
end
......@@ -27,5 +27,3 @@
a.list-group-item data-tag-id=tag.id href=search_path(q: "##{tag.name}")
= tag.name
span.badge = tag.posts_count
......@@ -20,14 +20,15 @@ a.list-group-item.post-list.mod-hover-hidden data-post-id=post.id href=post_path
| &nbsp;
.col-xs-4
small.pull-right
span.glyphicon.glyphicon-time
span.mod-hover-hidden-item
| 読了時間
span.glyphicon.glyphicon-time title="読了時間"
| &nbsp;#{post.read_time}&nbsp;&nbsp;
span.glyphicon.glyphicon-comment
span.mod-hover-hidden-item
| コメント
span.glyphicon.glyphicon-comment title="コメント"
| &nbsp;#{post.comments.count}&nbsp;&nbsp;
span.glyphicon.glyphicon-eye-open title="閲覧者数"
| &nbsp;#{post.visited_user_count}&nbsp;&nbsp;
.row
.col-xs-12
small.text-shadow
......
= render_breadcrumbs
.row
.panel.panel-default
.col-xs-9
.panel.panel-info
.panel-heading
h3.panel-title
a href=post_path(@post) = @post.title
ul.list-group
li.list-group-item
- @post.tags.each do |tag|
span.label.label-success
a href=tag.decorate.show_path
| ##{tag.name}
| &nbsp;
span.label.label-info
a href=(search_path(q: "@#{@post.author.name}"))
| @#{@post.author.name}
| &nbsp;
span.label.label-danger
a href=(search_path(q: "date:#{@post.display_date}")) = @post.display_date
.btn-group.pull-right style=("margin: -7px -12px 0 0;")
.panel-body.viewer.github
= h_application_format_markdown(@post.body)
.col-xs-3
p.btn-group
a.btn.btn-primary href=edit_post_path(@post)
| 編集&nbsp;
span.glyphicon.glyphicon-pencil
button.btn.btn-default.dropdown-toggle data-toggle="dropdown" type="button"
span.caret
......@@ -35,8 +28,45 @@
a data-target="#myModal" data-toggle="modal" href="#" Mail to...
li.divider
li= link_to 'Delete', post_path(@post), method: :delete, data: { confirm: 'Are you sure?' }
.panel-body.viewer.github
= h_application_format_markdown(@post.body)
.well
dl
dt 作成者
dd
a href=(search_path(q: "@#{@post.author.name}"))
| @#{@post.author.name}
dt タグ
dd
- @post.tags.each do |tag|
span.label.label-success
a href=tag.decorate.show_path
| ##{tag.name}
| &nbsp;
dt 指定日
dd
a href=(search_path(q: "date:#{@post.display_date}")) = @post.display_date
dt 作成日
dd
= @post.created_date
dt 最終更新日
dd
= @post.updated_date
dt 閲覧者数
dd
= @post.visited_user_count
dt コメント数
dd
= @post.comments.count
.row
.panel.panel-success
.panel-heading
h3.panel-title Comments
......
h1 テンプレートから作成
/! view:templates/show
.row
.panel.panel-info
h1
| Templates
small - テンプレートから作成
.panel.panel-info
.panel-heading
span.glyphicon.glyphicon-info-sign
| テンプレートの使い方
......@@ -10,7 +15,7 @@ h1 テンプレートから作成
li 「template」 というタグをつけた投稿はこのページに現れます
li コピーすることで同じフォーマットの文章が簡単に書けます
.list-group
.list-group
- if template_tag = Tag.find_by(name: 'template')
- template_tag.posts.decorate.each do |_post|
= render partial: 'post', locals: { post: _post }
......
class CreateFootprints < ActiveRecord::Migration
def change
create_table :footprints do |t|
t.integer :user_id, null: false
t.integer :post_id, null: false
t.timestamps
end
add_index :footprints, [:user_id, :post_id]
add_index :footprints, :post_id
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140501045300) do
ActiveRecord::Schema.define(version: 20140719132802) do
create_table "comments", force: true do |t|
t.integer "author_id"
......@@ -24,6 +24,16 @@ ActiveRecord::Schema.define(version: 20140501045300) do
add_index "comments", ["author_id", "updated_at"], name: "index_comments_on_author_id_and_updated_at", using: :btree
add_index "comments", ["post_id", "updated_at"], name: "index_comments_on_post_id_and_updated_at", using: :btree
create_table "footprints", force: true do |t|
t.integer "user_id", null: false
t.integer "post_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "footprints", ["post_id"], name: "index_footprints_on_post_id", using: :btree
add_index "footprints", ["user_id", "post_id"], name: "index_footprints_on_user_id_and_post_id", using: :btree
create_table "notifications", force: true do |t|
t.integer "user_id"
t.datetime "read_at"
......
require 'rails_helper'
describe PostsController, type: :controller do
let(:post) { FactoryGirl.create(:post) }
describe "GET 'show' without login" do
it "returns http redirect" do
get 'show', id: post.id
expect(response).to redirect_to('/')
end
end
describe "GET 'show' with login" do
let(:alice) { FactoryGirl.create(:alice) }
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show', id: post.id
expect(response).to be_success
end
it "returns http success" do
sign_in alice
get 'show', id: post.id
expect(Footprint.where(user_id: alice.id, post_id: post.id)).to exist
end
end
end
require 'rails_helper'
RSpec.describe Footprint, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment