diametric 0.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +28 -0
  3. data/Jarfile +20 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +264 -0
  6. data/Rakefile +49 -0
  7. data/bin/datomic-rest +33 -0
  8. data/bin/download-datomic +13 -0
  9. data/datomic_version.yml +4 -0
  10. data/diametric-java.gemspec +39 -0
  11. data/ext/diametric/DiametricCollection.java +147 -0
  12. data/ext/diametric/DiametricConnection.java +113 -0
  13. data/ext/diametric/DiametricDatabase.java +107 -0
  14. data/ext/diametric/DiametricEntity.java +90 -0
  15. data/ext/diametric/DiametricListenableFuture.java +47 -0
  16. data/ext/diametric/DiametricObject.java +66 -0
  17. data/ext/diametric/DiametricPeer.java +414 -0
  18. data/ext/diametric/DiametricService.java +102 -0
  19. data/ext/diametric/DiametricUUID.java +61 -0
  20. data/ext/diametric/DiametricUtils.java +183 -0
  21. data/lib/boolean_type.rb +3 -0
  22. data/lib/diametric.rb +42 -0
  23. data/lib/diametric/config.rb +54 -0
  24. data/lib/diametric/config/environment.rb +42 -0
  25. data/lib/diametric/entity.rb +659 -0
  26. data/lib/diametric/errors.rb +13 -0
  27. data/lib/diametric/generators/active_model.rb +42 -0
  28. data/lib/diametric/persistence.rb +48 -0
  29. data/lib/diametric/persistence/common.rb +82 -0
  30. data/lib/diametric/persistence/peer.rb +154 -0
  31. data/lib/diametric/persistence/rest.rb +107 -0
  32. data/lib/diametric/query.rb +259 -0
  33. data/lib/diametric/railtie.rb +52 -0
  34. data/lib/diametric/rest_service.rb +74 -0
  35. data/lib/diametric/service_base.rb +77 -0
  36. data/lib/diametric/transactor.rb +86 -0
  37. data/lib/diametric/version.rb +3 -0
  38. data/lib/diametric_service.jar +0 -0
  39. data/lib/tasks/create_schema.rb +27 -0
  40. data/lib/tasks/diametric_config.rb +45 -0
  41. data/lib/value_enums.rb +8 -0
  42. data/spec/conf_helper.rb +55 -0
  43. data/spec/config/free-transactor-template.properties +73 -0
  44. data/spec/config/logback.xml +59 -0
  45. data/spec/data/seattle-data0.dtm +452 -0
  46. data/spec/data/seattle-data1.dtm +326 -0
  47. data/spec/developer_create_sample.rb +39 -0
  48. data/spec/developer_query_spec.rb +120 -0
  49. data/spec/diametric/config_spec.rb +60 -0
  50. data/spec/diametric/entity_spec.rb +476 -0
  51. data/spec/diametric/peer_api_spec.rb +147 -0
  52. data/spec/diametric/persistence/peer_many2many_spec.rb +76 -0
  53. data/spec/diametric/persistence/peer_spec.rb +27 -0
  54. data/spec/diametric/persistence/rest_spec.rb +30 -0
  55. data/spec/diametric/persistence_spec.rb +59 -0
  56. data/spec/diametric/query_spec.rb +118 -0
  57. data/spec/diametric/rest_service_spec.rb +56 -0
  58. data/spec/diametric/transactor_spec.rb +68 -0
  59. data/spec/integration_spec.rb +107 -0
  60. data/spec/parent_child_sample.rb +42 -0
  61. data/spec/peer_integration_spec.rb +121 -0
  62. data/spec/peer_seattle_spec.rb +200 -0
  63. data/spec/rc2013_seattle_big.rb +82 -0
  64. data/spec/rc2013_seattle_small.rb +60 -0
  65. data/spec/rc2013_simple_sample.rb +72 -0
  66. data/spec/seattle_integration_spec.rb +106 -0
  67. data/spec/simple_validation_sample.rb +31 -0
  68. data/spec/spec_helper.rb +63 -0
  69. data/spec/support/entities.rb +157 -0
  70. data/spec/support/gen_entity_class.rb +9 -0
  71. data/spec/support/persistence_examples.rb +104 -0
  72. data/spec/test_version_file.yml +4 -0
  73. metadata +290 -0
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe Diametric::RestService, :service =>true do
5
+ let(:service) { Diametric::RestService }
6
+
7
+ before do
8
+ dir = File.join(File.dirname(__FILE__), "../..", "tmp/datomic")
9
+ FileUtils.rm_rf(dir)
10
+ FileUtils.mkdir_p(dir)
11
+ end
12
+
13
+ it "should find a class" do
14
+ service.should be_true
15
+ end
16
+
17
+ it "should find a default conf file" do
18
+ service.datomic_conf_file?.should be_true
19
+ end
20
+
21
+ it "should find a specified conf file" do
22
+ service.datomic_conf_file?("spec/test_version_file.yml").should be_true
23
+ end
24
+
25
+ it "should return false for version no" do
26
+ service.datomic_conf_file?("datomic-free-0.8.4122").should be_false
27
+ end
28
+
29
+ it "should know datomic version specified" do
30
+ service.datomic_version("spec/test_version_file.yml").should == "datomic-free-0.8.4122"
31
+ service.datomic_version("datomic-free-0.8.4122").should == "datomic-free-0.8.4122"
32
+ end
33
+
34
+ it "should know the specified version of datomic has been downloaded" do
35
+ service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_false
36
+ service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_false
37
+
38
+ service.download("spec/test_version_file.yml", "tmp/datomic")
39
+
40
+ service.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_true
41
+ service.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_true
42
+ end
43
+
44
+ context Diametric::RestService do
45
+ let(:rest) { Diametric::RestService.new("spec/test_version_file.yml", "tmp/datomic") }
46
+
47
+ it "should start and stop rest service" do
48
+ uri = URI("http://localhost:49621")
49
+ expect { Net::HTTP.get_response(uri) }.to raise_error
50
+ rest.start(:port => 49621, :db_alias => "free", :uri => "datomic:mem://")
51
+ expect { Net::HTTP.get_response(uri) }.not_to raise_error
52
+ rest.stop
53
+ expect { Net::HTTP.get_response(uri) }.to raise_error
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe "Transactor Service", :transactor =>true do
5
+ let(:transactor) { Diametric::Transactor }
6
+
7
+ before do
8
+ dir = File.join(File.dirname(__FILE__), "../..", "tmp/datomic")
9
+ FileUtils.rm_rf(dir)
10
+ FileUtils.mkdir_p(dir)
11
+ end
12
+
13
+ it "should find a class" do
14
+ transactor.should be_true
15
+ end
16
+
17
+ it "should find a default conf file" do
18
+ transactor.datomic_conf_file?.should be_true
19
+ end
20
+
21
+ it "should find a specified conf file" do
22
+ transactor.datomic_conf_file?("spec/test_version_file.yml").should be_true
23
+ end
24
+
25
+ it "should return false for version no" do
26
+ transactor.datomic_conf_file?("datomic-free-0.8.4122").should be_false
27
+ end
28
+
29
+ it "should know datomic version specified" do
30
+ transactor.datomic_version("spec/test_version_file.yml").should == "datomic-free-0.8.4122"
31
+ transactor.datomic_version("datomic-free-0.8.4122").should == "datomic-free-0.8.4122"
32
+ end
33
+
34
+ it "should know the specified version of datomic has been downloaded" do
35
+ transactor.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_false
36
+ transactor.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_false
37
+
38
+ transactor.download("spec/test_version_file.yml", "tmp/datomic")
39
+
40
+ transactor.downloaded?("spec/test_version_file.yml", "tmp/datomic").should be_true
41
+ transactor.downloaded?("datomic-free-0.8.4122", "tmp/datomic").should be_true
42
+ end
43
+
44
+ context Diametric::Transactor do
45
+ let(:transactor) { Diametric::Transactor.new("spec/test_version_file.yml", "tmp/datomic") }
46
+
47
+ it "should start and stop transactor" do
48
+ filename = File.join(File.dirname(__FILE__), "..", "config", "free-transactor-template.properties")
49
+ File.exists?(filename).should be_true
50
+ transactor.start(filename).should be_true
51
+ transactor.stop
52
+ end
53
+ end
54
+
55
+ context Diametric::Transactor do
56
+ let(:transactor) { Diametric::Transactor.new("spec/test_version_file.yml", "tmp/datomic") }
57
+
58
+ it "should be available to create_database and connect to" do
59
+ filename = File.join(File.dirname(__FILE__), "..", "config", "free-transactor-template.properties")
60
+ transactor.start(filename).should be_true
61
+ uri = "datomic:free://localhost:39082/transactor-#{SecureRandom.uuid}"
62
+ Diametric::Persistence::Peer.create_database(uri).should be_true
63
+ Diametric::Persistence::Peer.connect(uri).should be_true
64
+ transactor.stop
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'diametric/entity'
3
+ require 'datomic/client'
4
+ require 'securerandom'
5
+
6
+ # Datomic's `rest` needs to run for these tests to pass:
7
+ # bin/rest 9000 test datomic:mem://
8
+
9
+ describe Diametric::Entity, :integration => true do
10
+ before(:all) do
11
+ @datomic_uri = ENV['DATOMIC_URI'] || 'http://localhost:46291'
12
+ @storage = ENV['DATOMIC_STORAGE'] || 'free'
13
+ @dbname = ENV['DATOMIC_NAME'] || "test-#{SecureRandom.uuid}"
14
+ @client = Datomic::Client.new @datomic_uri, @storage
15
+ @client.create_database(@dbname)
16
+ sleep 0.5
17
+ end
18
+
19
+ it "can load the schema" do
20
+ resp = @client.transact(@dbname, Person.schema)
21
+ resp.code.should == 201
22
+ resp.data.should be_a(Hash)
23
+ resp.data.keys.sort.should == [:"db-after", :"db-before", :tempids, :"tx-data"]
24
+ end
25
+
26
+ describe "with a schema" do
27
+ before(:all) do
28
+ @client.transact(@dbname, Person.schema)
29
+ @client.transact(@dbname, Goat.schema)
30
+ end
31
+
32
+ it "can transact an entity" do
33
+ birthday = DateTime.parse("1976-09-04")
34
+ goat = Goat.new(:name => "Beans", :birthday => birthday)
35
+ resp = @client.transact(@dbname, goat.tx_data)
36
+ resp.code.should == 201
37
+ resp.data.should be_a(Hash)
38
+ resp.data.keys.sort.should == [:"db-after", :"db-before", :tempids, :"tx-data"]
39
+ end
40
+ end
41
+
42
+ describe "with an entity" do
43
+ before(:all) do
44
+ goat = Goat.new(:name => "Josef", :birthday => DateTime.parse("1976-09-04"))
45
+ @client.transact(@dbname, goat.tx_data)
46
+ end
47
+
48
+ it "can query for that entity" do
49
+ query, args = Diametric::Query.new(Goat).where(:name => "Josef").data
50
+ args = args.unshift({:"db/alias" => "#{@storage}/#{@dbname}"})
51
+ resp = @client.query(query, args)
52
+ resp.code.should == 200
53
+ resp.data.should be_a(Array)
54
+ resp.data.count.should == 1
55
+ resp.data.first.count.should == 3
56
+ end
57
+
58
+ it "can rehydrate an entity from a query" do
59
+ query, args = Diametric::Query.new(Goat).where(:name => "Josef").data
60
+ args = args.unshift({:"db/alias" => "#{@storage}/#{@dbname}"})
61
+ resp = @client.query(query, args)
62
+ resp.code.should == 200
63
+
64
+ goats = resp.data.map { |data| Goat.from_query(data) }
65
+ goats.first.name.should == "Josef"
66
+ end
67
+ end
68
+
69
+ describe "with persistence module" do
70
+ before(:all) do
71
+ Robin.create_schema
72
+ end
73
+
74
+ let(:query) { Diametric::Query.new(Robin) }
75
+ it "can create entity" do
76
+ robin = Robin.new
77
+
78
+ expect { robin.save! }.to raise_error(Diametric::Errors::ValidationError)
79
+ robin.save.should be_false
80
+ robin.name = "Mary"
81
+ robin.age = 3
82
+ expect { robin.save! }.not_to raise_error()
83
+ robin.persisted?.should be_true
84
+ end
85
+ it "can update entity" do
86
+ robin = Robin.new(:name => "Mary", :age => 2)
87
+ robin.save
88
+ robin.update(:age => 3)
89
+ robin.name.should == "Mary"
90
+ robin.age.should == 3
91
+ end
92
+ it "should search upadated attributes" do
93
+ robin = query.where(:name => "Mary").first
94
+ robin.name.should == "Mary"
95
+ robin.age.should == 3
96
+ end
97
+ it "can destroy entity" do
98
+ robin = Robin.new(:name => "Mary", :age => 2)
99
+ robin.save
100
+ number_of_robins = Robin.all.size
101
+ number_of_robins.should >= 1
102
+ robin.destroy
103
+ Robin.all.size.should == (number_of_robins -1)
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,42 @@
1
+ require 'conf_helper'
2
+
3
+ class Somebody
4
+ include Diametric::Entity
5
+ include Diametric::Persistence::Peer
6
+
7
+ attribute :name, String
8
+ attribute :parent, Ref, :cardinality => :one
9
+ end
10
+
11
+ describe "RailsConf 2013", :jruby => true do
12
+ context Somebody do
13
+ before(:all) do
14
+ datomic_uri = "datomic:mem://somebody-#{SecureRandom.uuid}"
15
+ @conn = Diametric::Persistence::Peer.connect(datomic_uri)
16
+ end
17
+ after(:all) do
18
+ @conn.release
19
+ end
20
+
21
+ it "should create schema" do
22
+ binding.pry
23
+ Sombody.create_schema(@conn)
24
+ end
25
+
26
+ it "should create instances" do
27
+ alice = Somebody.new
28
+ alice.name = "Alice Wonderland"
29
+ alice.parent = ""
30
+ yoko.save
31
+ binding.pry
32
+
33
+ clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
34
+ clinton.save
35
+ binding.pry
36
+
37
+ ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
38
+ ryan.save
39
+ binding.pry
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+ require 'diametric/entity'
3
+ require 'datomic/client'
4
+
5
+ # Datomic's `rest` needs to run for these tests to pass:
6
+ # bin/rest 9000 test datomic:mem://
7
+
8
+ describe Diametric::Entity, :integration => true, :jruby => true do
9
+ context Penguin do
10
+ before(:all) do
11
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://animals'
12
+ @conn = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
13
+ Penguin.create_schema(@conn)
14
+ end
15
+
16
+ after(:all) do
17
+ @conn.release
18
+ end
19
+
20
+ let(:query) { Diametric::Query.new(Penguin, @conn, true) }
21
+ it "should update entity" do
22
+ penguin = Penguin.new(:name => "Mary", :age => 2)
23
+ penguin.save(@conn)
24
+ penguin.update(:age => 3)
25
+ penguin.name.should == "Mary"
26
+ penguin.age.should == 3
27
+ end
28
+
29
+ it "should search upadated attributes" do
30
+ penguin = query.where(:name => "Mary").first
31
+ penguin.name.should == "Mary"
32
+ penguin.age.should == 3
33
+ end
34
+
35
+ it "should destroy entity" do
36
+ penguin = Penguin.new(:name => "Mary", :age => 2)
37
+ penguin.save(@conn)
38
+ number_of_penguins = Penguin.all.size
39
+ number_of_penguins.should >= 1
40
+ penguin.destroy
41
+ Penguin.all.size.should == (number_of_penguins -1)
42
+ end
43
+ end
44
+
45
+ context Choice do
46
+ before(:all) do
47
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://choices'
48
+ @conn2 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
49
+ Choice.create_schema(@conn2)
50
+ end
51
+
52
+ after(:all) do
53
+ @conn2.release
54
+ end
55
+
56
+ it "should save entity" do
57
+ choice = Choice.new(:item => "Boots", :checked => true)
58
+ choice.save.should_not be_nil
59
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :choice/checked]]", @conn2.db)
60
+ choice = Choice.from_dbid_or_entity(result.first.first, @conn2.db)
61
+ choice.checked.should be_true
62
+ end
63
+ end
64
+
65
+ context Customer do
66
+ before(:all) do
67
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://choices'
68
+ @conn3 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
69
+ Customer.create_schema(@conn3)
70
+ end
71
+
72
+ after(:all) do
73
+ @conn3.release
74
+ end
75
+
76
+ it "should save entity with Diametric uuid" do
77
+ id = Diametric::Persistence::Peer.squuid
78
+ customer = Customer.new(:name => "John Smith", :id => id)
79
+ customer.save.should_not be_nil
80
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :customer/name]]", @conn3.db)
81
+ customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
82
+ customer2.name.should == "John Smith"
83
+ customer2.id.to_s.should == id.to_s
84
+ end
85
+
86
+ it "should save entity with Ruby uuid" do
87
+ require 'uuid'
88
+ id = UUID.new.generate
89
+ customer = Customer.new(:name => "Wilber Hoe", :id => id)
90
+ customer.save.should_not be_nil
91
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?name] :where [?e :customer/name ?name]]", @conn3.db, ["Wilber Hoe"])
92
+ customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
93
+ customer2.name.should == "Wilber Hoe"
94
+ customer2.id.to_s.should == id.to_s
95
+ end
96
+ end
97
+
98
+ context Account do
99
+ before(:all) do
100
+ @datomic_uri = ENV['DATOMIC_URI'] || 'datomic:mem://account'
101
+ @conn4 = Diametric::Persistence.establish_base_connection({:uri => @datomic_uri})
102
+ Account.create_schema(@conn4)
103
+ end
104
+
105
+ after(:all) do
106
+ @conn4.release
107
+ end
108
+
109
+ it "should save entity" do
110
+ account = Account.new(:name => "This month's deposits", :deposit => [100.0, 200.0], :amount => 0.0)
111
+ account.save.should_not be_nil
112
+ result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :account/name]]", @conn4.db)
113
+ account2 = Customer.from_dbid_or_entity(result.first.first, @conn4.db)
114
+ account2.name.should == account.name
115
+ account2.amount.should == 0.0
116
+ account2.deposit.should include(100.0)
117
+ account2.deposit.should include(200.0)
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,200 @@
1
+ require 'spec_helper'
2
+ require 'diametric/entity'
3
+ require 'datomic/client'
4
+
5
+ describe Diametric::Entity, :integration => true, :jruby => true do
6
+ context District do
7
+ before(:all) do
8
+ datomic_uri = "datomic:mem://district-#{SecureRandom.uuid}"
9
+ @d_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
10
+ end
11
+ after(:all) do
12
+ @d_conn1.release
13
+ end
14
+ let(:district) { District.create_schema(@d_conn1) }
15
+ it "should create schema" do
16
+ district.should_not be_nil
17
+ end
18
+ it "should return future object" do
19
+ district.should be_a(Diametric::Persistence::ListenableFuture)
20
+ end
21
+ it "should return object by get from future do" do
22
+ district.get.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context District do
27
+ before(:all) do
28
+ datomic_uri = "datomic:mem://district-#{SecureRandom.uuid}"
29
+ @d_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
30
+ District.create_schema(@d_conn2).get
31
+ end
32
+ after(:all) do
33
+ @d_conn2.release
34
+ end
35
+ it "should save instance" do
36
+ district = District.new
37
+ district.name = "East"
38
+ district.region = District::Region::E
39
+ district.save(@d_conn2).should_not be_nil
40
+ district.tx_data.should be_empty
41
+ end
42
+ it "should get instance" do
43
+ query = Diametric::Query.new(District, @d_conn2, true)
44
+ district = query.where(:name => "East").first
45
+ district.name.should == "East"
46
+ district.region.should == District::Region::E
47
+ end
48
+ end
49
+
50
+ context Neighborhood do
51
+ before(:all) do
52
+ datomic_uri = "datomic:mem://neighborhood-#{SecureRandom.uuid}"
53
+ @n_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
54
+ end
55
+ after(:all) do
56
+ @n_conn1.release
57
+ end
58
+ it "should create schema" do
59
+ Neighborhood.create_schema(@n_conn1).get.should_not be_nil
60
+ end
61
+ end
62
+
63
+ context Neighborhood do
64
+ before(:all) do
65
+ datomic_uri = "datomic:mem://neighborhood-#{SecureRandom.uuid}"
66
+ @n_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
67
+ Neighborhood.create_schema(@n_conn2).get
68
+ District.create_schema(@n_conn2).get
69
+ end
70
+ after(:all) do
71
+ @n_conn2.release
72
+ end
73
+
74
+ it "should save instance" do
75
+ district = District.new
76
+ district.name = "East"
77
+ district.region = District::Region::E
78
+ neighborhood = Neighborhood.new
79
+ neighborhood.name = "Capitol Hill"
80
+ neighborhood.district = district
81
+ neighborhood.save(@n_conn2).should_not be_nil
82
+ district.tx_data.should be_empty
83
+ neighborhood.tx_data.should be_empty
84
+ end
85
+
86
+ it "should not include tx_data of saved entity" do
87
+ district = District.new
88
+ district.name = "Southwest"
89
+ district.region = District::Region::SW
90
+ district.save(@n_conn2)
91
+ neighborhood = Neighborhood.new
92
+ neighborhood.name = "Admiral (West Seattle)"
93
+ neighborhood.district = district
94
+
95
+ result = []
96
+ neighborhood.parse_tx_data(neighborhood.tx_data, result)
97
+ result.first[":neighborhood/district"].to_s.should match(/^\d+/)
98
+
99
+ neighborhood.save(@n_conn2)
100
+ district.tx_data.should be_empty
101
+ neighborhood.tx_data.should be_empty
102
+ end
103
+
104
+ it "should get instance" do
105
+ district = District.new
106
+ district.name = "East"
107
+ district.region = District::Region::E
108
+ neighborhood = Neighborhood.new
109
+ neighborhood.name = "Capitol Hill"
110
+ neighborhood.district = district
111
+ neighborhood.save(@n_conn2).should_not be_nil
112
+
113
+ query = Diametric::Query.new(Neighborhood, @n_conn2, true)
114
+ neighborhood = query.where(:name => "Capitol Hill").first
115
+ neighborhood.dbid.should_not be_nil
116
+ neighborhood.name.should == "Capitol Hill"
117
+ neighborhood.district.should be_a(District)
118
+ neighborhood.district.dbid.should_not be_nil
119
+ neighborhood.district.name.should == "East"
120
+ neighborhood.district.region.should == District::Region::E
121
+ end
122
+
123
+ it "should not resolve ref type dbid" do
124
+ district = District.new
125
+ district.name = "East"
126
+ district.region = District::Region::E
127
+ neighborhood = Neighborhood.new
128
+ neighborhood.name = "Capitol Hill"
129
+ neighborhood.district = district
130
+ neighborhood.save(@n_conn2).should_not be_nil
131
+
132
+ query = Diametric::Query.new(Neighborhood, @n_conn2, true)
133
+ neighborhood = query.where(:name => "Capitol Hill").first
134
+ neighborhood.name.should == "Capitol Hill"
135
+ neighborhood.district.should be_a(District)
136
+ end
137
+ end
138
+
139
+ context Community do
140
+ before(:all) do
141
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
142
+ @s_conn1 = Diametric::Persistence::Peer.connect(datomic_uri)
143
+ end
144
+ after(:all) do
145
+ @s_conn1.release
146
+ end
147
+ it "should create schema" do
148
+ Community.create_schema(@s_conn1).get.should_not be_nil
149
+ end
150
+ end
151
+
152
+ context Community do
153
+ before(:all) do
154
+ datomic_uri = "datomic:mem://community-#{SecureRandom.uuid}"
155
+ @s_conn2 = Diametric::Persistence::Peer.connect(datomic_uri)
156
+ Neighborhood.create_schema(@s_conn2).get
157
+ District.create_schema(@s_conn2).get
158
+ Community.create_schema(@s_conn2).get
159
+ end
160
+ after(:all) do
161
+ @s_conn2.release
162
+ end
163
+
164
+ it "should save instance" do
165
+ district = District.new
166
+ district.name = "East"
167
+ district.region = District::Region::E
168
+ neighborhood = Neighborhood.new
169
+ neighborhood.name = "Capitol Hill"
170
+ neighborhood.district = district
171
+ community = Community.new
172
+ community.name = "15th Ave Community"
173
+ community.url = "http://groups.yahoo.com/group/15thAve_Community/"
174
+ community.neighborhood = neighborhood
175
+ community.category = ["15th avenue residents"]
176
+ community.orgtype = Community::Orgtype::COMMUNITY
177
+ community.type = Community::Type::EMAIL_LIST
178
+ community.save(@n_conn2).should_not be_nil
179
+ end
180
+
181
+ it "should get instance" do
182
+ query = Diametric::Query.new(Community, @s_conn2, true)
183
+ community = query.where(:name => "15th Ave Community").first
184
+ community.dbid.should_not be_nil
185
+ community.name.should == "15th Ave Community"
186
+ community.url.should == "http://groups.yahoo.com/group/15thAve_Community/"
187
+ community.neighborhood.should be_a(Neighborhood)
188
+ community.neighborhood.dbid.should_not be_nil
189
+ community.neighborhood.name.should == "Capitol Hill"
190
+ community.neighborhood.district.should be_a(District)
191
+ community.neighborhood.district.dbid.should_not be_nil
192
+ community.neighborhood.district.name.should == "East"
193
+ community.neighborhood.district.region.should == District::Region::E
194
+ community.category == ["15th avenue residents"]
195
+ community.orgtype.should == Community::Orgtype::COMMUNITY
196
+ community.type.should == Community::Type::EMAIL_LIST
197
+ end
198
+ end
199
+
200
+ end