Permalink
Browse files

Merge pull request #469 from refinery/remove-controller-helper

Move ControllerHelper functionality to BlogController
  • Loading branch information...
2 parents 3cbf658 + 2434ae2 commit fcb0ed25271ff3cd173e12a751dc3fc2a903d03f @parndt parndt committed on GitHub Nov 26, 2016
@@ -2,16 +2,42 @@ module Refinery
module Blog
class BlogController < ::ApplicationController
- include ControllerHelper
-
helper :'refinery/blog/posts'
- before_filter :find_page, :find_all_blog_categories
+ before_action :find_page, :find_all_blog_categories
protected
+ def find_all_blog_categories
+ @categories = Refinery::Blog::Category.translated
+ end
+
+ def find_blog_post
+ unless (@post = post_finder_scope.with_globalize.friendly.find(params[:id])).try(:live?)
+ if current_refinery_user && current_refinery_user.has_plugin?("refinerycms_blog")
+ @post = post_finder_scope.friendly.find(params[:id])
+ else
+ error_404
+ end
+ end
+ end
+
+ def find_all_blog_posts
+ @posts = post_finder_scope.live.includes(
+ :comments, :categories, :translations
+ ).with_globalize.newest_first.page(params[:page])
+ end
+
def find_page
@page = Refinery::Page.find_by(:link_url => Refinery::Blog.page_url)
end
+
+ def find_tags
+ @tags = post_finder_scope.live.tag_counts_on(:tags)
+ end
+
+ def post_finder_scope
+ Refinery::Blog::Post
+ end
end
end
end
@@ -2,35 +2,7 @@ module Refinery
module Blog
module ControllerHelper
- protected
-
- def find_blog_post
- unless (@post = Refinery::Blog::Post.with_globalize.friendly.find(params[:id])).try(:live?)
- if current_refinery_user && current_refinery_user.has_plugin?("refinerycms_blog")
- @post = Refinery::Blog::Post.friendly.find(params[:id])
- else
- error_404
- end
- end
- end
-
- def find_all_blog_posts
- @posts = post_finder_scope.live.includes(
- :comments, :categories, :translations
- ).with_globalize.newest_first.page(params[:page])
- end
-
- def find_tags
- @tags = Refinery::Blog::Post.live.tag_counts_on(:tags)
- end
-
- def find_all_blog_categories
- @categories = Refinery::Blog::Category.translated
- end
-
- def post_finder_scope
- Refinery::Blog::Post
- end
+
end
end
end
@@ -1,10 +1,10 @@
<% if @categories.any? %>
<h2><%= t('.title') %></h2>
- <ul id='categories'>
+ <ul id="categories">
<% @categories.each do |category| %>
- <li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
+ <li<%= " class='selected'" if @category.present? && @category.id == category.id %>>
<%= link_to "#{category.title} (#{category.post_count})", refinery.blog_category_path(category) %>
</li>
<% end %>
</ul>
-<% end %>
+<% end %>
@@ -1,27 +0,0 @@
-require 'spec_helper'
-
-module Refinery
- module Blog
- describe ControllerHelper, type: :helper do
- describe "#find_tags" do
- let(:tags) { helper.find_tags }
-
- context "with draft posts" do
- let!(:blog_post) { FactoryGirl.create(:blog_post, :draft => true, :tag_list => "first, second" ) }
-
- it "does not return tags" do
- expect(tags).to be_empty
- end
- end
-
- context "with live posts" do
- let!(:blog_post) { FactoryGirl.create(:blog_post, :tag_list => "first, second" ) }
-
- it "does return tags" do
- expect(tags).to_not be_empty
- end
- end
- end
- end
- end
-end

0 comments on commit fcb0ed2

Please sign in to comment.