refinerycms-news 1.1.0 → 1.2.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.
@@ -1,12 +1,10 @@
1
1
  class NewsItem < ActiveRecord::Base
2
- belongs_to :image, :class_name => 'Image'
3
-
4
2
  translates :title, :body, :external_url
5
3
 
6
4
  attr_accessor :locale # to hold temporarily
7
5
 
8
6
  alias_attribute :content, :body
9
- validates_presence_of :title, :content, :publish_date
7
+ validates :title, :content, :publish_date, :presence => true
10
8
 
11
9
  has_friendly_id :title, :use_slug => true
12
10
 
@@ -16,8 +14,12 @@ class NewsItem < ActiveRecord::Base
16
14
 
17
15
  # If you're using a named scope that includes a changing variable you need to wrap it in a lambda
18
16
  # This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
17
+ scope :not_expired, lambda {
18
+ news_items = Arel::Table.new(NewsItem.table_name)
19
+ where(news_items[:expiration_date].eq(nil).or(news_items[:expiration_date].gt(Time.now)))
20
+ }
19
21
  scope :published, lambda {
20
- where( "publish_date < ?", Time.now )
22
+ not_expired.where("publish_date < ?", Time.now)
21
23
  }
22
24
  scope :latest, lambda { |*l_params|
23
25
  published.limit( l_params.first || 10)
@@ -21,18 +21,14 @@
21
21
  </div>
22
22
 
23
23
  <div class='field'>
24
- <%= f.label :content %>
25
- <%= f.text_area :content, :rows => "20", :class => "wymeditor widest" %>
24
+ <%= f.label :expiration_date %>
25
+ <%= f.datetime_select :expiration_date, :start_year => Time.now.year,
26
+ :include_blank => true %>
26
27
  </div>
27
28
 
28
29
  <div class='field'>
29
- <%= f.label :external_url %>
30
- <%= f.text_field :external_url, :class => "larger widest" %>
31
- </div>
32
-
33
- <div class='field'>
34
- <%= f.label :image %>
35
- <%= render :partial => "/shared/admin/image_picker", :locals => {:f => f, :field => :image_id, :image => @news_item.image } %>
30
+ <%= f.label :content %>
31
+ <%= f.text_area :content, :rows => "20", :class => "wymeditor widest" %>
36
32
  </div>
37
33
 
38
34
  <%= render :partial => "/shared/admin/form_actions",
@@ -4,7 +4,7 @@
4
4
  <span class="preview">
5
5
  <%= t('.published') %> <%= l(news_item.publish_date, :format => :short) %>
6
6
  </span>
7
- <% if ::Refinery::I18n.frontend_locales.many? and
7
+ <% if defined?(::Refinery::I18n) and ::Refinery::I18n.frontend_locales.many? and
8
8
  (locales = news_item.translations.collect{|t| t.locale}).present? %>
9
9
  <span class='preview'>
10
10
  <% locales.each do |locale| %>
@@ -1,9 +1,5 @@
1
- <% content_for :body_content_title do %>
2
- <%= t('plugins.refinerycms_news.title') %>
3
- <% end %>
4
-
5
1
  <% content_for :body_content_left do %>
6
- <%= @page[:body] if @news_items.offset == 0 %>
2
+ <%=raw @page[:body] if @news_items.offset == 0 %>
7
3
 
8
4
  <% if @news_items.any? %>
9
5
  <% @news_items.each do |item| %>
@@ -32,11 +32,5 @@ cs:
32
32
  title: Název
33
33
  body: Obsah
34
34
  publish_date: Datum zveřejnění
35
- external_url: Veřejná URL
36
- image: &image Obrázek
37
35
  models:
38
36
  news_item: Novinka
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -32,11 +32,5 @@ de:
32
32
  title: Titel
33
33
  body: Inhalt
34
34
  publish_date: Veröffentlichungsdatum
35
- external_url: Externe URL
36
- image: &image Image
37
35
  models:
38
36
  news_item: News-Eintrag
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -32,11 +32,6 @@ en:
32
32
  title: Title
33
33
  body: Body
34
34
  publish_date: Publish date
35
- external_url: External URL
36
- image: &image Image
35
+ expiration_date: Expiration date
37
36
  models:
38
37
  news_item: News Item
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -30,11 +30,5 @@ es-MX:
30
30
  title: Título
31
31
  body: Contenido
32
32
  publish_date: Fecha de publicación
33
- external_url: URL externa
34
- image: &image Imagen
35
33
  models:
36
34
  news_item: Noticia
37
- shared:
38
- admin:
39
- image_picker:
40
- image: *image
@@ -32,12 +32,5 @@ es:
32
32
  title: Título
33
33
  body: Contenido
34
34
  publish_date: Fecha de publicación
35
- external_url: URL externa
36
- image: &image Imagen
37
35
  models:
38
36
  news_item: Noticia
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
43
-
@@ -32,11 +32,5 @@ fr:
32
32
  title: Titre
33
33
  body: Texte
34
34
  publish_date: Date de publication
35
- external_url: Lien externe
36
- image: &image Image
37
35
  models:
38
36
  news_item: Nouvelle
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -32,12 +32,5 @@ it:
32
32
  title: Titolo
33
33
  body: Corpo
34
34
  publish_date: Data di pubblicazione
35
- external_url: URL esterni
36
- image: &image Immagine
37
35
  models:
38
36
  news_item: Notizia
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
43
-
@@ -31,12 +31,6 @@ lv:
31
31
  body: Saturs
32
32
  content: Saturs
33
33
  publish_date: Publikācijas datums
34
- external_url: ārējo URL
35
- image: &image Attēlu
34
+ expiration_date: Publikācijas beigu datums
36
35
  models:
37
36
  news_item: jaunums
38
- shared:
39
- admin:
40
- image_picker:
41
- image: *image
42
-
@@ -32,12 +32,5 @@ nb:
32
32
  title: Tittel
33
33
  body: Tekst
34
34
  publish_date: Publiseringsdato
35
- external_url: Ekstern adresse
36
- image: &image Bilde
37
35
  models:
38
36
  news_item: Nyhet
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
43
-
@@ -32,12 +32,5 @@ nl:
32
32
  title: Titel
33
33
  body: Inhoud
34
34
  publish_date: Publiceer datum
35
- external_url: Externe URL
36
- image: &image Beeld
37
35
  models:
38
36
  news_item: Nieuws Item
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
43
-
@@ -30,12 +30,5 @@ ru:
30
30
  title: "Заголовок"
31
31
  body: "Публикация"
32
32
  publish_date: "Дата публикации"
33
- external_url: "внешний URL"
34
- image: &image "Изображение"
35
33
  models:
36
34
  news_item: "Новость"
37
- shared:
38
- admin:
39
- image_picker:
40
- image: *image
41
-
@@ -32,11 +32,5 @@ sk:
32
32
  title: Názov
33
33
  body: Obsah
34
34
  publish_date: Dátum zverejnenia
35
- external_url: Verejná URL
36
- image: &image Obrázok
37
35
  models:
38
36
  news_item: Novinka
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -32,11 +32,5 @@ sl:
32
32
  title: Naslov
33
33
  body: Opis
34
34
  publish_date: Datum objave
35
- external_url: Externé URL
36
- image: &image "obrázok"
37
35
  models:
38
36
  news_item: Novice
39
- shared:
40
- admin:
41
- image_picker:
42
- image: *image
@@ -0,0 +1,15 @@
1
+ class AddExpirationDateToNewsItems < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ unless ::NewsItem.column_names.map(&:to_sym).include?(:expiration_date)
5
+ add_column ::NewsItem.table_name, :expiration_date, :datetime
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ if ::NewsItem.column_names.map(&:to_sym).include?(:expiration_date)
11
+ remove_column ::NewsItem.table_name, :expiration_date
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,19 @@
1
+ class RemoveImageIdAndExternalUrlFromNews < ActiveRecord::Migration
2
+ def self.up
3
+ if ::NewsItem.column_names.map(&:to_sym).include?(:external_url)
4
+ remove_column ::NewsItem.table_name, :external_url
5
+ end
6
+ if ::NewsItem.column_names.map(&:to_sym).include?(:image_id)
7
+ remove_column ::NewsItem.table_name, :image_id
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ unless ::NewsItem.column_names.map(&:to_sym).include?(:external_url)
13
+ add_column ::NewsItem.table_name, :external_url, :string
14
+ end
15
+ unless ::NewsItem.column_names.map(&:to_sym).include?(:image_id)
16
+ add_column ::NewsItem.table_name, :image_id, :integer
17
+ end
18
+ end
19
+ end
@@ -18,14 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.authors = %w(Resolve\\ Digital)
19
19
  s.require_paths = %w(lib)
20
20
 
21
- s.add_dependency 'refinerycms-core', '~> 0.9.9.15'
21
+ s.add_dependency 'refinerycms-core', '~> 1.0.0'
22
22
 
23
23
  s.files = [
24
24
  '#{files.join("',\n '")}'
25
25
  ]
26
- #{"s.test_files = [
27
- '#{Dir.glob("test/**/*.rb").join("',\n '")}'
28
- ]" if File.directory?("test")}
29
26
  end
