arbs 0.1.0 → 0.2.0
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/active_record/base.rb +21 -2
- data/lib/behavior_appender.rb +3 -11
- data/rakefile.rb +1 -1
- data/test/active_record/base_test.rb +86 -38
- data/test/active_record/schema_test.rb +9 -9
- data/test/behavior_appender_test.rb +66 -31
- data/test/test_helper.rb +1 -2
- metadata +4 -4
data/lib/active_record/base.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module ActiveRecord #:nodoc:
|
2
2
|
class Base #:nodoc:
|
3
|
-
stub_class_methods :
|
4
|
-
:validates_confirmation_of, :serialize, :validates_length_of, :before_save,
|
3
|
+
stub_class_methods :has_many, :before_save, :validates_presence_of, :validates_uniqueness_of,
|
4
|
+
:validates_confirmation_of, :serialize, :validates_length_of, :before_save,
|
5
|
+
:attr_accessible, :attr_protected, :after_create, :before_validation_on_create,
|
6
|
+
:validates_format_of, :validate
|
7
|
+
|
5
8
|
|
6
9
|
def initialize(attributes={})
|
7
10
|
attributes.each do |key, value|
|
@@ -16,5 +19,21 @@ module ActiveRecord #:nodoc:
|
|
16
19
|
def write_attribute(method_name, value)
|
17
20
|
instance_variable_set "@#{method_name}", value
|
18
21
|
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def belongs_to(association_name)
|
25
|
+
attr_accessor association_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_many(association_name)
|
29
|
+
attr_writer association_name
|
30
|
+
define_method association_name do
|
31
|
+
read_attribute(association_name) || write_attribute(association_name, [])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
alias has_and_belongs_to_many has_many
|
36
|
+
end
|
37
|
+
|
19
38
|
end
|
20
39
|
end
|
data/lib/behavior_appender.rb
CHANGED
@@ -16,19 +16,11 @@ class BehaviorAppender #:nodoc:
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
[:string, :text, :integer, :datetime, :boolean].each do |column_type|
|
19
|
+
[:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
|
20
20
|
define_method column_type do |*args|
|
21
21
|
args.pop if args.last.is_a?(Hash)
|
22
|
-
args.each do |
|
23
|
-
|
24
|
-
attr_reader arg.to_sym unless instance_methods.include?(arg.to_s)
|
25
|
-
attr_writer arg.to_sym unless instance_methods.include?("#{arg}=")
|
26
|
-
if column_type == :boolean
|
27
|
-
define_method "#{arg}?".to_sym do
|
28
|
-
self.send name
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
22
|
+
args.each do |name|
|
23
|
+
column name, column_type
|
32
24
|
end
|
33
25
|
end
|
34
26
|
end
|
data/rakefile.rb
CHANGED
@@ -33,7 +33,7 @@ Gem::manage_gems
|
|
33
33
|
specification = Gem::Specification.new do |s|
|
34
34
|
s.name = "arbs"
|
35
35
|
s.summary = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
|
36
|
-
s.version = "0.
|
36
|
+
s.version = "0.2.0"
|
37
37
|
s.author = 'Jay Fields'
|
38
38
|
s.description = "A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality."
|
39
39
|
s.homepage = 'http://arbs.rubyforge.org'
|
@@ -1,57 +1,105 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
test "stub validates_uniqueness_of" do
|
22
|
-
assert_equal true, ActiveRecord::Base.methods.include?("validates_uniqueness_of")
|
23
|
-
end
|
24
|
-
|
25
|
-
test "stub validates_confirmation_of" do
|
26
|
-
assert_equal true, ActiveRecord::Base.methods.include?("validates_confirmation_of")
|
27
|
-
end
|
28
|
-
|
29
|
-
test "stub serialize" do
|
30
|
-
assert_equal true, ActiveRecord::Base.methods.include?("serialize")
|
3
|
+
Expectations do
|
4
|
+
%w(
|
5
|
+
after_create
|
6
|
+
attr_accessible
|
7
|
+
attr_protected
|
8
|
+
before_save
|
9
|
+
before_validation_on_create
|
10
|
+
serialize
|
11
|
+
validates_presence_of
|
12
|
+
validates_uniqueness_of
|
13
|
+
validates_confirmation_of
|
14
|
+
validates_length_of
|
15
|
+
validates_format_of
|
16
|
+
validate
|
17
|
+
).each do |noop_class_method|
|
18
|
+
expect true do
|
19
|
+
ActiveRecord::Base.methods.include?(noop_class_method) || noop_class_method
|
20
|
+
end
|
31
21
|
end
|
32
22
|
|
33
|
-
|
23
|
+
expect ["foo", "bar"] do
|
34
24
|
klass = Class.new(ActiveRecord::Base) do
|
35
25
|
attr_accessor :foo, :bar
|
36
26
|
end
|
37
27
|
instance = klass.new(:foo=>"foo", :bar=>"bar")
|
38
|
-
|
28
|
+
[instance.foo, instance.bar]
|
39
29
|
end
|
40
|
-
|
41
|
-
|
30
|
+
|
31
|
+
expect "foo" do
|
42
32
|
klass = Class.new(ActiveRecord::Base) do
|
43
33
|
attr_accessor :foo
|
44
34
|
end
|
45
|
-
|
35
|
+
klass.new(:foo=>"foo").read_attribute(:foo)
|
46
36
|
end
|
47
|
-
|
48
|
-
|
37
|
+
|
38
|
+
expect 1 do
|
49
39
|
klass = Class.new(ActiveRecord::Base) do
|
50
40
|
attr_accessor :foo
|
51
41
|
end
|
52
42
|
instance = klass.new(:foo=>"foo")
|
53
43
|
instance.write_attribute(:foo, 1)
|
54
|
-
|
44
|
+
instance.foo
|
45
|
+
end
|
46
|
+
|
47
|
+
expect :some_fake_associated_object do
|
48
|
+
klass = Class.new(ActiveRecord::Base) do
|
49
|
+
belongs_to :foo
|
50
|
+
end
|
51
|
+
instance = klass.new
|
52
|
+
instance.foo = :some_fake_associated_object
|
53
|
+
instance.foo
|
54
|
+
end
|
55
|
+
|
56
|
+
expect :some_fake_associated_object do
|
57
|
+
klass = Class.new(ActiveRecord::Base) do
|
58
|
+
belongs_to :foo
|
59
|
+
end
|
60
|
+
instance = klass.new(:foo => :some_fake_associated_object)
|
61
|
+
instance.foo
|
62
|
+
end
|
63
|
+
|
64
|
+
expect [] do
|
65
|
+
klass = Class.new(ActiveRecord::Base) do
|
66
|
+
has_many :foos
|
67
|
+
end
|
68
|
+
instance = klass.new
|
69
|
+
instance.foos
|
70
|
+
end
|
71
|
+
|
72
|
+
expect [:value] do
|
73
|
+
klass = Class.new(ActiveRecord::Base) do
|
74
|
+
has_many :foos
|
75
|
+
end
|
76
|
+
instance = klass.new
|
77
|
+
instance.foos << :value
|
78
|
+
instance.foos
|
79
|
+
end
|
80
|
+
|
81
|
+
expect [:value] do
|
82
|
+
klass = Class.new(ActiveRecord::Base) do
|
83
|
+
has_many :foos
|
84
|
+
end
|
85
|
+
instance = klass.new
|
86
|
+
instance.foos = [:value]
|
87
|
+
instance.foos
|
88
|
+
end
|
89
|
+
|
90
|
+
expect [:value] do
|
91
|
+
klass = Class.new(ActiveRecord::Base) do
|
92
|
+
has_many :foos
|
93
|
+
end
|
94
|
+
instance = klass.new(:foos => [:value])
|
95
|
+
instance.foos
|
96
|
+
end
|
97
|
+
|
98
|
+
expect [] do
|
99
|
+
klass = Class.new(ActiveRecord::Base) do
|
100
|
+
has_and_belongs_to_many :foos
|
101
|
+
end
|
102
|
+
instance = klass.new
|
103
|
+
instance.foos
|
55
104
|
end
|
56
|
-
|
57
105
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Expectations do
|
4
|
+
expect true do
|
5
|
+
ActiveRecord::Schema.instance_methods.include?("add_index")
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
expect true do
|
9
|
+
ActiveRecord::Schema.instance_methods.include?("add_foreign_key")
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
Widget = :the_model_class
|
13
|
+
expect Widget do
|
14
14
|
schema = ActiveRecord::Schema.new
|
15
|
-
|
15
|
+
schema.create_table('widgets', nil) { |val| val.klass }
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -1,31 +1,30 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
|
-
|
3
|
+
Expectations do
|
4
4
|
|
5
|
-
|
5
|
+
expect true do
|
6
6
|
klass = Class.new
|
7
7
|
BehaviorAppender.new(klass).column("foo", "string")
|
8
|
-
|
8
|
+
klass.instance_methods.include?("foo")
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
expect true do
|
12
12
|
klass = Class.new
|
13
13
|
BehaviorAppender.new(klass).column("foo", "string")
|
14
|
-
|
14
|
+
klass.instance_methods.include?("foo=")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
expect "foo" do
|
18
18
|
klass = Class.new do
|
19
19
|
def foo
|
20
20
|
"foo"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
BehaviorAppender.new(klass).column("foo", "string")
|
24
|
-
|
25
|
-
assert_equal "foo", instance.foo
|
24
|
+
klass.new.foo
|
26
25
|
end
|
27
26
|
|
28
|
-
|
27
|
+
expect "foo" do
|
29
28
|
klass = Class.new do
|
30
29
|
def foo=(value)
|
31
30
|
@foo = "foo"
|
@@ -34,60 +33,96 @@ unit_tests do
|
|
34
33
|
BehaviorAppender.new(klass).column("foo", "string")
|
35
34
|
instance = klass.new
|
36
35
|
instance.foo = 3
|
37
|
-
|
36
|
+
instance.foo
|
38
37
|
end
|
39
|
-
|
40
|
-
|
38
|
+
|
39
|
+
expect true do
|
41
40
|
klass = Class.new
|
42
41
|
BehaviorAppender.new(klass).column("foo", "boolean")
|
43
|
-
|
42
|
+
klass.instance_methods.include?("foo?")
|
44
43
|
end
|
45
|
-
|
46
|
-
|
44
|
+
|
45
|
+
expect true do
|
47
46
|
klass = Class.new
|
48
47
|
BehaviorAppender.new(klass).string("foo")
|
49
|
-
|
48
|
+
klass.instance_methods.include?("foo")
|
50
49
|
end
|
51
50
|
|
52
|
-
|
51
|
+
expect true do
|
53
52
|
klass = Class.new
|
54
53
|
BehaviorAppender.new(klass).datetime("foo")
|
55
|
-
|
54
|
+
klass.instance_methods.include?("foo")
|
56
55
|
end
|
57
56
|
|
58
|
-
|
57
|
+
expect true do
|
59
58
|
klass = Class.new
|
60
59
|
BehaviorAppender.new(klass).boolean("foo")
|
61
|
-
|
60
|
+
klass.instance_methods.include?("foo")
|
62
61
|
end
|
63
62
|
|
64
|
-
|
63
|
+
expect true do
|
65
64
|
klass = Class.new
|
66
65
|
BehaviorAppender.new(klass).boolean("foo")
|
67
|
-
|
66
|
+
klass.instance_methods.include?("foo=")
|
68
67
|
end
|
69
68
|
|
70
|
-
|
69
|
+
expect true do
|
71
70
|
klass = Class.new
|
72
71
|
BehaviorAppender.new(klass).boolean("foo")
|
73
|
-
|
72
|
+
klass.instance_methods.include?("foo?")
|
74
73
|
end
|
75
74
|
|
76
|
-
|
75
|
+
expect true do
|
77
76
|
klass = Class.new
|
78
77
|
BehaviorAppender.new(klass).integer("foo")
|
79
|
-
|
78
|
+
klass.instance_methods.include?("foo")
|
80
79
|
end
|
81
80
|
|
82
|
-
|
81
|
+
expect true do
|
83
82
|
klass = Class.new
|
84
83
|
BehaviorAppender.new(klass).text("foo")
|
85
|
-
|
84
|
+
klass.instance_methods.include?("foo")
|
85
|
+
end
|
86
|
+
|
87
|
+
expect true do
|
88
|
+
klass = Class.new
|
89
|
+
BehaviorAppender.new(klass).float("foo")
|
90
|
+
klass.instance_methods.include?("foo")
|
91
|
+
end
|
92
|
+
|
93
|
+
expect true do
|
94
|
+
klass = Class.new
|
95
|
+
BehaviorAppender.new(klass).decimal("foo")
|
96
|
+
klass.instance_methods.include?("foo")
|
97
|
+
end
|
98
|
+
|
99
|
+
expect true do
|
100
|
+
klass = Class.new
|
101
|
+
BehaviorAppender.new(klass).timestamp("foo")
|
102
|
+
klass.instance_methods.include?("foo")
|
103
|
+
end
|
104
|
+
|
105
|
+
expect true do
|
106
|
+
klass = Class.new
|
107
|
+
BehaviorAppender.new(klass).time("foo")
|
108
|
+
klass.instance_methods.include?("foo")
|
109
|
+
end
|
110
|
+
|
111
|
+
expect true do
|
112
|
+
klass = Class.new
|
113
|
+
BehaviorAppender.new(klass).date("foo")
|
114
|
+
klass.instance_methods.include?("foo")
|
115
|
+
end
|
116
|
+
|
117
|
+
expect true do
|
118
|
+
klass = Class.new
|
119
|
+
BehaviorAppender.new(klass).binary("foo")
|
120
|
+
klass.instance_methods.include?("foo")
|
86
121
|
end
|
87
122
|
|
88
|
-
|
123
|
+
expect true do
|
89
124
|
klass = Class.new
|
90
125
|
BehaviorAppender.new(klass).string("foo" => "bar")
|
91
|
-
|
126
|
+
klass.instance_methods(false).empty?
|
92
127
|
end
|
93
128
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
platform:
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Fields
|
8
8
|
autorequire: arbs
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2008-04-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements: []
|
62
62
|
|
63
63
|
rubyforge_project: arbs
|
64
|
-
rubygems_version: 0.
|
64
|
+
rubygems_version: 1.0.1
|
65
65
|
signing_key:
|
66
66
|
specification_version: 2
|
67
67
|
summary: A duck that acts like ActiveRecord::Base, but doesn't have any of the AR::B functionality.
|