orientdb-ar 0.0.4-jruby → 0.0.5-jruby

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,4 +4,7 @@ class Address < OrientDB::AR::Embedded
4
4
  field :state, :string
5
5
  field :zip, :string
6
6
  field :country, :string
7
+
8
+ validates_presence_of :street, :city, :state
7
9
  end
10
+ Address.schema!
@@ -1,5 +1,6 @@
1
1
  class Customer < Person
2
2
  field :number, :int, :not_null => true
3
+ field :tab, :float
3
4
  embedds_one Address, :name => :address
4
5
  embedds_many PhoneNumber, :name => :phones
5
6
  end
@@ -0,0 +1,12 @@
1
+ class Invoice < OrientDB::AR::Base
2
+
3
+ field :number, :int, :mandatory => true, :index => true
4
+ links_one Customer, :not_null => true
5
+ field :sold_on, :date
6
+ field :total, :float
7
+ links_many InvoiceLine, :name => :lines
8
+
9
+ validates_presence_of :number, :customer
10
+
11
+ end
12
+ Invoice.schema!
@@ -0,0 +1,14 @@
1
+ class InvoiceLine < OrientDB::AR::Base
2
+
3
+ links_one Product, :not_null => true
4
+ field :quantity, :int, :not_null => true
5
+ field :price, :float, :not_null => true
6
+
7
+ validates_presence_of :product, :quantity
8
+
9
+ def invoice
10
+ Invoice.where(:lines.contains(:@rid, rid.lit))
11
+ end
12
+
13
+ end
14
+ InvoiceLine.schema!
@@ -1,6 +1,13 @@
1
1
  class Person < OrientDB::AR::Base
2
+
2
3
  field :name, :string, :not_null => true
3
4
  field :age, :int
4
5
  field :tags, [:list, :string]
6
+
7
+ self.default_validation_group = :all
8
+
9
+ validates_presence_of :name, :groups => :all
10
+ validates_presence_of :age, :groups => [:all, :admins]
11
+
5
12
  end
6
13
  Person.schema!
@@ -2,4 +2,5 @@ class PhoneNumber < OrientDB::AR::Embedded
2
2
  field :type, :string
3
3
  field :number, :string
4
4
  field :extension, :string
5
- end
5
+ end
6
+ PhoneNumber.schema!
@@ -0,0 +1,17 @@
1
+ class Product < OrientDB::AR::Base
2
+
3
+ field :sku, :string, :not_null => true
4
+ field :title, :string, :not_null => true
5
+ field :price, :float, :not_null => true
6
+
7
+ validates_presence_of :sku, :title
8
+
9
+ def invoice_lines(reload = false)
10
+ if !defined?(@invoice_lines) || reload
11
+ @invoice_lines = InvoiceLine.where(:product => rid.lit).all
12
+ end
13
+ @invoice_lines
14
+ end
15
+
16
+ end
17
+ Product.schema!
@@ -1,23 +1,19 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "ActiveModel" do
3
+ describe "ActiveModel::Serialization" do
4
4
 
5
- describe "Serialization" do
6
-
7
- it "should comply" do
8
- @person = SimplePerson.new
9
- @person.serializable_hash.should == {"name" => nil}
10
- @person.as_json.should == {"name" => nil}
11
- @person.to_json.should == %{{"name":null}}
12
- @person.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<simple-person>\n <name type=\"yaml\" nil=\"true\"></name>\n</simple-person>\n"
13
-
14
- @person.name = "Bob"
15
- @person.serializable_hash.should == {"name" => "Bob"}
16
- @person.as_json.should == {"name" => "Bob"}
17
- @person.to_json.should == %{{"name":"Bob"}}
18
- @person.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<simple-person>\n <name>Bob</name>\n</simple-person>\n"
19
- end
5
+ it "should comply" do
6
+ @person = SimplePerson.new
7
+ @person.serializable_hash.should == { "name" => nil }
8
+ @person.as_json.should == { "name" => nil }
9
+ @person.to_json.should == %{{"name":null}}
10
+ @person.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<simple-person>\n <name nil=\"true\"></name>\n</simple-person>\n"
20
11
 
