refinerycms-news 2.0.1 → 2.1.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.
- checksums.yaml +7 -0
 - data/.gitignore +4 -0
 - data/.rspec +1 -0
 - data/.travis.yml +23 -10
 - data/Gemfile +23 -54
 - data/Rakefile +2 -0
 - data/app/controllers/refinery/news/items_controller.rb +8 -11
 - data/app/helpers/refinery/news/items_helper.rb +14 -17
 - data/app/models/refinery/news/item.rb +9 -4
 - data/app/views/refinery/news/admin/items/_form.html.erb +9 -16
 - data/app/views/refinery/news/admin/items/_item.html.erb +6 -3
 - data/app/views/refinery/news/admin/items/edit.html.erb +1 -1
 - data/app/views/refinery/news/admin/items/index.html.erb +1 -1
 - data/app/views/refinery/news/admin/items/new.html.erb +1 -1
 - data/app/views/refinery/news/items/archive.html.erb +6 -6
 - data/app/views/refinery/news/items/index.html.erb +3 -3
 - data/app/views/refinery/news/items/show.html.erb +3 -3
 - data/app/views/refinery/news/items/widgets/_news_archive.html.erb +1 -5
 - data/app/views/refinery/news/shared/_body_content_right.html.erb +1 -1
 - data/config/locales/bg.yml +18 -18
 - data/config/locales/cs.yml +19 -19
 - data/config/locales/da.yml +47 -0
 - data/config/locales/de.yml +18 -18
 - data/config/locales/en.yml +3 -2
 - data/config/locales/es-MX.yml +18 -18
 - data/config/locales/es.yml +19 -19
 - data/config/locales/fr.yml +31 -19
 - data/config/locales/it.yml +18 -18
 - data/config/locales/ja.yml +48 -0
 - data/config/locales/lv.yml +20 -18
 - data/config/locales/nb.yml +18 -18
 - data/config/locales/nl.yml +30 -18
 - data/config/locales/pl.yml +29 -18
 - data/config/locales/ru.yml +18 -18
 - data/config/locales/sk.yml +31 -19
 - data/config/locales/sl.yml +0 -2
 - data/config/locales/zh-CN.yml +18 -18
 - data/config/locales/zh-TW.yml +29 -29
 - data/config/routes.rb +2 -2
 - data/readme.md +51 -2
 - data/refinerycms-news.gemspec +4 -5
 - data/spec/controllers/refinery/news/items_controller_spec.rb +67 -0
 - data/spec/{requests → features}/manage_news_items_spec.rb +6 -6
 - data/spec/{requests → features}/news_archive.rb +0 -0
 - data/spec/{requests → features}/visit_news_items_spec.rb +5 -7
 - data/spec/helpers/refinery/news/items_helper_spec.rb +34 -0
 - data/spec/models/refinery/news/item_spec.rb +38 -14
 - data/spec/spec_helper.rb +20 -46
 - metadata +26 -30
 - data/Guardfile +0 -20
 - data/app/views/refinery/news/admin/items/_locale_picker.html.erb +0 -11
 - data/config/locales/jp.yml +0 -36
 
    
        data/config/routes.rb
    CHANGED
    
    | 
         @@ -1,12 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Refinery::Core::Engine.routes.draw do
         
     | 
| 
       2 
2 
     | 
    
         
             
              namespace :news do
         
     | 
| 
       3 
3 
     | 
    
         
             
                root :to => "items#index"
         
     | 
| 
       4 
     | 
    
         
            -
                get 'archive/:year(/:month)', :to => 'items#archive', :as => 'items_archive'
         
     | 
| 
      
 4 
     | 
    
         
            +
                get 'archive/:year(/:month)', :to => 'items#archive', :as => 'items_archive', :constraints => { :year => /\d{4}/, :month => /\d{1,2}/ }
         
     | 
| 
       5 
5 
     | 
    
         
             
                resources :items, :only => [:show, :index], :path => ''
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              namespace :news, :path => '' do
         
     | 
