spec/hotseat/queue_spec.rb in hotseat-0.1.1 vs spec/hotseat/queue_spec.rb in hotseat-0.1.2
- old
+ new
@@ -51,11 +51,11 @@
it "should remove the queue object from a document" do
doc = Queue.unpatch( Queue.patch( sample_doc ) )
doc.should_not have_key(Hotseat.config[:object_name])
end
end
-
+
describe "#add_lock" do
it "should add a lock object on a patched document" do
doc = Queue.add_lock( Queue.patch( sample_doc ) )
patch = doc[Hotseat.config[:object_name]]
patch.should have_key('lock')
@@ -70,11 +70,11 @@
end
it "should leave the queue patch intact" do
@doc.should have_key(Hotseat.config[:object_name])
end
end
-
+
describe "#locked?" do
it "should be true for a locked document" do
doc = Queue.add_lock( Queue.patch( sample_doc ) )
Queue.locked?(doc).should be_true
end
@@ -85,29 +85,42 @@
it "should be false for an unlocked document" do
doc = Queue.remove_lock( Queue.add_lock( Queue.patch( sample_doc ) ) )
Queue.locked?(doc).should be_false
end
end
-
+
describe "#mark_done" do
before(:each) { @doc = Queue.mark_done( Queue.patch( sample_doc ) ) }
it "should leave the queue patch intact" do
@doc.should have_key(Hotseat.config[:object_name])
end
it "should add a 'done' object on a patched document" do
patch = @doc[Hotseat.config[:object_name]]
patch.should have_key('done')
end
end
-
+
describe "#add" do
- it "should add a document to the queue, given a doc id" do
+ before(:each) do
reset_test_queue!
- doc_id = DB.save_doc(sample_doc)['id']
- @q.add doc_id
- DB.get(doc_id).should have_key(Hotseat.config[:object_name])
+ @doc_id = DB.save_doc(sample_doc)['id']
end
+
+ it "should add a document to the queue, given a doc id" do
+ @q.add @doc_id
+ DB.get(@doc_id).should have_key(Hotseat.config[:object_name])
+ end
+
+ it "should save changes made in the block" do
+ @q.add(@doc_id) do |doc|
+ doc['field'] = 'changed value'
+ doc['another_field'] = 'another value'
+ end
+ doc = DB.get(@doc_id)
+ doc['field'].should == 'changed value'
+ doc['another_field'].should == 'another value'
+ end
end
describe "#add_bulk" do
it "should add multiple documents in bulk, given multiple doc ids" do
reset_test_queue!
@@ -267,9 +280,19 @@
it "should delete queue history from the document when forget=true" do
@q.remove @doc_id, :forget => true
doc = DB.get(@doc_id)
doc.should_not have_key(Hotseat.config[:object_name])
+ end
+
+ it "should save any changes made in the block" do
+ @q.remove(@doc_id) do |doc|
+ doc['field'] = 'changed value'
+ doc['another_field'] = 'another value'
+ end
+ doc = DB.get(@doc_id)
+ doc['field'].should == 'changed value'
+ doc['another_field'].should == 'another value'
end
end
describe "#remove_bulk" do
before(:each) do