publish 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -8,4 +8,5 @@ test/dummy/tmp/
8
8
  coverage
9
9
  rcov
10
10
  .rvmrc
11
- *.gem
11
+ *.gem
12
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,2 +1,7 @@
1
+ services: mongodb
1
2
  rvm:
2
- - 1.9.3
3
+ - 1.9.3
4
+
5
+ gemfile:
6
+ - Gemfile
7
+ - gemfiles/mongoid-master.gemfile
data/CHANGELOG.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  ### Improvements
6
6
 
7
+ * Now supports mongoid master
8
+
7
9
  * Callbacks (after_publish, before_publish).
8
10
 
9
11
  ## 0.1.0 - 2012-09-04
data/README.md CHANGED
@@ -7,11 +7,15 @@ Publish is a gem that adds the common functionality to publish (or set as draft)
7
7
 
8
8
  Add to Gemfile
9
9
 
10
- gem "publish", "~> 0.1.0"
10
+ ``` ruby
11
+ gem "publish", "~> 0.1.0"
12
+ ```
11
13
 
12
14
  Then run
13
15
 
14
- bundle install
16
+ ``` terminal
17
+ bundle install
18
+ ```
15
19
 
16
20
  ## Getting started
17
21
 
@@ -40,4 +44,26 @@ p.published? #true
40
44
  Post.published.count #1
41
45
 
42
46
  p.publication_status #Date.today or 'draft'
