spec/mongoid/token_spec.rb in mongoid_token-2.2.0 vs spec/mongoid/token_spec.rb in mongoid_token-3.0.0

- old
+ new

@@ -2,10 +2,11 @@ describe Mongoid::Token do after do Object.send(:remove_const, :Document) if Object.constants.include?(:Document) Object.send(:remove_const, :AnotherDocument) if Object.constants.include?(:AnotherDocument) + Object.send(:remove_const, :UntaintedDocument) if Object.constants.include?(:UntaintedDocument) end let(:document_class) do class Document include Mongoid::Document @@ -255,8 +256,32 @@ duplicate_name = "Got Duped." document_class.create!(:name => duplicate_name) expect{ document_class.create!(:name => duplicate_name) }.to raise_exception(Moped::Errors::OperationFailure) end end + end + end + + describe "with overriden id" do + # Capture warnings about overriding _id, for cleaner test output + before do + @orig_stdout = $stdout + $stdout = StringIO.new + document_class.send(:token, id: true) + end + + after do + $stdout = @orig_stdout + end + + let(:document){ document_class.new } + + it "should replace the _id field with a token" do + expect(document).to have_field(:_id) + expect(document).to_not have_field(:token) + end + + it "should have a default token" do + expect(document.id).to_not be_blank end end end