Merge lp:~3v1n0/u1db-qt/doc-path-change-fixes into lp:u1db-qt

Proposed by Marco Trevisan (Treviño) on 2015-03-02
Status: Merged
Approved by: Christian Dywan on 2015-03-05
Approved revision: 128
Merged at revision: 129
Proposed branch: lp:~3v1n0/u1db-qt/doc-path-change-fixes
Merge into: lp:u1db-qt
Prerequisite: lp:~3v1n0/u1db-qt/uri-path-parsing
Diff against target: 155 lines (+26/-13)
9 files modified
examples/u1db-qt-example-1/u1db-qt-example-1.qml (+1/-1)
examples/u1db-qt-example-2/u1db-qt-example-2.qml (+1/-1)
examples/u1db-qt-example-2b/u1db-qt-example-2b.qml (+1/-1)
examples/u1db-qt-example-3/u1db-qt-example-3.qml (+1/-1)
examples/u1db-qt-example-5/u1db-qt-example-5.qml (+1/-1)
examples/u1db-qt-example-6/u1db-qt-example-6.qml (+2/-5)
src/document.cpp (+16/-0)
src/index.cpp (+1/-0)
tests/tst_database.qml (+2/-3)
To merge this branch: bzr merge lp:~3v1n0/u1db-qt/doc-path-change-fixes
Reviewer Review Type Date Requested Status
Christian Dywan 2015-03-02 Approve on 2015-03-05
PS Jenkins bot continuous-integration Approve on 2015-03-02
Review via email: mp+251439@code.launchpad.net

Commit message

Document: ensure defaults and contents are set when database path changes

Description of the change

When database path changes (as it happens when you use a JS call to set it), document does not initialize defaults and contents correctly on it.

To post a comment you must log in.
126. By Marco Trevisan (Treviño) on 2015-03-02

Document: put current contents on database when path changes and new one is empty

127. By Marco Trevisan (Treviño) on 2015-03-02

Examples: use Qt.resolvedUrl to open databases

In this way we won't put settings inside user config

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
128. By Marco Trevisan (Treviño) on 2015-03-02

Fix tests

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Christian Dywan (kalikiana) wrote :

That's a nice fix. I didn't even realize before that the unit tests hint at this very bug.

review: Approve
129. By Marco Trevisan (Treviño) on 2015-03-06

