delayed_job_shallow_mongoid 0.2.7 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "delayed_job_shallow_mongoid"
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joey Aghion"]
12
- s.date = "2011-12-19"
12
+ s.date = "2012-01-04"
13
13
  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
14
  s.email = "joey@aghion.com"
15
15
  s.extra_rdoc_files = [
@@ -1,7 +1,8 @@
1
1
  module Delayed
2
2
  module ShallowMongoid
3
3
  def self.dump(arg)
4
- return arg unless arg.is_a?(::Mongoid::Document)
4
+ return arg unless arg.is_a?(::Mongoid::Document) && arg.persisted?
5
+ return arg if arg._updates.any? && !Delayed::Worker.delay_jobs
5
6
  if arg.embedded?
6
7
  ShallowMongoid::DocumentStub.new(arg._root.class, arg._root._id.to_s, selector_from(arg))
7
8
  else
@@ -11,6 +11,7 @@ class ChildModel
11
11
  end
12
12
  class TestModel
13
13
  include ::Mongoid::Document
14
+ field :title
14
15
  embeds_many :child_models
15
16
  end
16
17
 
@@ -34,86 +35,105 @@ describe Delayed::ShallowMongoid::DocumentStub do
34
35
  end
35
36
 
36
37
  describe ::Delayed::PerformableMethod do
37
- before(:each) do
38
- @model = TestModel.new(:_id => ::BSON::ObjectId.new)
39
- end
40
-
41
- context 'when saving job' do
42
- it "should transform object into shallow version" do
38
+ context "with an unsaved document" do
39
+ it "should not transform an unsaved document" do
40
+ @model = TestModel.new
43
41
  method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
44
- method.object.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
45
- method.object.id.should == @model._id.to_s
42
+ method.object.should_not be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
46
43
  end
47
- it "should transform arg into shallow version" do
48
- method = ::Delayed::PerformableMethod.new('test', :lines, [@model])
49
- method.args.first.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
50
- method.args.first.id.should == @model._id.to_s
44
+ end
45
+
46
+ context "with a saved document" do
47
+ before(:each) do
48
+ @model = TestModel.create #new(:_id => ::BSON::ObjectId.new)
51
49
  end
52
- context "with an embedded document" do
53
- before(:each) do
54
- @child = ChildModel.new(:_id => ::BSON::ObjectId.new)
55
- @model.child_models << @child
50
+
51
+ context 'when saving job' do
52
+ context 'when jobs are run immediately' do
53
+ before { ::Delayed::Worker.delay_jobs = false }
54
+ after { ::Delayed::Worker.delay_jobs = true }
55
+ it "should not transform if there are pending changes and jobs are run immediately" do
56
+ @model.title = "updated"
57
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
58
+ method.object.should_not be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
59
+ end
56
60
  end
57
- after(:each) do
58
- @method.object.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
59
- @method.object.id.should == @model.id.to_s
60
- @method.object.klass.should == @model.class
61
+ it "should transform object into shallow version" do
62
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
63
+ method.object.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
64
+ method.object.id.should == @model._id.to_s
61
65
  end
62
- it "should store the selector" do
63
- @method = ::Delayed::PerformableMethod.new(@child, :to_s, [])
64
- @method.object.selector.should == ['child_models', ['find', @child._id.to_s]]
66
+ it "should transform arg into shallow version" do
67
+ method = ::Delayed::PerformableMethod.new('test', :lines, [@model])
68
+ method.args.first.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
69
+ method.args.first.id.should == @model._id.to_s
65
70
  end
66
- it "should store the deeply nested selector" do
67
- @grandchild = GrandchildModel.new(:_id => ::BSON::ObjectId.new)
68
- @model.child_models.first.grandchild_models << @grandchild
69
- @method = ::Delayed::PerformableMethod.new(@grandchild, :to_s, [])
70
- @method.object.selector.should == ['child_models', ['find', @child._id.to_s], 'grandchild_models', ['find', @grandchild._id.to_s]]
71
+ context "with an embedded document" do
72
+ before(:each) do
73
+ @child = ChildModel.new(:_id => ::BSON::ObjectId.new)
74
+ @model.child_models.push @child
75
+ end
76
+ after(:each) do
77
+ @method.object.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
78
+ @method.object.id.should == @model.id.to_s
79
+ @method.object.klass.should == @model.class
80
+ end
81
+ it "should store the selector" do
82
+ @method = ::Delayed::PerformableMethod.new(@child, :to_s, [])
83
+ @method.object.selector.should == ['child_models', ['find', @child._id.to_s]]
84
+ end
85
+ it "should store the deeply nested selector" do
86
+ @grandchild = GrandchildModel.new(:_id => ::BSON::ObjectId.new)
87
+ @model.child_models.first.grandchild_models.push @grandchild
88
+ @method = ::Delayed::PerformableMethod.new(@grandchild, :to_s, [])
89
+ @method.object.selector.should == ['child_models', ['find', @child._id.to_s], 'grandchild_models', ['find', @grandchild._id.to_s]]
90
+ end
71
91
  end
72
92
  end
73
- end
74
93
 
75
- context 'when running job' do
76
- it "should look up document" do
77
- method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
78
- TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
79
- method.perform
80
- end
81
- it "should do nothing if document not found" do
82
- method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
83
- error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, @model._id)
84
- TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
85
- method.perform.should be_true
86
- end
87
- it "should find embedded document" do
88
- child = ChildModel.new(:_id => ::BSON::ObjectId.new)
89
- @model.child_models << child
90
- method = ::Delayed::PerformableMethod.new(child, :to_s, [])
91
- TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
92
- method.perform
93
- end
94
- end
95
-
96
- context "display_name" do
97
- it "should return underlying class when a stub is being used" do
98
- method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
99
- method.display_name.should == "TestModel[#{@model._id}]#to_s"
100
- end
101
- it "should return usual name when no stub is involved" do
102
- method = ::Delayed::PerformableMethod.new(:test, :to_s, [])
103
- method.display_name.should == "Symbol#to_s"
94
+ context 'when running job' do
95
+ it "should look up document" do
96
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
97
+ TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
98
+ method.perform
99
+ end
100
+ it "should do nothing if document not found" do
101
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
102
+ error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, @model._id)
103
+ TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
104
+ method.perform.should be_true
105
+ end
106
+ it "should find embedded document" do
107
+ child = ChildModel.new(:_id => ::BSON::ObjectId.new)
108
+ @model.child_models.push child
109
+ method = ::Delayed::PerformableMethod.new(child, :to_s, [])
110
+ TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
111
+ method.perform
112
+ end
104
113
  end
