|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 2 | +# use this file except in compliance with the License. You may obtain a copy of |
| 3 | +# the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations under |
| 11 | +# the License. |
| 12 | + |
| 13 | +defmodule ChooseCorrectIndexForDocs do |
| 14 | + use CouchTestCase |
| 15 | + |
| 16 | + @db_name "find-conflicts" |
| 17 | + |
| 18 | + setup do |
| 19 | + doc = %{"_id" => "doc", "a" => 2} |
| 20 | + conflicts = [%{"_id" => "doc", "_rev" => "1-23202479633c2b380f79507a776743d5", "a" => 1}] |
| 21 | + |
| 22 | + MangoDatabase.recreate(@db_name) |
| 23 | + MangoDatabase.save_doc(@db_name, doc) |
| 24 | + MangoDatabase.save_docs_with_conflicts(@db_name, conflicts) |
| 25 | + :ok |
| 26 | + end |
| 27 | + |
| 28 | + test "retrieve conflicts" do |
| 29 | + MangoDatabase.create_index(@db_name, ["_conflicts"]) |
| 30 | + selector = %{"_conflicts" => %{"$exists" => true}} |
| 31 | + {:ok, result} = MangoDatabase.find(@db_name, selector, conflicts: true) |
| 32 | + |
| 33 | + assert Enum.at(result, 0)["_conflicts"] == ["1-23202479633c2b380f79507a776743d5"] |
| 34 | + assert Enum.at(result, 0)["_rev"] == "1-3975759ccff3842adf690a5c10caee42" |
| 35 | + end |
| 36 | +end |
0 commit comments