publish 0.2.0 → 0.3.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 +8 -8
- data/CHANGELOG.md +11 -1
- data/Gemfile +3 -1
- data/README.md +17 -9
- data/gemfiles/mongoid-master.gemfile +2 -0
- data/lib/mongoid/publish.rb +7 -8
- data/lib/mongoid/publish/version.rb +1 -1
- data/publish.gemspec +1 -0
- data/test/publish/mongoid/publish_test.rb +43 -41
- data/test/test_helper.rb +5 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTE4YmQ5ZTA4ZDc1MzM3NzViYjljODcyZTFlZjQxMDc5ZDllOGFlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmVmZTEyNTdkYWY5YjEyN2MwM2M1ZmFlOTE2NDg5OGUxMjE4YjcyYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTJkNTgyM2E5MTNjNGNlZGIyMzUzZmNhMjYwNWZhNzUzODY2ZDkwOGE4ZGEw
|
10
|
+
ZGZlZGJiZDI3NTcyNjg1Y2Q5MzRjMzg5Yjk2Y2M4OWE1YWIzYThlZDJlZGZl
|
11
|
+
NzZiYTcyNmRjMjhkZTBkZmRjMzUwZThiMjllMDJjZDIzMDFmMmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTQ0Njk3ZDFmZDhmMTM4NjhhNzBkNjI4MTUzN2U2MjM2Njc3ZDEwN2RkMzc3
|
14
|
+
NmJjNGJlMGRmOWE1ODYyMWQwNGVhYTdiNzNjZTExODE3ODYyYzA3ZjNiNDYz
|
15
|
+
OWJjZmViOGQ5MjI3OTdkNWZkOWVjNWRmMWE3ZTgwODIxMmZlYTk=
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,17 @@
|
|
2
2
|
|
3
3
|
## Next Release (branch: master)
|
4
4
|
|
5
|
-
*
|
5
|
+
* TODO
|
6
|
+
|
7
|
+
## 0.3.0 - 2013-04-04
|
8
|
+
|
9
|
+
* Changes published_at field type from Date to Time
|
10
|
+
|
11
|
+
* Removes scope `published_and_orderly`
|
12
|
+
|
13
|
+
## 0.2.0 - 2013-03-22
|
14
|
+
|
15
|
+
* New method `list` - see README
|
6
16
|
|
7
17
|
## 0.1.2 - 2013-03-04
|
8
18
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Publish [](http://travis-ci.org/lucasrenan/publish) [](http://gemnasium.com/lucasrenan/publish) [](https://codeclimate.com/github/lucasrenan/publish)
|
1
|
+
# Publish [](http://travis-ci.org/lucasrenan/publish) [](http://gemnasium.com/lucasrenan/publish) [](https://codeclimate.com/github/lucasrenan/publish) [](https://coveralls.io/r/lucasrenan/publish)
|
2
2
|
|
3
3
|
|
4
4
|
Publish is a gem that adds the common functionality to publish (or set as draft) a document using Mongoid.
|
@@ -8,7 +8,7 @@ Publish is a gem that adds the common functionality to publish (or set as draft)
|
|
8
8
|
Add to Gemfile
|
9
9
|
|
10
10
|
``` ruby
|
11
|
-
gem "publish", "~> 0.
|
11
|
+
gem "publish", "~> 0.3.0"
|
12
12
|
```
|
13
13
|
|
14
14
|
Then run
|
@@ -31,19 +31,27 @@ class Post
|
|
31
31
|
field :text
|
32
32
|
end
|
33
33
|
|
34
|
-
Post.published.count #0
|
34
|
+
Post.published.count # 0
|
35
35
|
|
36
36
|
p = Post.new
|
37
|
-
p.published? #false
|
38
|
-
p.published_at #nil
|
37
|
+
p.published? # false
|
38
|
+
p.published_at # nil
|
39
39
|
|
40
|
-
p.publish! #p.published = true
|
40
|
+
p.publish! # p.published = true
|
41
41
|
|
42
|
-
p.published? #true
|
42
|
+
p.published? # true
|
43
43
|
|
44
|
-
Post.published.count #1
|
44
|
+
Post.published.count # 1
|
45
45
|
|
46
|
-
p.publication_status #
|
46
|
+
p.publication_status # Time.now or 'draft'
|
47
|
+
```
|
48
|
+
|
49
|
+
Filtering
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
Post.published # scope - where(:published => true, :published_at.lte => Time.now)
|
53
|
+
|
54
|
+
Post.list(false) # scope - criteria.published
|
47
55
|
```
|
48
56
|
|
49
57
|
## Callbacks (before_publish and after_publish)
|
data/lib/mongoid/publish.rb
CHANGED
@@ -3,35 +3,34 @@ module Mongoid
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
field :published_at, :type =>
|
6
|
+
field :published_at, :type => Time
|
7
7
|
field :published, :type => Boolean, :default => false
|
8
8
|
|
9
|
-
scope :published, -> { where(:published => true, :published_at.lte =>
|
10
|
-
scope :published_and_orderly, -> { where(:published => true, :published_at.lte => Date.today).desc(:published_at, :created_at) }
|
9
|
+
scope :published, -> { where(:published => true, :published_at.lte => Time.now) }
|
11
10
|
|
12
11
|
before_save :set_published_at
|
13
12
|
end
|
14
13
|
|
15
14
|
include Mongoid::Publish::Callbacks
|
16
|
-
|
15
|
+
|
17
16
|
def published?
|
18
|
-
return true if self.published && self.published_at && self.published_at <=
|
17
|
+
return true if self.published && self.published_at && self.published_at <= Time.now
|
19
18
|
false
|
20
19
|
end
|
21
20
|
|
22
21
|
def publish!
|
23
22
|
self.published = true
|
24
|
-
self.published_at =
|
23
|
+
self.published_at = Time.now
|
25
24
|
self.save
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def publication_status
|
29
28
|
self.published? ? self.published_at : "draft"
|
30
29
|
end
|
31
30
|
|
32
31
|
private
|
33
32
|
def set_published_at
|
34
|
-
self.published_at =
|
33
|
+
self.published_at = Time.now if self.published && self.published_at.nil?
|
35
34
|
end
|
36
35
|
|
37
36
|
module ClassMethods
|
data/publish.gemspec
CHANGED
@@ -7,72 +7,74 @@ class PublishTest < ActiveSupport::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test "should create published at field" do
|
10
|
-
assert
|
11
|
-
assert_nil
|
10
|
+
assert @post.respond_to?(:published_at)
|
11
|
+
assert_nil @post.published_at
|
12
12
|
end
|
13
13
|
|
14
14
|
test "should create published field" do
|
15
|
-
assert
|
16
|
-
assert_equal
|
15
|
+
assert @post.respond_to?(:published)
|
16
|
+
assert_equal @post.published?, false
|
17
17
|
end
|
18
18
|
|
19
|
-
test "should be
|
20
|
-
post
|
19
|
+
test "should be not published if published_at is not setted" do
|
20
|
+
post = build(:post)
|
21
21
|
post.published = true
|
22
22
|
|
23
|
-
assert_equal post.published
|
23
|
+
assert_equal false, post.published?
|
24
24
|
end
|
25
25
|
|
26
|
-
test "should
|
26
|
+
test "should publish setting published field manually" do
|
27
27
|
@post.published = true
|
28
|
-
@post.save
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
Timecop.freeze do
|
30
|
+
@post.save
|
31
|
+
|
32
|
+
assert @post.published?
|
33
|
+
assert_equal @post.published_at, Time.now
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
|
-
test "should
|
36
|
-
|
37
|
+
test "should publish a post calling publish! method" do
|
38
|
+
post = build(:post)
|
39
|
+
post.publish!
|
40
|
+
post.reload
|
37
41
|
|
38
|
-
|
42
|
+
assert post.published?
|
43
|
+
assert_equal 1, Post.published.count
|
39
44
|
end
|
40
45
|
|
41
|
-
test "should return
|
42
|
-
|
43
|
-
|
44
|
-
create(:post, :title => "1", :published => true, :published_at => 1.day.ago)
|
46
|
+
test "should return publication status as 'draft' if it's not published yet" do
|
47
|
+
assert_equal "draft", Post.last.publication_status
|
48
|
+
end
|
45
49
|
|
46
|
-
|
50
|
+
test "should sets published at time automatically after publish" do
|
51
|
+
Timecop.freeze do
|
52
|
+
@post.publish!
|
53
|
+
assert_equal @post.publication_status, Time.now
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
|
-
test "should
|
50
|
-
post =
|
51
|
-
post.
|
52
|
-
|
57
|
+
test "should sets published at with just date" do
|
58
|
+
@post.published_at = Date.today
|
59
|
+
@post.save
|
60
|
+
|
61
|
+
assert_equal Date.today, @post.published_at.to_date
|
62
|
+
end
|
53
63
|
|
54
|
-
|
55
|
-
|
64
|
+
test "should list published posts" do
|
65
|
+
2.times { create(:post, :published => true) }
|
66
|
+
|
67
|
+
assert_equal Post.published.size, 2
|
56
68
|
end
|
57
|
-
|
69
|
+
|
58
70
|
test "should concat with criteria methods" do
|
59
71
|
create(:post, :published => true, :title => "normal post")
|
60
72
|
create(:post, :published => true, :title => "my special post")
|
61
|
-
|
62
|
-
assert_equal Post.where(:title => /special/).published.count
|
63
|
-
assert_equal Post.published.where(:title => /special/).count
|
64
|
-
end
|
65
|
-
|
66
|
-
test "should return publication status as draft if is not published yet" do
|
67
|
-
assert_equal Post.last.publication_status, "draft"
|
68
|
-
end
|
69
|
-
|
70
|
-
test "should return published at date if is published" do
|
71
|
-
@post.publish!
|
72
|
-
|
73
|
-
assert_equal Post.last.publication_status, Date.today
|
73
|
+
|
74
|
+
assert_equal 1, Post.where(:title => /special/).published.count
|
75
|
+
assert_equal 1, Post.published.where(:title => /special/).count
|
74
76
|
end
|
75
|
-
|
77
|
+
|
76
78
|
test "should list posts excluding drafts" do
|
77
79
|
3.times { create(:post, :published => true) }
|
78
80
|
create(:post, :published => false)
|
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
1
4
|
#generates coverage report
|
2
5
|
require 'simplecov'
|
3
6
|
SimpleCov.start('rails') do
|
@@ -10,6 +13,8 @@ ENV["RAILS_ENV"] = "test"
|
|
10
13
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
11
14
|
require "rails/test_help"
|
12
15
|
|
16
|
+
require "timecop"
|
17
|
+
|
13
18
|
ActionMailer::Base.delivery_method = :test
|
14
19
|
ActionMailer::Base.perform_deliveries = true
|
15
20
|
ActionMailer::Base.default_url_options[:host] = "test.com"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: publish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Renan
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongoid
|
@@ -68,6 +68,20 @@ dependencies:
|
|
68
68
|
- - ~>
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: 0.7.0
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: timecop
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.6.1
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.6.1
|
71
85
|
description: Adds the functionality to publish/unpublish mongoid docs
|
72
86
|
email:
|
73
87
|
- contato@lucasrenan.com
|