bcms_news 1.2.4 → 1.4.0
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.
- data/Gemfile +6 -0
- data/README.markdown +7 -5
- data/app/assets/javascripts/bcms_news/application.js +9 -0
- data/app/assets/stylesheets/bcms_news/application.css +7 -0
- data/app/controllers/bcms_news/news_articles_controller.rb +14 -0
- data/app/helpers/bcms_news/application_helper.rb +5 -0
- data/app/models/{news_article.rb → bcms_news/news_article.rb} +24 -22
- data/app/portlets/news_archive_portlet.rb +4 -4
- data/app/portlets/news_article_portlet.rb +2 -2
- data/app/portlets/recent_news_portlet.rb +21 -7
- data/app/views/{cms → bcms_news}/news_articles/_form.html.erb +1 -1
- data/app/views/{news_articles/index.rss.builder → bcms_news/news_articles/feed.rss.builder} +3 -3
- data/app/views/bcms_news/news_articles/render.html.erb +5 -0
- data/app/views/layouts/templates/default.html.erb +1 -1
- data/config/routes.rb +10 -0
- data/db/bcms_news.seeds.rb +9 -9
- data/db/migrate/{20090410193313_create_news_articles.rb → 20111229220000_create_news_articles.rb} +2 -2
- data/db/migrate/20120103165543_bcms_news_130.rb +13 -0
- data/lib/bcms_news.rb +3 -2
- data/lib/bcms_news/engine.rb +2 -1
- data/lib/bcms_news/version.rb +1 -1
- data/lib/generators/bcms_news/install/install_generator.rb +10 -2
- data/test/bcms_news_test.rb +7 -0
- data/test/integration/news_articles_test.rb +16 -6
- data/test/test_helper.rb +42 -9
- data/test/unit/news_article_test.rb +28 -26
- data/test/unit/recent_news_portlet_test.rb +40 -32
- metadata +35 -21
- data/app/controllers/cms/news_articles_controller.rb +0 -2
- data/app/controllers/news_articles_controller.rb +0 -7
- data/app/views/cms/news_articles/render.html.erb +0 -5
- data/lib/bcms_news/routes.rb +0 -11
- data/lib/generators/bcms_news/install/USAGE +0 -10
data/Gemfile
CHANGED
@@ -2,8 +2,14 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
# Avoids unnecessary Content Length warnings that Rack 1.3.6/Rails 3.1.3 + Webrick throw
|
6
|
+
# Removed if http://stackoverflow.com/questions/7082364/what-does-warn-could-not-determine-content-length-of-response-body-mean-and-h is ever fixed.
|
7
|
+
# Must run with `rails s thin`
|
8
|
+
gem "thin"
|
9
|
+
|
5
10
|
# Gem Environments
|
6
11
|
group :development do
|
7
12
|
gem "mysql"
|
13
|
+
gem "mocha"
|
8
14
|
end
|
9
15
|
|
data/README.markdown
CHANGED
@@ -28,20 +28,22 @@ The News Module defines a new content type, "News Article" which comes with the
|
|
28
28
|
|
29
29
|
### 1. Install Module
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
Note: If you have already run `rake db:seed` on your local database, you should run the following task to add the News specific seed data.
|
31
|
+
As per the [standard module installation guide](http://guides.browsercms.org/installing_modules.html), you can install this module using the following steps:
|
34
32
|
|
35
33
|
```
|
34
|
+
$ rails g cms:install bcms_news
|
35
|
+
$ bundle install
|
36
|
+
$ rake db:migrate
|
36
37
|
$ rake db:seed:bcms_news
|
37
38
|
```
|
39
|
+
Note: The last step is required if you have ever run `rake db:seed` on your local database, as you need to add the news specific seed data to your project. On a brand new project, `rake db:seed` would also install this content.
|
38
40
|
|
39
41
|
### 2. Configure RSS Feeds
|
40
42
|
|
41
|
-
To have autodiscovery links to the News RSS feed, add the following to your
|
43
|
+
To have autodiscovery links to the News RSS feed, add the following to your page templates in the `head` element.
|
42
44
|
|
43
45
|
```
|
44
|
-
<%= auto_discovery_link_tag( :rss,
|
46
|
+
<%= auto_discovery_link_tag( :rss, bcms_news.news_feed_url, {:title => "RSS Feed for News Articles"}) %>
|
45
47
|
```
|
46
48
|
|
47
49
|
### 3. Publish Pages
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module BcmsNews
|
2
|
+
class NewsArticlesController < Cms::ContentBlockController
|
3
|
+
|
4
|
+
# Better as something like: allow :guests, :only=>:feed
|
5
|
+
skip_filter :redirect_to_cms_site, :only=>:feed
|
6
|
+
skip_filter :login_required, :only=>:feed
|
7
|
+
skip_filter :cms_access_required, :only=>:feed
|
8
|
+
|
9
|
+
# Different method to avoid clashing with the backend content library for this.
|
10
|
+
def feed
|
11
|
+
@articles = NewsArticle.released.all(:limit => 15, :order => "release_date desc")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
class NewsArticle < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
1
|
+
class BcmsNews::NewsArticle < ActiveRecord::Base
|
2
|
+
acts_as_content_block :taggable => true
|
3
|
+
|
4
|
+
has_attachment :file
|
4
5
|
|
5
|
-
belongs_to :category
|
6
|
+
belongs_to :category, :class_name=>"Cms::Category"
|
6
7
|
|
7
8
|
validates_presence_of :name, :release_date
|
8
9
|
|
9
10
|
before_validation :set_slug
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
scope :released_on, lambda {|date|
|
15
|
-
d = if date.kind_of?(Hash)
|
16
|
-
Date.new(date[:year].to_i, date[:month].to_i, date[:day].to_i)
|
17
|
-
else
|
18
|
-
date
|
12
|
+
class << self
|
13
|
+
def released
|
14
|
+
where(:published => true).where("release_date <= ?", Time.now)
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
def released_on(date)
|
18
|
+
d = if date.kind_of?(Hash)
|
19
|
+
Date.new(date[:year].to_i, date[:month].to_i, date[:day].to_i)
|
20
|
+
else
|
21
|
+
date
|
22
|
+
end
|
23
|
+
|
24
|
+
where("release_date >= ? AND release_date < ?", d.beginning_of_day, (d.beginning_of_day + 1.day))
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_slug(slug)
|
28
|
+
where(:slug => slug)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
30
32
|
def category_name
|
31
33
|
category ? category.name : nil
|
32
34
|
end
|
@@ -52,7 +54,7 @@ class NewsArticle < ActiveRecord::Base
|
|
52
54
|
|
53
55
|
def set_attachment_section
|
54
56
|
if !attachment_file.blank?
|
55
|
-
attachment.section = Section.first(:conditions => {:name => 'News'})
|
57
|
+
attachment.section = Cms::Section.first(:conditions => {:name => 'News'})
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
class NewsArchivePortlet < Portlet
|
1
|
+
class NewsArchivePortlet < Cms::Portlet
|
2
2
|
|
3
3
|
# Mark this as 'true' to allow the portlet's template to be editable via the CMS admin UI.
|
4
4
|
enable_template_editor false
|
5
5
|
|
6
6
|
def render
|
7
7
|
if self.category_id.blank?
|
8
|
-
@articles = NewsArticle.released.all(:order => "release_date desc", :limit => self.limit)
|
8
|
+
@articles = BcmsNews::NewsArticle.released.all(:order => "release_date desc", :limit => self.limit)
|
9
9
|
else
|
10
|
-
@category = Category.find(self.category_id)
|
11
|
-
@articles = NewsArticle.released.all(:conditions => ["category_id = ?", @category.id], :order => "release_date desc", :limit => self.limit)
|
10
|
+
@category = Cms::Category.find(self.category_id)
|
11
|
+
@articles = BcmsNews::NewsArticle.released.all(:conditions => ["category_id = ?", @category.id], :order => "release_date desc", :limit => self.limit)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class NewsArticlePortlet < Portlet
|
1
|
+
class NewsArticlePortlet < Cms::Portlet
|
2
2
|
|
3
3
|
# Mark this as 'true' to allow the portlet's template to be editable via the CMS admin UI.
|
4
4
|
enable_template_editor false
|
@@ -6,7 +6,7 @@ class NewsArticlePortlet < Portlet
|
|
6
6
|
def render
|
7
7
|
# @news_article should already be set by the page route
|
8
8
|
if !@news_article && params[:news_article_id]
|
9
|
-
@news_article = NewsArticle.find(params[:news_article_id])
|
9
|
+
@news_article = BcmsNews::NewsArticle.find(params[:news_article_id])
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -1,20 +1,34 @@
|
|
1
|
-
class RecentNewsPortlet < Portlet
|
1
|
+
class RecentNewsPortlet < Cms::Portlet
|
2
2
|
|
3
3
|
# Mark this as 'true' to allow the portlet's template to be editable via the CMS admin UI.
|
4
4
|
enable_template_editor false
|
5
5
|
|
6
6
|
def render
|
7
7
|
order = "release_date DESC"
|
8
|
-
if
|
9
|
-
order = "#{
|
8
|
+
if !attributes.sort_by.blank? and !attributes.sort_order.blank?
|
9
|
+
order = "#{attributes.sort_by} #{attributes.sort_order}"
|
10
10
|
end
|
11
11
|
|
12
|
-
if
|
13
|
-
@articles = NewsArticle.released.all(:order => order, :limit =>
|
12
|
+
if attributes.category_id.blank?
|
13
|
+
@articles = BcmsNews::NewsArticle.released.all(:order => order, :limit => attributes.limit)
|
14
14
|
else
|
15
|
-
@category = Category.find(
|
16
|
-
@articles = NewsArticle.released.all(:conditions => ["category_id = ?", @category.id],
|
15
|
+
@category = Cms::Category.find(attributes.category_id)
|
16
|
+
@articles = BcmsNews::NewsArticle.released.all(:conditions => ["category_id = ?", @category.id],
|
17
|
+
:order => order, :limit => attributes.limit)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def category
|
22
|
+
@category
|
23
|
+
end
|
24
|
+
|
25
|
+
# For testing
|
26
|
+
def articles
|
27
|
+
@articles
|
28
|
+
end
|
29
|
+
|
30
|
+
# For testing
|
31
|
+
def attributes
|
32
|
+
@portlet
|
33
|
+
end
|
20
34
|
end
|
@@ -3,5 +3,5 @@
|
|
3
3
|
<%= f.cms_drop_down :category_id, categories_for('News Article').map{|c| [c.path, c.id]} %>
|
4
4
|
<%= f.cms_text_area :summary, :style => "height: 100px" %>
|
5
5
|
<%= f.cms_text_editor :body %>
|
6
|
-
<%= f.cms_file_field :
|
6
|
+
<%= f.cms_file_field :file, :label => "File" %>
|
7
7
|
<%= f.cms_tag_list %>
|
@@ -2,7 +2,7 @@ xml.instruct! :xml, :version=>"1.0"
|
|
2
2
|
xml.rss(:version=>"2.0") do
|
3
3
|
xml.channel do
|
4
4
|
xml.title("News Articles")
|
5
|
-
xml.link(
|
5
|
+
xml.link(news_feed_url(:format => "rss"))
|
6
6
|
xml.description("")
|
7
7
|
xml.language('en-us')
|
8
8
|
for article in @articles
|
@@ -10,8 +10,8 @@ xml.rss(:version=>"2.0") do
|
|
10
10
|
xml.title(article.name)
|
11
11
|
xml.description(article.summary) unless article.summary.blank?
|
12
12
|
xml.pubDate(article.release_date.strftime("%a, %d %b %Y %H:%M:%S %z")) unless article.release_date.blank?
|
13
|
-
xml.link(news_article_url(article.route_params))
|
14
|
-
xml.guid(news_article_url(article.route_params))
|
13
|
+
xml.link(main_app.news_article_url(article.route_params))
|
14
|
+
xml.guid(main_app.news_article_url(article.route_params))
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
5
5
|
<title><%= page_title %></title>
|
6
6
|
<%= yield :html_head %>
|
7
|
-
<%= auto_discovery_link_tag( :rss,
|
7
|
+
<%= auto_discovery_link_tag( :rss, bcms_news.news_feed_url, {:title => "RSS Feed for News Articles"}) %>
|
8
8
|
</head>
|
9
9
|
<body style="margin: 0; padding: 0; text-align: center;">
|
10
10
|
<%= cms_toolbar %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
BcmsNews::Engine.routes.draw do
|
2
|
+
|
3
|
+
# This is going to be added under /bcms_news/news/articles.rss
|
4
|
+
# Add a routing extension (w/ mount_bcms_news or ), or make a non-isolated engine.
|
5
|
+
# Alternatively, just mount as /news rather than /bcms_news then update the match.
|
6
|
+
get '/articles/feed', :to=>"news_articles#feed", :defaults => { :format => 'rss' }, :as=>'news_feed'
|
7
|
+
|
8
|
+
content_blocks :news_articles
|
9
|
+
|
10
|
+
end
|
data/db/bcms_news.seeds.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Create the content type, category type and section for news
|
2
|
-
ContentType.create!(:name => "NewsArticle", :group_name => "News")
|
3
|
-
CategoryType.create!(:name => "News Article")
|
4
|
-
news = Section.create!(:name => "News",
|
2
|
+
Cms::ContentType.create!(:name => "BcmsNews::NewsArticle", :group_name => "News")
|
3
|
+
Cms::CategoryType.create!(:name => "News Article")
|
4
|
+
news = Cms::Section.create!(:name => "News",
|
5
5
|
:path => "/news",
|
6
|
-
:parent => Section.root.first,
|
7
|
-
:group_ids => Group.all.map(&:id))
|
6
|
+
:parent => Cms::Section.root.first,
|
7
|
+
:group_ids => Cms::Group.all.map(&:id))
|
8
8
|
|
9
9
|
# Create the page to display the recent news
|
10
|
-
overview = Page.create!(:name => "Overview",
|
10
|
+
overview = Cms::Page.create!(:name => "Overview",
|
11
11
|
:path => "/news/articles",
|
12
12
|
:section => news,
|
13
13
|
:template_file_name => "default.html.erb")
|
@@ -20,7 +20,7 @@ RecentNewsPortlet.create!(:name => "Recent News Portlet",
|
|
20
20
|
|
21
21
|
|
22
22
|
# Create the page to display the news archives
|
23
|
-
archives = Page.create!(:name => "Archive",
|
23
|
+
archives = Cms::Page.create!(:name => "Archive",
|
24
24
|
:path => "/news/archive",
|
25
25
|
:section => news,
|
26
26
|
:template_file_name => "default.html.erb")
|
@@ -30,7 +30,7 @@ NewsArchivePortlet.create!(:name => "News Archive Portlet",
|
|
30
30
|
:connect_to_container => "main")
|
31
31
|
|
32
32
|
# Create the page to display a given news article
|
33
|
-
article = Page.create!(:name => "Article",
|
33
|
+
article = Cms::Page.create!(:name => "Article",
|
34
34
|
:path => "/news/article",
|
35
35
|
:section => news,
|
36
36
|
:template_file_name => "default.html.erb")
|
@@ -43,7 +43,7 @@ NewsArticlePortlet.create!(:name => "News Article Portlet",
|
|
43
43
|
route = article.page_routes.build(
|
44
44
|
:name => "News Article",
|
45
45
|
:pattern => "/news/articles/:year/:month/:day/:slug",
|
46
|
-
:code => "@news_article = NewsArticle.released_on(params).with_slug(params[:slug]).first")
|
46
|
+
:code => "@news_article = BcmsNews::NewsArticle.released_on(params).with_slug(params[:slug]).first")
|
47
47
|
route.add_condition(:method, "get")
|
48
48
|
route.add_requirement(:year, '\d{4,}')
|
49
49
|
route.add_requirement(:month, '\d{2,}')
|
data/db/migrate/{20090410193313_create_news_articles.rb → 20111229220000_create_news_articles.rb}
RENAMED
@@ -13,8 +13,8 @@ class CreateNewsArticles < ActiveRecord::Migration
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.down
|
16
|
-
ContentType.delete_all(['name = ?', 'NewsArticle'])
|
17
|
-
CategoryType.all(:conditions => ['name = ?', 'News Article']).each(&:destroy)
|
16
|
+
Cms::ContentType.delete_all(['name = ?', 'NewsArticle'])
|
17
|
+
Cms::CategoryType.all(:conditions => ['name = ?', 'News Article']).each(&:destroy)
|
18
18
|
drop_table :news_release_versions
|
19
19
|
drop_table :news_releases
|
20
20
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Upgrade to BcmsNew v1.3.0
|
2
|
+
class BcmsNews130 < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
# These need to be done since v1.2 had a different table name
|
5
|
+
rename_table :news_articles, :bcms_news_news_articles
|
6
|
+
rename_table :news_article_versions, :bcms_news_news_article_versions
|
7
|
+
|
8
|
+
# This is needed to match new BrowserCMS 3.4 naming convention for versioning column.
|
9
|
+
if column_exists? :bcms_news_news_article_versions, :news_article_id
|
10
|
+
rename_column :bcms_news_news_article_versions, :news_article_id, :original_record_id
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/bcms_news.rb
CHANGED
data/lib/bcms_news/engine.rb
CHANGED
data/lib/bcms_news/version.rb
CHANGED
@@ -3,10 +3,18 @@ require 'cms/module_installation'
|
|
3
3
|
class BcmsNews::InstallGenerator < Cms::ModuleInstallation
|
4
4
|
add_migrations_directory_to_source_root __FILE__
|
5
5
|
|
6
|
-
|
6
|
+
|
7
|
+
def copy_migrations
|
8
|
+
rake 'bcms_news:install:migrations'
|
9
|
+
end
|
7
10
|
|
8
11
|
def add_seed_data_to_project
|
9
12
|
copy_file "../bcms_news.seeds.rb", "db/bcms_news.seeds.rb"
|
10
|
-
append_to_file "db/seeds.rb", "load File.expand_path('../bcms_news.seeds.rb', __FILE__)"
|
13
|
+
append_to_file "db/seeds.rb", "load File.expand_path('../bcms_news.seeds.rb', __FILE__)\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_routes
|
17
|
+
mount_engine(BcmsNews)
|
11
18
|
end
|
19
|
+
|
12
20
|
end
|
@@ -1,12 +1,22 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
class NewsArticlesTest < ActionController::IntegrationTest
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
def setup
|
5
|
+
Factory(:article_type)
|
6
|
+
Factory(:article)
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
silence_stream(STDOUT) do
|
9
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), '../../test/dummy/db/seeds.rb'))
|
10
|
+
require file
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
test "Access the RSS feed via the 'ugly' URL" do
|
15
|
+
get "/bcms_news/articles/feed"
|
16
|
+
|
17
|
+
assert_response :success, "What the heck is a 406 response code?"
|
18
|
+
assert @response.body.include?("<rss")
|
19
|
+
# Checking vs @response.body rather than using assert_select since the later throws invalid warnings when parsing XML
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,46 @@
|
|
1
|
+
# Configure Rails Environment
|
1
2
|
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path('../../config/environment', __FILE__)
|
3
|
-
require 'rails/test_help'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
11
|
|
12
|
-
|
12
|
+
module FakeFactoryGirl
|
13
|
+
mattr_accessor :count
|
14
|
+
|
15
|
+
# To clean up tests without actually adding factory girl yet.
|
16
|
+
def Factory(name, options={})
|
17
|
+
FakeFactoryGirl.count += 1
|
18
|
+
|
19
|
+
if name == :article
|
20
|
+
create_article(options)
|
21
|
+
else
|
22
|
+
create_content_type(options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_content_type(options)
|
27
|
+
Cms::ContentType.create!(:name=>'BcmsNews::NewsArticle', :group_name=>"Not Blank")
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_article(options)
|
31
|
+
defaults =
|
32
|
+
{
|
33
|
+
name: "News Item #{FakeFactoryGirl.count}",
|
34
|
+
release_date: 1.week.ago,
|
35
|
+
publish_on_save: true,
|
36
|
+
}
|
37
|
+
defaults.merge!(options)
|
38
|
+
BcmsNews::NewsArticle.create!(defaults)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class ActiveSupport::TestCase
|
43
|
+
include FakeFactoryGirl
|
44
|
+
FakeFactoryGirl.count = 0
|
45
|
+
|
13
46
|
end
|
@@ -1,40 +1,42 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module BcmsNews
|
4
|
+
class NewsArticleTest < ActiveSupport::TestCase
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def test_news_article
|
7
|
+
a = NewsArticle.create!(:name => "Test Article", :release_date => Date.parse("2008-12-25"))
|
8
|
+
assert a.save
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
b = NewsArticle.released_on(Date.parse("2008-12-25")).with_slug("test-article").first
|
11
|
+
assert_equal a, b
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
b = NewsArticle.released_on(:year => "2008", :month => "12", :day => "25").with_slug("test-article").first
|
14
|
+
assert_equal a, b
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
assert_equal({
|
17
|
+
:year => "2008",
|
18
|
+
:month => "12",
|
19
|
+
:day => "25",
|
20
|
+
:slug => "test-article"
|
21
|
+
}, b.route_params)
|
22
|
+
end
|
22
23
|
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def test_released_should_show_articles_from_today_and_previous_dates
|
26
|
+
today = Factory(:article, :name=>"Today", release_date: Date.today)
|
27
|
+
tomorrow = Factory(:article,:name => "Tomorrow", :release_date => 1.day.from_now)
|
28
|
+
yesterday = Factory(:article,:name => "Yesterday", :release_date => 1.day.ago)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# only published articles are considered to be releasable
|
31
|
+
assert today.published?
|
32
|
+
assert tomorrow.published?
|
33
|
+
assert yesterday.published?
|
33
34
|
|
34
|
-
|
35
|
+
released = NewsArticle.released.order("release_date asc").all
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
assert_equal [yesterday, today], released
|
38
|
+
end
|
38
39
|
|
39
40
|
|
41
|
+
end
|
40
42
|
end
|
@@ -1,46 +1,54 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module BcmsNews
|
4
|
+
class RecentNewsArticleTest < ActiveSupport::TestCase
|
4
5
|
|
6
|
+
def setup
|
7
|
+
@past_article_1 = Factory(:article)
|
8
|
+
@past_article_2 = Factory(:article)
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def test_finds_all_articles
|
14
|
-
article_1 = NewsArticle.create!(:name => "News Item A", :release_date => Date.parse("2009-1-1"))
|
15
|
-
article_2 = NewsArticle.create!(:name => "News Item B", :release_date => Date.parse("2009-1-1"))
|
16
|
-
p = RecentNewsPortlet.new
|
17
|
-
|
18
|
-
params = StubPortlet.new
|
19
|
-
p.instance_variable_set(:@portlet, params)
|
20
|
-
p.render
|
11
|
+
# Note: There is probably a more elegant way to correctly set the
|
12
|
+
# parameters for a portlet than this. But it works for testing purposes.
|
13
|
+
class StubAttributes
|
14
|
+
attr_accessor :sort_by, :category_id, :limit
|
15
|
+
end
|
21
16
|
|
22
|
-
assert_equal [article_1, article_2], p.instance_variable_get(:@articles)
|
23
17
|
|
18
|
+
def test_finds_all_articles
|
19
|
+
p = RecentNewsPortlet.new
|
20
|
+
|
21
|
+
expects_attributes(p)
|
24
22
|
|
25
|
-
|
23
|
+
p.render
|
24
|
+
|
25
|
+
assert_equal [@past_article_1, @past_article_2], p.articles
|
26
|
+
end
|
26
27
|
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def test_looks_up_articles_based_on_category_id
|
30
|
+
c_type = Cms::CategoryType.create!(:name => "News")
|
31
|
+
assert_equal true, c_type.persisted?
|
32
|
+
c = Cms::Category.create!(:name => "Category A", :category_type_id => c_type.id)
|
33
|
+
@article_in_category = Factory(:article, :category_id => c.id)
|
33
34
|
|
34
|
-
|
35
|
+
p = RecentNewsPortlet.new
|
36
|
+
|
37
|
+
params = expects_attributes(p)
|
38
|
+
params.category_id = c.id
|
35
39
|
|
36
|
-
|
37
|
-
params.category_id = c.id
|
38
|
-
p.instance_variable_set(:@portlet, params)
|
39
|
-
p.render
|
40
|
+
p.render
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
assert_equal(c, p.category)
|
43
|
+
assert_equal([@article_in_category], p.articles)
|
44
|
+
end
|
45
45
|
|
46
|
+
private
|
47
|
+
|
48
|
+
def expects_attributes(portlet)
|
49
|
+
params = StubAttributes.new
|
50
|
+
portlet.expects(:attributes).returns(params).at_least_once
|
51
|
+
params
|
52
|
+
end
|
53
|
+
end
|
46
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_news
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,57 +9,70 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2011-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: browsercms
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - <
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: 3.6.0
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.5.0.rc2
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
|
-
version_requirements:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.6.0
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.5.0.rc2
|
25
36
|
description: The News Module for BrowserCMS
|
26
37
|
email: github@browsermedia.com
|
27
38
|
executables: []
|
28
39
|
extensions: []
|
29
40
|
extra_rdoc_files:
|
30
|
-
- LICENSE.txt
|
31
41
|
- README.markdown
|
32
42
|
files:
|
33
|
-
-
|
34
|
-
-
|
35
|
-
- app/controllers/
|
36
|
-
- app/
|
37
|
-
- app/models/news_article.rb
|
43
|
+
- app/assets/javascripts/bcms_news/application.js
|
44
|
+
- app/assets/stylesheets/bcms_news/application.css
|
45
|
+
- app/controllers/bcms_news/news_articles_controller.rb
|
46
|
+
- app/helpers/bcms_news/application_helper.rb
|
47
|
+
- app/models/bcms_news/news_article.rb
|
38
48
|
- app/portlets/news_archive_portlet.rb
|
39
49
|
- app/portlets/news_article_portlet.rb
|
40
50
|
- app/portlets/recent_news_portlet.rb
|
41
|
-
- app/views/
|
42
|
-
- app/views/
|
51
|
+
- app/views/bcms_news/news_articles/_form.html.erb
|
52
|
+
- app/views/bcms_news/news_articles/feed.rss.builder
|
53
|
+
- app/views/bcms_news/news_articles/render.html.erb
|
43
54
|
- app/views/layouts/templates/default.html.erb
|
44
|
-
- app/views/news_articles/index.rss.builder
|
45
55
|
- app/views/portlets/news_archive/_form.html.erb
|
46
56
|
- app/views/portlets/news_archive/render.html.erb
|
47
57
|
- app/views/portlets/news_article/_form.html.erb
|
48
58
|
- app/views/portlets/news_article/render.html.erb
|
49
59
|
- app/views/portlets/recent_news/_form.html.erb
|
50
60
|
- app/views/portlets/recent_news/render.html.erb
|
51
|
-
-
|
61
|
+
- config/routes.rb
|
52
62
|
- db/bcms_news.seeds.rb
|
63
|
+
- db/migrate/20111229220000_create_news_articles.rb
|
64
|
+
- db/migrate/20120103165543_bcms_news_130.rb
|
53
65
|
- lib/bcms_news/engine.rb
|
54
|
-
- lib/bcms_news/routes.rb
|
55
66
|
- lib/bcms_news/version.rb
|
56
67
|
- lib/bcms_news.rb
|
57
68
|
- lib/generators/bcms_news/install/install_generator.rb
|
58
|
-
- lib/generators/bcms_news/install/USAGE
|
59
69
|
- lib/tasks/install.rake
|
70
|
+
- README.markdown
|
60
71
|
- Gemfile
|
72
|
+
- LICENSE.txt
|
61
73
|
- COPYRIGHT.txt
|
62
74
|
- GPL.txt
|
75
|
+
- test/bcms_news_test.rb
|
63
76
|
- test/integration/news_articles_test.rb
|
64
77
|
- test/test_helper.rb
|
65
78
|
- test/unit/news_article_test.rb
|
@@ -78,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
91
|
version: '0'
|
79
92
|
segments:
|
80
93
|
- 0
|
81
|
-
hash:
|
94
|
+
hash: 898571447684150772
|
82
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
96
|
none: false
|
84
97
|
requirements:
|
@@ -87,14 +100,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
100
|
version: '0'
|
88
101
|
segments:
|
89
102
|
- 0
|
90
|
-
hash:
|
103
|
+
hash: 898571447684150772
|
91
104
|
requirements: []
|
92
105
|
rubyforge_project: bcms_news
|
93
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.24
|
94
107
|
signing_key:
|
95
108
|
specification_version: 3
|
96
109
|
summary: The News Module for BrowserCMS
|
97
110
|
test_files:
|
111
|
+
- test/bcms_news_test.rb
|
98
112
|
- test/integration/news_articles_test.rb
|
99
113
|
- test/test_helper.rb
|
100
114
|
- test/unit/news_article_test.rb
|
data/lib/bcms_news/routes.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module Cms
|
2
|
-
module Routes
|
3
|
-
def routes_for_bcms_news
|
4
|
-
|
5
|
-
match '/news/articles.rss', :to=>"news_articles#index", :as=>'news_articles', :method=>:get, :defaults => { :format => 'rss' }
|
6
|
-
namespace(:cms) do
|
7
|
-
content_blocks :news_articles
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|