12
+ @person.name = "Bob"
13
+ @person.serializable_hash.should == { "name" => "Bob" }
14
+ @person.as_json.should == { "name" => "Bob" }
15
+ @person.to_json.should == %{{"name":"Bob"}}
16
+ @person.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<simple-person>\n <name>Bob</name>\n</simple-person>\n"
21
17
  end
22
18
 
23
19
  end
data/spec/spec_helper.rb CHANGED
@@ -15,22 +15,51 @@ unless defined?(SPEC_HELPER_LOADED)
15
15
  #require 'rspec/autorun'
16
16
  require 'fileutils'
17
17
 
18
- TEST_DB_PATH = "#{TEMP_DIR}/test/db_#{rand(999) + 1}"
19
- puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
18
+ TEST_URL = ENV["ORIENTDB_TEST_URL"]
19
+ TEST_USERNAME = ENV["ORIENTDB_TEST_USERNAME"] || 'admin'
20
+ TEST_PASSWORD = ENV["ORIENTDB_TEST_PASSWORD"] || 'admin'
21
+ TEST_POOLED = ENV["ORIENTDB_TEST_POOLED"].to_s[0, 1].downcase == 't'
20
22
 
21
- require 'fileutils'
22
- puts ">> Removing tmp directory #{TEMP_DIR} ..."
23
- FileUtils.remove_dir TEMP_DIR + '/test', true
24
- puts ">> Creating OrientDB database..."
25
- FileUtils.mkdir_p TEST_DB_PATH
26
- OrientDB::AR::Base.connection = OrientDB::DocumentDatabase.new("local:#{TEST_DB_PATH}/test").create
27
- puts ">> Connection : #{OrientDB::AR::Base.connection}"
28
-
29
- require SPEC_ROOT + '/models/person'
30
- require SPEC_ROOT + '/models/simple_person'
31
- require SPEC_ROOT + '/models/phone_number'
32
- require SPEC_ROOT + '/models/address'
33
- require SPEC_ROOT + '/models/customer'
23
+ puts "ENV :: TEST_URL : #{TEST_URL} | TEST_USERNAME : #{TEST_USERNAME} | TEST_PASSWORD : #{TEST_PASSWORD} | TEST_POOLED : #{TEST_POOLED}"
24
+
25
+ if TEST_URL
26
+ if TEST_POOLED
27
+ puts ">> Testing [#{TEST_URL[0,TEST_URL.index(':')]}] Pooled Database :: TEST_DB URL : #{TEST_URL} : #{TEST_USERNAME} : #{TEST_PASSWORD}"
28
+ OrientDB::AR::Base.connection = OrientDB::DocumentDatabasePool.connect(TEST_URL, TEST_USERNAME, TEST_PASSWORD)
29
+ else
30
+ puts ">> Testing [#{TEST_URL[0,TEST_URL.index(':')]}] Database :: TEST_DB URL : #{TEST_URL} : #{TEST_USERNAME} : #{TEST_PASSWORD}"
31
+ OrientDB::AR::Base.connection = OrientDB::DocumentDatabase.connect(TEST_URL, TEST_USERNAME, TEST_PASSWORD)
32
+ end
33
+ else
34
+ TEST_DB_PATH = "#{TEMP_DIR}/databases/db_#{rand(999) + 1}"
35
+ FileUtils.remove_dir "#{TEMP_DIR}/databases" rescue nil
36
+ FileUtils.mkdir_p TEST_DB_PATH
37
+ puts ">> Testing [local] Database :: TEST_DB PATH : #{TEST_DB_PATH}"
38
+ FileUtils.remove_dir "#{TEMP_DIR}/databases/"
39
+ FileUtils.mkdir_p TEST_DB_PATH
40
+ puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
41
+ OrientDB::AR::Base.connection = OrientDB::DocumentDatabase.new("local:#{TEST_DB_PATH}/test").create
42
+ end
43
+
44
+ at_exit do
45
+ puts " [ EXITING ] ".center(120, "~")
46
+ begin
47
+ puts ">> Will close connection ..."
48
+ pp OrientDB::AR::Base.connection
49
+ puts ">> Closing ..."
50
+ OrientDB::AR::Base.connection.close
51
+ puts ">> Closed ..."
52
+ rescue Exception => e
53
+ puts "EXCEPTION: #{e.class.name} : #{e.message}"
54
+ pp e.backtrace
55
+ end
56
+ puts " [ THE END ] ".center(120, "~")
57
+ exit!
58
+ end
59
+
60
+ %w{ person simple_person address phone_number customer flo_admin product invoice_line invoice }.each do |name|
61
+ require SPEC_ROOT + '/models/' + name
62
+ end
34
63
 
