Skip to content

Commit

Permalink
Rewritten specs in present, added .rspec.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 20, 2012
1 parent e36bf39 commit 6f7cb65
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--format=documentation
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
0.5.1
-----

* [#4](https://github.com/joeyAghion/delayed_job_shallow_mongoid/pull/4): Fix: `const_missing: uninitialized constant Delayed::DelayMail (NameError)` - [@dblock](http://github.com/dblock).

0.5.0
-----

Expand Down
6 changes: 3 additions & 3 deletions spec/document_stub_spec.rb
@@ -1,15 +1,15 @@
require 'spec_helper'

describe Delayed::ShallowMongoid::DocumentStub do
it "should have a klass" do
it "has a klass" do
@shallow = Delayed::ShallowMongoid::DocumentStub.new(TestModel, 111)
@shallow.klass.should == TestModel
end
it "should have an id" do
it "has an id" do
@shallow = Delayed::ShallowMongoid::DocumentStub.new(TestModel, 111)
@shallow.id.should == 111
end
it "should have an optional selector" do
it "has an optional selector" do
@shallow = Delayed::ShallowMongoid::DocumentStub.new(TestModel, 111)
@shallow.selector.should == nil
end
Expand Down
11 changes: 8 additions & 3 deletions spec/performable_mailer_spec.rb
Expand Up @@ -8,17 +8,22 @@
@mailer_class = mock('MailerClass', :signup => @email)
@mailer = ::Delayed::PerformableMailer.new(@mailer_class, :signup, [@model])
end
it "should call the method and #deliver on the mailer" do
it "calls the method and #deliver on the mailer" do
TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
@mailer_class.should_receive(:signup).with(@model)
@email.should_receive(:deliver)
@mailer.perform
end
it "should do nothing if an argument document is not found" do
it "does nothing if an argument document is not found" do
error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model._id ])
TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
@mailer.perform.should be_true
end
it "does nothing if an argument document is nil" do
error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model._id ])
TestModel.should_receive(:find).with(@model._id.to_s).and_return(nil)
@mailer.perform.should be_true
end
end
context "failing mailer from bad record" do
before do
Expand All @@ -29,7 +34,7 @@
@mailer_class = mock('MailerClass', :signup => @email)
@mailer = ::Delayed::PerformableMailer.new(@mailer_class, :signup, [@model])
end
it "should fail if an exception comes up" do
it "fails if an exception comes up" do
TestModel.stub(:find).with(@model._id.to_s).and_return(@model)
-> {
@mailer.perform
Expand Down
26 changes: 13 additions & 13 deletions spec/performable_method_spec.rb
Expand Up @@ -2,7 +2,7 @@

describe ::Delayed::PerformableMethod do
context "with an unsaved document" do
it "should not transform an unsaved document" do
it "does not transform an unsaved document" do
@model = TestModel.new
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
method.object.should_not be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
Expand All @@ -18,18 +18,18 @@
context 'when jobs are run immediately' do
before { ::Delayed::Worker.delay_jobs = false }
after { ::Delayed::Worker.delay_jobs = true }
it "should not transform if there are pending changes and jobs are run immediately" do
it "does not transform if there are pending changes and jobs are run immediately" do
@model.title = "updated"
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
method.object.should_not be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
end
end
it "should transform object into shallow version" do
it "transforms object into shallow version" do
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
method.object.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
method.object.id.should == @model._id.to_s
end
it "should transform arg into shallow version" do
it "transforms arg into shallow version" do
method = ::Delayed::PerformableMethod.new('test', :lines, [@model])
method.args.first.should be_a_kind_of(Delayed::ShallowMongoid::DocumentStub)
method.args.first.id.should == @model._id.to_s
Expand All @@ -44,11 +44,11 @@
@method.object.id.should == @model.id.to_s
@method.object.klass.should == @model.class
end
it "should store the selector" do
it "stores the selector" do
@method = ::Delayed::PerformableMethod.new(@child, :to_s, [])
@method.object.selector.should == ['child_models', ['find', @child._id.to_s]]
end
it "should store the deeply nested selector" do
it "stores the deeply nested selector" do
@grandchild = GrandchildModel.new(:_id => Moped::BSON::ObjectId.new)
@model.child_models.first.grandchild_models.push @grandchild
@method = ::Delayed::PerformableMethod.new(@grandchild, :to_s, [])
Expand All @@ -58,24 +58,24 @@
end

context 'when running job' do
it "should look up document" do
it "looks up document" do
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
TestModel.should_receive(:find).with(@model._id.to_s).and_return(@model)
method.perform
end
it "should do nothing if document not found" do
it "does nothing if document not found" do
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
error = ::Mongoid::Errors::DocumentNotFound.new(TestModel, nil, [ @model.id ])
TestModel.should_receive(:find).with(@model._id.to_s).and_raise(error)
method.perform.should be_true
end
it "should do nothing if document find returned nil" do
it "does nothing if document find returned nil" do
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
@model.destroy
TestModel.should_receive(:find).with(@model._id.to_s).and_return(nil)
method.perform.should be_true
end
it "should find embedded document" do
it "finds embedded document" do
child = ChildModel.new(:_id => Moped::BSON::ObjectId.new)
@model.child_models.push child
method = ::Delayed::PerformableMethod.new(child, :to_s, [])
Expand All @@ -85,15 +85,15 @@
end

context "display_name" do
it "should return underlying class when a stub is being used" do
it "returns underlying class when a stub is being used" do
method = ::Delayed::PerformableMethod.new(@model, :to_s, [])
method.display_name.should == "TestModel[#{@model._id}]#to_s"
end
it "should return usual name when no stub is involved" do
it "returns usual name when no stub is involved" do
method = ::Delayed::PerformableMethod.new(:test, :to_s, [])
method.display_name.should == "Symbol#to_s"
end
it "should include selector when document is embedded" do
it "includes selector when document is embedded" do
child = ChildModel.new(:_id => Moped::BSON::ObjectId.new)
@model.child_models.push child
method = ::Delayed::PerformableMethod.new(child, :to_s, [])
Expand Down

0 comments on commit 6f7cb65

Please sign in to comment.