tb_blog 1.3.5 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/javascripts/admin/blog/posts.js +1 -1
  4. data/app/controllers/admin/post_categories_controller.rb +3 -3
  5. data/app/controllers/admin/posts_controller.rb +4 -13
  6. data/app/controllers/concerns/render_post_action.rb +7 -0
  7. data/app/controllers/posts_controller.rb +10 -11
  8. data/app/helpers/admin/posts_helper.rb +1 -1
  9. data/app/helpers/blog_helper.rb +1 -1
  10. data/app/models/spud_post.rb +1 -1
  11. data/app/models/spud_post_category.rb +0 -1
  12. data/app/models/spud_post_site.rb +1 -1
  13. data/app/models/{spud → tb_core}/spud_post_model.rb +20 -17
  14. data/app/views/posts/index.html.erb +1 -1
  15. data/app/views/posts/index.rss.builder +5 -5
  16. data/app/views/posts/show.html.erb +1 -1
  17. data/lib/generators/spud/blog/random_posts_generator.rb +1 -1
  18. data/lib/spud_blog/engine.rb +8 -9
  19. data/lib/spud_blog/version.rb +1 -1
  20. data/spec/controllers/admin/posts_controller_spec.rb +6 -9
  21. data/spec/controllers/posts_controller_spec.rb +11 -3
  22. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  23. data/spec/dummy/config/environments/development.rb +0 -7
  24. data/spec/dummy/config/environments/production.rb +0 -4
  25. data/spec/dummy/config/environments/test.rb +1 -1
  26. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  27. data/spec/dummy/db/migrate/20180730141254_create_active_storage_tables.active_storage.rb +26 -0
  28. data/spec/dummy/db/schema.rb +112 -110
  29. data/spec/factories/spud_post_factories.rb +3 -3
  30. data/spec/helpers/admin/posts_helper_spec.rb +1 -1
  31. data/spec/helpers/blog_helper_spec.rb +1 -1
  32. data/spec/models/spud_post_spec.rb +2 -2
  33. data/spec/rails_helper.rb +9 -2
  34. metadata +95 -95
  35. data/app/controllers/concerns/post_view_for_action.rb +0 -11
  36. data/spec/dummy/db/migrate/20161020155436_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70bb8cf7f6dbeee3e6e1f371513b89d10135262c
4
- data.tar.gz: e1183d3648505305f4d973e1fe2d005641f10536
3
+ metadata.gz: 8c8bb8dfa74cf36c2c41159cb5a6aa995a3499a3
4
+ data.tar.gz: 43a7bc493de1c0a89b8c1d460a3767c9343d789e
5
5
  SHA512:
6
- metadata.gz: 943ec8e61fb4b5a1d45a2661267492887d36d03b6c5687754efb2afaa52cac020f304bbc749b7c8179baa88908394856791512fba9352f3ab99664a29e6c4ae3
7
- data.tar.gz: 4e41738e830ede90f06149f3ca017cd3597ba1510f36cd2ca1e9b7a5f7d0333ac3bdcf3c0347174eb078610d740ae5b8c5f585beccefdadbcb22bc9cf0a03a08
6
+ metadata.gz: e1f8027428d3d63313405febe56b4ebc7662284199914b313e3d789f485cb024c33df767e33f464b50d44b17a2ba6a428c2752a6e5a68a185e634bd5d252e218
7
+ data.tar.gz: b31bfe914eda56b33f4f77486865e903fa92a8905afa4d68fed4097ccb21f4c58ce5276a0b782ad600844194a6d1a74f113a14034fa6d0b460d903b0a19927cb
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
23
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
26
  Bundler::GemHelper.install_tasks