30
27
  EOF
31
28
 
@@ -2,7 +2,7 @@ module Refinery
2
2
  module News
3
3
  class << self
4
4
  def version
5
- %q{1.1.0}
5
+ %q{1.2.0}
6
6
  end
7
7
  end
8
8
  end
@@ -3,33 +3,28 @@ require 'spec_helper'
3
3
  Dir[File.expand_path('../../../features/support/factories.rb', __FILE__)].each {|f| require f}
4
4
 
5
5
  describe NewsItem do
6
- describe "validations" do
7
- before(:each) do
8
- @attr = {
9
- :title => "RefinyerCMS",
10
- :content => "Some random text ...",
11
- :publish_date => Date.today
12
- }
13
- end
14
-
15
- it "rejects empty title" do
16
- NewsItem.new(@attr.merge(:title => "")).should_not be_valid
17
- end
6
+
7
+ let(:time_now) { Time.now }
8
+ let(:news_item) { Factory(:news_item) }
18
9
 
19
- it "rejects empty content" do
20
- NewsItem.new(@attr.merge(:content => "")).should_not be_valid
10
+ describe "validations" do
11
+ subject do
12
+ news_item = NewsItem.create! :title => "RefinyerCMS",
13
+ :content => "Some random text ...",
14
+ :publish_date => time_now
15
+ news_item
21
16
  end
