aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/refinery/blog/admin/settings_controller.rb2
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb2
-rw-r--r--app/models/refinery/blog/post.rb8
-rw-r--r--config/initializers/url_validator.rb5
-rw-r--r--db/migrate/20120223022021_add_access_count_to_posts.rb8
-rw-r--r--db/seeds.rb1
-rw-r--r--lib/generators/refinery/blog/blog_generator.rb6
-rw-r--r--lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb15
-rw-r--r--spec/requests/refinery/blog/posts_spec.rb36
9 files changed, 77 insertions, 6 deletions
diff --git a/app/controllers/refinery/blog/admin/settings_controller.rb b/app/controllers/refinery/blog/admin/settings_controller.rb
index 96687ad..68daa19 100644
--- a/app/controllers/refinery/blog/admin/settings_controller.rb
+++ b/app/controllers/refinery/blog/admin/settings_controller.rb
@@ -8,7 +8,7 @@ module Refinery
if request.post?
Refinery::Blog::Comment::Notification.recipients = params[:recipients]
- flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
+ flash[:notice] = t('updated', :scope => 'refinery.blog.admin.settings.notification_recipients',
:recipients => Refinery::Blog::Comment::Notification.recipients)
unless request.xhr? or from_dialog?
redirect_back_or_default(refinery.blog_admin_posts_path)
diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb
index abd60f4..bde3a9c 100644
--- a/app/controllers/refinery/blog/posts_controller.rb
+++ b/app/controllers/refinery/blog/posts_controller.rb
@@ -23,6 +23,8 @@ module Refinery
@comment = Comment.new
@canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical?
+
+ @post.increment!(:access_count, 1)
respond_with (@post) do |format|
format.html { present(@post) }
diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb
index dbea93f..ddfc3cc 100644
--- a/app/models/refinery/blog/post.rb
+++ b/app/models/refinery/blog/post.rb
@@ -78,6 +78,14 @@ module Refinery
def live
where( "published_at <= ? and draft = ?", Time.now, false)
end
+
+ def recent(count)
+ live.limit(count)
+ end
+
+ def popular(count)
+ unscoped.order("access_count DESC").limit(count)
+ end
def previous(item)
where(["published_at < ? and draft = ?", item.published_at, false]).limit(1)
diff --git a/config/initializers/url_validator.rb b/config/initializers/url_validator.rb
index 15635e0..d956d04 100644
--- a/config/initializers/url_validator.rb
+++ b/config/initializers/url_validator.rb
@@ -47,11 +47,10 @@ class RedirectFollower
def initialize(url, limit=5)
@url, @redirect_limit = url, limit
- logger.level = Logger::INFO
end
def logger
- @logger ||= Logger.new(STDOUT)
+ @logger ||= Rails.logger
end
def resolve
@@ -82,4 +81,4 @@ class RedirectFollower
response['location']
end
end
-end \ No newline at end of file
+end
diff --git a/db/migrate/20120223022021_add_access_count_to_posts.rb b/db/migrate/20120223022021_add_access_count_to_posts.rb
new file mode 100644
index 0000000..02cd131
--- /dev/null
+++ b/db/migrate/20120223022021_add_access_count_to_posts.rb
@@ -0,0 +1,8 @@
+class AddAccessCountToPosts < ActiveRecord::Migration
+ def change
+ add_column Refinery::Blog::Post.table_name, :access_count, :integer, :default => 0
+
+ add_index Refinery::Blog::Post.table_name, :access_count
+
+ end
+end \ No newline at end of file
diff --git a/db/seeds.rb b/db/seeds.rb
index eee5a4b..91018db 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -10,7 +10,6 @@ if defined?(Refinery::Page) and !Refinery::Page.exists?(:link_url => '/blog')
:title => "Blog",
:link_url => "/blog",
:deletable => false,
- :position => ((Refinery::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/blogs?(\/|\/.+?|)$"
)
diff --git a/lib/generators/refinery/blog/blog_generator.rb b/lib/generators/refinery/blog/blog_generator.rb
index 6c0a604..a9a54da 100644
--- a/lib/generators/refinery/blog/blog_generator.rb
+++ b/lib/generators/refinery/blog/blog_generator.rb
@@ -1,6 +1,12 @@
module Refinery
class BlogGenerator < Rails::Generators::Base
+ source_root File.expand_path("../templates", __FILE__)
+
+ def generate_blog_initializer
+ template "config/initializers/refinery/blog.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "blog.rb")
+ end
+
def rake_db
rake("refinery_blog:install:migrations")
end
diff --git a/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb b/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb
new file mode 100644
index 0000000..8a2bc8e
--- /dev/null
+++ b/lib/generators/refinery/blog/templates/config/initializers/refinery/blog.rb.erb
@@ -0,0 +1,15 @@
+Refinery::Blog.configure do |config|
+ # config.validate_source_url = <%= Refinery::Blog.validate_source_url.inspect %>
+
+ # config.comments_per_page = <%= Refinery::Blog.comments_per_page.inspect %>
+
+ # config.posts_per_page = <%= Refinery::Blog.posts_per_page.inspect %>
+
+ # config.post_teaser_length = <%= Refinery::Blog.post_teaser_length.inspect %>
+
+ # config.approximate_ascii = <%= Refinery::Blog.approximate_ascii.inspect %>
+
+ # config.strip_non_ascii = <%= Refinery::Blog.strip_non_ascii.inspect %>
+
+ # config.share_this_key = <%= Refinery::Blog.share_this_key.inspect %>
+end
diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb
index 815ca26..6f34cb9 100644
--- a/spec/requests/refinery/blog/posts_spec.rb
+++ b/spec/requests/refinery/blog/posts_spec.rb
@@ -101,8 +101,42 @@ module Refinery
comment.body.should eq(body)
end
end
+
+ context "post popular" do
+ let(:blog_post) { FactoryGirl.create(:blog_post) }
+ let(:blog_post2) { FactoryGirl.create(:blog_post) }
+
+ before do
+ visit refinery.blog_post_path(blog_post)
+ end
+
+ it "should increment access count" do
+ blog_post.reload.access_count.should eq(1)
+ visit refinery.blog_post_path(blog_post)
+ blog_post.reload.access_count.should eq(2)
+ end
+
+ it "should be most popular" do
+ Refinery::Blog::Post.popular(2).first.should eq(blog_post)
+ end
+ end
+
+ context "post recent" do
+ let(:blog_post) { FactoryGirl.create(:blog_post) }
+ let(:blog_post2) { FactoryGirl.create(:blog_post) }
+
+ before do
+ visit refinery.blog_post_path(blog_post2)
+ visit refinery.blog_post_path(blog_post)
+ end
+
+ it "should be the most recent" do
+ Refinery::Blog::Post.recent(2).first.should eq(blog_post2)
+ end
+ end
+
end
-
+
describe "#show draft preview" do
let(:blog_post) { FactoryGirl.create(:blog_post_draft) }
context "when logged in as admin" do