@@ -120,7 +120,7 @@ var clickedPreviewButton = function(e){
120
120
  // Cross site scripting tag
121
121
  var csrf = document.createElement('input');
122
122
  csrf.name = 'authenticity_token';
123
- csrf.value = tb.util.getCsrfToken();
123
+ csrf.value = Rails.csrfToken();
124
124
  $previewForm.append(csrf);
125
125
 
126
126
  // Submit it
@@ -15,11 +15,11 @@ class Admin::PostCategoriesController < Admin::ApplicationController
15
15
  end
16
16
 
17
17
  def update
18
- if @post_category.update_attributes(category_params)
18
+ if @post_category.update(category_params)
19
19
  flash.now[:notice] = 'Post Category was successfully updated'
20
20
  respond_with @post_category, location: admin_post_categories_path
21
21
  else
22
- render 'new', status: 422
22
+ render 'new', status: :unprocessable_entity
23
23
  end
24
24
  end
25
25
 
@@ -34,7 +34,7 @@ class Admin::PostCategoriesController < Admin::ApplicationController
34
34
  flash.now[:notice] = 'Post Category was successfully created'
35
35
  respond_with @post_category, location: admin_post_categories_path
36
36
  else
37
- render 'new', status: 422
37
+ render 'new', status: :unprocessable_entity
38
38
  end
39
39
  end
40
40
 
@@ -1,6 +1,6 @@
1
1
  class Admin::PostsController < Admin::ApplicationController
2
2
  include BlogUrlHelpers
3
- include PostViewForAction
3
+ include RenderPostAction
4
4
 
5
5
  respond_to :html, :xml, :json
6
6
  before_action :load_blog
@@ -21,9 +21,7 @@ class Admin::PostsController < Admin::ApplicationController
21
21
  end
22
22
 
23
23
  def update
24
- if @post.update_attributes(post_params)
25
- flash[:notice] = 'Post was successfully updated.'
26
- end
24
+ flash[:notice] = 'Post was successfully updated.' if @post.update(post_params)
27
25
  respond_with @post, location: admin_posts_path
28
26
  end
29
27
 
@@ -51,12 +49,7 @@ class Admin::PostsController < Admin::ApplicationController
51
49
  SpudPost.new
52
50
  end
53
51
  @post.assign_attributes(post_params)
54
- @post.postprocess_content()
55
- render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
56
- end
57
-
58
- def render_preview
59
- render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
52
+ render_post_action :show, controller: :posts, layout: @config.layout
60
53
  end
61
54
 
62
55
  private
@@ -71,9 +64,7 @@ class Admin::PostsController < Admin::ApplicationController
71
64
 
72
65
  def post_params
73
66
  permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :custom_author, category_ids: []]
74
- if Spud::Blog.permitted_attributes.present?
75
- permitted += Spud::Blog.permitted_attributes
76
- end
67
+ permitted += Spud::Blog.permitted_attributes if Spud::Blog.permitted_attributes.present?
77
68
  p = params.require(:spud_post).permit(permitted)
78
69
  p[:updated_at] = DateTime.now
79
70
  return p
@@ -0,0 +1,7 @@
1
+ module RenderPostAction
2
+ extend ActiveSupport::Concern
3
+
4
+ def render_post_action(action, args = {})
5
+ render action, args.merge(prefixes: [@config.key, 'posts'])
6
+ end
7
+ end
@@ -1,6 +1,6 @@
1
1
  class PostsController < ApplicationController
2
2
  include BlogUrlHelpers
3
- include PostViewForAction
3
+ include RenderPostAction
4
4
 
5
5
  respond_to :html, :json, :rss
6
6
 
@@ -13,18 +13,18 @@ class PostsController < ApplicationController
13
13
  @posts = @posts.search(params[:search]) if params[:search]
14
14
  respond_with @posts do |format|
15
15
  format.html do
16
- render post_view_for_action(:index)
16
+ render_post_action :index
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
21
  # The sole purpose of this action is to redirect from a POST to an seo-friendly url
22
22
  def filter
23
- if !params[:category_url_name].blank? && !params[:archive_date].blank?
23
+ if params[:category_url_name].present? && params[:archive_date].present?
24
24
  redirect_to post_category_archive_path(params[:category_url_name], params[:archive_date])
25
- elsif !params[:category_url_name].blank?
25
+ elsif params[:category_url_name].present?
26
26
  redirect_to post_category_path(params[:category_url_name])
27
- elsif !params[:archive_date].blank?
27
+ elsif params[:archive_date].present?
28
28
  redirect_to post_archive_path(params[:archive_date])
29
29
  else
30
30
  redirect_to posts_path
@@ -39,20 +39,20 @@ class PostsController < ApplicationController
39
39
  return
40
40
  end
41
41
  respond_with @posts do |format|
42
- format.html { render post_view_for_action :index }
42
+ format.html { render_post_action :index }
43
43
  end
44
44
  end
45
45
 
46
46
  def archive
47
47
  @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
48
48
  respond_with @posts do |format|
