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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzNhOTQ5NmRlOTUwMWFiZjg0OGZkOTFkZDdmNWRmMDk0Zjc0ZWY3OQ==
4
+ OTE4YmQ5ZTA4ZDc1MzM3NzViYjljODcyZTFlZjQxMDc5ZDllOGFlNw==
5
5
  data.tar.gz: !binary |-
6
- OGRkNzAxZDI1OGVkZWI0YmYyMmY2NzYzMDhiMWVhNWJhZjEzYjkzYQ==
6
+ NmVmZTEyNTdkYWY5YjEyN2MwM2M1ZmFlOTE2NDg5OGUxMjE4YjcyYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTU3ZGEyMWEwYjY3YzEwZjdlZTUxNWFlNzk3OWVlYjg3NGYyNDc4MmVlZjBi
10
- OTVmMGY2N2MxODk1MjMxYzJjYzY5ZGExZTM2NzY1YjU1ZTM5NjI2YjYyN2Yw
11
- ZWY1NWYyOWFkNjNiOTgzZDMzMDE3NGYyYzI2NjA4NWQ2MDRjNjY=
9
+ YTJkNTgyM2E5MTNjNGNlZGIyMzUzZmNhMjYwNWZhNzUzODY2ZDkwOGE4ZGEw
10
+ ZGZlZGJiZDI3NTcyNjg1Y2Q5MzRjMzg5Yjk2Y2M4OWE1YWIzYThlZDJlZGZl
11
+ NzZiYTcyNmRjMjhkZTBkZmRjMzUwZThiMjllMDJjZDIzMDFmMmY=
12
12
  data.tar.gz: !binary |-
13
- NWE3YzVlNGQ1NTU1NzUwYmFmY2Y3YWIzZjkyZDIxMTg5MzBhYmQ0NTEyZTIz
14
- NDkxNTQ2Y2I0Y2M3NTE0MGI0YWJjNmNhYzYyMGQ0Y2VhMzFiZjcyMTc1OWQ0
15
- NWExMjJmMWRjZGJhZTViMjQzZTlmNzE5MGRhZThkMDhkYmQ0ZjY=
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
- * Create a todo list
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
@@ -3,4 +3,6 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "factory_girl_rails", "~> 4.2.0"
6
- gem "colorific", "~> 1.0.2"
6
+ gem "colorific", "~> 1.0.2"
7
+
8
+ gem "coveralls", require: false
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Publish [![Build Status](https://secure.travis-ci.org/lucasrenan/publish.png?branch=master)](http://travis-ci.org/lucasrenan/publish) [![Build Status](https://gemnasium.com/lucasrenan/publish.png)](http://gemnasium.com/lucasrenan/publish) [![Code Climate](https://codeclimate.com/github/lucasrenan/publish.png)](https://codeclimate.com/github/lucasrenan/publish)
1
+ # Publish [![Build Status](https://secure.travis-ci.org/lucasrenan/publish.png?branch=master)](http://travis-ci.org/lucasrenan/publish) [![Build Status](https://gemnasium.com/lucasrenan/publish.png)](http://gemnasium.com/lucasrenan/publish) [![Code Climate](https://codeclimate.com/github/lucasrenan/publish.png)](https://codeclimate.com/github/lucasrenan/publish) [![Coverage Status](https://coveralls.io/repos/lucasrenan/publish/badge.png?branch=master)](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.2.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 #Date.today or 'draft'
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)
@@ -5,4 +5,6 @@ gem 'mongoid', github: 'mongoid/mongoid'
5
5
  gem 'factory_girl_rails', '~> 4.2.0'
6
6
  gem 'rails', '>= 4.0.0.beta1'
7
7
 
8
+ gem 'coveralls', require: false
9
+
8
10
  gemspec path: '../'
@@ -3,35 +3,34 @@ module Mongoid
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- field :published_at, :type => Date
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 => Date.today) }
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 <= Date.today
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 = Date.today
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 = Date.today if self.published && self.published_at.nil?
33
+ self.published_at = Time.now if self.published && self.published_at.nil?
35
34
  end
36
35
 
37
36
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Publish
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/publish.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency "rails", ">= 3.2.0"
24
24
  gem.add_development_dependency "rake", "~> 10.0"
25
25
  gem.add_development_dependency "simplecov", "~> 0.7.0"
26
+ gem.add_development_dependency "timecop", "~> 0.6.1"
26
27
  end
@@ -7,72 +7,74 @@ class PublishTest < ActiveSupport::TestCase
7
7
  end
8
8
 
9
9
  test "should create published at field" do
10
- assert @post.respond_to?(:published_at)
11
- assert_nil @post.published_at
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 @post.respond_to?(:published)
16
- assert_equal @post.published?, false
15
+ assert @post.respond_to?(:published)
16
+ assert_equal @post.published?, false
17
17
  end
18
18
 
19
- test "should be unpublished if published at is not setted" do
20
- post = build(: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?, false
23
+ assert_equal false, post.published?
24
24
  end
25
25
 
26
- test "should change unpublished post to published" do
26
+ test "should publish setting published field manually" do
27
27
  @post.published = true
28
- @post.save
29
28
 
30
- assert_not_nil @post.published_at
31
- assert_equal @post.published?, true
32
- assert_equal @post.published_at, Date.today
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 return published posts" do
36
- 2.times { create(:post, :published => true) }
37
+ test "should publish a post calling publish! method" do
38
+ post = build(:post)
39
+ post.publish!
40
+ post.reload
37
41
 
38
- assert_equal Post.published.size, 2
42
+ assert post.published?
43
+ assert_equal 1, Post.published.count
39
44
  end
40
45
 
41
- test "should return orderly published posts" do
42
- create(:post, :title => "2", :published => true, :published_at => 1.month.ago)
43
- create(:post, :title => "3", :published => true, :published_at => 1.year.ago)
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
- assert_equal Post.published_and_orderly.map(&:title), ["1", "2", "3"]
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 publish a post" do
50
- post = build(:post)
51
- post.publish!
52
- post.reload
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
- assert post.published?
55
- assert_equal Post.published.size, 1
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, 1
63
- assert_equal Post.published.where(:title => /special/).count, 1
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.2.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-03-22 00:00:00.000000000 Z
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