Add a quick front apge

This commit is contained in:
Andrew Tomaka 2015-08-12 16:45:30 -04:00
parent 0e50dd92f8
commit 6993bb0ecd
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_post, except: [:index, :new, :create]
before_filter :set_subcreddit before_filter :set_subcreddit
def index
@posts = Post.all
end
def show def show
@comments = @post.comments.arrange(order: :created_at) @comments = @post.comments.arrange(order: :created_at)
end end

View file

@ -6,6 +6,7 @@ class SubcredditsController < ApplicationController
end end
def show def show
@posts = @subcreddit.posts
end end
def new 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 } - subcreddit_name(@subcreddit)
- if @subcreddit.closed? - if @subcreddit && @subcreddit.closed?
= "Board has been closed" = "Board has been closed"
- else - else
.posts.contents == render partial: 'posts/post_meta'
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', ''

View file

@ -3,6 +3,8 @@ Rails.application.routes.draw do
get 'signin', to: 'user_sessions#new', as: :signin get 'signin', to: 'user_sessions#new', as: :signin
get 'signout', to: 'user_sessions#destroy', as: :signout get 'signout', to: 'user_sessions#destroy', as: :signout
resources :posts, only: [:index]
resources :subcreddits, path: 'c', except: [:destroy] do resources :subcreddits, path: 'c', except: [:destroy] do
resources :posts, path: '', constraints: { id: /\d+\-.+/ }, except: [:index] do resources :posts, path: '', constraints: { id: /\d+\-.+/ }, except: [:index] do
resources :comments, path: '', constraints: { id: /\d+/ }, except: [:index] 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 :user_sessions, only: [:new, :create, :destroy]
resources :users, path: 'u', only: [:show, :new, :create] resources :users, path: 'u', only: [:show, :new, :create]
root to: 'subcreddits#index' root to: 'posts#index'
end end

View file

@ -14,6 +14,21 @@ describe PostsController, type: :controller do
.to receive(:current_user).and_return(user) .to receive(:current_user).and_return(user)
end 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 describe '#show' do
let(:post) { create(:post) } let(:post) { create(:post) }
before(:each) { get :show, subcreddit_id: post.subcreddit, id: post } before(:each) { get :show, subcreddit_id: post.subcreddit, id: post }

View file

@ -29,7 +29,8 @@ describe SubcredditsController, type: :controller do
end end
describe '#show' do 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 } before(:each) { get :show, id: subcreddit }
it 'should render :show' do it 'should render :show' do
@ -39,6 +40,10 @@ describe SubcredditsController, type: :controller do
it 'should assign the Subcreddit to @subcreddit' do it 'should assign the Subcreddit to @subcreddit' do
expect(assigns(:subcreddit)).to eq(subcreddit) expect(assigns(:subcreddit)).to eq(subcreddit)
end end
it 'should assign the post to show to @post' do
expect(assigns(:posts)).to eq(posts)
end
end end
describe '#new' do 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