| 
       9 
     | 
    
         
            -
                namespace :admin, :path =>  
     | 
| 
      
 9 
     | 
    
         
            +
                namespace :admin, :path => Refinery::Core.backend_route do
         
     | 
| 
       10 
10 
     | 
    
         
             
                  scope :path => 'news' do
         
     | 
| 
       11 
11 
     | 
    
         
             
                    root :to => "items#index"
         
     | 
| 
       12 
12 
     | 
    
         
             
                    resources :items, :except => :show
         
     | 
    
        data/readme.md
    CHANGED
    
    | 
         @@ -19,7 +19,9 @@ Key features: 
     | 
|
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
            Include the latest [gem](http://rubygems.org/gems/refinerycms-news) into your Refinery CMS application's Gemfile:
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 23 
     | 
    
         
            +
            gem "refinerycms-news", '~> 2.0.0'
         
     | 
| 
      
 24 
     | 
    
         
            +
            ```
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
26 
     | 
    
         
             
            Then type the following at command line inside your Refinery CMS application's root directory:
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
         @@ -28,6 +30,45 @@ Then type the following at command line inside your Refinery CMS application's r 
     | 
|
| 
       28 
30 
     | 
    
         
             
                rake db:migrate
         
     | 
| 
       29 
31 
     | 
    
         
             
                rake db:seed
         
     | 
| 
       30 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
            ## How to display a news feed on the homepage:
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            Assuming you've already overridden the homepage view:
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                $ rake refinery:override view=refinery/pages/home
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            You can render the `recent_posts` partial. However, you will need to set the recent News items manually, since this is normally handled in the News::Items controller:
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            ```erb
         
     | 
| 
      
 42 
     | 
    
         
            +
            <% @items = Refinery::News::Item.latest(5) %>
         
     | 
| 
      
 43 
     | 
    
         
            +
            <%= render :partial => '/refinery/news/items/recent_posts' %>
         
     | 
| 
      
 44 
     | 
    
         
            +
            ```
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            ## Configuring the number of items per page
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            To modify the number of items per page for the news items index without
         
     | 
| 
      
 49 
     | 
    
         
            +
            affecting the archive page you must override the method in the controller that
         
     | 
| 
      
 50 
     | 
    
         
            +
            sets `@items` for the index: `find_published_news_items`.
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            Currently the method body is:
         
     | 
| 
      
 53 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 54 
     | 
    
         
            +
            @items = Item.published.translated.page(params[:page])
         
     | 
| 
      
 55 
     | 
    
         
            +
            ```
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            The `page` convenience method needs to be replaced with `paginate` and
         
     | 
| 
      
 58 
     | 
    
         
            +
            `per_page` passed as an option.  Add a decorator for the items controller with
         
     | 
| 
      
 59 
     | 
    
         
            +
            the following contents:
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 62 
     | 
    
         
            +
            module Refinery::News
         
     | 
| 
      
 63 
     | 
    
         
            +
              ItemsController.class_eval do
         
     | 
| 
      
 64 
     | 
    
         
            +
                def find_published_news_items
         
     | 
| 
      
 65 
     | 
    
         
            +
                  @items = Item.published.translated.paginate :page => params[:page],
         
     | 
| 
      
 66 
     | 
    
         
            +
                                                              :per_page => 8
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
            end
         
     | 
| 
      
 70 
     | 
    
         
            +
            ```
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
       31 
72 
     | 
    
         
             
            ## Customising the views
         
     | 
| 
       32 
73 
     | 
    
         | 
| 
       33 
74 
     | 
    
         
             
            Type this command at your project root to override the default front end views:
         
     | 
| 
         @@ -42,4 +83,12 @@ Type this command at your project root to override the default front end views: 
     | 
|
| 
       42 
83 
     | 
    
         | 
| 
       43 
84 
     | 
    
         
             
            To get RSS for your entire site, insert this into the head section of your layout after installing:
         
     | 
| 
       44 
85 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
            ```erb
         
     | 
| 
      
 87 
     | 
    
         
            +
            <%= auto_discovery_link_tag(:rss, refinery.news_items_url(:format => 'rss')) %>
         
     | 
| 
      
 88 
     | 
    
         
            +
            ```
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            ## More Information
         
     | 
| 
      
 91 
     | 
    
         
            +
            * Check out our [Website](http://refinerycms.com/)
         
     | 
| 
      
 92 
     | 
    
         
            +
            * Refinery Documentation is available in the [guides](http://refinerycms.com/guides)
         
     | 
| 
      
 93 
     | 
    
         
            +
            * Questions can be asked on our [Google Group](http://group.refinerycms.org)
         
     | 
| 
      
 94 
     | 
    
         
            +
            * Questions can also be asked in our IRC room, [#refinerycms on freenode](irc://irc.freenode.net/refinerycms)
         
     | 
    
        data/refinerycms-news.gemspec
    CHANGED
    
    | 
         @@ -2,9 +2,8 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       4 
4 
     | 
    
         
             
              s.name              = %q{refinerycms-news}
         
     | 
| 
       5 
     | 
    
         
            -
              s.version           = %q{2.0 
     | 
| 
      
 5 
     | 
    
         
            +
              s.version           = %q{2.1.0}
         
     | 
| 
       6 
6 
     | 
    
         
             
              s.description       = %q{A really straightforward open source Ruby on Rails news engine designed for integration with Refinery CMS.}
         
     | 
| 
       7 
     | 
    
         
            -
              s.date              = "#{Date.today.strftime("%Y-%m-%d")}"
         
     | 
| 
       8 
7 
     | 
    
         
             
              s.summary           = %q{Ruby on Rails news engine for Refinery CMS.}
         
     | 
| 
       9 
8 
     | 
    
         
             
              s.email             = %q{info@refinerycms.com}
         
     | 
| 
       10 
9 
     | 
    
         
             
              s.homepage          = %q{http://refinerycms.com}
         
     | 
| 
         @@ -14,7 +13,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       14 
13 
     | 
    
         
             
              s.files             = `git ls-files`.split("\n")
         
     | 
| 
       15 
14 
     | 
    
         
             
              s.test_files        = `git ls-files -- spec/*`.split("\n")
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              s.add_dependency    'refinerycms-core',     '~> 2.0 
     | 
| 
       18 
     | 
    
         
            -
              s.add_dependency    'refinerycms-settings', '~> 2. 
     | 
| 
       19 
     | 
    
         
            -
              s.add_dependency    'friendly_id',          '~> 4.0. 
     | 
| 
      
 16 
     | 
    
         
            +
              s.add_dependency    'refinerycms-core',     '~> 2.1.0'
         
     | 
| 
      
 17 
     | 
    
         
            +
              s.add_dependency    'refinerycms-settings', '~> 2.1.0'
         
     | 
| 
      
 18 
     | 
    
         
            +
              s.add_dependency    'friendly_id',          '~> 4.0.9'
         
     | 
| 
       20 
19 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "spec_helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Refinery
         
     | 
| 
      
 4 
     | 
    
         
            +
              module News
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe ItemsController do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  let!(:item) { FactoryGirl.create(:news_item) }
         
     | 
| 
      
 7 
     | 
    
         
            +
                  let(:refinery_page) { Refinery::Page.where(:link_url => "/news").first }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  describe "#index" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                    it "assigns items and page" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                      get :index
         
     | 
| 
      
 12 
     | 
    
         
            +
                      assigns(:items).first.should eq(item)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      assigns(:page).should eq(refinery_page)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    it "renders 'index' template" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      get :index
         
     | 
| 
      
 18 
     | 
    
         
            +
                      response.should render_template(:index)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  describe "#show" do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    it "assigns item and page" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                      get :show, :id => item.id
         
     | 
| 
      
 25 
     | 
    
         
            +
                      assigns(:item).should eq(item)
         
     | 
| 
      
 26 
     | 
    
         
            +
                      assigns(:page).should eq(refinery_page)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    it "renders 'show' template" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                      get :show, :id => item.id
         
     | 
| 
      
 31 
     | 
    
         
            +
                      response.should render_template(:show)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  describe "#archive" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                    context "when month is present" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                      it "assigns archive_date and items" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                        Refinery::News::Item.stub_chain(:archived, :translated, :by_archive, :page).and_return(item)
         
     | 
| 
      
 39 
     | 
    
         
            +
                        get :archive, :month => 05, :year => 1999
         
     | 
| 
      
 40 
     | 
    
         
            +
                        assigns(:archive_date).should eq(Time.parse("05/1999"))
         
     | 
| 
      
 41 
     | 
    
         
            +
                        assigns(:items).should eq(item)
         
     | 
| 
      
 42 
     | 
    
         
            +
                        assigns(:archive_for_month).should be_true
         
     | 
| 
      
 43 
     | 
    
         
            +
                      end
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    context "when month isnt present" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                      it "assigns archive_date and items" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                        Refinery::News::Item.stub_chain(:archived, :translated, :by_year, :page).and_return(item)
         
     | 
| 
      
 49 
     | 
    
         
            +
                        get :archive, :year => 1999
         
     | 
| 
      
 50 
     | 
    
         
            +
                        assigns(:archive_date).should eq(Time.parse("01/1999"))
         
     | 
| 
      
 51 
     | 
    
         
            +
                        assigns(:items).should eq(item)
         
     | 
| 
      
 52 
     | 
    
         
            +
                      end
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    it "renders 'archive' template" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                      get :archive, :year => 1999
         
     | 
| 
      
 57 
     | 
    
         
            +
                      response.should render_template(:archive)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                    it "assigns page" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                      get :archive, :year => 1999
         
     | 
| 
      
 62 
     | 
    
         
            +
                      assigns(:page).should eq(refinery_page)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "spec_helper"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe "manage news items" do
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
      
 4 
     | 
    
         
            +
              refinery_login_with :refinery_user
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
              context "when no news items" do
         
     | 
| 
       7 
7 
     | 
    
         
             
                it "invites to create one" do
         
     | 
| 
         @@ -16,7 +16,7 @@ describe "manage news items" do 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
                  within "#actions" do
         
     | 
| 
       18 
18 
     | 
    
         
             
                    page.should have_content("Add News Item")
         
     | 
| 
       19 
     | 
    
         
            -
                    page.should have_selector("a[href='/ 
     | 
| 
      
 19 
     | 
    
         
            +
                    page.should have_selector("a[href='/#{Refinery::Core.backend_route}/news/items/new']")
         
     | 
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         
             
              end
         
     | 
| 
         @@ -35,7 +35,7 @@ describe "manage news items" do 
     | 
|
| 
       35 
35 
     | 
    
         
             
                  page.should have_content("'My first news item' was successfully added.")
         
     | 
| 
       36 
36 
     | 
    
         
             
                  page.body.should =~ /Remove this news item forever/
         
     | 
| 
       37 
37 
     | 
    
         
             
                  page.body.should =~ /Edit this news item/
         
     | 
| 
       38 
     | 
    
         
            -
                  page.body.should =~ %r{/ 
     | 
| 
      
 38 
     | 
    
         
            +
                  page.body.should =~ %r{/#{Refinery::Core.backend_route}/news/items/my-first-news-item/edit}
         
     | 
| 
       39 
39 
     | 
    
         
             
                  page.body.should =~ /View this news item live/
         
     | 
| 
       40 
40 
     | 
    
         
             
                  page.body.should =~ %r{/news/items/my-first-news-item}
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
         @@ -44,7 +44,7 @@ describe "manage news items" do 
     | 
|
| 
       44 
44 
     | 
    
         
             
              end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
              describe "edit/update" do
         
     | 
| 
       47 
     | 
    
         
            -
                before 
     | 
| 
      
 47 
     | 
    
         
            +
                before { FactoryGirl.create(:news_item, :title => "Update me") }
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                it "updates news item" do
         
     | 
| 
       50 
50 
     | 
    
         
             
                  visit refinery.news_admin_items_path
         
     | 
| 
         @@ -61,7 +61,7 @@ describe "manage news items" do 
     | 
|
| 
       61 
61 
     | 
    
         
             
              end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
              describe "destroy" do
         
     | 
| 
       64 
     | 
    
         
            -
                before 
     | 
| 
      
 64 
     | 
    
         
            +
                before { FactoryGirl.create(:news_item, :title => "Delete me") }
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                it "removes news item" do
         
     | 
| 
       67 
67 
     | 
    
         
             
                  visit refinery.news_admin_items_path
         
     | 
| 
         @@ -75,7 +75,7 @@ describe "manage news items" do 
     | 
|
| 
       75 
75 
     | 
    
         
             
              end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
              context "duplicate news item titles" do
         
     | 
| 
       78 
     | 
    
         
            -
                before 
     | 
| 
      
 78 
     | 
    
         
            +
                before { FactoryGirl.create(:news_item, :title => "I was here first") }
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
                it "isn't a problem" do
         
     | 
| 
       81 
81 
     | 
    
         
             
                  visit refinery.new_news_admin_item_path
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,13 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "spec_helper"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe "visit news items" do
         
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                @published_news_item = Factory.create(:news_item, :title => "published", :source => "http://refinerycms.com", :publish_date => 1.hour.ago)
         
     | 
| 
       10 
     | 
    
         
            -
                @unpublished_news_item = Factory.create(:news_item, :title => "unpublished", :publish_date => 1.day.from_now)
         
     | 
| 
      
 4 
     | 
    
         
            +
              before do
         
     | 
| 
      
 5 
     | 
    
         
            +
                FactoryGirl.create(:page, :link_url => "/")
         
     | 
| 
      
 6 
     | 
    
         
            +
                FactoryGirl.create(:page, :link_url => "/news", :title => "News")
         
     | 
| 
      
 7 
     | 
    
         
            +
                FactoryGirl.create(:news_item, :title => "unpublished", :publish_date => 1.day.from_now)
         
     | 
| 
      
 8 
     | 
    
         
            +
                @published_news_item = FactoryGirl.create(:news_item, :title => "published", :source => "http://refinerycms.com", :publish_date => 1.hour.ago)
         
     | 
| 
       11 
9 
     | 
    
         
             
              end
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
       13 
11 
     | 
    
         
             
              it "shows news link in menu" do
         
     | 
| 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Refinery
         
     | 
| 
      
 4 
     | 
    
         
            +
              module News
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe ItemsHelper do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  describe '#news_item_archive_links' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      2.times { FactoryGirl.create(:news_item, :publish_date => Time.utc(2012, 05)) }
         
     | 
| 
      
 9 
     | 
    
         
            +
                      3.times { FactoryGirl.create(:news_item, :publish_date => Time.utc(2012, 04)) }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    it 'returns list of links to archives' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                      expected = '<ul><li><a href="/news/archive/2012/5">May 2012 (2)</a></li><li><a href="/news/archive/2012/4">April 2012 (3)</a></li></ul>'
         
     | 
| 
      
 14 
     | 
    
         
            +
                      helper.news_item_archive_links.should eq(expected)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    end
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  describe "#archive_date_format" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                    context "when date_for_month is true" do
         
     | 
| 
      
 20 
     | 
    
         
            +
                      it "returns month and year" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                        expect(helper.archive_date_format(true)).to eq("%B %Y")
         
     | 
| 
      
 22 
     | 
    
         
            +
                      end
         
     | 
| 
      
 23 
     | 
    
         
            +
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    context "when date_for_month is nil" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                      it "returns year" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                        expect(helper.archive_date_format(nil)).to eq("%Y")
         
     | 
| 
      
 28 
     | 
    
         
            +
                      end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
         @@ -5,7 +5,20 @@ module Refinery 
     | 
|
| 
       5 
5 
     | 
    
         
             
                describe Item do
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                  let(:time_now) { Time.now }
         
     | 
| 
       8 
     | 
    
         
            -
                  let(:news_item) {  
     | 
| 
      
 8 
     | 
    
         
            +
                  let(:news_item) { FactoryGirl.create(:news_item) }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  describe "#archive" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                    let(:publish_date) { Time.utc(2012,1,15) }
         
     | 
| 
      
 12 
     | 
    
         
            +
                    let(:future_date) { Time.utc(2012,2,15) }
         
     | 
| 
      
 13 
     | 
    
         
            +
                    let(:archive_range) { Time.parse("2012-01-17") }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    it "should show 5 news items with publish dates in same month" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                      5.times { FactoryGirl.create(:news_item, :publish_date => publish_date) }
         
     | 
| 
      
 17 
     | 
    
         
            +
                      2.times { FactoryGirl.create(:news_item, :publish_date => future_date) }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      Refinery::News::Item.by_archive(archive_range).count.should == 5
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
       9 
22 
     | 
    
         | 
| 
       10 
23 
     | 
    
         
             
                  describe "validations" do
         
     | 
| 
       11 
24 
     | 
    
         
             
                    subject do
         
     | 
| 
         @@ -29,8 +42,8 @@ module Refinery 
     | 
|
| 
       29 
42 
     | 
    
         | 
| 
       30 
43 
     | 
    
         
             
                  describe "default scope" do
         
     | 
| 
       31 
44 
     | 
    
         
             
                    it "orders by publish date in DESC order" do
         
     | 
| 
       32 
     | 
    
         
            -
                      news_item1 =  
     | 
| 
       33 
     | 
    
         
            -
                      news_item2 =  
     | 
| 
      
 45 
     | 
    
         
            +
                      news_item1 = FactoryGirl.create(:news_item, :publish_date => 1.hour.ago)
         
     | 
| 
      
 46 
     | 
    
         
            +
                      news_item2 = FactoryGirl.create(:news_item, :publish_date => 2.hours.ago)
         
     | 
| 
       34 
47 
     | 
    
         
             
                      news_items = Refinery::News::Item.all
         
     | 
| 
       35 
48 
     | 
    
         
             
                      news_items.first.should == news_item1
         
     | 
| 
       36 
49 
     | 
    
         
             
                      news_items.second.should == news_item2
         
     | 
| 
         @@ -38,7 +51,7 @@ module Refinery 
     | 
|
| 
       38 
51 
     | 
    
         
             
                  end
         
     | 
| 
       39 
52 
     | 
    
         | 
| 
       40 
53 
     | 
    
         
             
                  describe ".not_expired" do
         
     | 
| 
       41 
     | 
    
         
            -
                    let!(:news_item) {  
     | 
| 
      
 54 
     | 
    
         
            +
                    let!(:news_item) { FactoryGirl.create(:news_item) }
         
     | 
| 
       42 
55 
     | 
    
         | 
| 
       43 
56 
     | 
    
         
             
                    specify "expiration date not set" do
         
     | 
| 
       44 
57 
     | 
    
         
             
                      Refinery::News::Item.not_expired.count.should == 1
         
     | 
| 
         @@ -59,33 +72,44 @@ module Refinery 
     | 
|
| 
       59 
72 
     | 
    
         | 
| 
       60 
73 
     | 
    
         
             
                  describe ".published" do
         
     | 
| 
       61 
74 
     | 
    
         
             
                    it "returns only published news items" do
         
     | 
| 
       62 
     | 
    
         
            -
                       
     | 
| 
       63 
     | 
    
         
            -
                       
     | 
| 
      
 75 
     | 
    
         
            +
                      FactoryGirl.create(:news_item)
         
     | 
| 
      
 76 
     | 
    
         
            +
                      FactoryGirl.create(:news_item, :publish_date => Time.now + 1.hour)
         
     | 
| 
       64 
77 
     | 
    
         
             
                      Refinery::News::Item.published.count.should == 1
         
     | 
| 
       65 
78 
     | 
    
         
             
                    end
         
     | 
| 
       66 
79 
     | 
    
         
             
                  end
         
     | 
| 
       67 
80 
     | 
    
         | 
| 
       68 
81 
     | 
    
         
             
                  describe ".latest" do
         
     | 
| 
       69 
82 
     | 
    
         
             
                    it "returns 10 latest news items by default" do
         
     | 
| 
       70 
     | 
    
         
            -
                      5.times {  
     | 
| 
       71 
     | 
    
         
            -
                      5.times {  
     | 
| 
      
 83 
     | 
    
         
            +
                      5.times { FactoryGirl.create(:news_item) }
         
     | 
| 
      
 84 
     | 
    
         
            +
                      5.times { FactoryGirl.create(:news_item, :publish_date => Time.now + 1.hour) }
         
     | 
| 
       72 
85 
     | 
    
         
             
                      Refinery::News::Item.latest.count.should == 5
         
     | 
| 
       73 
     | 
    
         
            -
                      7.times {  
     | 
| 
       74 
     | 
    
         
            -
                      Refinery::News::Item.latest. 
     | 
| 
      
 86 
     | 
    
         
            +
                      7.times { FactoryGirl.create(:news_item) }
         
     | 
| 
      
 87 
     | 
    
         
            +
                      Refinery::News::Item.latest.count.should == 10
         
     | 
| 
       75 
88 
     | 
    
         
             
                    end
         
     | 
| 
       76 
89 
     | 
    
         | 
| 
       77 
90 
     | 
    
         
             
                    it "returns latest n news items" do
         
     | 
| 
       78 
     | 
    
         
            -
                      4.times {  
     | 
| 
       79 
     | 
    
         
            -
                      Refinery::News::Item.latest(3). 
     | 
| 
      
 91 
     | 
    
         
            +
                      4.times { FactoryGirl.create(:news_item) }
         
     | 
| 
      
 92 
     | 
    
         
            +
                      Refinery::News::Item.latest(3).count.should == 3
         
     | 
| 
       80 
93 
     | 
    
         
             
                    end
         
     | 
| 
       81 
94 
     | 
    
         
             
                  end
         
     | 
| 
       82 
95 
     | 
    
         | 
| 
       83 
96 
     | 
    
         
             
                  describe ".not_published?" do
         
     | 
| 
       84 
97 
     | 
    
         
             
                    it "returns not published news items" do
         
     | 
| 
       85 
     | 
    
         
            -
                      news_item =  
     | 
| 
      
 98 
     | 
    
         
            +
                      news_item = FactoryGirl.create(:news_item, :publish_date => Time.now + 1.hour)
         
     | 
| 
       86 
99 
     | 
    
         
             
                      news_item.not_published?.should be_true
         
     | 
| 
       87 
100 
     | 
    
         
             
                    end
         
     | 
| 
       88 
101 
     | 
    
         
             
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  describe ".archived" do
         
     | 
| 
      
 104 
     | 
    
         
            +
                    it "returns all published/expired news items" do
         
     | 
| 
      
 105 
     | 
    
         
            +
                      expired = FactoryGirl.create(:news_item, :publish_date => Time.now - 2.months, :expiration_date => Time.now - 1.months)
         
     | 
| 
      
 106 
     | 
    
         
            +
                      published = FactoryGirl.create(:news_item, :publish_date => Time.now - 1.month)
         
     | 
| 
      
 107 
     | 
    
         
            +
                      not_published = FactoryGirl.create(:news_item, :publish_date => Time.now + 1.month)
         
     | 
| 
      
 108 
     | 
    
         
            +
                      expect(Refinery::News::Item.archived).to include(expired)
         
     | 
| 
      
 109 
     | 
    
         
            +
                      expect(Refinery::News::Item.archived).to include(published)
         
     | 
| 
      
 110 
     | 
    
         
            +
                      expect(Refinery::News::Item.archived).to_not include(not_published)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    end
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
       89 
113 
     | 
    
         
             
                end
         
     | 
| 
       90 
114 
     | 
    
         
             
              end
         
     | 
| 
       91 
     | 
    
         
            -
            end
         
     | 
| 
      
 115 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -1,56 +1,30 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              ENV["RAILS_ENV"] ||= 'test'
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Configure Rails Environment
         
     | 
| 
      
 4 
     | 
    
         
            +
            ENV["RAILS_ENV"] ||= 'test'
         
     | 
| 
       6 
5 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            require File.expand_path("../dummy/config/environment", __FILE__)
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
            require 'rspec/rails'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'capybara/rspec'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'factory_girl_rails'
         
     | 
| 
       12 
11 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
            Rails.backtrace_cleaner.remove_silencers!
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
              # set javascript driver for capybara
         
     | 
| 
       23 
     | 
    
         
            -
              Capybara.javascript_driver = :selenium
         
     | 
| 
       24 
     | 
    
         
            -
            end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            def each_run
         
     | 
| 
       27 
     | 
    
         
            -
              ActiveSupport::Dependencies.clear
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              FactoryGirl.reload
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              # Requires supporting files with custom matchers and macros, etc,
         
     | 
| 
       32 
     | 
    
         
            -
              # in ./support/ and its subdirectories including factories.
         
     | 
| 
       33 
     | 
    
         
            -
              ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
         
     | 
| 
       34 
     | 
    
         
            -
                Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
         
     | 
| 
       35 
     | 
    
         
            -
              }.flatten.sort.each do |support_file|
         
     | 
| 
       36 
     | 
    
         
            -
                require support_file
         
     | 
| 
       37 
     | 
    
         
            -
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
            RSpec.configure do |config|
         
     | 
| 
      
 15 
     | 
    
         
            +
              config.mock_with :rspec
         
     | 
| 
      
 16 
     | 
    
         
            +
              config.treat_symbols_as_metadata_keys_with_true_values = true
         
     | 
| 
      
 17 
     | 
    
         
            +
              config.filter_run :focus => true
         
     | 
| 
      
 18 
     | 
    
         
            +
              config.run_all_when_everything_filtered = true
         
     | 
| 
       38 
19 
     | 
    
         
             
            end
         
     | 
| 
       39 
20 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
            #  
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
              Spork.prefork do
         
     | 
| 
       43 
     | 
    
         
            -
                # Loading more in this block will cause your tests to run faster. However,
         
     | 
| 
       44 
     | 
    
         
            -
                # if you change any configuration or code from libraries loaded here, you'll
         
     | 
| 
       45 
     | 
    
         
            -
                # need to restart spork for it take effect.
         
     | 
| 
       46 
     | 
    
         
            -
                setup_environment
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
            # set javascript driver for capybara
         
     | 
| 
      
 22 
     | 
    
         
            +
            Capybara.javascript_driver = :selenium
         
     | 
| 
       48 
23 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
               
     | 
| 
       55 
     | 
    
         
            -
              each_run
         
     | 
| 
      
 24 
     | 
    
         
            +
            # Requires supporting files with custom matchers and macros, etc,
         
     | 
| 
      
 25 
     | 
    
         
            +
            # in ./support/ and its subdirectories including factories.
         
     | 
| 
      
 26 
     | 
    
         
            +
            ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
         
     | 
| 
      
 27 
     | 
    
         
            +
              Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
         
     | 
| 
      
 28 
     | 
    
         
            +
            }.flatten.sort.each do |support_file|
         
     | 
| 
      
 29 
     | 
    
         
            +
              require support_file
         
     | 
| 
       56 
30 
     | 
    
         
             
            end
         
     |