35
64
  require SPEC_ROOT + '/lint_behavior'
36
65
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: orientdb-ar
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: jruby
7
7
  authors:
8
8
  - Adrian Madrid
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-01-26 00:00:00 -07:00
14
- default_executable: orientdbar_console
13
+ date: 2012-01-12 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: orientdb
@@ -19,9 +18,9 @@ dependencies:
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
- - - "="
21
+ - - ">="
23
22
  - !ruby/object:Gem::Version
24
- version: 0.0.15
23
+ version: 0.0.20
25
24
  type: :runtime
26
25
  version_requirements: *id001
27
26
  - !ruby/object:Gem::Dependency
@@ -36,27 +35,38 @@ dependencies:
36
35
  type: :runtime
37
36
  version_requirements: *id002
38
37
  - !ruby/object:Gem::Dependency
39
- name: awesome_print
38
+ name: jnunemaker-validatable
40
39
  prerelease: false
41
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.4
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: awesome_print
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
42
52
  none: false
43
53
  requirements:
44
54
  - - ">="
45
55
  - !ruby/object:Gem::Version
46
56
  version: "0"
47
57
  type: :development
48
- version_requirements: *id003
58
+ version_requirements: *id004
49
59
  - !ruby/object:Gem::Dependency
50
60
  name: rspec
51
61
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
53
63
  none: false
54
64
  requirements:
55
65
  - - ">="
56
66
  - !ruby/object:Gem::Version
57
67
  version: "2.4"
58
68
  type: :development
59
- version_requirements: *id004
69
+ version_requirements: *id005
60
70
  description: Active Model wrappers to persist Ruby objects under OrientDB in JRuby.
61
71
  email:
62
72
  - aemadrid@gmail.com
@@ -84,12 +94,15 @@ files:
84
94
  - lib/orientdb-ar/embedded.rb
85
95
  - lib/orientdb-ar/ext.rb
86
96
  - lib/orientdb-ar/relations.rb
97
+ - lib/orientdb-ar/relations/embedds_many.rb
98
+ - lib/orientdb-ar/relations/embedds_one.rb
99
+ - lib/orientdb-ar/relations/links_many.rb
100
+ - lib/orientdb-ar/relations/links_one.rb
87
101
  - lib/orientdb-ar/sql.rb
88
102
  - lib/orientdb-ar/sql/delete.rb
89
103
  - lib/orientdb-ar/sql/insert.rb
90
104
  - lib/orientdb-ar/sql/query.rb
91
105
  - lib/orientdb-ar/sql/update.rb
92
- - lib/orientdb-ar/validations.rb
93
106
  - orientdb-ar.gemspec
94
107
  - spec/base_spec.rb
95
108
  - spec/dirty_spec.rb
@@ -99,13 +112,15 @@ files:
99
112
  - spec/models/address.rb
100
113
  - spec/models/customer.rb
101
114
  - spec/models/flo_admin.rb
115
+ - spec/models/invoice.rb
116
+ - spec/models/invoice_line.rb
102
117
  - spec/models/person.rb
103
118
  - spec/models/phone_number.rb
119
+ - spec/models/product.rb
104
120
  - spec/models/simple_person.rb
105
121
  - spec/serialization_spec.rb
106
122
  - spec/spec.opts
107
123
  - spec/spec_helper.rb
108
- has_rdoc: true
109
124
  homepage: http://rubygems.org/gems/orientdb
110
125
  licenses: []
111
126
 
@@ -129,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
144
  requirements: []
130
145
 
131
146
  rubyforge_project: orientdb-ar
132
- rubygems_version: 1.4.2
147
+ rubygems_version: 1.8.9
133
148
  signing_key:
134
149
  specification_version: 3
135
150
  summary: ActiveRecord-like persistency through OrientDB in JRuby
@@ -1,11 +0,0 @@
1
- module OrientDB::AR
2
- module Validations
3
-
4
- attr_reader :errors
5
-
6
- def valid?
7
- true
8
- end
9
-
10
- end
11
- end