<commit_before>#encoding: utf-8
require "spec_helper"

module Mongoid
  describe Locker do

    describe 'state machine' do
      
      describe ':lock' do
        subject { ::Document.create title: "Tale of Two Plugins", state: :unlocked }
        it { should be_unlocked }
        specify { subject.locked_at.should be_nil}
 
        it "should become locked if it's lockable" do
          subject.lock
          subject.should be_locked
        end
        
        it "should have a locked_at time" do
          subject.lock
          subject.locked_at.should_not be_nil
        end
        
        it "should not be timed_out" do
          subject.class.stub(:timeout).and_return 30
          subject.lock
          subject.can_relock?.should be_false
        end
          
        it "raises an exception if it's already locked" do
          subject.lock
          subject.lock.should raise_error
        end

        it "allows a new lock if it's timed out" do
          subject.class.stub(:timeout).and_return 1
          subject.lock
          sleep(5)
          subject.can_relock?.should be_true
        end
      end
      
      describe ':unlock' do
        subject { ::Document.create title: "Tale of Two Plugins" }
        it "should become unlocked when I unlock it" do
          subject.lock
          subject.unlock
          subject.should be_unlocked
        end
      end
        
    end
    
	end
end<commit_msg>Cleaned up the spec and added some tests<commit_after>#encoding: utf-8
require "spec_helper"

class Doc
  include Mongoid::Document
  include Mongoid::Locker
  
  field :title, type: String
  
  enable_locking_with :locked_at
  
  self.timeout = 1
  
end

module Mongoid
  describe Locker do

    describe 'state machine' do
      subject { Doc.create title: "Tale of Two Plugins" }
      [:lock, :unlock, :relock, :locked?, :unlocked?, :locked_at].each do |meth|
        it { should respond_to meth}
      end
      specify { subject.locked_at.should be_nil}
            
      describe ':lock' do
        subject { Doc.create title: "Tale of Two Plugins" }
 
        it "should become locked if it's lockable" do
          subject.lock
          subject.should be_locked
        end
        
        it "should have a locked_at time" do
          subject.lock
          subject.locked_at.should_not be_nil
        end
        
        it "should not be timed out" do
          subject.class.stubs(:timeout).returns 30
          subject.lock
          subject.timed_out?.should be_false
        end
          
        it "raises an exception if it's already locked" do
          subject.lock
          subject.lock.should raise_error
        end

        it "allows a new lock if it's timed out" do
          subject.class.stubs(:timeout).returns 1
          subject.lock
          sleep(5)
          subject.timed_out?.should be_true
        end
      end
      
      describe ':unlock' do
        subject { Doc.create title: "Tale of Two Plugins" }
        it "should become unlocked when I unlock it" do
          subject.lock
          subject.unlock
          subject.should be_unlocked
        end
      end
        
    end
    
	end
end
{'fraction_non_alphanumeric': 0.06436420722135008, 'fraction_numerical': 0.003453689167974882, 'mean_word_length': 1.7068819031435853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1524990', 'n_tokens_mistral': 913, 'n_tokens_neox': 880, 'n_words': 287}