105
- it "should include selector when document is embedded" do
106
- child = ChildModel.new(:_id => ::BSON::ObjectId.new)
107
- @model.child_models << child
108
- method = ::Delayed::PerformableMethod.new(child, :to_s, [])
109
- method.display_name.should == "TestModel[#{@model._id}].child_models.find(\"#{child._id}\")#to_s"
114
+
115
+ context "display_name" do
116
+ it "should return underlying class when a stub is being used" do
117
+ method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
118
+ method.display_name.should == "TestModel[#{@model._id}]#to_s"
119
+ end
120
+ it "should return usual name when no stub is involved" do
121
+ method = ::Delayed::PerformableMethod.new(:test, :to_s, [])
122
+ method.display_name.should == "Symbol#to_s"
123
+ end
124
+ it "should include selector when document is embedded" do
125
+ child = ChildModel.new(:_id => ::BSON::ObjectId.new)
126
+ @model.child_models.push child
127
+ method = ::Delayed::PerformableMethod.new(child, :to_s, [])
128
+ method.display_name.should == "TestModel[#{@model._id}].child_models.find(\"#{child._id}\")#to_s"
129
+ end
110
130
  end
111
131
  end
112
132
  end
113
133
 
114
134
  describe ::Delayed::PerformableMailer do
115
135
  before do
116
- @model = TestModel.new(:_id => ::BSON::ObjectId.new)
136
+ @model = TestModel.create
117
137
  @email = mock('email', :deliver => true)
118
138
  @mailer_class = mock('MailerClass', :signup => @email)
119
139
  @mailer = ::Delayed::PerformableMailer.new(@mailer_class, :signup, [@model])
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,17 @@ require 'action_mailer'
6
6
  require 'mongoid'
7
7
  require 'delayed_job_shallow_mongoid'
8
8
 
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')
13
+ end
14
+
9
15
  RSpec.configure do |config|
10
- # some (optional) config here
16
+ config.before(:each) do
17
+ Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
18
+ end
19
+ config.after(:all) do
20
+ Mongoid.master.command({'dropDatabase' => 1})
21
+ end
11
22
  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.2.7
4
+ version: 0.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-19 00:00:00.000000000Z
12
+ date: 2012-01-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: delayed_job
16
- requirement: &2168767700 !ruby/object:Gem::Requirement
16
+ requirement: &70252554101280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2168767700
24
+ version_requirements: *70252554101280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &2168767040 !ruby/object:Gem::Requirement
27
+ requirement: &70252554100560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.0.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2168767040
35
+ version_requirements: *70252554100560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: actionmailer
38
- requirement: &2168766380 !ruby/object:Gem::Requirement
38
+ requirement: &70252554099840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2168766380
46
+ version_requirements: *70252554099840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &2168765780 !ruby/object:Gem::Requirement
49
+ requirement: &70252554098960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2168765780
57
+ version_requirements: *70252554098960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2168765040 !ruby/object:Gem::Requirement
60
+ requirement: &70252554098280 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2168765040
68
+ version_requirements: *70252554098280
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &2168764440 !ruby/object:Gem::Requirement
71
+ requirement: &70252554097780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.6.4
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2168764440
79
+ version_requirements: *70252554097780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2168763800 !ruby/object:Gem::Requirement
82
+ requirement: &70252553963220 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2168763800
90
+ version_requirements: *70252553963220
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: ruby-debug19
93
- requirement: &2168763160 !ruby/object:Gem::Requirement
93
+ requirement: &70252553962740 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2168763160
101
+ version_requirements: *70252553962740
102
102
  description: When the object or arg to a delayed_job is a Mongoid document, store
103
103
  only a small stub of the object instead of the full serialization.
104
104
  email: joey@aghion.com
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  segments:
140
140
  - 0
141
- hash: 265545571011826092
141
+ hash: -213852032855460183
142
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  none: false
144
144
  requirements: