Merge branch 'atomaka/feature/front-page' into 'master'

Add a quick front apge

Hack in a front page so that we can keep trucking along.  This uses posts#index to show all posts.  We also added some title stuff in this commit.

See merge request !21
This commit is contained in:
Andrew Tomaka 2015-12-11 20:08:29 +00:00
commit d5c7229f90
10 changed files with 72 additions and 16 deletions

View file

@ -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

View file

@ -6,6 +6,7 @@ class SubcredditsController < ApplicationController
end
def show
@posts = @subcreddit.posts
end
def new

View 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

View 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', ''

View file

@ -0,0 +1 @@
== render 'post_meta'

View file

@ -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'

View file

@ -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

View file

@ -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 }

View file

@ -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

View 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