veneer 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +12 -1
- data/README.md +55 -87
- data/Rakefile +1 -1
- data/lib/veneer.rb +6 -1
- data/lib/veneer/adapters/activerecord.rb +2 -0
- data/lib/veneer/adapters/activerecord/class_wrapper.rb +99 -5
- data/lib/veneer/adapters/activerecord/instance_wrapper.rb +4 -2
- data/lib/veneer/adapters/activerecord/pre_3.0_class_wrapper.rb +62 -1
- data/lib/veneer/adapters/activerecord/property.rb +22 -0
- data/lib/veneer/adapters/datamapper.rb +1 -0
- data/lib/veneer/adapters/datamapper/class_wrapper.rb +90 -6
- data/lib/veneer/adapters/datamapper/property.rb +25 -0
- data/lib/veneer/adapters/mongomapper.rb +1 -0
- data/lib/veneer/adapters/mongomapper/class_wrapper.rb +68 -0
- data/lib/veneer/adapters/mongomapper/property.rb +16 -0
- data/lib/veneer/base/class_wrapper.rb +110 -7
- data/lib/veneer/base/property.rb +27 -0
- data/lib/veneer/lint.rb +4 -180
- data/lib/veneer/lint/adapter.rb +282 -0
- data/lib/veneer/lint/base.rb +10 -0
- data/lib/veneer/lint/properties.rb +78 -0
- data/lib/veneer/version.rb +1 -1
- data/test/support/helpers.rb +10 -1
- data/test/test_helper.rb +3 -3
- data/test/veneer/activerecord/test_adapter.rb +80 -0
- data/test/veneer/activerecord/test_properties.rb +73 -0
- data/test/veneer/datamapper/test_adapter.rb +71 -0
- data/test/veneer/datamapper/test_properties.rb +59 -0
- data/test/veneer/{adapters/test_mongomapper.rb → mongomapper/test_adapter.rb} +35 -11
- data/test/veneer/mongomapper/test_properties.rb +56 -0
- data/test/veneer_test.rb +35 -0
- data/veneer.gemspec +2 -0
- metadata +57 -51
- data/test/veneer/adapters/test_active_record.rb +0 -56
- data/test/veneer/adapters/test_datamapper.rb +0 -56
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "..", "test_helper"))
|
2
|
+
require 'mongo_mapper'
|
3
|
+
|
4
|
+
require 'veneer/adapters/mongomapper'
|
5
|
+
|
6
|
+
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
|
7
|
+
MongoMapper.database = 'veneer_test'
|
8
|
+
|
9
|
+
class MongoBar
|
10
|
+
include MongoMapper::Document
|
11
|
+
|
12
|
+
key :name, String
|
13
|
+
key :string_field, String, :length => 255
|
14
|
+
key :integer_field, Integer
|
15
|
+
key :float_field, Float
|
16
|
+
key :date_field, Date
|
17
|
+
key :boolean_field, Boolean
|
18
|
+
key :hash_field, Hash
|
19
|
+
key :set_field, Set
|
20
|
+
key :time_field, Time
|
21
|
+
key :object_field, Object
|
22
|
+
key :binary_field, Binary
|
23
|
+
|
24
|
+
|
25
|
+
validates_presence_of :integer_field
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class MongoMapperPropertiesTest < ::Test::Unit::TestCase
|
30
|
+
include Veneer::Lint::Properties
|
31
|
+
|
32
|
+
def setup
|
33
|
+
@klass = ::MongoBar
|
34
|
+
@properties_mapping = {
|
35
|
+
:_id => String, #ObjectID
|
36
|
+
:string_field => String,
|
37
|
+
:integer_field => Integer,
|
38
|
+
:float_field => Float,
|
39
|
+
:date_field => Date,
|
40
|
+
:boolean_field => TrueClass,
|
41
|
+
:hash_field => Hash,
|
42
|
+
:set_field => Set,
|
43
|
+
:time_field => Time,
|
44
|
+
:object_field => Object,
|
45
|
+
:binary_field => StringIO
|
46
|
+
}
|
47
|
+
@primary_keys = [:_id]
|
48
|
+
@properties_with_length = {
|
49
|
+
:string_field => 255,
|
50
|
+
:integer_field => nil
|
51
|
+
}
|
52
|
+
@properties_with_validations = {
|
53
|
+
:integer_field => [ActiveModel::Validations::PresenceValidator]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
data/test/veneer_test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class VeneerTestCase < Test::Unit::TestCase
|
4
|
+
context "Venner" do
|
5
|
+
setup do
|
6
|
+
clear_constants! :Foo, :Bar
|
7
|
+
Veneer::Base::ClassWrapper.subclasses.clear
|
8
|
+
end
|
9
|
+
|
10
|
+
should "keep track of all class wrappers" do
|
11
|
+
assert_equal 0, Veneer::Base::ClassWrapper.subclasses.size
|
12
|
+
class ::Foo < Veneer::Base::ClassWrapper; end
|
13
|
+
assert_equal 1, Veneer::Base::ClassWrapper.subclasses.size
|
14
|
+
assert_equal Veneer::Base::ClassWrapper.subclasses.first, ::Foo
|
15
|
+
end
|
16
|
+
|
17
|
+
should "defer to the adapters class_models to gather all class models" do
|
18
|
+
class ::Foo < Veneer::Base::ClassWrapper
|
19
|
+
def self.model_classes
|
20
|
+
[:foo_models]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ::Bar < Veneer::Base::ClassWrapper
|
25
|
+
def self.model_classes
|
26
|
+
[:bar_models]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
result = Veneer.model_classes
|
31
|
+
assert_equal result, [:foo_models, :bar_models]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/veneer.gemspec
CHANGED
metadata
CHANGED
@@ -1,34 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: veneer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Daniel Neighman
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
date: 2011-10-27 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hashie
|
16
|
+
requirement: &70270790409440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70270790409440
|
25
|
+
description: Veneer provides basic querying, saving, deleteing and creating interface
|
26
|
+
for data stores.
|
27
|
+
email:
|
24
28
|
- has.sox@gmail.com
|
25
29
|
executables: []
|
26
|
-
|
27
30
|
extensions: []
|
28
|
-
|
29
31
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
32
|
+
files:
|
32
33
|
- ..gemspec
|
33
34
|
- .document
|
34
35
|
- .gitignore
|
@@ -44,65 +45,70 @@ files:
|
|
44
45
|
- lib/veneer/adapters/activerecord/instance_wrapper.rb
|
45
46
|
- lib/veneer/adapters/activerecord/pre_3.0_class_wrapper.rb
|
46
47
|
- lib/veneer/adapters/activerecord/pre_3.0_instance_wrapper.rb
|
48
|
+
- lib/veneer/adapters/activerecord/property.rb
|
47
49
|
- lib/veneer/adapters/data_mapper.rb
|
48
50
|
- lib/veneer/adapters/datamapper.rb
|
49
51
|
- lib/veneer/adapters/datamapper/class_wrapper.rb
|
50
52
|
- lib/veneer/adapters/datamapper/instance_wrapper.rb
|
53
|
+
- lib/veneer/adapters/datamapper/property.rb
|
51
54
|
- lib/veneer/adapters/mongomapper.rb
|
52
55
|
- lib/veneer/adapters/mongomapper/class_wrapper.rb
|
53
56
|
- lib/veneer/adapters/mongomapper/instance_wrapper.rb
|
57
|
+
- lib/veneer/adapters/mongomapper/property.rb
|
54
58
|
- lib/veneer/base/class_wrapper.rb
|
55
59
|
- lib/veneer/base/instance_wrapper.rb
|
60
|
+
- lib/veneer/base/property.rb
|
56
61
|
- lib/veneer/core_ext/kernel.rb
|
57
62
|
- lib/veneer/errors.rb
|
58
63
|
- lib/veneer/lint.rb
|
64
|
+
- lib/veneer/lint/adapter.rb
|
65
|
+
- lib/veneer/lint/base.rb
|
66
|
+
- lib/veneer/lint/properties.rb
|
59
67
|
- lib/veneer/proxy.rb
|
60
68
|
- lib/veneer/version.rb
|
61
69
|
- test/support/helpers.rb
|
62
70
|
- test/test_helper.rb
|
63
|
-
- test/veneer/
|
64
|
-
- test/veneer/
|
65
|
-
- test/veneer/
|
71
|
+
- test/veneer/activerecord/test_adapter.rb
|
72
|
+
- test/veneer/activerecord/test_properties.rb
|
73
|
+
- test/veneer/datamapper/test_adapter.rb
|
74
|
+
- test/veneer/datamapper/test_properties.rb
|
75
|
+
- test/veneer/mongomapper/test_adapter.rb
|
76
|
+
- test/veneer/mongomapper/test_properties.rb
|
66
77
|
- test/veneer/proxy_test.rb
|
78
|
+
- test/veneer_test.rb
|
67
79
|
- veneer.gemspec
|
68
|
-
|
69
|
-
homepage: ""
|
80
|
+
homepage: ''
|
70
81
|
licenses: []
|
71
|
-
|
72
82
|
post_install_message:
|
73
83
|
rdoc_options: []
|
74
|
-
|
75
|
-
require_paths:
|
84
|
+
require_paths:
|
76
85
|
- lib
|
77
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
87
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
|
84
|
-
- 0
|
85
|
-
version: "0"
|
86
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
93
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
version: "0"
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
95
98
|
requirements: []
|
96
|
-
|
97
99
|
rubyforge_project: veneer
|
98
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.8.6
|
99
101
|
signing_key:
|
100
102
|
specification_version: 3
|
101
103
|
summary: Basic query interface for persistant data stores
|
102
|
-
test_files:
|
104
|
+
test_files:
|
103
105
|
- test/support/helpers.rb
|
104
106
|
- test/test_helper.rb
|
105
|
-
- test/veneer/
|
106
|
-
- test/veneer/
|
107
|
-
- test/veneer/
|
107
|
+
- test/veneer/activerecord/test_adapter.rb
|
108
|
+
- test/veneer/activerecord/test_properties.rb
|
109
|
+
- test/veneer/datamapper/test_adapter.rb
|
110
|
+
- test/veneer/datamapper/test_properties.rb
|
111
|
+
- test/veneer/mongomapper/test_adapter.rb
|
112
|
+
- test/veneer/mongomapper/test_properties.rb
|
108
113
|
- test/veneer/proxy_test.rb
|
114
|
+
- test/veneer_test.rb
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
-
|
3
|
-
require 'activerecord'
|
4
|
-
require 'veneer/adapters/activerecord'
|
5
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
6
|
-
|
7
|
-
class CreateActiveRecordFoo < ActiveRecord::Migration
|
8
|
-
|
9
|
-
def self.up
|
10
|
-
create_table :active_record_foos, :force => true do |t|
|
11
|
-
t.string :name
|
12
|
-
t.string :title
|
13
|
-
t.string :description
|
14
|
-
t.integer :order_field1
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.down
|
19
|
-
drop_table :active_record_foos
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
CreateActiveRecordFoo.up
|
24
|
-
|
25
|
-
class ActiveRecordFoo < ActiveRecord::Base
|
26
|
-
def self.veneer_spec_reset!
|
27
|
-
delete_all
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate
|
31
|
-
errors.add(:name, "Name cannot be 'invalid'") if name == "invalid"
|
32
|
-
end
|
33
|
-
|
34
|
-
def v_with_m_test
|
35
|
-
errors.add(:name, "Name cannot be v_with_m_test") if name == "v_with_m_test"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class ActiveRecordVeneerTest < ::Test::Unit::TestCase
|
40
|
-
include Veneer::Lint
|
41
|
-
|
42
|
-
def setup
|
43
|
-
@klass = ::ActiveRecordFoo
|
44
|
-
@valid_attributes = {:name => "foo", :title => "title", :description => "description"}
|
45
|
-
@invalid_attributes = @valid_attributes.dup.merge(:name => "invalid")
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_valid_items(num)
|
49
|
-
attr = @valid_attributes
|
50
|
-
|
51
|
-
(1..num).each do |i|
|
52
|
-
ActiveRecordFoo.create(:name => "#{attr[:name]}#{i}", :title => "#{attr[:title]}#{i}", :description => "#{attr[:description]}#{i}")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
-
require 'dm-core'
|
3
|
-
require 'dm-validations'
|
4
|
-
require 'dm-migrations'
|
5
|
-
require 'veneer/adapters/datamapper'
|
6
|
-
|
7
|
-
DataMapper.setup(:default, 'sqlite3::memory:')
|
8
|
-
|
9
|
-
class DMFoo
|
10
|
-
include DataMapper::Resource
|
11
|
-
|
12
|
-
property :id, Serial
|
13
|
-
property :name, String
|
14
|
-
property :title, String
|
15
|
-
property :description, String
|
16
|
-
property :order_field1, Integer
|
17
|
-
|
18
|
-
validates_with_method :name, :method => :check_name
|
19
|
-
|
20
|
-
def check_name
|
21
|
-
if name == "invalid"
|
22
|
-
[false, "Invalid name"]
|
23
|
-
else
|
24
|
-
true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def v_with_m_test
|
29
|
-
if name == "v_with_m_test"
|
30
|
-
[false, "name cannot be v_with_m_test"]
|
31
|
-
else
|
32
|
-
true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
DataMapper.auto_migrate!
|
38
|
-
|
39
|
-
class DataMapperVeneerTest < ::Test::Unit::TestCase
|
40
|
-
include Veneer::Lint
|
41
|
-
|
42
|
-
def setup
|
43
|
-
@klass = ::DMFoo
|
44
|
-
@valid_attributes = {:name => "foo", :title => "title", :description => "description"}
|
45
|
-
@invalid_attributes = @valid_attributes.dup.merge(:name => "invalid")
|
46
|
-
end
|
47
|
-
|
48
|
-
def create_valid_items(num)
|
49
|
-
attr = @valid_attributes
|
50
|
-
|
51
|
-
(1..num).each do |i|
|
52
|
-
DMFoo.create(:name => "#{attr[:name]}#{i}", :title => "#{attr[:title]}#{i}", :description => "#{attr[:description]}#{i}")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|