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.
@@ -1,7 +1,10 @@
1
1
  module ActiveRecord #:nodoc:
2
2
  class Base #:nodoc:
3
- stub_class_methods :belongs_to, :has_many, :before_save, :validates_presence_of, :validates_uniqueness_of,
4
- :validates_confirmation_of, :serialize, :validates_length_of, :before_save, :attr_accessible
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
@@ -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 |arg|
23
- klass.class_eval do
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
@@ -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.1.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
- unit_tests do
4
-
5
- test "stub belongs_to" do
6
- assert_equal true, ActiveRecord::Base.methods.include?("belongs_to")
7
- end
8
-
9
- test "stub has_many" do
10
- assert_equal true, ActiveRecord::Base.methods.include?("has_many")
11
- end
12
-
13
- test "stub before_save" do
14
- assert_equal true, ActiveRecord::Base.methods.include?("before_save")
15
- end
16
-
17
- test "stub validates_presence_of" do
18
- assert_equal true, ActiveRecord::Base.methods.include?("validates_presence_of")
19
- end
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
- test "initialize via options" do
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
- assert_equal ["foo", "bar"], [instance.foo, instance.bar]
28
+ [instance.foo, instance.bar]
39
29
  end
40
-
41
- test "read attribute returns the instance_variable" do
30
+
31
+ expect "foo" do
42
32
  klass = Class.new(ActiveRecord::Base) do
43
33
  attr_accessor :foo
44
34
  end
45
- assert_equal "foo", klass.new(:foo=>"foo").read_attribute(:foo)
35
+ klass.new(:foo=>"foo").read_attribute(:foo)
46
36
  end
47
-
48
- test "write attribute sets the instance_variable" do
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
- assert_equal 1, instance.foo
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
- unit_tests do
4
- test "stub add index" do
5
- assert_equal true, ActiveRecord::Schema.instance_methods.include?("add_index")
3
+ Expectations do
4
+ expect true do
5
+ ActiveRecord::Schema.instance_methods.include?("add_index")
6
6
  end
7
7
 
8
- test "stub foreign key" do
9
- assert_equal true, ActiveRecord::Schema.instance_methods.include?("add_foreign_key")
8
+ expect true do
9
+ ActiveRecord::Schema.instance_methods.include?("add_foreign_key")
10
10
  end
11
11
 
12
- Table = 1
13
- test "create table" do
12
+ Widget = :the_model_class
13
+ expect Widget do
14
14
  schema = ActiveRecord::Schema.new
15
- assert_equal 1, schema.create_table("tables", nil) { |val| val.klass }
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
- unit_tests do
3
+ Expectations do
4
4
 
5
- test "column creates readers for each column" do
5
+ expect true do
6
6
  klass = Class.new
7
7
  BehaviorAppender.new(klass).column("foo", "string")
8
- assert_equal true, klass.instance_methods.include?("foo")
8
+ klass.instance_methods.include?("foo")
9
9
  end
10
10
 
11
- test "column creates writers for each column" do
11
+ expect true do
12
12
  klass = Class.new
13
13
  BehaviorAppender.new(klass).column("foo", "string")
14
- assert_equal true, klass.instance_methods.include?("foo=")
14
+ klass.instance_methods.include?("foo=")
15
15
  end
16
16
 
17
- test "column doesnt create readers if methods already exist" do
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
- instance = klass.new
25
- assert_equal "foo", instance.foo
24
+ klass.new.foo
26
25
  end
27
26
 
28
- test "column doesnt create writer if methods already exist" do
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
- assert_equal "foo", instance.foo
36
+ instance.foo
38
37
  end
39
-
40
- test "boolean method is defined if the type is boolean" do
38
+
39
+ expect true do
41
40
  klass = Class.new
42
41
  BehaviorAppender.new(klass).column("foo", "boolean")
43
- assert_equal true, klass.instance_methods.include?("foo?")
42
+ klass.instance_methods.include?("foo?")
44
43
  end
45
-
46
- test "string columns are created" do
44
+
45
+ expect true do
47
46
  klass = Class.new
48
47
  BehaviorAppender.new(klass).string("foo")
49
- assert_equal true, klass.instance_methods.include?("foo")
48
+ klass.instance_methods.include?("foo")
50
49
  end
51
50
 
52
- test "datetime columns are created" do
51
+ expect true do
53
52
  klass = Class.new
54
53
  BehaviorAppender.new(klass).datetime("foo")
55
- assert_equal true, klass.instance_methods.include?("foo")
54
+ klass.instance_methods.include?("foo")
56
55
  end
57
56
 
58
- test "boolean columns are created" do
57
+ expect true do
59
58
  klass = Class.new
60
59
  BehaviorAppender.new(klass).boolean("foo")
61
- assert_equal true, klass.instance_methods.include?("foo")
60
+ klass.instance_methods.include?("foo")
62
61
  end
63
62
 
64
- test "boolean columns are created with writer" do
63
+ expect true do
65
64
  klass = Class.new
66
65
  BehaviorAppender.new(klass).boolean("foo")
67
- assert_equal true, klass.instance_methods.include?("foo=")
66
+ klass.instance_methods.include?("foo=")
68
67
  end
69
68
 
70
- test "boolean columns are created with ?" do
69
+ expect true do
71
70
  klass = Class.new
72
71
  BehaviorAppender.new(klass).boolean("foo")
73
- assert_equal true, klass.instance_methods.include?("foo?")
72
+ klass.instance_methods.include?("foo?")
74
73
  end
75
74
 
76
- test "integer columns are created" do
75
+ expect true do
77
76
  klass = Class.new
78
77
  BehaviorAppender.new(klass).integer("foo")
79
- assert_equal true, klass.instance_methods.include?("foo")
78
+ klass.instance_methods.include?("foo")
80
79
  end
81
80
 
82
- test "text columns are created" do
81
+ expect true do
83
82
  klass = Class.new
84
83
  BehaviorAppender.new(klass).text("foo")
85
- assert_equal true, klass.instance_methods.include?("foo")
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
- test "string options are ignored" do
123
+ expect true do
89
124
  klass = Class.new
90
125
  BehaviorAppender.new(klass).string("foo" => "bar")
91
- assert_equal true, klass.instance_methods(false).empty?
126
+ klass.instance_methods(false).empty?
92
127
  end
93
128
  end
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
1
  require 'rubygems'
3
- require 'dust'
2
+ require 'expectations'
4
3
  require 'active_support'
5
4
  require File.dirname(__FILE__) + '/../lib/arbs'
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.1.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: 2007-12-21 00:00:00 -08:00
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.9.5
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.