49
- format.html { render post_view_for_action :index }
49
+ format.html { render_post_action :index }
50
50
  end
51
51
  end
52
52
 
53
53
  def show
54
54
  respond_with @post do |format|
55
- format.html { render post_view_for_action :show }
55
+ format.html { render_post_action :show }
56
56
  end
57
57
  end
58
58
 
@@ -60,7 +60,7 @@ class PostsController < ApplicationController
60
60
 
61
61
  def find_post
62
62
  @post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(url_name: params[:id]).first
63
- raise Spud::NotFoundError, item: 'post' if @post.blank? || @post.is_private?
63
+ raise TbCore::NotFoundError, item: 'post' if @post.blank? || @post.is_private?
64
64
  end
65
65
 
66
66
  def load_page_number
@@ -81,8 +81,7 @@ class PostsController < ApplicationController
81
81
  def load_blog
82
82
  @config = SpudBlogConfig.find(params[:blog_key])
83
83
  if @config.blank?
84
- raise Spud::NotFoundError(item: 'blog')
85
- return false
84
+ raise TbCore::NotFoundError(item: 'blog')
86
85
  else
87
86
  self.class.layout(@config.layout)
88
87
  end
@@ -13,7 +13,7 @@ module Admin::PostsHelper
13
13
 
14
14
  def link_to_disqus_comment_count(post)
15
15
  # TODO: It would be great to link directly to the thread
16
- # ie: https://myblog.disqus.com/admin/moderate/#/all/search/thread:4584301535
16
+ # ie: https://myblog.disqus.com/admin/moderate/#/all/search/thread:4584301535
17
17
  #
18
18
  # However, we do not know the thread ID at this time. We may be able to fetch it
19
19
  # via the Disqus JavaScript API.
@@ -19,7 +19,7 @@ module BlogHelper
19
19
  end
20
20
 
21
21
  def spud_blog_rss_link
22
- return tag :link, rel: 'alternate', type: 'application/rss+xml', title: "#{Spud::Core.site_name} Blog RSS", href: posts_path(format: :rss)
22
+ return tag :link, rel: 'alternate', type: 'application/rss+xml', title: "#{TbCore.site_name} Blog RSS", href: posts_path(format: :rss)
23
23
  end
24
24
 
25
25
  def disqus_comment_count_for_post(post)
@@ -1,3 +1,3 @@
1
- class SpudPost < Spud::SpudPostModel
1
+ class SpudPost < TbCore::SpudPostModel
2
2
  # Copy this file to your app to extend the base SpudPost model
3
3
  end
@@ -1,5 +1,4 @@
1
1
  class SpudPostCategory < ActiveRecord::Base
2
- spud_searchable
3
2
 
4
3
  has_and_belongs_to_many :posts,
5
4
  class_name: 'SpudPost',
@@ -2,7 +2,7 @@ class SpudPostSite < ActiveRecord::Base
2
2
  belongs_to :spud_post
3
3
 
4
4
  def spud_site
5
- return Spud::Core.site_config_for_id(spud_site_id)
5
+ return TbCore.site_config_for_id(spud_site_id)
6
6
  end
7
7
 
8
8
  end
@@ -1,10 +1,8 @@
1
- class Spud::SpudPostModel < ActiveRecord::Base
1
+ class TbCore::SpudPostModel < ActiveRecord::Base
2
2
  include TbRedirects::HasRedirects
3
3
 
4
4
  self.table_name = 'spud_posts'
5
5
 
6
- spud_searchable
7
-
8
6
  has_many :spud_post_categories_posts, foreign_key: 'spud_post_id'
9
7
  has_many :categories,
10
8
  class_name: 'SpudPostCategory',
@@ -34,8 +32,6 @@ class Spud::SpudPostModel < ActiveRecord::Base
34
32
  before_validation :set_url_name
35
33
  before_validation :set_identifier
36
34
 
37
- acts_as_tb_liquid_content
38
-
39
35
  def self.for_spud_site(_spud_site_id)
40
36
  ActiveSupport::Deprecation.warn 'SpudBlog.for_spud_site is deprecated and will be removed in the future'
41
37
  return all()
@@ -56,7 +52,7 @@ class Spud::SpudPostModel < ActiveRecord::Base
56
52
  def self.from_archive(date_string)
57
53
  date = Date.strptime(date_string, '%Y-%b')
58
54
  return where(published_at: date..date.end_of_month)
