rdomino 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rdomino.rb +32 -0
- data/lib/rdomino/1modules.rb +77 -0
- data/lib/rdomino/database.rb +380 -0
- data/lib/rdomino/database_collection.rb +43 -0
- data/lib/rdomino/database_directory.rb +20 -0
- data/lib/rdomino/database_library.rb +34 -0
- data/lib/rdomino/databases/testdb.rb +9 -0
- data/lib/rdomino/document.rb +112 -0
- data/lib/rdomino/document_collection.rb +41 -0
- data/lib/rdomino/item.rb +57 -0
- data/lib/rdomino/name.rb +9 -0
- data/lib/rdomino/richtext_item.rb +7 -0
- data/lib/rdomino/server.rb +22 -0
- data/lib/rdomino/session.rb +115 -0
- data/lib/rdomino/version.rb +3 -0
- data/lib/rdomino/view.rb +89 -0
- data/readme.rdoc +1 -0
- data/spec/helper.rb +1 -0
- data/spec/rdomino/database_directory_spec.rb +14 -0
- data/spec/rdomino/database_helper_spec.rb +17 -0
- data/spec/rdomino/database_spec.rb +111 -0
- data/spec/rdomino/datetime_spec.rb +12 -0
- data/spec/rdomino/document_collection_spec.rb +56 -0
- data/spec/rdomino/document_spec.rb +55 -0
- data/spec/rdomino/dxl_spec.rb +16 -0
- data/spec/rdomino/item_spec.rb +26 -0
- data/spec/rdomino/name_spec.rb +13 -0
- data/spec/rdomino/session_spec.rb +46 -0
- data/spec/rdomino/view_spec.rb +43 -0
- metadata +132 -0
data/lib/rdomino/view.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module Rdomino
|
2
|
+
|
3
|
+
class View
|
4
|
+
include Enumerable, DomObject, DcView
|
5
|
+
attr_reader :document
|
6
|
+
|
7
|
+
def initialize(db,name)
|
8
|
+
if @obj = db.getView(name)
|
9
|
+
unid = @obj.universalID
|
10
|
+
@document = Document.new(@obj.parent.getdocumentbyunid(unid))
|
11
|
+
else
|
12
|
+
@document = @obj = nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# first column of categorized view
|
17
|
+
def categories
|
18
|
+
nvn = @obj.CreateViewNav( 0 )
|
19
|
+
r=[]
|
20
|
+
nve = nvn.GetFirst
|
21
|
+
while nve
|
22
|
+
r << nve.ColumnValues
|
23
|
+
nve = nvn.GetNextCategory(nve)
|
24
|
+
end
|
25
|
+
r
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_document_by_key(value,exact_match=true)
|
29
|
+
r = @obj.getDocumentByKey(value,exact_match)
|
30
|
+
r ? Document.new(r) : r
|
31
|
+
end
|
32
|
+
|
33
|
+
alias :[] :get_document_by_key
|
34
|
+
|
35
|
+
# def [](p)
|
36
|
+
# r = get_document_by_key(p)
|
37
|
+
# unless r.empty?
|
38
|
+
# r
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
def get_all_documents_by_key(arg)
|
43
|
+
DocumentCollection.new(@obj.getAllDocumentsByKey(arg))
|
44
|
+
end
|
45
|
+
|
46
|
+
def refresh
|
47
|
+
obj.Refresh
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def title
|
52
|
+
document.g :$Title
|
53
|
+
end
|
54
|
+
|
55
|
+
def comment
|
56
|
+
document.g :$comment
|
57
|
+
end
|
58
|
+
|
59
|
+
def ==(v)
|
60
|
+
title == v.title and comment == v.comment
|
61
|
+
end
|
62
|
+
|
63
|
+
def select_after(time)
|
64
|
+
doc = getlastdocument
|
65
|
+
while doc.created > time
|
66
|
+
puts doc.created
|
67
|
+
doc = getprevdocument(doc)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def refresh_selection_formula(value)
|
72
|
+
unless @obj.SelectionFormula == value
|
73
|
+
r = {}
|
74
|
+
r[:old] = @obj.SelectionFormula
|
75
|
+
r[:new] = value
|
76
|
+
@obj.SelectionFormula= value
|
77
|
+
r
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_array
|
82
|
+
map{|doc|
|
83
|
+
doc.columnvalues
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/readme.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
blabla
|
data/spec/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../lib/rdomino'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe DatabaseDirectory do
|
4
|
+
|
5
|
+
it 'finds Databases by matchers' do
|
6
|
+
Session.get('test')
|
7
|
+
DatabaseDirectory.new("",/^imbeh/).each do |db|
|
8
|
+
db.filepath.should match(/^imbeh/)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe DatabaseHelper, 'is cool' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@h = Object.new
|
7
|
+
@h.extend DatabaseHelper
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'detects replica_ids' do
|
11
|
+
@h.is_replica_id?('0123456789012345').should be_true
|
12
|
+
@h.is_replica_id?('012345678901234').should be_false
|
13
|
+
@h.is_replica_id?('mail\k\avkoj.nsf').should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe Database do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@s = Session.get('test')
|
7
|
+
@db = @s[:testdb].load_fixtures
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'loads fixtures from xlm' do
|
11
|
+
@db.count.should == 3
|
12
|
+
p 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'loads fixtures from yml' do
|
16
|
+
@db = @db.load_fixtures :yml
|
17
|
+
@db.count.should == 1
|
18
|
+
@db.search("Name='Horst'").count.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'loads fixtures from hash' do
|
22
|
+
@db = @db.load_fixtures :name => 'Paula'
|
23
|
+
@db.count.should == 1
|
24
|
+
@db.search("Name='Paula'").count.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'loads fixtures from string' do
|
28
|
+
@db = @db.load_fixtures( <<-HERE )
|
29
|
+
form|name
|
30
|
+
Person|Theo
|
31
|
+
HERE
|
32
|
+
@db.count.should == 1
|
33
|
+
@db.search("Name='Theo'").count.should == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes specific Module' do
|
37
|
+
@db.foo.should == "bar"
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'finds document by id and unid' do
|
41
|
+
doc = @db.load_fixtures(:name => 'Paula').first
|
42
|
+
unid = doc.unid
|
43
|
+
@db.find(unid).unid.should == unid
|
44
|
+
id = doc.id
|
45
|
+
@db.find(id).id.should == id
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'acesses design documents' do
|
49
|
+
@db.design_documents{|d|}. # more design documents
|
50
|
+
should be > @db.design_documents(:views ){|d| } # than views
|
51
|
+
@db.design_documents(:icon).should be_a(Document)
|
52
|
+
@db.design_documents(:icon).unid.should == @db.icon.unid
|
53
|
+
# @db.design_documents(:icon).id.should == @db.icon.id
|
54
|
+
# fails expected: "FFFF0010", got: "11A"
|
55
|
+
# @db.find("FFFF0010").unid.should == @db.find("11A").unid
|
56
|
+
|
57
|
+
@db.design_documents(:acl).should be_a(Document)
|
58
|
+
@db.icon.should be_a(Document)
|
59
|
+
@db.acl.should be_a(Document)
|
60
|
+
#@db.design_documents(:databasescript).should be_a(Document)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'accesses flags' do
|
64
|
+
# @db.flags.should == 'JF'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'accesses default_frameset' do
|
68
|
+
@db.default_frameset.should == 'fsdefault'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'can modify the replication cut of intervall' do
|
72
|
+
@db.cut_off_intervall = 90
|
73
|
+
@db.cut_off_intervall.should == 90
|
74
|
+
@db.cut_off_intervall = 91
|
75
|
+
@db.cut_off_intervall.should == 91
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'accesses view' do
|
79
|
+
@db['people'].should be_a(View)
|
80
|
+
@db['blabla'].should be_nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'refreshes view from other database' do
|
84
|
+
# view = @db['categorized']
|
85
|
+
# view.document.removepermanently(true) if view
|
86
|
+
# @db.refresh_view_design( @s[:design_library,"categorized"], :open => true ).should == :pasted
|
87
|
+
# @db.refresh_view_design( @s[:design_library,"categorized"] ).should == :no_action
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'shows content' do
|
91
|
+
@db = @db.load_fixtures
|
92
|
+
@db.by.should == {"Group" => 1, "Person" => 2}
|
93
|
+
@db.by(:name,"Form='Person'").should == {"Tobias"=>1, "Frank"=>1}
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'can search' do
|
97
|
+
@db.search("Form='Person'").count.should == 2
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'creates document' do
|
101
|
+
lambda {
|
102
|
+
@doc = @db.create_document(:form=> 'test')
|
103
|
+
}.should change(@db, :count).by(1)
|
104
|
+
|
105
|
+
lambda{
|
106
|
+
@doc.remove(true)
|
107
|
+
}.should change(@db,:count).by(-1)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe DocumentCollection, 'DocumentCollection' do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@s = Session.get 'test'
|
7
|
+
@db = @s[:scratch]
|
8
|
+
@db.load_fixtures(:yml)
|
9
|
+
end
|
10
|
+
|
11
|
+
# shared_examples_for 'updating attributes' do
|
12
|
+
|
13
|
+
it 'requires confirmation' do
|
14
|
+
$terminal = HighLine.new(StringIO.new("n\n"), StringIO.new)
|
15
|
+
@db.search("tk='mail'").update_attributes( :tk => 'new').should be_nil
|
16
|
+
@db.search("tk='new'").count.should == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'shoud not modify without confirmation' do
|
20
|
+
$terminal = HighLine.new(StringIO.new("y\n"), StringIO.new)
|
21
|
+
@db.search("tk='mail'").update_attributes( :tk => 'new', :name => 'new').should == 2
|
22
|
+
@db.search("tk='new'").count.should == 2
|
23
|
+
@db.search("name='new'").count.should == 2
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'proceed without asking' do
|
27
|
+
@db.search("tk='mail'").update_attributes!( :tk => 'new', :name => 'new').should == 2
|
28
|
+
@db.search("tk='new'").count.should == 2
|
29
|
+
@db.search("name='new'").count.should == 2
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'updates string' do
|
33
|
+
@db.search("tk='mail'").update_attributes!( 'tk' => 'new', 'name' => 'new').should == 2
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
it 'fills_nonexistent_fields' do
|
38
|
+
dc = @db.search("@isunavailable(hans)")
|
39
|
+
dc.count.should == 4
|
40
|
+
dc.update_attributes!(:hans => '')
|
41
|
+
@db.search("@isunavailable(hans)").count.should == 0
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'creates empty fields' do
|
45
|
+
@db.each{|d| d.create_empty_fields( %w(tk tkk) )}
|
46
|
+
@db.search("@isunavailable(tkk)").count.should == 0
|
47
|
+
@db.search("tk=''").count.should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'can be limited to change maximum' do
|
51
|
+
@db.search("1=1").each_limit{|d| puts d.g(:tk) }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe Document do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@s = Session.get('test')
|
7
|
+
@db = @s[:scratch]
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@doc = @db.load_fixtures( :name => "Frank").first
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accesses id and unid' do
|
15
|
+
@doc.id.should be_a(String)
|
16
|
+
@doc.unid.should have(32).characters
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'get items' do
|
20
|
+
@doc.get(:name)[0].should == 'Frank'
|
21
|
+
@doc.g(:name).should == 'Frank'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'replaces item' do
|
25
|
+
@doc.replace :name => 'Horst'
|
26
|
+
@doc.g(:name).should == 'Horst'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accesses items' do
|
30
|
+
@doc.items.map{|i| i.name}.sort.join(',').should == '$UpdatedBy,name'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'updates attributes' do
|
34
|
+
@doc.update_attributes(:name => 'Horst').should == 'name:Frank->Horst'
|
35
|
+
@doc.g(:name).should == 'Horst'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'updates attributes without change' do
|
39
|
+
@doc.update_attributes(:name => 'Frank').should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'updates attributes with numbers' do
|
43
|
+
@doc.update_attributes(:name => 3).should == 'name:Frank->3'
|
44
|
+
@doc.g(:name).should == 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'updates attributes with unavailable field' do
|
48
|
+
@doc.update_attributes(:foo => 'bar').should == 'foo:->bar'
|
49
|
+
@doc.g(:foo).should == 'bar'
|
50
|
+
end
|
51
|
+
|
52
|
+
# it 'handles time'
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe Database, ' for Dxl' do
|
4
|
+
|
5
|
+
it 'should export dxl' do
|
6
|
+
d = Session.get('test')
|
7
|
+
db = d[:testdb].load_fixtures
|
8
|
+
dir = File.dirname(__FILE__)+'/dxl/'
|
9
|
+
db.dxl_to_file(dir+'db.xml')
|
10
|
+
db.search("Form = 'Person'").dxl_to_file(dir+'dc.xml')
|
11
|
+
d[:testdb,:people].refresh["Frank"].dxl_to_file(dir+'doc.xml')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
|
4
|
+
describe Item do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@s = Session.get 'test'
|
8
|
+
@doc = @s[:scratch].load_fixtures(:li => ['z1','z2']).first
|
9
|
+
@li = @doc[:li]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates nonexistent item' do
|
13
|
+
item = @doc.find_or_create_item(:name)
|
14
|
+
item << 'v'
|
15
|
+
item.values.should == ['v']
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'appends text' do
|
19
|
+
@li.values.should == ['z1','z2']
|
20
|
+
@li << "z3"
|
21
|
+
@li.values.should == ['z1','z2','z3']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe Name, 'DominoName' do
|
4
|
+
|
5
|
+
it 'works' do
|
6
|
+
Session.get
|
7
|
+
Name.abbreviated("CN=BYDSL1/OU=Server/OU=LEV/OU=DE/O=BAYER").
|
8
|
+
should == "BYDSL1/Server/LEV/DE/BAYER"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__)+'/../helper'
|
2
|
+
module Rdomino
|
3
|
+
describe Session, 'handles Session' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@s = Session.get 'test'
|
7
|
+
@db = @s[:testdb].load_fixtures
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'gets Datbase by replica_id' do
|
11
|
+
@s['!!C1257700002E52E7'].replicaId.should == 'C1257700002E52E7'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'get Database' do
|
15
|
+
@db.should be_a(Database)
|
16
|
+
@db.Title.should == '$Testdb'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should get views' do
|
20
|
+
@s[:testdb,:people].Name.should == 'People'
|
21
|
+
@s[:testdb,'People'].Name.should == 'People'
|
22
|
+
@s[:testdb,:person_search].count.should == 2
|
23
|
+
@s[:testdb,"search:Form='Person'"].count.should == 2
|
24
|
+
@s[:testdb,"non existent view"].should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# it 'should have addressbooks' do
|
28
|
+
# abs = Session.addressbooks
|
29
|
+
# abs.should be_a(Array)
|
30
|
+
# abs.length.should be > 2
|
31
|
+
# abs.each do |d|
|
32
|
+
# d.should be_a(Database)
|
33
|
+
# end
|
34
|
+
# Session.private_addressbooks.length.should == 1
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# it 'should have locations' do
|
38
|
+
# ls= Session.locations
|
39
|
+
# ls.should be_a(DocumentCollection)
|
40
|
+
# ls.count.should be > 3
|
41
|
+
# ls.each { |l| "#{l.get :name}: #{l.get :userid}" }
|
42
|
+
# end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|