22
17
 
23
- it "rejects empty publish date" do
24
- NewsItem.new(@attr.merge(:publish_date => "")).should_not be_valid
25
- end
18
+ it { should be_valid }
19
+ its(:errors) { should be_empty }
20
+ its(:title) { should == "RefinyerCMS" }
21
+ its(:content) { should == "Some random text ..." }
22
+ its(:publish_date) { should == time_now }
26
23
  end
27
24
 
28
25
  describe "attribute aliasing" do
29
- it "aliases content to body" do
30
- news_item = Factory(:news_item)
31
- news_item.content.should == news_item.body
32
- end
26
+ subject { news_item }
27
+ its(:content) { should == news_item.body }
33
28
  end
34
29
 
35
30
  describe "default scope" do
@@ -42,6 +37,26 @@ describe NewsItem do
42
37
  end
43
38
  end
44
39
 
40
+ describe ".not_expired" do
41
+ let!(:news_item) { Factory(:news_item) }
42
+
43
+ specify "expiration date not set" do
44
+ NewsItem.not_expired.count.should == 1
45
+ end
46
+
47
+ specify "expiration date set in future" do
48
+ news_item.expiration_date = Time.now + 1.hour
49
+ news_item.save!
50
+ NewsItem.not_expired.count.should == 1
51
+ end
52
+
53
+ specify "expiration date in past" do
54
+ news_item.expiration_date = Time.now - 1.hour
55
+ news_item.save!
56
+ NewsItem.not_expired.count.should == 0
57
+ end
58
+ end
59
+
45
60
  describe ".published" do
