riot-datamapper 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/riot-datamapper/has_association.rb +8 -0
- data/lib/riot-datamapper/version.rb +1 -1
- data/test/has_association_test.rb +17 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -59,7 +59,7 @@ class Comment
|
|
59
59
|
property :body, Text
|
60
60
|
|
61
61
|
belongs_to :post
|
62
|
-
belongs_to :user
|
62
|
+
belongs_to :user, :required => false
|
63
63
|
end
|
64
64
|
|
65
65
|
|
@@ -105,7 +105,7 @@ context "Comment Model" do
|
|
105
105
|
asserts_topic.has_property :body, 'Text'
|
106
106
|
|
107
107
|
asserts_topic.has_association :belongs_to, :post
|
108
|
-
asserts_topic.has_association :belongs_to, :user
|
108
|
+
asserts_topic.has_association :belongs_to, :user, :required => false
|
109
109
|
end
|
110
110
|
|
111
111
|
context "Post Model" do
|
@@ -27,6 +27,14 @@ module Riot
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
if options[:required]
|
31
|
+
if relationship.instance_variable_get("@required") == options[:required]
|
32
|
+
pass_msg << options_msg unless options[:through]
|
33
|
+
else
|
34
|
+
return fail(fail_msg + options_msg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
if relationship.class.to_s.include?(through_type || MAPPINGS[type])
|
31
39
|
pass_msg << type_msg
|
32
40
|
else
|
@@ -28,7 +28,7 @@ context "has_association macro" do
|
|
28
28
|
property :id, Serial
|
29
29
|
|
30
30
|
belongs_to :user
|
31
|
-
belongs_to :post
|
31
|
+
belongs_to :post, :required => false
|
32
32
|
end
|
33
33
|
DataMapper.finalize
|
34
34
|
end
|
@@ -49,10 +49,6 @@ context "has_association macro" do
|
|
49
49
|
Riot::DataMapper::HasAssociation.new.evaluate(Post,:has_n, :users, :through => :bubbles).first
|
50
50
|
end.equals :fail
|
51
51
|
|
52
|
-
asserts "that it passes when the model belongs_to :post" do
|
53
|
-
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :post).first
|
54
|
-
end.equals :pass
|
55
|
-
|
56
52
|
asserts "that it fails when the model does not belongs_to :foo" do
|
57
53
|
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :foo).first
|
58
54
|
end.equals :fail
|
@@ -69,4 +65,20 @@ context "has_association macro" do
|
|
69
65
|
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :user).first
|
70
66
|
end.equals :pass
|
71
67
|
|
68
|
+
asserts "that it passes when the model belongs_to :user" do
|
69
|
+
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :user).first
|
70
|
+
end.equals :pass
|
71
|
+
|
72
|
+
asserts "that it fails when the model belongs_to :wah" do
|
73
|
+
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :wah).first
|
74
|
+
end.equals :fail
|
75
|
+
|
76
|
+
asserts "that it passes when the model belongs_to :post, :required => false" do
|
77
|
+
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :post, :required => false).first
|
78
|
+
end.equals :pass
|
79
|
+
|
80
|
+
asserts "that it fails when the model belongs_to :post, :required => true" do
|
81
|
+
Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :post, :required => true).first
|
82
|
+
end.equals :fail
|
83
|
+
|
72
84
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: riot-datamapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Arthur Chiu
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-18 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: riot
|