59
- rescue
55
+ rescue StandardError
60
56
  logger.debug 'fallback'
61
57
  return where('')
62
58
  end
@@ -76,18 +72,23 @@ class Spud::SpudPostModel < ActiveRecord::Base
76
72
  end
77
73
  end
78
74
 
79
- def postprocess_content
80
- template = Liquid::Template.parse(content)
81
- self.content_processed = template.render()
82
- end
75
+ # def postprocess_content
76
+ # template = Liquid::Template.parse(content)
77
+ # self.content_processed = template.render()
78
+ # end
79
+ #
80
+ # def content_processed
81
+ # postprocess_content if self[:content_processed].blank?
82
+ # self[:content_processed]
83
+ # end
83
84
 
84
- def content_processed
85
- postprocess_content if self[:content_processed].blank?
86
- self[:content_processed]
87
- end
85
+ # def content_processed=(content)
86
+ # self[:content_processed] = content
87
+ # end
88
88
 
89
- def content_processed=(content)
90
- self[:content_processed] = content
89
+ def content_processed
90
+ ActiveSupport::Deprecation.warn '#content_processed is deprecated. Use #content instead.'
91
+ content
91
92
  end
92
93
 
93
94
  def display_date
@@ -109,8 +110,10 @@ class Spud::SpudPostModel < ActiveRecord::Base
109
110
  def author_name
110
111
  if custom_author.present?
111
112
  custom_author
112
- else
113
+ elsif author.present?
113
114
  author.full_name
115
+ else
116
+ ''
114
117
  end
115
118
  end
116
119
 
@@ -35,7 +35,7 @@
35
35
  <p><%= disqus_comment_count_for_post(post) %></p>
36
36
  <% end %>
37
37
  <div class="blog-post-content">
38
- <%= truncate_html post.content_processed.html_safe, :length => 250 %>
38
+ <%= truncate_html post.content.html_safe, :length => 250 %>
39
39
  </div>
40
40
  </div>
41
41
  <% end %>
@@ -1,9 +1,9 @@
1
- xml.instruct! :xml, :version => "1.0"
2
- xml.rss :version => "2.0" do
1
+ xml.instruct! :xml, version: '1.0'
2
+ xml.rss version: '2.0' do
3
3
  xml.channel do
4
- xml.title "#{Spud::Core.site_name} Blog Articles"
5
- xml.description "Blog articles for #{Spud::Core.site_name}"
6
- xml.link posts_path(:format => :rss)
4
+ xml.title "#{TbCore.site_name} Blog Articles"
5
+ xml.description "Blog articles for #{TbCore.site_name}"
6
+ xml.link posts_path(format: :rss)
7
7
 
8
8
  for article in @posts
9
9
  xml.item do
@@ -25,7 +25,7 @@
25
25
  </p>
26
26
  <% end %>
27
27
  <div class="blog-post-content">
28
- <%= raw @post.content_processed %>
28
+ <%= raw @post.content %>
29
29
  </div>
30
30
  <p><%= link_to 'Back to all posts', posts_path %></p>
31
31
  </div>
@@ -35,7 +35,7 @@ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
35
35
 
36
36
  def random_word
37
37
  chars = 'abcdefghjkmnpqrstuvwxyz'
38
- length = rand(8) + 1
38
+ length = rand(1..8)
39
39
  return (1..length).collect { chars[rand(chars.length)] }.join('')
40
40
  end
41
41
 
@@ -1,6 +1,5 @@
1
1
  require 'tb_core'
2
2
  require 'tb_redirects'
3
- require 'tb_liquid'
4
3
  require 'truncate_html'
5
4
 
6
5
  module Spud
@@ -46,22 +45,22 @@ module Spud
46
45
  url: "admin/#{config.key}",
47
46
  thumbnail: 'admin/posts_thumb.png'
48
47
  }
49
- Spud::Core.config.admin_applications += [blog_app]
48
+ TbCore.config.admin_applications += [blog_app]
50
49
  end
51
50
  end
52
51
 
53
52
  initializer 'tb_blog.assets' do
54
- Spud::Core.append_admin_javascripts('admin/blog/application')
55
- Spud::Core.append_admin_stylesheets('admin/blog/application')
53
+ TbCore.append_admin_javascripts('admin/blog/application')
54
+ TbCore.append_admin_stylesheets('admin/blog/application')
56
55
  Rails.application.config.assets.precompile += ['admin/posts_thumb.png', 'admin/news_thumb.png']