46
61
  it "returns only published news items" do
47
62
  Factory(:news_item)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: refinerycms-news
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Resolve Digital
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-07 00:00:00 +12:00
13
+ date: 2011-05-27 00:00:00 +12:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.9.9.15
24
+ version: 1.0.0
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  description: A really straightforward open source Ruby on Rails news engine designed for integration with RefineryCMS.
@@ -65,6 +65,8 @@ files:
65
65
  - db/migrate/2_add_external_url_to_news_items.rb
66
66
  - db/migrate/3_translate_news_items.rb
67
67
  - db/migrate/4_add_image_id_to_news_items.rb
68
+ - db/migrate/5_add_expiration_date_to_news_items.rb
69
+ - db/migrate/6_remove_image_id_and_external_url_from_news.rb
68
70
  - db/seeds/refinerycms_news.rb
69
71
  - features/manage_news_items.feature
70
72
  - features/step_definitions/news_steps.rb
@@ -78,8 +80,6 @@ files:
78
80
  - license.md
79
81
  - readme.md
80
82
  - spec/models/news_item_spec.rb
81
- - test/fixtures/news_items.yml
82
- - test/unit/news_items_test.rb
83
83
  has_rdoc: true
84
84
  homepage: http://refinerycms.com
85
85
  licenses: []
@@ -104,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements: []
105
105
 
106
106
  rubyforge_project:
107
- rubygems_version: 1.6.1
107
+ rubygems_version: 1.6.2
108
108
  signing_key:
109
109
  specification_version: 3
110
110
  summary: Ruby on Rails news engine for RefineryCMS.
111
- test_files:
112
- - test/unit/news_items_test.rb
111
+ test_files: []
112
+
@@ -1,14 +0,0 @@
1
- website_launched:
2
- title: New website launched!
3
- body: Oh yes our brand new website is here and it is running on Refinery CMS.
4
- publish_date: <%= Date.today - 4.days %>
5
-
6
- new_team_member:
7
- title: Amanda joins Resolve Digital
8
- body: Welcome Amanda to the Resolve Digital team.
9
- publish_date: <%= Date.today - 2.days %>
10
-
11
- product_launch:
12
- title: Secret new product launched
13
- body: Oh yes our brand new website is here and it is running on Refinery CMS.
14
- publish_date: <%= Date.today.tomorrow %>
@@ -1,34 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NewsItemsTest < ActiveSupport::TestCase
4
-
5
- self.fixture_path = File.expand_path("../../fixtures", __FILE__)
6
- fixtures :news_items
7
-
8
- def setup
9
- @new_news_item = NewsItem.new
10
- @new_valid_news_item = NewsItem.new(:title => "valid post", :content => "yep looks valid", :publish_date => Date.today)
11
- end
12
-
13
- def test_should_not_save_without_title_and_body
14
- assert !@new_news_item.save
15
-
16
- assert_equal "can't be blank", @new_news_item.errors.on('title')
17
- assert_equal "can't be blank", @new_news_item.errors.on('content')
18
- assert_equal "can't be blank", @new_news_item.errors.on('publish_date')
19
-
20
- assert @new_valid_news_item.save
21
- end
22
-
23
- def test_per_page
24
- assert_equal 20, NewsItem.per_page
25
- end
26
-
27
- def test_named_scopes
28
- assert_equal 2, NewsItem.published.size
29
- assert NewsItem.latest.size < 10
30
-
31
- assert_equal news_items(:new_team_member), NewsItem.latest.first
32
- end
33
-
34
- end