ismasan-ar_publish_control 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -76,10 +76,13 @@ Adds published, unpublished and published_only(boolean) named_scopes to your mod
76
76
  @upcoming_post = Post.upcoming
77
77
  @upcoming_post.first.upcoming? # => true
78
78
 
79
- # Finally, you can fetch objects that have expired (ie. they have an unpublish_at date set in the past)
79
+ # You can fetch objects that have expired (ie. they have an unpublish_at date set in the past)
80
80
  @expired_posts = Post.expired
81
81
  @expired_posts.first.expired? # => true
82
82
 
83
+ # Finally, if you want those objects where is_published == false, regardless of dates
84
+ @drafts = Post.draft
85
+
83
86
  All of these named_scopes can be chained with other finder conditions and paginated with will_paginate
84
87
 
85
88
  == REQUIREMENTS:
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ar_publish_control}
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ismael Celis"]
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module ArPublishControl
5
- VERSION = '0.0.8'
5
+ VERSION = '0.0.9'
6
6
  # This is a gem version of http://github.com/avdgaag/acts_as_publishable ( a Rails plugin)
7
7
  # Thanks to Avdaag for his awesome, super readable code which I ripped off for this gem.
8
8
  #
@@ -31,12 +31,16 @@ module ArPublishControl
31
31
  # You can use two named_scopes to find the published or unpublished objects.
32
32
  # You can chain them with other scopes and use them on association collections:
33
33
  #
34
- # Post.all.size # => 15
35
- # Post.published.size # => 10
36
- # Post.unpublished.size # => 5
34
+ # Post.all.count # => 15
35
+ # Post.published.count # => 10
36
+ # Post.unpublished.count # => 5 includes upcoming and expired
37
+ # Post.draft.count # => where is_published == false regardless of date
37
38
  # @post.comments.published
38
39
  #
39
40
  # Post.recent.published
41
+ #
42
+ # Klass.unpublished includes all objects which is_published flag is set to false and/or are expired or upcoming.
43
+ # If you specifically want those where is_published == false regardless of dates, use Klass.draft
40
44
  #
41
45
  # There's a third named_scope that you can pass a boolean in order to find only published items or all of them
42
46
  # This is useful in controller for permission-based publish control
@@ -46,7 +50,7 @@ module ArPublishControl
46
50
  #
47
51
  # Available statuses. This constant is useful for autogenerated routes, controller actions and view helpers
48
52
  #
49
- STATUSES = [:published, :unpublished, :upcoming, :expired]
53
+ STATUSES = [:published, :draft, :upcoming, :expired]
50
54
 
51
55
  module Publishable
52
56
 
@@ -99,6 +103,7 @@ module ArPublishControl
99
103
  named_scope :unpublished, lambda{{:conditions => unpublished_conditions}}
100
104
  named_scope :upcoming, lambda{{:conditions => upcoming_conditions}}
101
105
  named_scope :expired, lambda {{:conditions => expired_conditions}}
106
+ named_scope :draft, :conditions => {:is_published => false}
102
107
 
103
108
  named_scope :published_only, lambda {|*args|
104
109
  bool = (args.first.nil? ? true : (args.first)) # nil = true by default
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe ArPublishControl do
4
4
  it "should have array of available statuses" do
5
- (ArPublishControl::STATUSES == [:published, :unpublished, :upcoming, :expired]).should be_true
5
+ (ArPublishControl::STATUSES == [:published, :draft, :upcoming, :expired]).should be_true
6
6
  end
7
7
  end
8
8
 
@@ -170,6 +170,20 @@ describe Post, 'expired' do
170
170
  end
171
171
  end
172
172
 
173
+ describe Post, 'draft' do
174
+ before(:each) do
175
+ Post.destroy_all
176
+ @p1 = Post.create(:title => 'p1',:is_published => true,:publish_at => 2.weeks.ago) #published
177
+ @p2 = Post.create(:title => 'p2',:is_published => true,:publish_at => 2.weeks.ago,:unpublish_at => 1.day.ago)#expired
178
+ @p3 = Post.create(:title => 'p3',:is_published => false,:publish_at => 3.days.ago,:unpublish_at => 2.hours.ago)#unpublished and expired
179
+ end
180
+
181
+ it "should have draft" do
182
+ Post.draft.count.should == 1
183
+ Post.draft.first.should == @p3
184
+ end
185
+ end
186
+
173
187
  describe "new record" do
174
188
  it "should default to Time.now" do
175
189
  # d = Time.now
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ismasan-ar_publish_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis