beef-articles 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ test/*.log
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.12
1
+ 0.3.13
@@ -1,6 +1,6 @@
1
1
  class Admin::ArticlesController < Admin::BaseController
2
2
  unloadable
3
- sortable_attributes :published_at, :title, :permalink, :published_to, :body, :description, :allow_comments
3
+ sortable_attributes :created_at, :published_at, :title, :permalink, :published_to, :body, :description, :allow_comments, :created_by => 'created_by.name'
4
4
 
5
5
  # GET /articles
6
6
  # GET /articles.xml
@@ -73,8 +73,11 @@ class Admin::CategoriesController < Admin::BaseController
73
73
  # DELETE /categories/1.xml
74
74
  def destroy
75
75
  @category = Category.find(params[:id])
76
- @category.destroy
77
- flash[:notice] = 'Category was successfully deleted.'
76
+ if @category.destroy
77
+ flash[:notice] = 'Category was successfully deleted.'
78
+ else
79
+ flash[:error] = 'Category could not be deleted.'
80
+ end
78
81
 
79
82
  respond_to do |format|
80
83
  format.html { redirect_to(admin_categories_url) }
@@ -20,7 +20,7 @@ class ArticlesController < ApplicationController
20
20
 
21
21
  @articles = Article.in_time_delta( params[:year], params[:month], params[:day] ).published.tagged_with(params[:tag], :on => :tags).authored_by(@user).categorised(@category).paginate( :page => params[:page], :per_page => params[:per_page] || Article.per_page, :include => [:created_by] )
22
22
 
23
- @tags = Article.published.authored_by(@user).categorised(@category).tag_counts
23
+ @tags = Article.published.authored_by(@user).categorised(@category).tag_counts(:limit => 20)
24
24
 
25
25
  respond_to do |format|
26
26
  format.html # index.html.erb
@@ -8,14 +8,15 @@ class CommentsController < ApplicationController
8
8
 
9
9
  @comment = @commentable.comments.build(params[:comment])
10
10
 
11
- unless Settings.defensio_api_key.blank?
11
+ if defined?( Viking ) and !Settings.defensio_api_key.blank?
12
+ viking = Viking.connect(:defensio, :api_key => Settings.defensio_api_key, :blog => root_url)
12
13
  viking_response = viking.check_comment( :user_ip => request.remote_ip,
13
14
  :article_date => @commentable.published_at,
14
- :comment_author => @comment.author,
15
+ :comment_author => @comment.name,
15
16
  :comment_type => 'comment',
16
17
  :comment_content => @comment.comment,
17
18
  :comment_author_email => @comment.email,
18
- :user_logged_in => logged_in?,
19
+ :user_logged_in => signed_in?,
19
20
  :referrer => request.referer,
20
21
  :permalink => @commentable )
21
22
 
@@ -11,7 +11,7 @@ module ArticlesHelper
11
11
  tabs = Article.published.all(:select => 'users.name, users.permalink', :group => 'created_by_id', :joins => :created_by ).collect do |user|
12
12
  content_tag :li, link_to( user.name, articles_authored_path(user.permalink) )
13
13
  end
14
- content_tag( :h3, 'Authors' ) + content_tag( :ul, tabs.join, :class => "authors" ) if tabs.any?
14
+ content_tag( :h2, 'Authors' ) + content_tag( :ul, tabs.join, :class => "authors" ) if tabs.any?
15
15
  end
16
16
 
17
17
  def comments_link(article)
@@ -94,17 +94,17 @@ module ArticlesHelper
94
94
  content_tag :ul, html, html_options.reverse_merge!( :class => 'archive' ) unless html.empty?
95
95
  end
96
96
 
97
- def related_articles(content_node, &block)
98
- articles = Article.find_tagged_with content_node.tag_list, :conditions => ['published_at <= ? AND content_nodes.id != ?', Time.now, content_node.id ], :limit => 3, :include => :created_by
97
+ def related_articles(taggable, &block)
98
+ articles = Article.published.all(taggable.related_search_options(:tags, Article, :limit => 3))
99
+ return if articles.empty?
99
100
  if block_given?
100
101
  yield(articles)
101
102
  else
102
- articles_list(articles)
103
+ content_tag(:div, content_tag( :h2, 'Related' ) + articles_list(articles), :class => "related")
103
104
  end
104
105
  end
105
106
 
106
107
  def recent_articles(options = {}, &block)
107
- options.merge!(:order => 'published_at DESC')
108
108
  options.reverse_merge!(:limit => 3)
109
109
  articles = Article.published.all(options)
110
110
  if block_given?
@@ -116,7 +116,7 @@ module ArticlesHelper
116
116
 
117
117
  def articles_list(articles)
118
118
  return if articles.empty?
119
- articles.collect! { |article| content_tag( 'li', "#{link_to(article.title, article)}") }
119
+ articles.collect! { |article| content_tag( 'li', "#{link_to(article.title, article)} #{article.published_at.to_formatted_s(:short_dot)}") }
120
120
  content_tag( 'ul', articles.join, :class => 'article-list' )
121
121
  end
122
122
 
@@ -9,6 +9,22 @@ class Category < ActiveRecord::Base
9
9
  named_scope :with, lambda { |many| {:joins => many.to_sym, :group => 'categories.id'} }
10
10
 
11
11
  before_save :set_url
12
+ before_destroy :no_content?
13
+
14
+ def has_content?
15
+ has_content = false
16
+ self.class.reflect_on_all_associations.each do |assoc|
17
+ if send(assoc.name).any?
18
+ has_content = true
19
+ break
20
+ end
21
+ end
22
+ return has_content
23
+ end
24
+
25
+ def no_content?
26
+ !has_content?
27
+ end
12
28
 
13
29
  private
14
30
 
@@ -9,10 +9,12 @@
9
9
  <table>
10
10
  <thead>
11
11
  <tr>
12
- <%= sortable_table_header :name => "Title", :sort => "title" %>
13
- <th>Status</th>
14
- <th>Author</th>
12
+ <%= sortable_table_header :name => "Title", :sort => "title" %>
13
+ <%= sortable_table_header :name => "Status", :sort => "published_at" %>
14
+ <%= sortable_table_header :name => "Author", :sort => "created_by" %>
15
+ <%= sortable_table_header :name => "Editor", :sort => "updated_by" %>
15
16
  <%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
17
+ <%= sortable_table_header :name => "Created", :sort => "created_at" %>
16
18
  <%= sortable_table_header :name => "Published At", :sort => "published_at" %>
17
19
  <%= sortable_table_header :name => "Published To", :sort => "published_to" %>
18
20
  <th colspan="3">Actions</th>
@@ -24,7 +26,9 @@
24
26
  <td><%= link_to h( article.title ), admin_article_path(article) %></td>
25
27
  <td><%= content_status(article) %></td>
26
28
  <td><%= article.author %></td>
29
+ <td><%= article.editor %></td>
27
30
  <td><%= article.updated_at.strftime('%d %b') %></td>
31
+ <td><%= article.created_at.strftime('%d %b') %></td>
28
32
  <td><%= article.published_at.strftime('%d %b') unless article.published_at.nil? %></td>
29
33
  <td><%= article.published_to.strftime('%d %b') unless article.published_to.nil? %></td>
30
34
  <td><%= link_to 'Show', article_url(article), :class => 'show' if article.published? %></td>
@@ -35,10 +39,12 @@
35
39
  </tbody>
36
40
  <tfoot>
37
41
  <tr>
38
- <%= sortable_table_header :name => "Title", :sort => "title" %>
39
- <th>Status</th>
40
- <th>Author</th>
42
+ <%= sortable_table_header :name => "Title", :sort => "title" %>
43
+ <%= sortable_table_header :name => "Status", :sort => "published_at" %>
44
+ <%= sortable_table_header :name => "Author", :sort => "created_by" %>
45
+ <%= sortable_table_header :name => "Editor", :sort => "updated_by" %>
41
46
  <%= sortable_table_header :name => "Updated", :sort => "updated_at" %>
47
+ <%= sortable_table_header :name => "Created", :sort => "created_at" %>
42
48
  <%= sortable_table_header :name => "Published At", :sort => "published_at" %>
43
49
  <%= sortable_table_header :name => "Published To", :sort => "published_to" %>
44
50
  <th colspan="3">Actions</th>
@@ -5,7 +5,7 @@
5
5
  </dt>
6
6
  <dd>
7
7
  <p class="post-meta">
8
- <span class="date"><%= article.published_at.to_formatted_s(:short_dot) %></span> | posted by <%= link_to article.author, articles_authored_path(article.created_by) %>
8
+ <span class="date"><%= article.published_at.to_formatted_s(:short_dot) %></span> | posted by <%= link_to article.author, articles_authored_path(article.created_by.permalink) %>
9
9
  </p>
10
10
  <p><%=h article.description %></p>
11
11
  </dd>
@@ -20,7 +20,7 @@
20
20
  <!-- eo:main-content -->
21
21
 
22
22
  <!-- so:supporting-content -->
23
- <div id="supporting-content">
23
+ <div id="sidebar">
24
24
  <%= article_categories %>
25
25
  <%= article_authors %>
26
26
 
@@ -1,33 +1,24 @@
1
1
  <% content_for 'header' do %>
2
2
  <%= auto_discovery_link_tag :rss, articles_path(:rss) %>
3
3
  <% end %>
4
+ <h1><%=h @article.title %></h1>
5
+ <%= link_to 'RSS', articles_path(:rss), :class => 'rss' %>
4
6
 
5
7
  <div id="main-content">
6
- <h1>News</h1>
7
- <%= link_to 'RSS', articles_path(:rss), :class => 'rss' %>
8
- <div class="post">
9
- <h2><%=h @article.title %></h2>
10
- <p class="post-meta">
11
- on <span class="date"><%= @article.published_at.to_formatted_s(:short_dot) %></span> by <%= link_to @article.author, articles_authored_path(@article.created_by) %>
12
- </p>
13
- <%= @article.body %>
8
+ <p class="post-meta">
9
+ on <span class="date"><%= @article.published_at.to_formatted_s(:short_dot) %></span> by <%= link_to @article.author, articles_authored_path(@article.created_by.permalink) %>
10
+ </p>
11
+ <%= @article.body %>
12
+
13
+ <%= gallery @article.assets %>
14
+ <%= documents @article.assets %>
14
15
 
15
- <% unless @article.assets.documents.empty? -%>
16
- <ul>
17
- <% for document in @article.assets.documents %>
18
- <li><%= link_to document.filename %></li>
19
- <% end %>
20
- </ul>
21
- <% end -%>
22
-
23
- <a href="#" id="share-title" title="Share This Article">Share This</a>
24
- <p class="share-links">
25
- <%= mail_link @article %> <%= digg_link @article %> <%= delicious_link @article %> <%= facebook_link @article %> <%= stumble_link @article %> <%= twitter_link @article %> <%= reddit_link @article %> <%= technorati_link @article %>
26
- </p>
27
- </div><!-- eo:post -->
28
-
29
-
30
- <% if @article.allow_comments? or !@article.comments.empty? -%>
16
+ <a href="#" id="share-title" title="Share This Article">Share This</a>
17
+ <p class="share-links">
18
+ <%= mail_link @article %> <%= digg_link @article %> <%= delicious_link @article %> <%= facebook_link @article %> <%= stumble_link @article %> <%= twitter_link @article %> <%= reddit_link @article %> <%= technorati_link @article %>
19
+ </p>
20
+
21
+ <% if @article.allow_comments? or @article.comments.any? -%>
31
22
  <div id="comments">
32
23
  <h2>Comments</h2>
33
24
 
@@ -41,15 +32,22 @@
41
32
  <h2 id="respond">Leave a Comment</h2>
42
33
  <%= render :partial => 'comments/form', :locals => { :commentable => @article } %>
43
34
  <% end -%>
44
- </div>
35
+ </div><!-- eo:comments -->
45
36
  <% end -%>
46
37
 
47
38
  </div><!-- eo:main-content -->
48
39
 
49
- <div id="supporting-content">
50
- <h3>Latest Posts</h3>
40
+ <div id="sidebar">
41
+ <%= related_articles(@article) %>
42
+
43
+ <h2>Latest Posts</h2>
51
44
  <%= recent_articles %>
45
+
46
+ <%= article_categories %>
52
47
 
53
- <h3>Archive</h3>
48
+ <%= article_authors %>
49
+
50
+ <h2>Archive</h2>
54
51
  <%= archive %>
55
- </div><!-- eo: supporting-content -->
52
+
53
+ </div><!-- eo:sidebar -->
data/articles.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{articles}
5
- s.version = "0.3.12"
5
+ s.version = "0.3.13"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Steve England"]
9
- s.date = %q{2009-08-27}
9
+ s.date = %q{2009-09-01}
10
10
  s.email = %q{steve@wearebeef.co.uk}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -49,6 +49,8 @@ Gem::Specification.new do |s|
49
49
  "lib/articles.rb",
50
50
  "rails/init.rb",
51
51
  "test/articles_test.rb",
52
+ "test/database.yml",
53
+ "test/schema.rb",
52
54
  "test/test_helper.rb"
53
55
  ]
54
56
  s.homepage = %q{http://github.com/beef/articles}
@@ -58,6 +60,7 @@ Gem::Specification.new do |s|
58
60
  s.summary = %q{Article/Blogging engine}
59
61
  s.test_files = [
60
62
  "test/articles_test.rb",
63
+ "test/schema.rb",
61
64
  "test/test_helper.rb"
62
65
  ]
63
66
 
@@ -1,7 +1,28 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ArticlesTest < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ context('When an category has articles') do
5
+ setup do
6
+ @category = Factory(:category, :title => 'My filled up category')
7
+ 4.times do
8
+ Factory(:article, :category => @category)
9
+ end
10
+ end
11
+
12
+ should 'not be able to delete it' do
13
+ @category.destroy
14
+ assert_valid(Category.find_by_id(@category.id))
15
+ end
16
+ end
17
+
18
+ context('When an category has no articles') do
19
+ setup do
20
+ @category = Factory(:category, :title => 'My empty category')
21
+ end
22
+
23
+ should 'be able to delete it' do
24
+ @category.destroy
25
+ assert_nil(Category.find_by_id(@category.id))
26
+ end
6
27
  end
7
28
  end
data/test/database.yml ADDED
@@ -0,0 +1,21 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: acts_as_content_node_plugin.sqlite.db
4
+ sqlite3:
5
+ :adapter: sqlite3
6
+ :dbfile: acts_as_content_node_plugin.sqlite3.db
7
+ sqlite3mem:
8
+ :adapter: sqlite3
9
+ :dbfile: ":memory:"
10
+ postgresql:
11
+ :adapter: postgresql
12
+ :username: postgres
13
+ :password: postgres
14
+ :database: acts_as_content_node_plugin_test
15
+ :min_messages: ERROR
16
+ mysql:
17
+ :adapter: mysql
18
+ :host: localhost
19
+ :username: root
20
+ :password:
21
+ :database: acts_as_content_node_plugin_test
data/test/schema.rb ADDED
@@ -0,0 +1,25 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table "articles", :force => true do |t|
3
+ t.string "title"
4
+ t.string "permalink"
5
+ t.datetime "published_at"
6
+ t.datetime "published_to"
7
+ t.text "body"
8
+ t.string "description"
9
+ t.boolean "allow_comments", :default => false
10
+ t.string "cached_tag_list"
11
+ t.integer "created_by_id"
12
+ t.integer "updated_by_id"
13
+ t.integer "category_id"
14
+ t.datetime "created_at"
15
+ t.datetime "updated_at"
16
+ end
17
+
18
+ create_table "categories", :force => true do |t|
19
+ t.string "title"
20
+ t.string "description"
21
+ t.string "permalink"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+ end
data/test/test_helper.rb CHANGED
@@ -1,10 +1,56 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'shoulda'
3
+ require 'active_record'
4
+ require 'shoulda/rails'
5
+ require 'factory_girl'
6
+ require 'faker'
7
+
8
+ # Setting this makes parameterize work
9
+ $KCODE = 'UTF8'
10
+
11
+ # Makes TimeZone work
12
+ Time.zone = 'UTC'
4
13
 
5
14
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
6
16
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'articles'
8
17
 
9
- class Test::Unit::TestCase
18
+ RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
19
+ ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
20
+
21
+ require "acts_as_commentable"
22
+ require "acts_as_content_node"
23
+ require "has_assets"
24
+ module PluginMock
25
+ def acts_as_textiled(*args); end
26
+ def acts_as_taggable_on(*args); end
10
27
  end
28
+
29
+ ActiveRecord::Base.extend PluginMock
30
+ ActiveRecord::Base.send :include, Beef::Has::Assets
31
+ ActiveRecord::Base.send :include, Beef::Acts::ContentNode
32
+ ActiveRecord::Base.send :include, Beef::Acts::Publishable
33
+
34
+ require "models/article"
35
+ require "models/category"
36
+
37
+ ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + "/database.yml"))
38
+ ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")
39
+ ActiveRecord::Migration.verbose = false
40
+ load(File.join(File.dirname(__FILE__), "schema.rb"))
41
+
42
+ Factory.define :article do |article|
43
+ article.title {Faker::Lorem.words(5).join(' ')}
44
+ article.description {Faker::Lorem.sentence}
45
+ article.body {Faker::Lorem.paragraphs.join("\n\n\n")}
46
+ article.association :category, :factory => :category
47
+ end
48
+
49
+ Factory.define :published_article, :parent => :article do |article|
50
+ article.published_at { Time.at(Time.now.to_i - rand(3.years)) }
51
+ end
52
+
53
+ Factory.define :category do |f|
54
+ f.title {Faker::Lorem.words(5).join(' ')}
55
+ end
56
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beef-articles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve England
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-27 00:00:00 -07:00
12
+ date: 2009-09-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -78,10 +78,11 @@ files:
78
78
  - lib/articles.rb
79
79
  - rails/init.rb
80
80
  - test/articles_test.rb
81
+ - test/database.yml
82
+ - test/schema.rb
81
83
  - test/test_helper.rb
82
84
  has_rdoc: false
83
85
  homepage: http://github.com/beef/articles
84
- licenses:
85
86
  post_install_message:
86
87
  rdoc_options:
87
88
  - --charset=UTF-8
@@ -102,10 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  requirements: []
103
104
 
104
105
  rubyforge_project:
105
- rubygems_version: 1.3.5
106
+ rubygems_version: 1.2.0
106
107
  signing_key:
107
108
  specification_version: 3
108
109
  summary: Article/Blogging engine
109
110
  test_files:
110
111
  - test/articles_test.rb
112
+ - test/schema.rb
111
113
  - test/test_helper.rb