47
+ ```
48
+
49
+ ## Callbacks (before_publish and after_publish)
50
+
51
+ ``` ruby
52
+ class Product
53
+ include Mongoid::Document
54
+ include Mongoid::Publish
55
+
56
+ field :name
57
+
58
+ before_publish do
59
+ puts "before publish"
60
+ end
61
+
62
+ after_publish
63
+ puts "after publish"
64
+ end
65
+ end
66
+
67
+ product = Product.new
68
+ product.publish! #=> before publish after publish
43
69
  ```
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'mongoid', github: 'mongoid/mongoid'
4
+
5
+ gem 'factory_girl_rails', '~> 3.5.0'
6
+ gem 'colorific', '~> 1.0.2'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,22 @@
1
+ module Mongoid
2
+ module Publish
3
+ module Callbacks
4
+ extend ActiveSupport::Concern
5
+
6
+ CALLBACKS = [
7
+ :after_publish,
8
+ :before_publish
9
+ ].freeze
10
+
11
+ included do
12
+ extend ActiveModel::Callbacks
13
+
14
+ define_model_callbacks :publish
15
+
16
+ def publish!
17
+ run_callbacks(:publish) { super }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Publish
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -12,6 +12,8 @@ module Mongoid
12
12
  before_save :set_published_at
13
13
  end
14
14
 
15
+ include Mongoid::Publish::Callbacks
16
+
15
17
  def published?
16
18
  return true if self.published && self.published_at && self.published_at <= Date.today
17
19
  false
data/lib/publish.rb CHANGED
@@ -1,3 +1,5 @@
1
- #not support other orms yet
1
+ #for now, supports just mongoid
2
2
  require "mongoid"
3
+
4
+ require "mongoid/publish/callbacks"
3
5
  require "mongoid/publish"
data/publish.gemspec CHANGED
@@ -18,11 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.platform = Gem::Platform::RUBY
19
19
 
20
20
 
21
- gem.add_dependency "mongoid", "~> 3.0.0"
21
+ gem.add_dependency "mongoid", ">= 3.0.0"
22
22
 
23
23
  gem.add_development_dependency "rails", "~> 3.2.0"
24
24
  gem.add_development_dependency "rake", "~> 0.9"
25
- gem.add_development_dependency "rspec-rails", "~> 2.10.1"
26
25
  gem.add_development_dependency "simplecov", "~> 0.6.1"
27
- gem.add_development_dependency "capybara", "~> 1.1.2"
28
26
  end
@@ -0,0 +1,16 @@
1
+ class Product
2
+ include Mongoid::Document
3
+ include Mongoid::Publish
4
+
5
+ attr_reader :before_publish_called, :after_publish_called
6
+
7
+ field :name
8
+
9
+ before_publish do
10
+ @before_publish_called = true
11
+ end
12
+
13
+ after_publish do |object|
14
+ @after_publish_called = true
15
+ end
16
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class NavigationTest < ActiveSupport::IntegrationCase
3
+ class NavigationTest < ActiveSupport::TestCase
4
4
  test "truth" do
5
5
  assert_kind_of Dummy::Application, Rails.application
6
6
  end
@@ -0,0 +1,30 @@
1
+ require File.expand_path("../../../../test_helper", __FILE__)
2
+
3
+ class CallbacksTest < ActiveSupport::TestCase
4
+
5
+ setup do
6
+ @klass = Product
7
+ @product = FactoryGirl.build(:product)
8
+ end
9
+
10
+ test "should includes the before_publish callback" do
11
+ assert @klass.respond_to?(:before_publish)
12
+ end
13
+
14
+ test "should includes the after_publish callback" do
15
+ assert @klass.respond_to?(:after_publish)
16
+ end
17
+
18
+ test "should not execute callbacks publish callbacks if not call publish!" do
19
+ assert_nil @product.before_publish_called
20
+ assert_nil @product.after_publish_called
21
+ end
22
+
23
+ test "should execute the before_publish and after_publish callbacks" do
24
+ @product.publish!
25
+
26
+ assert @product.before_publish_called
27
+ assert @product.after_publish_called
28
+ end
29
+
30
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../../test_helper", __FILE__)
2
2
 
3
- class PostTest < ActiveSupport::TestCase
3
+ class PublishTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
6
  @post = FactoryGirl.create(:post)
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :product do
3
+ name "macbook"
4
+ end
5
+ end
data/test/test_helper.rb CHANGED
@@ -16,12 +16,6 @@ ActionMailer::Base.default_url_options[:host] = "test.com"
16
16
 
17
17
  Rails.backtrace_cleaner.remove_silencers!
18
18
 
19
- # Configure capybara for integration testing
20
- require "capybara/rails"
21
- Capybara.default_driver = :rack_test
22
- Capybara.default_selector = :css
23
-
24
-
25
19
  # Load support files
26
20
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
27
21
 
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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,14 +11,14 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-04 00:00:00.000000000 Z
14
+ date: 2012-10-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: mongoid
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
23
  version: 3.0.0
24
24
  type: :runtime
@@ -26,7 +26,7 @@ dependencies:
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  none: false
28
28
  requirements:
29
- - - ~>
29
+ - - ! '>='
30
30
  - !ruby/object:Gem::Version
31
31
  version: 3.0.0
32
32
  - !ruby/object:Gem::Dependency
@@ -61,22 +61,6 @@ dependencies:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0.9'
64
- - !ruby/object:Gem::Dependency
65
- name: rspec-rails
66
- requirement: !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ~>
70
- - !ruby/object:Gem::Version
71
- version: 2.10.1
72
- type: :development
73
- prerelease: false
74
- version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ~>
78
- - !ruby/object:Gem::Version
79
- version: 2.10.1
80
64
  - !ruby/object:Gem::Dependency
81
65
  name: simplecov
82
66
  requirement: !ruby/object:Gem::Requirement
@@ -93,22 +77,6 @@ dependencies:
93
77
  - - ~>
94
78
  - !ruby/object:Gem::Version
95
79
  version: 0.6.1
96
- - !ruby/object:Gem::Dependency
97
- name: capybara
98
- requirement: !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: 1.1.2
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ~>
110
- - !ruby/object:Gem::Version
111
- version: 1.1.2
112
80
  description: Adds the functionality to publish/unpublish mongoid docs
113
81
  email:
114
82
  - contato@lucasrenan.com
@@ -122,11 +90,12 @@ files:
122
90
  - .travis.yml
123
91
  - CHANGELOG.md
124
92
  - Gemfile
125
- - Gemfile.lock
126
93
  - MIT-LICENSE
127
94
  - README.md
128
95
  - Rakefile
96
+ - gemfiles/mongoid-master.gemfile
129
97
  - lib/mongoid/publish.rb
98
+ - lib/mongoid/publish/callbacks.rb
130
99
  - lib/mongoid/publish/version.rb
131
100
  - lib/publish.rb
132
101
  - publish.gemspec
@@ -136,6 +105,7 @@ files:
136
105
  - test/dummy/app/helpers/application_helper.rb
137
106
  - test/dummy/app/helpers/posts_helper.rb
138
107
  - test/dummy/app/models/post.rb
108
+ - test/dummy/app/models/product.rb
139
109
  - test/dummy/app/views/layouts/application.html.erb
140
110
  - test/dummy/app/views/posts/_form.html.erb
141
111
  - test/dummy/app/views/posts/edit.html.erb
@@ -170,9 +140,10 @@ files:
170
140
  - test/dummy/public/stylesheets/scaffold.css
171
141
  - test/dummy/script/rails
172
142
  - test/integration/navigation_test.rb
173
- - test/publish/mongoid/post_test.rb
143
+ - test/publish/mongoid/publish/callbacks_test.rb
144
+ - test/publish/mongoid/publish_test.rb
174
145
  - test/support/factories/posts.rb
175
- - test/support/integration_case.rb
146
+ - test/support/factories/products.rb
176
147
  - test/test_helper.rb
177
148
  homepage: https://github.com/lucasrenan/publish
178
149
  licenses: []
@@ -205,6 +176,7 @@ test_files:
205
176
  - test/dummy/app/helpers/application_helper.rb
206
177
  - test/dummy/app/helpers/posts_helper.rb
207
178
  - test/dummy/app/models/post.rb
179
+ - test/dummy/app/models/product.rb
208
180
  - test/dummy/app/views/layouts/application.html.erb
209
181
  - test/dummy/app/views/posts/_form.html.erb
210
182
  - test/dummy/app/views/posts/edit.html.erb
@@ -239,7 +211,8 @@ test_files:
239
211
  - test/dummy/public/stylesheets/scaffold.css
240
212
  - test/dummy/script/rails
241
213
  - test/integration/navigation_test.rb
242
- - test/publish/mongoid/post_test.rb
214
+ - test/publish/mongoid/publish/callbacks_test.rb
215
+ - test/publish/mongoid/publish_test.rb
243
216
  - test/support/factories/posts.rb
244
- - test/support/integration_case.rb
217
+ - test/support/factories/products.rb
245
218
  - test/test_helper.rb
data/Gemfile.lock DELETED
@@ -1,155 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- publish (0.0.6)
5
- mongoid (~> 3.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actionmailer (3.2.6)
11
- actionpack (= 3.2.6)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.6)
14
- activemodel (= 3.2.6)
15
- activesupport (= 3.2.6)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- journey (~> 1.0.1)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.1.3)
23
- activemodel (3.2.6)
24
- activesupport (= 3.2.6)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.6)
27
- activemodel (= 3.2.6)
28
- activesupport (= 3.2.6)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.6)
32
- activemodel (= 3.2.6)
33
- activesupport (= 3.2.6)
34
- activesupport (3.2.6)
35
- i18n (~> 0.6)
36
- multi_json (~> 1.0)
37
- addressable (2.2.8)
38
- arel (3.0.2)
39
- builder (3.0.0)
40
- capybara (1.1.2)
41
- mime-types (>= 1.16)
42
- nokogiri (>= 1.3.3)
43
- rack (>= 1.0.0)
44
- rack-test (>= 0.5.4)
45
- selenium-webdriver (~> 2.0)
46
- xpath (~> 0.1.4)
47
- childprocess (0.3.3)
48
- ffi (~> 1.0.6)
49
- colorific (1.0.2)
50
- minitest (~> 2.8.0)
51
- ruby-progressbar (~> 0.0.10)
52
- diff-lcs (1.1.3)
53
- erubis (2.7.0)
54
- factory_girl (3.5.0)
55
- activesupport (>= 3.0.0)
56
- factory_girl_rails (3.5.0)
57
- factory_girl (~> 3.5.0)
58
- railties (>= 3.0.0)
59
- ffi (1.0.11)
60
- hike (1.2.1)
61
- i18n (0.6.0)
62
- journey (1.0.4)
63
- json (1.7.3)
64
- libwebsocket (0.1.3)
65
- addressable
66
- mail (2.4.4)
67
- i18n (>= 0.4.0)
68
- mime-types (~> 1.16)
69
- treetop (~> 1.4.8)
70
- mime-types (1.19)
71
- minitest (2.8.1)
72
- mongoid (3.0.0)
73
- activemodel (~> 3.1)
74
- moped (~> 1.1.1)
75
- origin (~> 1.0.3)
76
- tzinfo (~> 0.3.22)
77
- moped (1.1.1)
78
- multi_json (1.3.6)
79
- nokogiri (1.5.5)
80
- origin (1.0.4)
81
- polyglot (0.3.3)
82
- rack (1.4.1)
83
- rack-cache (1.2)
84
- rack (>= 0.4)
85
- rack-ssl (1.3.2)
86
- rack
87
- rack-test (0.6.1)
88
- rack (>= 1.0)
89
- rails (3.2.6)
90
- actionmailer (= 3.2.6)
91
- actionpack (= 3.2.6)
92
- activerecord (= 3.2.6)
93
- activeresource (= 3.2.6)
94
- activesupport (= 3.2.6)
95
- bundler (~> 1.0)
96
- railties (= 3.2.6)
97
- railties (3.2.6)
98
- actionpack (= 3.2.6)
99
- activesupport (= 3.2.6)
100
- rack-ssl (~> 1.3.2)
101
- rake (>= 0.8.7)
102
- rdoc (~> 3.4)
103
- thor (>= 0.14.6, < 2.0)
104
- rake (0.9.2.2)
105
- rdoc (3.12)
106
- json (~> 1.4)
107
- rspec (2.10.0)
108
- rspec-core (~> 2.10.0)
109
- rspec-expectations (~> 2.10.0)
110
- rspec-mocks (~> 2.10.0)
111
- rspec-core (2.10.1)
112
- rspec-expectations (2.10.0)
113
- diff-lcs (~> 1.1.3)
114
- rspec-mocks (2.10.1)
115
- rspec-rails (2.10.1)
116
- actionpack (>= 3.0)
117
- activesupport (>= 3.0)
118
- railties (>= 3.0)
119
- rspec (~> 2.10.0)
120
- ruby-progressbar (0.0.10)
121
- rubyzip (0.9.9)
122
- selenium-webdriver (2.24.0)
123
- childprocess (>= 0.2.5)
124
- libwebsocket (~> 0.1.3)
125
- multi_json (~> 1.0)
126
- rubyzip
127
- simplecov (0.6.4)
128
- multi_json (~> 1.0)
129
- simplecov-html (~> 0.5.3)
130
- simplecov-html (0.5.3)
131
- sprockets (2.1.3)
132
- hike (~> 1.2)
133
- rack (~> 1.0)
134
- tilt (~> 1.1, != 1.3.0)
135
- thor (0.15.4)
136
- tilt (1.3.3)
137
- treetop (1.4.10)
138
- polyglot
139
- polyglot (>= 0.3.1)
140
- tzinfo (0.3.33)
141
- xpath (0.1.4)
142
- nokogiri (~> 1.3)
143
-
144
- PLATFORMS
145
- ruby
146
-
147
- DEPENDENCIES
148
- capybara (~> 1.1.2)
149
- colorific (~> 1.0.2)
150
- factory_girl_rails (~> 3.5.0)
151
- publish!
152
- rails (~> 3.2.0)
153
- rake (~> 0.9)
154
- rspec-rails (~> 2.10.1)
155
- simplecov (~> 0.6.1)
@@ -1,5 +0,0 @@
1
- # Define a bare test case to use with Capybara
2
- class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
- include Capybara::DSL
4
- include Rails.application.routes.url_helpers
5
- end