|
103 | 103 | document.class.send(:include, Mongoid::Token::Collisions) |
104 | 104 | end |
105 | 105 | context "when there is a duplicate key error" do |
106 | | - it "should return true" do |
| 106 | + before do |
107 | 107 | allow(document).to receive("token").and_return("tokenvalue123") |
108 | | - err = double('Mongo::Error::OperationFailure') |
109 | | - allow(err).to(receive("message") |
110 | | - .and_return('insertDocument :: caused by :: 11000 E11000'\ |
111 | | - ' duplicate key error index: mongoid_token_'\ |
112 | | - 'test.documents.$token_1 dup key: '\ |
113 | | - '{ : "tokenvalue123" } (11000) (on localhost'\ |
114 | | - ':27017, legacy retry, attempt 1) (on localh'\ |
115 | | - 'ost:27017, legacy retry, attempt 1)')) |
116 | | - expect(document.duplicate_token_error?(err, document, :token)).to( |
117 | | - be(true) |
118 | | - ) |
| 108 | + allow(err).to(receive("message").and_return(message)) |
| 109 | + end |
| 110 | + let(:err) { double('Mongo::Error::OperationFailure', code: 11000) } |
| 111 | + subject { document.duplicate_token_error?(err, document, :token) } |
| 112 | + |
| 113 | + context "mongodb version 2.6, 3.0" do |
| 114 | + let(:message) do |
| 115 | + "insertDocument :: caused by :: 11000 "\ |
| 116 | + "E11000 duplicate key error index: "\ |
| 117 | + "mongoid_token_test.documents.$token_1 "\ |
| 118 | + "dup key: { : \"tokenvalue123\" } (11000) "\ |
| 119 | + "(on localhost:27017, legacy retry, attempt 1) "\ |
| 120 | + "(on localhost:27017, legacy retry, attempt 1)" |
| 121 | + end |
| 122 | + |
| 123 | + it { is_expected.to be(true) } |
| 124 | + end |
| 125 | + |
| 126 | + context "mongodb version 4" do |
| 127 | + let(:message) do |
| 128 | + "E11000 duplicate key error collection: "\ |
| 129 | + "mongoid_token_test.docs index: token_1 "\ |
| 130 | + "dup key: { : \"tokenvalue123\" } (11000) "\ |
| 131 | + "(on localhost:27017, legacy retry, attempt 1) "\ |
| 132 | + "(on localhost:27017, legacy retry, attempt 1)" |
| 133 | + end |
| 134 | + |
| 135 | + it { is_expected.to be(true) } |
119 | 136 | end |
120 | 137 | end |
121 | 138 | end |
|
0 commit comments