veneer 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/..gemspec +21 -0
- data/.gitignore +2 -5
- data/Gemfile +4 -0
- data/README.md +171 -0
- data/Rakefile +3 -36
- data/lib/..rb +3 -0
- data/lib/veneer/adapters/active_record.rb +1 -1
- data/lib/veneer/adapters/activerecord/class_wrapper.rb +11 -79
- data/lib/veneer/adapters/activerecord/instance_wrapper.rb +3 -11
- data/lib/veneer/adapters/activerecord/pre_3.0_class_wrapper.rb +24 -0
- data/lib/veneer/adapters/activerecord/pre_3.0_instance_wrapper.rb +15 -0
- data/lib/veneer/adapters/activerecord.rb +9 -2
- data/lib/veneer/adapters/data_mapper.rb +1 -1
- data/lib/veneer/adapters/datamapper/class_wrapper.rb +29 -50
- data/lib/veneer/adapters/datamapper/instance_wrapper.rb +3 -14
- data/lib/veneer/adapters/mongomapper/class_wrapper.rb +2 -56
- data/lib/veneer/adapters/mongomapper.rb +2 -2
- data/lib/veneer/base/class_wrapper.rb +46 -11
- data/lib/veneer/base/instance_wrapper.rb +12 -14
- data/lib/veneer/core_ext/kernel.rb +0 -1
- data/lib/veneer/errors.rb +0 -1
- data/lib/veneer/lint.rb +183 -0
- data/lib/veneer/version.rb +3 -0
- data/lib/veneer.rb +1 -4
- data/test/test_helper.rb +4 -3
- data/test/veneer/adapters/{active_record/active_record_setup.rb → test_active_record.rb} +23 -1
- data/test/veneer/adapters/test_datamapper.rb +56 -0
- data/test/veneer/adapters/test_mongomapper.rb +49 -0
- data/test/veneer/proxy_test.rb +20 -45
- data/veneer.gemspec +15 -108
- metadata +40 -60
- data/README.textile +0 -142
- data/VERSION +0 -1
- data/datamapper_setup.rb +0 -2
- data/lib/veneer/base/conditional.rb +0 -77
- data/test/macros/class_wrapper/create_macro.rb +0 -54
- data/test/macros/class_wrapper/delete_macro.rb +0 -31
- data/test/macros/class_wrapper/find_macro.rb +0 -119
- data/test/macros/class_wrapper/hooks.rb +0 -41
- data/test/macros/class_wrapper/validations.rb +0 -91
- data/test/macros/instance_wrapper/destroy_macro.rb +0 -36
- data/test/macros/instance_wrapper/new_record_macro.rb +0 -39
- data/test/macros/instance_wrapper/save_macro.rb +0 -55
- data/test/macros/veneer_constants_interface.rb +0 -26
- data/test/support/before_save_mixin.rb +0 -14
- data/test/support/valiations_method_method.rb +0 -0
- data/test/veneer/adapters/active_record/class_wrapper_test.rb +0 -23
- data/test/veneer/adapters/active_record/instance_wrapper_test.rb +0 -21
- data/test/veneer/adapters/datamapper/class_wrapper_test.rb +0 -24
- data/test/veneer/adapters/datamapper/datamapper_setup.rb +0 -34
- data/test/veneer/adapters/datamapper/instance_wrapper_test.rb +0 -21
- data/test/veneer/adapters/mongomapper/class_wrapper_test.rb +0 -24
- data/test/veneer/adapters/mongomapper/instance_wrapper_test.rb +0 -21
- data/test/veneer/adapters/mongomapper/mongomapper_setup.rb +0 -25
- data/test/veneer/base/conditonal_test.rb +0 -118
@@ -1,118 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "..", "test_helper")
|
2
|
-
|
3
|
-
class VeneerBaseConditionalTest < Test::Unit::TestCase
|
4
|
-
context "Conditional from hash" do
|
5
|
-
should "create a conditonal object from a blank hash" do
|
6
|
-
c = Veneer::Conditional.from_hash({})
|
7
|
-
assert_instance_of Veneer::Conditional, c
|
8
|
-
end
|
9
|
-
|
10
|
-
should "create a conditional with a limit" do
|
11
|
-
c = Veneer::Conditional.from_hash(:limit => 5)
|
12
|
-
assert_equal c.limit, 5
|
13
|
-
end
|
14
|
-
|
15
|
-
should "have an offset specified" do
|
16
|
-
c = Veneer::Conditional.from_hash(:offset => 5)
|
17
|
-
assert_equal c.offset, 5
|
18
|
-
end
|
19
|
-
|
20
|
-
context "Veneer::Conditional::Order" do
|
21
|
-
should "let me specify a field" do
|
22
|
-
c = Veneer::Conditional::Order.new("foo")
|
23
|
-
assert_equal c.field, :foo
|
24
|
-
end
|
25
|
-
|
26
|
-
should "be decending in order by default" do
|
27
|
-
c = Veneer::Conditional::Order.new("foo")
|
28
|
-
assert_equal :desc, c.direction
|
29
|
-
end
|
30
|
-
|
31
|
-
should "let me specify an ascending order" do
|
32
|
-
c = Veneer::Conditional::Order.new("foo", "asc")
|
33
|
-
assert_equal :asc, c.direction
|
34
|
-
end
|
35
|
-
|
36
|
-
should "let me specify a decending order" do
|
37
|
-
["desc", :desc].each do |dir|
|
38
|
-
c = Veneer::Conditional::Order.new("foo", dir)
|
39
|
-
assert_equal :desc, c.direction
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should "have an order specified as an array" do
|
45
|
-
c = Veneer::Conditional.from_hash(:order => ["foo", "bar"])
|
46
|
-
conditionals = [:foo, :bar].map do |f|
|
47
|
-
Veneer::Conditional::Order.new(f)
|
48
|
-
end
|
49
|
-
assert_equal c.order.first, conditionals.first
|
50
|
-
assert_equal c.order.last, conditionals.last
|
51
|
-
end
|
52
|
-
|
53
|
-
should "let me specify the order with a direction" do
|
54
|
-
c = Veneer::Conditional.from_hash(:order => ["foo asc", "bar", "baz desc"])
|
55
|
-
conditionals = [[:foo, :asc], [:bar, :desc], [:baz, :desc]].map do |(f,d)|
|
56
|
-
Veneer::Conditional::Order.new(f, d)
|
57
|
-
end
|
58
|
-
|
59
|
-
(0..2).each do |i|
|
60
|
-
assert_equal c.order[i], conditionals[i]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "conditions" do
|
65
|
-
context "condition object" do
|
66
|
-
should "let me specify an equal condition" do
|
67
|
-
c = Veneer::Conditional::Condition.new(:foo, "val", :eql)
|
68
|
-
assert_equal :foo, c.field
|
69
|
-
assert_equal :eql, c.operator
|
70
|
-
assert_equal "val", c.value
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
should "let me specify conditions" do
|
75
|
-
c = Veneer::Conditional.from_hash(:conditions => {:foo => "bar"})
|
76
|
-
condition = c.conditions.first
|
77
|
-
assert_instance_of Veneer::Conditional::Condition, condition
|
78
|
-
end
|
79
|
-
|
80
|
-
should "let me specify conditions for different operators" do
|
81
|
-
c = Veneer::Conditional.from_hash(:conditions => {
|
82
|
-
"foo not" => "bar",
|
83
|
-
"bar not" => 5,
|
84
|
-
"baz gte" => 6
|
85
|
-
})
|
86
|
-
foo = c.conditions.detect{|x| x.field == :foo}
|
87
|
-
assert_not_nil foo
|
88
|
-
assert_equal "bar", foo.value
|
89
|
-
assert_equal :not, foo.operator
|
90
|
-
|
91
|
-
bar = c.conditions.detect{|x| x.field == :bar}
|
92
|
-
assert_not_nil bar
|
93
|
-
assert_equal 5, bar.value
|
94
|
-
assert_equal :not, bar.operator
|
95
|
-
|
96
|
-
baz = c.conditions.detect{|x| x.field == :baz}
|
97
|
-
assert_not_nil baz
|
98
|
-
assert_equal 6, baz.value
|
99
|
-
assert_equal :gte, baz.operator
|
100
|
-
end
|
101
|
-
|
102
|
-
should "not error for valid operators" do
|
103
|
-
[:eql, :gt, :gte, :lt, :lte, :in, :not].each do |op|
|
104
|
-
assert_nothing_raised do
|
105
|
-
Veneer::Conditional::Condition.new(:foo, "bar", op)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
should "error if the operator isn't valid" do
|
111
|
-
assert_raises Veneer::Errors::ConditionalOperatorNotSupported do
|
112
|
-
Veneer::Conditional::Condition.new(:foo, "bar", :not_real)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|