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:
commit
d5c7229f90
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_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
|
||||||
|
|
|
@ -6,6 +6,7 @@ class SubcredditsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@posts = @subcreddit.posts
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
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 }
|
- 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', ''
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
|
@ -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
|
||||||
|
|
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