Index: ensure we've the index set on db when path changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/u1db-qt-example-1/u1db-qt-example-1.qml'
--- examples/u1db-qt-example-1/u1db-qt-example-1.qml 2015-03-06 02:38:22 +0000
+++ examples/u1db-qt-example-1/u1db-qt-example-1.qml 2015-03-06 02:38:22 +0000
@@ -36,7 +36,7 @@
36 36
37 U1db.Database {37 U1db.Database {
38 id: aDatabase38 id: aDatabase
39 path: "file:///tmp/aDatabase1.db";39 path: Qt.resolvedUrl("aDatabase1");
40 }40 }
41 41
42 /*!42 /*!
4343
=== modified file 'examples/u1db-qt-example-2/u1db-qt-example-2.qml'
--- examples/u1db-qt-example-2/u1db-qt-example-2.qml 2013-05-02 18:20:33 +0000
+++ examples/u1db-qt-example-2/u1db-qt-example-2.qml 2015-03-06 02:38:22 +0000
@@ -35,7 +35,7 @@
35 35
36 U1db.Database {36 U1db.Database {
37 id: aDatabase37 id: aDatabase
38 path: "aDatabase2"38 path: Qt.resolvedUrl("aDatabase2")
39 }39 }
40 40
41 Timer {41 Timer {
4242
=== modified file 'examples/u1db-qt-example-2b/u1db-qt-example-2b.qml'
--- examples/u1db-qt-example-2b/u1db-qt-example-2b.qml 2013-05-02 18:20:33 +0000
+++ examples/u1db-qt-example-2b/u1db-qt-example-2b.qml 2015-03-06 02:38:22 +0000
@@ -36,7 +36,7 @@
3636
37 U1db.Database {37 U1db.Database {
38 id: aDatabase38 id: aDatabase
39 path: "aDatabase2b"39 path: Qt.resolvedUrl("aDatabase2b")
40 }40 }
41 41
42 /*!42 /*!
4343
=== modified file 'examples/u1db-qt-example-3/u1db-qt-example-3.qml'
--- examples/u1db-qt-example-3/u1db-qt-example-3.qml 2013-05-02 18:19:33 +0000
+++ examples/u1db-qt-example-3/u1db-qt-example-3.qml 2015-03-06 02:38:22 +0000
@@ -49,7 +49,7 @@
4949
50 U1db.Database {50 U1db.Database {
51 id: aDatabase51 id: aDatabase
52 path: "aDatabase3"52 path: Qt.resolvedUrl("aDatabase3")
53 }53 }
5454
55 /*!55 /*!
5656
=== modified file 'examples/u1db-qt-example-5/u1db-qt-example-5.qml'
--- examples/u1db-qt-example-5/u1db-qt-example-5.qml 2013-05-02 18:20:33 +0000
+++ examples/u1db-qt-example-5/u1db-qt-example-5.qml 2015-03-06 02:38:22 +0000
@@ -27,7 +27,7 @@
2727
28 U1db.Database {28 U1db.Database {
29 id: aDatabase29 id: aDatabase
30 path: "aDatabase5"30 path: Qt.resolvedUrl("aDatabase5")
31 }31 }
3232
33 U1db.Document {33 U1db.Document {
3434
=== modified file 'examples/u1db-qt-example-6/u1db-qt-example-6.qml'
--- examples/u1db-qt-example-6/u1db-qt-example-6.qml 2013-08-09 10:42:18 +0000
+++ examples/u1db-qt-example-6/u1db-qt-example-6.qml 2015-03-06 02:38:22 +0000
@@ -21,7 +21,6 @@
21import U1db 1.0 as U1db21import U1db 1.0 as U1db
22import Ubuntu.Components 0.122import Ubuntu.Components 0.1
2323
24
25Item {24Item {
2625
27 width: units.gu(45)26 width: units.gu(45)
@@ -29,7 +28,7 @@
2928
30 U1db.Database {29 U1db.Database {
31 id: aDatabase30 id: aDatabase
32 path: "aDatabase6"31 path: Qt.resolvedUrl("aDatabase6");
33 }32 }
3433
35 U1db.Document {34 U1db.Document {
@@ -143,9 +142,7 @@
143 anchors.left: parent.left142 anchors.left: parent.left
144 anchors.right: parent.right143 anchors.right: parent.right
145 wrapMode: Text.WordWrap144 wrapMode: Text.WordWrap
146 text: {145 text: sync_output.message_value
147 text: sync_output
148 }
149 }146 }
150 }147 }
151148
152149
=== modified file 'src/document.cpp'
--- src/document.cpp 2015-02-19 10:37:54 +0000
+++ src/document.cpp 2015-03-06 02:38:22 +0000
@@ -71,6 +71,22 @@
71{71{
72 if (!m_docId.isEmpty())72 if (!m_docId.isEmpty())
73 {73 {
74 if (m_create && m_defaults.isValid())
75 {
76 // Make sure we create defaults on new path
77 m_create = false;
78 setCreate(true);
79 }
80
81 if (m_contents.isValid() && m_database && !m_docId.isEmpty())
82 {
83 if (!m_database->getDocUnchecked(m_docId).isValid())
84 {
85 // Put current contents on new database
86 m_database->putDoc(m_contents, m_docId);
87 }
88 }
89
74 m_contents = m_database->getDocUnchecked(m_docId);90 m_contents = m_database->getDocUnchecked(m_docId);
75 Q_EMIT contentsChanged(m_contents);91 Q_EMIT contentsChanged(m_contents);
76 }92 }
7793
=== modified file 'src/index.cpp'
--- src/index.cpp 2014-01-31 19:20:07 +0000
+++ src/index.cpp 2015-03-06 02:38:22 +0000
@@ -61,6 +61,7 @@
61void61void
62Index::onPathChanged(const QString& path)62Index::onPathChanged(const QString& path)
63{63{
64 m_database->putIndex(m_name, m_expression);
64 Q_EMIT dataInvalidated();65 Q_EMIT dataInvalidated();
65}66}
6667
6768
=== modified file 'tests/tst_database.qml'
--- tests/tst_database.qml 2013-08-12 15:28:13 +0000
+++ tests/tst_database.qml 2015-03-06 02:38:22 +0000
@@ -127,13 +127,12 @@
127 myDatabase.putDoc({'foo': 'bar'} ,'dl' + Number(i).toLocaleString())127 myDatabase.putDoc({'foo': 'bar'} ,'dl' + Number(i).toLocaleString())
128 myDatabase.path = ":memory:"128 myDatabase.path = ":memory:"
129 spyPathChanged.wait()129 spyPathChanged.wait()
130 compare(myDatabase.listDocs(), [])130 compare(myList.count, 2)
131 compare(myList.count, 0)
132 myDatabase.first_row_loaded = false131 myDatabase.first_row_loaded = false
133 myDatabase.last_row_loaded = false132 myDatabase.last_row_loaded = false
134 myDatabase.path = path133 myDatabase.path = path
135 spyPathChanged.wait()134 spyPathChanged.wait()
136 compare(myList.count, 100)135 compare(myList.count, 102)
137 spyDocLoaded.wait()136 spyDocLoaded.wait()
138 // FIXME compare(myDatabase.first_row_loaded, true)137 // FIXME compare(myDatabase.first_row_loaded, true)
139 // FIXME compare(myDatabase.last_row_loaded, false)138 // FIXME compare(myDatabase.last_row_loaded, false)

Subscribers

People subscribed via source and target branches

to all changes: