ismasan-ar_publish_control 0.0.7 → 0.0.8
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 +3 -1
- 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
@@ -103,6 +103,8 @@ Add the necessary fields to you schema, in a migration:
|
|
103
103
|
add_column :posts, :is_published, :boolean, :default => true
|
104
104
|
add_column :posts, :publish_at, :datetime
|
105
105
|
add_column :posts, :unpublish_at, :datetime
|
106
|
+
# update existing records if you have them
|
107
|
+
Post.update_all "publish_at = created_at"
|
106
108
|
end
|
107
109
|
def self.down
|
108
110
|
remove_column :posts, :is_published
|
@@ -111,7 +113,7 @@ Add the necessary fields to you schema, in a migration:
|
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
114
|
-
|
116
|
+
rake db:migrate
|
115
117
|
|
116
118
|
Then, in your Rails app's environment:
|
117
119
|
|
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.8'
|
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
|
#
|
@@ -44,6 +44,10 @@ module ArPublishControl
|
|
44
44
|
# @post = Post.published.find(params[:id])
|
45
45
|
# @comments = @post.comments.only_published( logged_in? )
|
46
46
|
#
|
47
|
+
# Available statuses. This constant is useful for autogenerated routes, controller actions and view helpers
|
48
|
+
#
|
49
|
+
STATUSES = [:published, :unpublished, :upcoming, :expired]
|
50
|
+
|
47
51
|
module Publishable
|
48
52
|
|
49
53
|
def self.included(base) #:nodoc:
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
+
describe ArPublishControl do
|
4
|
+
it "should have array of available statuses" do
|
5
|
+
(ArPublishControl::STATUSES == [:published, :unpublished, :upcoming, :expired]).should be_true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
describe Comment do
|
4
10
|
before(:each) do
|
5
11
|
Post.destroy_all
|
@@ -110,10 +116,13 @@ describe Post, "unpublished by default" do
|
|
110
116
|
before(:each) do
|
111
117
|
Article.destroy_all
|
112
118
|
@a1 = Article.create(:title=>'a1')
|
119
|
+
@invalid = Article.create(:title=>'a2', :publish_at => '')
|
113
120
|
end
|
114
121
|
|
115
122
|
it "should be valid" do
|
116
123
|
@a1.should be_valid
|
124
|
+
@a1.publish_at.should_not be_nil
|
125
|
+
@invalid.publish_at.should_not be_blank
|
117
126
|
end
|
118
127
|
|
119
128
|
it "should be unpublished by default" do
|