57
56
  end
58
57
 
59
58
  # Triggers a I18n.enforce_available_locales deprecation warning. Why?
60
- # initializer 'tb_blog.user_association', :after => 'tb_core.model_overrides' do
61
- # SpudUser.class_eval do
62
- # has_many :posts, :class_name => 'SpudPost'
63
- # end
64
- # end
59
+ initializer 'tb_blog.user_association', after: 'tb_core.model_overrides' do
60
+ SpudUser.class_eval do
61
+ has_many :posts, class_name: 'SpudPost', dependent: :nullify
62
+ end
63
+ end
65
64
  end
66
65
  end
67
66
  end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Blog
3
- VERSION = '1.3.5'.freeze
3
+ VERSION = '1.4.3'.freeze
4
4
  end
5
5
  end
@@ -8,18 +8,18 @@ describe Admin::PostsController, type: :controller do
8
8
 
9
9
  describe '#create_redirect_if_necessary' do
10
10
  before(:each) do
11
- @post = FactoryGirl.create(:spud_post)
11
+ @post = FactoryBot.create(:spud_post)
12
12
  end
13
13
 
14
14
  it 'should create a redirect' do
15
15
  expect do
16
- put :update, id: @post.id, spud_post: { url_name: 'new-url' }, blog_key: 'blog'
16
+ put :update, params: { id: @post.id, spud_post: { url_name: 'new-url' }, blog_key: 'blog' }
17
17
  end.to change(@post.tb_redirects, :count).by(1)
18
18
  end
19
19
 
20
20
  it 'should not create a redirect' do
21
21
  expect do
22
- put :update, id: @post.id, spud_post: { title: 'Hello World' }, blog_key: 'blog'
22
+ put :update, params: { id: @post.id, spud_post: { title: 'Hello World' }, blog_key: 'blog' }
23
23
  end.to_not change(@post.tb_redirects, :count)
24
24
  end
25
25
  end
@@ -28,18 +28,15 @@ describe Admin::PostsController, type: :controller do
28
28
  context 'with a new post' do
29
29
  it 'should set the attributes without saving' do
30
30
  expect do
31
- post :preview, blog_key: 'blog', post_id: nil, spud_post: { title: 'Hello World' }
31
+ post :preview, params: { blog_key: 'blog', post_id: nil, spud_post: { title: 'Hello World' } }
32
32
  end.to_not change(SpudPost, :count)
33
33
  end
34
34
  end
35
35
  context 'with an existing post' do
36
36
  it 'should set the attributes without saving' do
37
- @post = FactoryGirl.create(:spud_post)
37
+ @post = FactoryBot.create(:spud_post)
38
38
  expect do
39
- post :preview,
40
- blog_key: @post.blog_key,
41
- post_id: @post.id,
42
- spud_post: { title: 'Hello World' }
39
+ post :preview, params: { blog_key: @post.blog_key, post_id: @post.id, spud_post: { title: 'Hello World' } }
43
40
  @post.reload
44
41
  end.to_not change(@post, :title)
45
42
  end
@@ -8,8 +8,8 @@ describe PostsController, type: :controller do
8
8
 
9
9
  describe 'index' do
10
10
  it 'should display a list of posts' do
11
- 2.times { |_i| FactoryGirl.create(:spud_post) }
12
- get :index, blog_key: 'blog'
11
+ 2.times { |_i| FactoryBot.create(:spud_post) }
12
+ get :index, params: { blog_key: 'blog' }
13
13
  expect(assigns(:posts).count).to be > 1
14
14
  end
15
15
 
@@ -21,10 +21,18 @@ describe PostsController, type: :controller do
21
21
  {}
22
22
  end
23
23
  }
24
- get :index, blog_key: 'blog'
24
+ get :index, params: { blog_key: 'blog' }
25
25
  expect(assigns(:posts).count).to be 0
26
26
  Spud::Blog.config.query_for_user = nil
27
27
  end
28
28
  end
29
29
 
30
+ describe 'show' do
31
+ it 'renders the post' do
32
+ post = FactoryBot.create(:spud_post)
33
+ get :show, params: { blog_key: post.blog_key, id: post.url_name }
34
+ expect(response).to have_http_status(:success)
35
+ end
36
+ end
37
+
30
38
  end