ismasan-ar_publish_control 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -4
- data/ar_publish_control.gemspec +1 -1
- data/lib/ar_publish_control.rb +5 -1
- data/spec/ar_publish_control_spec.rb +9 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -37,11 +37,11 @@ Adds published, unpublished and published_only(boolean) named_scopes to your mod
|
|
37
37
|
<%= f.check_box :is_published %>
|
38
38
|
</p>
|
39
39
|
<p>
|
40
|
-
<%= f.label :
|
40
|
+
<%= f.label :publish_at, "From" %>
|
41
41
|
<%= f.date_select :publish_at %>
|
42
42
|
</p>
|
43
43
|
<p>
|
44
|
-
<%= f.label :
|
44
|
+
<%= f.label :unpublish_at, "To" %>
|
45
45
|
<%= f.date_select :unpublish_at %>
|
46
46
|
</p>
|
47
47
|
...
|
@@ -54,6 +54,7 @@ Adds published, unpublished and published_only(boolean) named_scopes to your mod
|
|
54
54
|
|
55
55
|
def show
|
56
56
|
@post = Post.published.find(params[:id])
|
57
|
+
@post.published? # => true
|
57
58
|
end
|
58
59
|
|
59
60
|
# You can nest scopes:
|
@@ -65,10 +66,11 @@ Adds published, unpublished and published_only(boolean) named_scopes to your mod
|
|
65
66
|
@posts = Post.unpublished
|
66
67
|
|
67
68
|
# All posts if logged_in?, only published otherwise
|
68
|
-
@posts = Post.published_only?( logged_in? ).paginate(:page => params[:page])
|
69
|
+
@posts = Post.published_only?( !logged_in? ).paginate(:page => params[:page])
|
69
70
|
|
70
71
|
# Unpublish
|
71
72
|
@post.unpublish!
|
73
|
+
@post.unpublished? # => true
|
72
74
|
|
73
75
|
# You can access the ones marked as "published" but with a publish date in the future
|
74
76
|
@upcoming_post = Post.upcoming
|
@@ -78,7 +80,7 @@ Adds published, unpublished and published_only(boolean) named_scopes to your mod
|
|
78
80
|
@expired_posts = Post.expired
|
79
81
|
@expired_posts.first.expired? # => true
|
80
82
|
|
81
|
-
All of these named_scopes can be
|
83
|
+
All of these named_scopes can be chained with other finder conditions and paginated with will_paginate
|
82
84
|
|
83
85
|
== REQUIREMENTS:
|
84
86
|
|
data/ar_publish_control.gemspec
CHANGED
data/lib/ar_publish_control.rb
CHANGED
@@ -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.
|
5
|
+
VERSION = '0.0.5'
|
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
|
#
|
@@ -145,6 +145,10 @@ module ArPublishControl
|
|
145
145
|
|
146
146
|
module InstanceMethods
|
147
147
|
|
148
|
+
def publish_at
|
149
|
+
read_attribute(:publish_at) || Time.now
|
150
|
+
end
|
151
|
+
|
148
152
|
# Publish at is NOW if not set
|
149
153
|
def init_publish_date
|
150
154
|
write_attribute(:publish_at, Time.now) if publish_at.nil?
|
@@ -160,3 +160,12 @@ describe Post, 'expired' do
|
|
160
160
|
Post.expired.size.should == 2
|
161
161
|
end
|
162
162
|
end
|
163
|
+
|
164
|
+
describe "new record" do
|
165
|
+
it "should default to Time.now" do
|
166
|
+
d = Time.now
|
167
|
+
Time.stub!(:now).and_return d
|
168
|
+
a = Article.new
|
169
|
+
a.publish_at.should == d
|
170
|
+
end
|
171
|
+
end
|