Add a quick front apge
This commit is contained in:
parent
0e50dd92f8
commit
6993bb0ecd
10 changed files with 72 additions and 16 deletions
|
@ -2,6 +2,10 @@ class PostsController < ApplicationController
|
|||
before_filter :set_post, except: [:index, :new, :create]
|
||||
before_filter :set_subcreddit
|
||||
|
||||
def index
|
||||
@posts = Post.all
|
||||
end
|
||||
|
||||
def show
|
||||
@comments = @post.comments.arrange(order: :created_at)
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ class SubcredditsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@posts = @subcreddit.posts
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
9
app/helpers/subcreddits_helper.rb
Normal file
9
app/helpers/subcreddits_helper.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
module SubcredditsHelper
|
||||
def subcreddit_name(subcreddit)
|
||||
if subcreddit
|
||||
content_for(:title) { link_to subcreddit.name, subcreddit }
|
||||
else
|
||||
content_for(:title) { link_to 'frontpage', root_path }
|
||||
end
|
||||
end
|
||||
end
|
15
app/views/posts/_post_meta.html.slim
Normal file
15
app/views/posts/_post_meta.html.slim
Normal file
|
@ -0,0 +1,15 @@
|
|||
.posts.contents
|
||||
ul
|
||||
- @posts.order('created_at DESC').each_with_index do |post, rank|
|
||||
li
|
||||
.post
|
||||
p.title= link_to post.title, subcreddit_post_path(post.subcreddit, post)
|
||||
p.details
|
||||
= "submitted #{distance_of_time_in_words post.created_at, Time.now} ago by "
|
||||
== link_to post.user_username, post.user
|
||||
- if @subcreddit == nil
|
||||
= " to "
|
||||
== link_to "/c/#{post.subcreddit.slug}", post.subcreddit
|
||||
ul.links.list-inline
|
||||
li= link_to "#{post.comments_count} comments", subcreddit_post_path(post.subcreddit, post)
|
||||
li= link_to 'share', ''
|
1
app/views/posts/index.html.slim
Normal file
1
app/views/posts/index.html.slim
Normal file
|
@ -0,0 +1 @@
|
|||
== render 'post_meta'
|
|
@ -1,16 +1,5 @@
|
|||
- content_for(:title) { link_to @subcreddit.name, @subcreddit }
|
||||
- if @subcreddit.closed?
|
||||
- subcreddit_name(@subcreddit)
|
||||
- if @subcreddit && @subcreddit.closed?
|
||||
= "Board has been closed"
|
||||
- else
|
||||
.posts.contents
|
||||
ul
|
||||
- @subcreddit.posts.order('created_at DESC').each_with_index do |post, rank|
|
||||
li
|
||||
.post
|
||||
p.title= link_to post.title, subcreddit_post_path(@subcreddit, post)
|
||||
p.details
|
||||
= "submitted #{distance_of_time_in_words post.created_at, Time.now} ago by "
|
||||
== link_to post.user_username, post.user
|
||||
ul.links.list-inline
|
||||
li= link_to "#{post.comments_count} comments", subcreddit_post_path(@subcreddit, post)
|
||||
li= link_to 'share', ''
|
||||
== render partial: 'posts/post_meta'
|
||||
|
|
|
@ -3,6 +3,8 @@ Rails.application.routes.draw do
|
|||
get 'signin', to: 'user_sessions#new', as: :signin
|
||||
get 'signout', to: 'user_sessions#destroy', as: :signout
|
||||
|
||||
resources :posts, only: [:index]
|
||||
|
||||
resources :subcreddits, path: 'c', except: [:destroy] do
|
||||
resources :posts, path: '', constraints: { id: /\d+\-.+/ }, except: [:index] do
|
||||
resources :comments, path: '', constraints: { id: /\d+/ }, except: [:index]
|
||||
|
@ -12,5 +14,5 @@ Rails.application.routes.draw do
|
|||
resources :user_sessions, only: [:new, :create, :destroy]
|
||||
resources :users, path: 'u', only: [:show, :new, :create]
|
||||
|
||||
root to: 'subcreddits#index'
|
||||
root to: 'posts#index'
|
||||
end
|
||||
|
|
|
@ -14,6 +14,21 @@ describe PostsController, type: :controller do
|
|||
.to receive(:current_user).and_return(user)
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
let(:posts) { 10.times.collect { create(:post) } }
|
||||
before(:each) { get :index }
|
||||
|
||||
it 'should render :index' do
|
||||
expect(response).to render_template(:index)
|
||||
end
|
||||
|
||||
it 'should assign all Posts to @post' do
|
||||
posts.each do |post|
|
||||
expect(assigns(:posts)).to include(post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
let(:post) { create(:post) }
|
||||
before(:each) { get :show, subcreddit_id: post.subcreddit, id: post }
|
||||
|
|
|
@ -29,7 +29,8 @@ describe SubcredditsController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#show' do
|
||||
let(:subcreddit) { create(:subcreddit) }
|
||||
let!(:subcreddit) { create(:subcreddit) }
|
||||
let(:posts) { 5.times.collect { create(:post, subcreddit: subcreddit) } }
|
||||
before(:each) { get :show, id: subcreddit }
|
||||
|
||||
it 'should render :show' do
|
||||
|
@ -39,6 +40,10 @@ describe SubcredditsController, type: :controller do
|
|||
it 'should assign the Subcreddit to @subcreddit' do
|
||||
expect(assigns(:subcreddit)).to eq(subcreddit)
|
||||
end
|
||||
|
||||
it 'should assign the post to show to @post' do
|
||||
expect(assigns(:posts)).to eq(posts)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#new' do
|
||||
|
|
15
spec/helpers/subcreddits_helper_spec.rb
Normal file
15
spec/helpers/subcreddits_helper_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe SubcredditsHelper do
|
||||
describe '#subcreddit_name' do
|
||||
context 'when valid subcreddit provided' do
|
||||
let(:subcreddit) { create(:subcreddit) }
|
||||
|
||||
it 'should set the title to a link to the subcreddit'
|
||||
end
|
||||
|
||||
context 'when an invalid subcreddit is provided' do
|
||||
it 'should set the title to a link to the frontpage'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue