delayed_job_shallow_mongoid 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ services: mongodb
3
+ rvm:
4
+ - 1.9.3
5
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ 0.5.0
2
+ -----
3
+
4
+ * [#3](https://github.com/joeyAghion/delayed_job_shallow_mongoid/pull/3): Added Mongoid 3.x support - [@dblock](http://github.com/dblock).
5
+
6
+ 0.4.0 (10/27/2012)
7
+ ------------------
8
+
9
+ * [#2](https://github.com/joeyAghion/delayed_job_shallow_mongoid/pull/2): Silently return on documents that cannot be fetched - [@mixonic](https://github.com/mixonic).
10
+
11
+ 0.3.0 (2/12/2012)
12
+ -----------------
13
+
14
+ * Delayed_job 3's requires are no longer relative to its root - [@joeyAghion](https://github.com/joeyAghion).
15
+ * Relaxed requirement for mongoid ~> 2.0 - [@dblock](http://github.com/dblock).
16
+
17
+ 0.2.8 (1/4/2012)
18
+ ----------------
19
+
20
+ * Don't transform object into stub if there are pending updates and jobs are being run immediately - [@joeyAghion](https://github.com/joeyAghion).
21
+ * Don't transform object into stub if not yet persisted - [@joeyAghion](https://github.com/joeyAghion).
22
+
23
+ 0.2.7 (12/19/2011)
24
+ ------------------
25
+
26
+ * Added support for embedded documents - [@joeyAghion](https://github.com/joeyAghion).
27
+
28
+ 0.2.0 (11/29/2011)
29
+ ------------------
30
+
31
+ * Reorganize and fix behavior for mailers - [@joeyAghion](https://github.com/joeyAghion).
32
+
33
+ 0.1.0 (28/11/2011)
34
+ ------------------
35
+
36
+ * Intial public release - [@joeyAghion](https://github.com/joeyAghion).
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source "http://rubygems.org"
2
+
2
3
  gemspec
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  delayed_job_shallow_mongoid
2
2
  ===========================
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/joeyAghion/delayed_job_shallow_mongoid.png?branch=master)](http://travis-ci.org/joeyAghion/delayed_job_shallow_mongoid)
5
+
4
6
  This library short-circuits serialization of [Mongoid](http://mongoid.org) model instances when a delayed job is called on them, or when they're passed as arguments to a delayed job. Rather than generate and store the fully-serialized YAML, a simple stub is stored. When the job is run, the stub is recognized and a `find` is done to look up the underlying document. If a referenced model isn't found at this point, the job simply does nothing.
5
7
 
8
+ Going forward, only [Mongoid 3](http://mongoid.org) will be supported. Feel free to fork and submit pull-requests for backward-compatibility.
9
+
6
10
  Contributions
7
11
  -------------
8
12
 
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require 'bundler/gem_tasks'
5
6
  begin
6
7
  Bundler.setup(:default, :development)
7
8
  rescue Bundler::BundlerError => e
@@ -12,33 +13,9 @@ end
12
13
  require 'rake'
13
14
  require 'rspec/core/rake_task'
14
15
 
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "delayed_job_shallow_mongoid"
19
- gem.homepage = "http://github.com/joeyAghion/delayed_job_shallow_mongoid"
20
- gem.license = "MIT"
21
- gem.summary = %Q{More efficient Mongoid document serialization for delayed_job.}
22
- gem.description = %Q{When the object or arg to a delayed_job is a Mongoid document, store only a small stub of the object instead of the full serialization.}
23
- gem.email = "joey@aghion.com"
24
- gem.authors = ["Joey Aghion"]
25
- # dependencies defined in Gemfile
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
16
  desc "Run all tests"
30
17
  RSpec::Core::RakeTask.new(:spec) do |spec|
31
18
  spec.pattern = "spec/**/*_spec.rb"
32
19
  end
33
20
 
34
21
  task :default => :spec
35
-
36
- require 'rake/rdoctask'
37
- Rake::RDocTask.new do |rdoc|
38
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
-
40
- rdoc.rdoc_dir = 'rdoc'
41
- rdoc.title = "delayed_job_shallow_mongoid #{version}"
42
- rdoc.rdoc_files.include('README*')
43
- rdoc.rdoc_files.include('lib/**/*.rb')
44
- end
data/VERSION CHANGED
@@ -1 +1,2 @@
1
- 0.4.0
1
+ 0.5.0
2
+
@@ -1,15 +1,11 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
-
6
2
  Gem::Specification.new do |s|
7
3
  s.name = "delayed_job_shallow_mongoid"
8
- s.version = "0.4.0"
4
+ s.version = "0.5.0"
9
5
 
10
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
7
  s.authors = ["Joey Aghion"]
12
- s.date = "2012-10-27"
8
+ s.date = "2012-11-19"
13
9
  s.description = "When the object or arg to a delayed_job is a Mongoid document, store only a small stub of the object instead of the full serialization."
14
10
  s.email = "joey@aghion.com"
15
11
  s.extra_rdoc_files = [
@@ -18,12 +14,15 @@ Gem::Specification.new do |s|
18
14
  ]
19
15
  s.files = [
20
16
  ".document",
17
+ ".travis.yml",
18
+ "CHANGELOG.md",
21
19
  "Gemfile",
22
20
  "LICENSE.txt",
23
21
  "README.md",
24
22
  "Rakefile",
25
23
  "VERSION",
26
24
  "delayed_job_shallow_mongoid.gemspec",
25
+ "lib/delayed/performable_mailer.rb",
27
26
  "lib/delayed/shallow_mongoid.rb",
28
27
  "lib/delayed/shallow_mongoid/document_stub.rb",
29
28
  "lib/delayed/shallow_mongoid/performable_mailer.rb",
@@ -42,33 +41,29 @@ Gem::Specification.new do |s|
42
41
  s.specification_version = 3
43
42
 
44
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<delayed_job_shallow_mongoid>, [">= 0"])
44
+ s.add_runtime_dependency(%q<delayed_job>, ["~> 3.0"])
45
+ s.add_runtime_dependency(%q<mongoid>, ["~> 3.0"])
46
46
  s.add_development_dependency(%q<actionmailer>, [">= 0"])
47
47
  s.add_development_dependency(%q<shoulda>, [">= 0"])
48
- s.add_development_dependency(%q<bundler>, [">= 0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
50
49
  s.add_development_dependency(%q<rspec>, [">= 0"])
51
50
  s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
52
- s.add_development_dependency(%q<bson_ext>, ["~> 1.5"])
53
51
  else
54
- s.add_dependency(%q<delayed_job_shallow_mongoid>, [">= 0"])
52
+ s.add_dependency(%q<delayed_job>, ["~> 3.0"])
53
+ s.add_dependency(%q<mongoid>, ["~> 3.0"])
55
54
  s.add_dependency(%q<actionmailer>, [">= 0"])
56
55
  s.add_dependency(%q<shoulda>, [">= 0"])
57
- s.add_dependency(%q<bundler>, [">= 0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
56
  s.add_dependency(%q<rspec>, [">= 0"])
60
57
  s.add_dependency(%q<ruby-debug19>, [">= 0"])
61
- s.add_dependency(%q<bson_ext>, ["~> 1.5"])
62
58
  end
63
59
  else
64
- s.add_dependency(%q<delayed_job_shallow_mongoid>, [">= 0"])
60
+ s.add_dependency(%q<delayed_job>, ["~> 3.0"])
61
+ s.add_dependency(%q<mongoid>, ["~> 3.0"])
65
62
  s.add_dependency(%q<actionmailer>, [">= 0"])
66
63
  s.add_dependency(%q<shoulda>, [">= 0"])
67
- s.add_dependency(%q<bundler>, [">= 0"])
68
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
64
+ s.add_dependency(%q<rake >, ["~> 10.0"])
69
65
  s.add_dependency(%q<rspec>, [">= 0"])
70
66
  s.add_dependency(%q<ruby-debug19>, [">= 0"])
71
- s.add_dependency(%q<bson_ext>, ["~> 1.5"])
72
67
  end
73
68
  end
74
69
 
@@ -0,0 +1,7 @@
1
+ module Delayed
2
+ class PerformableMailer < PerformableMethod
3
+ def perform
4
+ ShallowMongoid.load(object).send(method_name, *args.map{|a| ShallowMongoid.load(a) }).deliver
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,7 @@
1
1
  module Delayed
2
2
  class PerformableMethod
3
+ attr_accessor :object, :method_name, :args
4
+
3
5
  def initialize(object, method_name, args)
4
6
  raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)
5
7
 
@@ -7,17 +9,18 @@ module Delayed
7
9
  self.args = args.map{|a| ShallowMongoid.dump(a) }
8
10
  self.method_name = method_name.to_sym
9
11
  end
10
-
12
+
11
13
  def perform
12
14
  begin
13
15
  klass = ShallowMongoid.load(object)
16
+ return true unless klass
14
17
  delayed_arguments = *args.map{|a| ShallowMongoid.load(a) }
15
18
  rescue Mongoid::Errors::DocumentNotFound
16
19
  return true # do nothing if document has been removed
17
20
  end
18
21
  klass.send(method_name, *delayed_arguments)
19
22
  end
20
-
23
+
21
24
  def display_name
22
25
  if object.is_a?(ShallowMongoid::DocumentStub)
23
26
  "#{object.description}##{method_name}"
@@ -45,7 +45,7 @@ describe ::Delayed::PerformableMethod do
45
45
 
46
46
  context "with a saved document" do
47
47
  before(:each) do
48
- @model = TestModel.create #new(:_id => ::BSON::ObjectId.new)
48
+ @model = TestModel.create #new(:_id => Moped::BSON::ObjectId.new)
49
49
  end
50
50
 
51
51
  context 'when saving job' do
@@ -70,7 +70,7 @@ describe ::Delayed::PerformableMethod do
70
70
  end
71
71
  context "with an embedded document" do
72
72
  before(:each) do
73
- @child = ChildModel.new(:_id => ::BSON::ObjectId.new)
73
+ @child = ChildModel.new(:_id => Moped::BSON::ObjectId.new)
74
74
  @model.child_models.push @child
75
75
  end
76
76
  after(:each) do
@@ -83,7 +83,7 @@ describe ::Delayed::PerformableMethod do
83
83
  @method.object.selector.should == ['child_models', ['find', @child._id.to_s]]
84
84
  end
85
85
  it "should store the deeply nested selector" do
86
- @grandchild = GrandchildModel.new(:_id => ::BSON::ObjectId.new)
86
+ @grandchild = GrandchildModel.new(:_id => Moped::BSON::ObjectId.new)
87
87
  @model.child_models.first.grandchild_models.push @grandchild
88
88
  @method = ::Delayed::PerformableMethod.new(@grandchild, :to_s, [])
89
89
  @method.object.selector.should == ['child_models', ['find', @child._id.to_s], 'grandchild_models', ['find', @grandchild._id.to_s]]
@@ -99,19 +99,25 @@ describe ::Delayed::PerformableMethod do
99
99
  end
100
100
  it "should do nothing if document not found" do
101
101
  method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
102
- error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, @model._id)
102
+ error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model.id ])
103
103
  TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
104
104
  method.perform.should be_true
105
105
  end
106
+ it "should do nothing if document find returned nil" do
107
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
108
+ @model.destroy
109
+ TestModel.should_receive(:find).with(@model._id.to_s).and_return(nil)
110
+ method.perform.should be_true
111
+ end
106
112
  it "should find embedded document" do
107
- child = ChildModel.new(:_id => ::BSON::ObjectId.new)
113
+ child = ChildModel.new(:_id => Moped::BSON::ObjectId.new)
108
114
  @model.child_models.push child
109
115
  method = ::Delayed::PerformableMethod.new(child, :to_s, [])
110
116
  TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
111
117
  method.perform
112
118
  end
113
119
  end
114
-
120
+
115
121
  context "display_name" do
116
122
  it "should return underlying class when a stub is being used" do
117
123
  method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
@@ -122,7 +128,7 @@ describe ::Delayed::PerformableMethod do
122
128
  method.display_name.should == "Symbol#to_s"
123
129
  end
124
130
  it "should include selector when document is embedded" do
125
- child = ChildModel.new(:_id => ::BSON::ObjectId.new)
131
+ child = ChildModel.new(:_id => Moped::BSON::ObjectId.new)
126
132
  @model.child_models.push child
127
133
  method = ::Delayed::PerformableMethod.new(child, :to_s, [])
128
134
  method.display_name.should == "TestModel[#{@model._id}].child_models.find(\"#{child._id}\")#to_s"
@@ -146,7 +152,7 @@ describe ::Delayed::PerformableMailer do
146
152
  @mailer.perform
147
153
  end
148
154
  it "should do nothing if an argument document is not found" do
149
- error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, @model._id)
155
+ error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model._id ])
150
156
  TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
151
157
  @mailer.perform.should be_true
152
158
  end
@@ -154,7 +160,7 @@ describe ::Delayed::PerformableMailer do
154
160
  context "failing mailer from bad record" do
155
161
  before do
156
162
  @model = TestModel.create
157
- error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, @model._id)
163
+ error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model._id ])
158
164
  @email = mock('email')
159
165
  @email.stub(:deliver).and_raise(error)
160
166
  @mailer_class = mock('MailerClass', :signup => @email)
data/spec/spec_helper.rb CHANGED
@@ -7,16 +7,15 @@ require 'mongoid'
7
7
  require 'delayed_job_shallow_mongoid'
8
8
 
9
9
  Mongoid.configure do |config|
10
- name = "delayed_job_shallow_mongoid_test"
11
- config.master = Mongo::Connection.new.db(name)
12
- config.logger = Logger.new('/dev/null')
10
+ config.connect_to('delayed_job_shallow_mongoid_test')
13
11
  end
14
12
 
15
13
  RSpec.configure do |config|
16
14
  config.before(:each) do
17
- Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
15
+ Mongoid.purge!
16
+ Mongoid::IdentityMap.clear
18
17
  end
19
18
  config.after(:all) do
20
- Mongoid.master.command({'dropDatabase' => 1})
19
+ Mongoid.default_session.drop
21
20
  end
22
- end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_shallow_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,42 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-27 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: delayed_job_shallow_mongoid
15
+ name: delayed_job
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '3.0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: actionmailer
31
+ name: mongoid
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
37
+ version: '3.0'
38
+ type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '3.0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: shoulda
47
+ name: actionmailer
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: bundler
63
+ name: shoulda
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -76,13 +76,13 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: jeweler
79
+ name: rake
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 1.6.4
85
+ version: '10.0'
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 1.6.4
93
+ version: '10.0'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: rspec
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -123,22 +123,6 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: bson_ext
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ~>
132
- - !ruby/object:Gem::Version
133
- version: '1.5'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ~>
140
- - !ruby/object:Gem::Version
141
- version: '1.5'
142
126
  description: When the object or arg to a delayed_job is a Mongoid document, store
143
127
  only a small stub of the object instead of the full serialization.
144
128
  email: joey@aghion.com
@@ -149,12 +133,15 @@ extra_rdoc_files:
149
133
  - README.md
150
134
  files:
151
135
  - .document
136
+ - .travis.yml
137
+ - CHANGELOG.md
152
138
  - Gemfile
153
139
  - LICENSE.txt
154
140
  - README.md
155
141
  - Rakefile
156
142
  - VERSION
157
143
  - delayed_job_shallow_mongoid.gemspec
144
+ - lib/delayed/performable_mailer.rb
158
145
  - lib/delayed/shallow_mongoid.rb
159
146
  - lib/delayed/shallow_mongoid/document_stub.rb
160
147
  - lib/delayed/shallow_mongoid/performable_mailer.rb
@@ -177,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
164
  version: '0'
178
165
  segments:
179
166
  - 0
180
- hash: -2014166991515156884
167
+ hash: 2112816115078860276
181
168
  required_rubygems_version: !ruby/object:Gem::Requirement
182
169
  none: false
183
170
  requirements: