bcms_news 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ BrowserCMS News Module
2
+ ======================
3
+
4
+ This is the BrowserCMS News Module. This includes...
@@ -0,0 +1,2 @@
1
+ class Cms::NewsArticlesController < Cms::ContentBlockController
2
+ end
@@ -0,0 +1,7 @@
1
+ class NewsArticlesController < ApplicationController
2
+
3
+ def index
4
+ @articles = NewsArticle.released.all(:limit => 15, :order => "release_date desc")
5
+ end
6
+
7
+ end
@@ -0,0 +1,65 @@
1
+ class NewsArticle < ActiveRecord::Base
2
+
3
+ acts_as_content_block :belongs_to_attachment => true, :taggable => true
4
+
5
+ belongs_to :category
6
+
7
+ validates_presence_of :name, :release_date
8
+
9
+ before_validation :set_slug
10
+
11
+ named_scope :released, :conditions =>
12
+ ["news_articles.published = ? and news_articles.release_date <= ?", true, Time.now]
13
+
14
+ named_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
19
+ end
20
+
21
+ {:conditions => [
22
+ "news_articles.release_date >= ? AND news_articles.release_date < ?",
23
+ d.beginning_of_day,
24
+ (d.beginning_of_day + 1.day)
25
+ ]}
26
+ }
27
+
28
+ named_scope :with_slug, lambda{|slug| {:conditions => ["news_articles.slug = ?",slug]}}
29
+
30
+ def category_name
31
+ category ? category.name : nil
32
+ end
33
+
34
+ def set_slug
35
+ self.slug = name.to_slug unless name.blank?
36
+ end
37
+
38
+ def route_params
39
+ {:year => release_date.strftime("%Y"),
40
+ :month => release_date.strftime("%m"),
41
+ :day => release_date.strftime("%d"),
42
+ :slug => slug}
43
+ end
44
+
45
+ def year
46
+ release_date ? release_date.year : nil
47
+ end
48
+
49
+ def month
50
+ release_date ? release_date.month : nil
51
+ end
52
+
53
+ def set_attachment_section
54
+ if new_record? && !attachment_file.blank?
55
+ attachment.section = Section.first(:conditions => {:name => 'News'})
56
+ end
57
+ end
58
+
59
+ def set_attachment_file_path
60
+ if new_record? && !attachment_file.blank?
61
+ attachment.file_path = "/news/articles/attachment/#{Time.now.to_s(:year_month_day)}/#{name.to_slug}.#{attachment_file.original_filename.split('.').last.to_s.downcase}"
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,12 @@
1
+ class NewsArchivePortlet < Portlet
2
+
3
+ def render
4
+ if self.category_id.blank?
5
+ @articles = NewsArticle.all(:order => "release_date desc", :limit => self.limit)
6
+ else
7
+ @category = Category.find(self.category_id)
8
+ @articles = NewsArticle.all(:conditions => ["category_id = ?", @category.id], :order => "release_date desc", :limit => self.limit)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,10 @@
1
+ class NewsArticlePortlet < Portlet
2
+
3
+ def render
4
+ # @news_article should already be set by the page route
5
+ if !@news_article && params[:news_article_id]
6
+ @news_article = NewsArticle.find(params[:news_article_id])
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,17 @@
1
+ class RecentNewsPortlet < Portlet
2
+
3
+ def render
4
+ order = "release_date DESC"
5
+ if !@portlet.sort_by.blank? and !@portlet.sort_order.blank?
6
+ order = "#{@portlet.sort_by} #{@portlet.sort_order}"
7
+ end
8
+
9
+ if @portlet.category_id.blank?
10
+ @articles = NewsArticle.all(:order => order, :limit => @portlet.limit)
11
+ else
12
+ @category = Category.find(@portlet.category_id)
13
+ @articles = NewsArticle.all(:conditions => ["category_id = ?", @category.id], :order => order, :limit => @portlet.limit)
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,7 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_date_picker :release_date %>
3
+ <%= f.cms_drop_down :category_id, categories_for('News Article').map{|c| [c.path, c.id]} %>
4
+ <%= f.cms_text_area :summary, :style => "height: 100px" %>
5
+ <%= f.cms_text_editor :body %>
6
+ <%= f.cms_file_field :attachment_file, :label => "File" %>
7
+ <%= f.cms_tag_list %>
@@ -0,0 +1,2 @@
1
+ <h2><%=h @content_block.name %></h2>
2
+ <p><%= @content_block.body %></p>
@@ -0,0 +1,18 @@
1
+ xml.instruct! :xml, :version=>"1.0"
2
+ xml.rss(:version=>"2.0") do
3
+ xml.channel do
4
+ xml.title("News Articles")
5
+ xml.link(news_articles_url(:format => "rss"))
6
+ xml.description("")
7
+ xml.language('en-us')
8
+ for article in @articles
9
+ xml.item do
10
+ xml.title(article.name)
11
+ xml.description(article.summary) unless article.summary.blank?
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))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_drop_down :category_id, categories_for('News Article').map{|c| [c.path, c.id]}, { :selected=>f.object.category_id.to_i, :include_blank=>"Show News Articles in any Category", :instructions=>"Select a category to show News Articles from only that category." } %>
3
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,23 @@
1
+ <% content_for :html_head do %>
2
+ <%= auto_discovery_link_tag :rss, news_articles_url, "RSS Feed for News Articles" %>
3
+ <% end %>
4
+ <div>
5
+ <% @articles.group_by(&:year).sort_by(&:first).reverse.each do |year, year_articles| %>
6
+ <!-- <%= year %> -->
7
+ <% year_articles.group_by(&:month).sort_by(&:first).reverse.each do |month, month_articles| %>
8
+ <b class="month"><%= Date::MONTHNAMES[month] %></b>
9
+ <% for article in month_articles.sort_by(&:release_date).reverse %>
10
+ <div class="news-item">
11
+ <% unless article.release_date.blank? -%>
12
+ <span class="release-date"><b><%= article.release_date.to_s(:long) %></b></span><br/>
13
+ <% end %>
14
+
15
+ <%= link_to "<b>#{h(article.name)}</b>", news_article_path(article.route_params) %><br/>
16
+ <% unless article.summary.blank? -%>
17
+ <p><%=h article.summary %></p>
18
+ <% end %>
19
+ </div>
20
+ <% end %>
21
+ <% end %>
22
+ <% end %>
23
+ </div>
@@ -0,0 +1,2 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,8 @@
1
+ <% if @news_article -%>
2
+ <% page_title @news_article.name %>
3
+ <h2><%=h @news_article.name %></h2>
4
+ <p><%= @news_article.body %></p>
5
+ <% else -%>
6
+ <b>Missing required parameter</b><br/>
7
+ This portlet expects a request parameter 'news_article_id'. Be sure the calling page provides it.
8
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_field :limit, :label => "Number to show", :size => 2 %>
3
+ <%= f.cms_drop_down :sort_by, %w(name release_date).collect { |field| [field.titleize, field] } %>
4
+ <%= f.cms_drop_down :sort_order, %w(asc desc).collect { |field| ["#{field.titleize}ending", field.upcase] } %>
5
+ <%= f.cms_drop_down :category_id, categories_for('News Article').map{|c| [c.path, c.id]}, {:selected=>f.object.category_id.to_i, :include_blank=>"Show News Articles in any Category", :instructions=>"Select a category to show News Articles from only that category." } %>
6
+ <%= f.cms_text_field :more_link %>
7
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,24 @@
1
+ <% content_for :html_head do %>
2
+ <%= auto_discovery_link_tag :rss, news_articles_url, "RSS Feed for News Articles" %>
3
+ <% end %>
4
+ <b>Latest News</b>
5
+ <br/>
6
+ <br/>
7
+
8
+ <% for article in @articles %>
9
+ <div class="news-item-browser">
10
+ <% if article.release_date -%>
11
+ <b><%= article.release_date.to_date.to_s(:long) %></b>
12
+ <br/>
13
+ <% end %>
14
+
15
+ <%= link_to h(article.name), news_article_path(article.route_params) %>
16
+
17
+ </div>
18
+ <% end %>
19
+
20
+ <% unless @portlet.more_link.blank? -%>
21
+ <div class="news-item-browser">
22
+ <%= link_to "MORE", @portlet.more_link %>
23
+ </div>
24
+ <% end %>
@@ -0,0 +1,73 @@
1
+ class CreateNewsArticles < ActiveRecord::Migration
2
+ def self.up
3
+ create_versioned_table :news_articles do |t|
4
+ t.string :name
5
+ t.string :slug
6
+ t.datetime :release_date
7
+ t.belongs_to :category
8
+ t.belongs_to :attachment
9
+ t.integer :attachment_version
10
+ t.text :summary
11
+ t.text :body, :size => (64.kilobytes + 1)
12
+ end
13
+
14
+ # Create the content type, category type and section for news
15
+ ContentType.create!(:name => "NewsArticle", :group_name => "News")
16
+ CategoryType.create!(:name => "News Article")
17
+ news = Section.create!(:name => "News",
18
+ :path => "/news",
19
+ :parent => Section.root.first,
20
+ :group_ids => Group.all(&:id))
21
+
22
+ # Create the page to display the recent news
23
+ overview = Page.create!(:name => "Overview",
24
+ :path => "/news/articles",
25
+ :section => news,
26
+ :template_file_name => "default.html.erb")
27
+ RecentNewsPortlet.create!(:name => "Recent News Portlet",
28
+ :limit => 5,
29
+ :more_link => "/news/archive",
30
+ :template => RecentNewsPortlet.default_template,
31
+ :connect_to_page_id => overview.id,
32
+ :connect_to_container => "main")
33
+
34
+
35
+ # Create the page to display the news archives
36
+ archives = Page.create!(:name => "Archive",
37
+ :path => "/news/archive",
38
+ :section => news,
39
+ :template_file_name => "default.html.erb")
40
+ NewsArchivePortlet.create!(:name => "News Archive Portlet",
41
+ :template => NewsArchivePortlet.default_template,
42
+ :connect_to_page_id => archives.id,
43
+ :connect_to_container => "main")
44
+
45
+ # Create the page to display a given news article
46
+ article = Page.create!(:name => "Article",
47
+ :path => "/news/article",
48
+ :section => news,
49
+ :template_file_name => "default.html.erb")
50
+ NewsArticlePortlet.create!(:name => "News Article Portlet",
51
+ :template => NewsArticlePortlet.default_template,
52
+ :connect_to_page_id => article.id,
53
+ :connect_to_container => "main")
54
+
55
+ # Create Page Route to article page
56
+ route = article.page_routes.build(
57
+ :name => "News Article",
58
+ :pattern => "/news/articles/:year/:month/:day/:slug",
59
+ :code => "@news_article = NewsArticle.released_on(params).with_slug(params[:slug]).first")
60
+ route.add_condition(:method, "get")
61
+ route.add_requirement(:year, '\d{4,}')
62
+ route.add_requirement(:month, '\d{2,}')
63
+ route.add_requirement(:day, '\d{2,}')
64
+ route.save!
65
+ end
66
+
67
+ def self.down
68
+ ContentType.delete_all(['name = ?', 'NewsArticle'])
69
+ CategoryType.all(:conditions => ['name = ?', 'News Article']).each(&:destroy)
70
+ drop_table :news_release_versions
71
+ drop_table :news_releases
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_news
3
+
4
+ news_articles '/news/articles.rss',
5
+ :controller => "news_articles",
6
+ :conditions => {:method => :get},
7
+ :format => "rss"
8
+
9
+ namespace(:cms) do |cms|
10
+ cms.content_blocks :news_articles
11
+ end
12
+ end
13
+ end
data/lib/bcms_news.rb ADDED
@@ -0,0 +1 @@
1
+ require 'bcms_news/routes'
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ Cms.add_to_rails_paths gem_root
3
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '/../test_helper')
2
+
3
+ class NewsArticlesControllerTest < ActionController::TestCase
4
+
5
+ test "User can call RSS Feed" do
6
+ get :index, {:format => "rss"}
7
+ assert :success
8
+ assert_select "rss"
9
+
10
+ end
11
+
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(__FILE__), '/../test_helper')
2
+
3
+ class NewsArticleTest < ActiveSupport::TestCase
4
+
5
+ def test_news_article
6
+ a = NewsArticle.create!(:name => "Test Article", :release_date => Date.parse("2008-12-25"))
7
+ assert a.save
8
+
9
+ b = NewsArticle.released_on(Date.parse("2008-12-25")).with_slug("test-article").first
10
+ assert_equal a, b
11
+
12
+ b = NewsArticle.released_on(:year => "2008", :month => "12", :day => "25").with_slug("test-article").first
13
+ assert_equal a, b
14
+
15
+ assert_equal({
16
+ :year => "2008",
17
+ :month => "12",
18
+ :day => "25",
19
+ :slug => "test-article"
20
+ }, b.route_params)
21
+ end
22
+
23
+
24
+ def test_released_should_show_articles_from_today_and_previous_dates
25
+ today = NewsArticle.create!(:name => "Today", :release_date => Date.today, :publish_on_save => true)
26
+ tomorrow = NewsArticle.create!(:name => "Tomorrow", :release_date => Date.tomorrow, :publish_on_save => true)
27
+ yesterday = NewsArticle.create!(:name => "Yesterday", :release_date => Date.yesterday, :publish_on_save => true)
28
+
29
+ # only published articles are considered to be releasable
30
+ assert today.published?
31
+ assert tomorrow.published?
32
+ assert yesterday.published?
33
+
34
+ released = NewsArticle.released.all(:order => "release_date asc")
35
+
36
+ assert_equal [yesterday, today], released
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '/../test_helper')
2
+
3
+ class RecentNewsArticleTest < ActiveSupport::TestCase
4
+
5
+
6
+ # Note: There is probably a more elegant way to correctly set the
7
+ # parameters for a portlet than this. But it works for testing purposes.
8
+ class StubPortlet
9
+ attr_accessor :sort_by, :category_id, :limit
10
+ end
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
21
+
22
+ assert_equal [article_1, article_2], p.instance_variable_get(:@articles)
23
+
24
+
25
+ end
26
+
27
+
28
+ def test_looks_up_articles_based_on_category_id
29
+ c_type = CategoryType.create!(:name => "News")
30
+ c = Category.create!(:name => "Category A", :category_type => c_type)
31
+ article_1 = NewsArticle.create!(:name => "News Item A", :category => c, :release_date => Date.parse("2009-1-1"))
32
+ article_2 = NewsArticle.create!(:name => "News Item B", :release_date => Date.parse("2009-1-1"))
33
+
34
+ p = RecentNewsPortlet.new
35
+
36
+ params = StubPortlet.new
37
+ params.category_id = c.id
38
+ p.instance_variable_set(:@portlet, params)
39
+ p.render
40
+
41
+ assert_equal(c, p.instance_variable_get(:@category))
42
+ assert_equal([article_1], p.instance_variable_get(:@articles))
43
+ end
44
+
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_news
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - BrowserMedia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: The News Module for BrowserCMS
17
+ email: github@browsermedia.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE.txt
24
+ - README
25
+ files:
26
+ - app/controllers/cms/news_articles_controller.rb
27
+ - app/controllers/news_articles_controller.rb
28
+ - app/models/news_article.rb
29
+ - app/portlets/news_archive_portlet.rb
30
+ - app/portlets/news_article_portlet.rb
31
+ - app/portlets/recent_news_portlet.rb
32
+ - app/views/cms/news_articles/_form.html.erb
33
+ - app/views/cms/news_articles/render.html.erb
34
+ - app/views/news_articles/index.rss.builder
35
+ - app/views/portlets/news_archive/_form.html.erb
36
+ - app/views/portlets/news_archive/render.html.erb
37
+ - app/views/portlets/news_article/_form.html.erb
38
+ - app/views/portlets/news_article/render.html.erb
39
+ - app/views/portlets/recent_news/_form.html.erb
40
+ - app/views/portlets/recent_news/render.html.erb
41
+ - db/migrate/20090410193313_create_news_articles.rb
42
+ - lib/bcms_news.rb
43
+ - lib/bcms_news/routes.rb
44
+ - rails/init.rb
45
+ - LICENSE.txt
46
+ - README
47
+ has_rdoc: true
48
+ homepage: http://browsercms.org
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: browsercms
69
+ rubygems_version: 1.3.1
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: The News Module for BrowserCMS
73
+ test_files:
74
+ - test/functional/news_articles_controller_test.rb
75
+ - test/performance/browsing_test.rb
76
+ - test/test_helper.rb
77
+ - test/unit/news_article_test.rb
78
+ - test/unit/recent_news_portlet_test.rb