westarete-activerecord_null_object 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/activerecord_null_object.gemspec +2 -2
- data/lib/null_object.rb +2 -18
- data/spec/null_object_spec.rb +26 -9
- metadata +3 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{activerecord_null_object}
|
5
|
-
s.version = "0.0
|
5
|
+
s.version = "0.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Scott Woods"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-02}
|
10
10
|
s.description = %q{}
|
11
11
|
s.email = %q{info@westarete.com}
|
12
12
|
s.extra_rdoc_files = [
|
data/lib/null_object.rb
CHANGED
@@ -13,24 +13,8 @@ module ActiveRecordNullObject
|
|
13
13
|
true
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def save
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
def save!
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_attributes(attributes)
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
def update_attributes!(attributes)
|
33
|
-
true
|
16
|
+
def validate
|
17
|
+
errors.add_to_base("is a null object and can't be saved")
|
34
18
|
end
|
35
19
|
|
36
20
|
end
|
data/spec/null_object_spec.rb
CHANGED
@@ -38,39 +38,56 @@ describe NullAuthor do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#new_record?" do
|
41
|
-
it "should return
|
42
|
-
@null_author.new_record?.should
|
41
|
+
it "should return true" do
|
42
|
+
@null_author.new_record?.should be_true
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "#save" do
|
47
|
-
it "should return
|
48
|
-
@null_author.save.should
|
47
|
+
it "should return false" do
|
48
|
+
@null_author.save.should be_false
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not create a new record" do
|
52
52
|
lambda { @null_author.save }.should_not change { NullAuthor.count }
|
53
53
|
end
|
54
|
+
|
55
|
+
it "should add an error" do
|
56
|
+
@null_author.errors.on(:base).should == "is a null object and can't be saved"
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
describe "#save!" do
|
57
|
-
it "should
|
58
|
-
@null_author.save
|
61
|
+
it "should raise an exception" do
|
62
|
+
lambda { @null_author.save! }.should raise_error(ActiveRecord::RecordInvalid)
|
59
63
|
end
|
60
64
|
|
61
65
|
it "should not create a new record" do
|
62
|
-
lambda {
|
66
|
+
lambda {
|
67
|
+
begin
|
68
|
+
@null_author.save!
|
69
|
+
rescue ActiveRecord::RecordInvalid
|
70
|
+
end
|
71
|
+
}.should_not change { NullAuthor.count }
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should add an error" do
|
75
|
+
@null_author.errors.on(:base).should == "is a null object and can't be saved"
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
66
79
|
describe "#update_attributes" do
|
67
|
-
it "should return
|
68
|
-
@null_author.update_attributes({}).should
|
80
|
+
it "should return false" do
|
81
|
+
@null_author.update_attributes({}).should be_false
|
69
82
|
end
|
70
83
|
|
71
84
|
it "should not create a new record" do
|
72
85
|
lambda { @null_author.update_attributes({}) }.should_not change { NullAuthor.count }
|
73
86
|
end
|
87
|
+
|
88
|
+
it "should add an error" do
|
89
|
+
@null_author.errors.on(:base).should == "is a null object and can't be saved"
|
90
|
+
end
|
74
91
|
end
|
75
92
|
|
76
93
|
describe "#name" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: westarete-activerecord_null_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Woods
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -39,7 +39,6 @@ files:
|
|
39
39
|
- spec/spec_helper.rb
|
40
40
|
has_rdoc: true
|
41
41
|
homepage: http://github.com/westarete/activerecord_null_object/
|
42
|
-
licenses:
|
43
42
|
post_install_message:
|
44
43
|
rdoc_options:
|
45
44
|
- --charset=UTF-8
|
@@ -60,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
59
|
requirements: []
|
61
60
|
|
62
61
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.2.0
|
64
63
|
signing_key:
|
65
64
|
specification_version: 2
|
66
65
|
summary: Implements the Null Object Pattern for nil values in ActiveRecord associations.
|