riot-datamapper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,7 +42,7 @@ class User
42
42
  property :monkey, Boolean, :default => false
43
43
  property :name, String, :default => 'monkey', :required => true
44
44
 
45
- has n, :comments
45
+ has n, :comments, :through => :posts
46
46
  has 1, :address
47
47
  end
48
48
 
@@ -58,8 +58,18 @@ class Comment
58
58
  property :title, String
59
59
  property :body, Text
60
60
 
61
+ belongs_to :post
61
62
  belongs_to :user
62
63
  end
64
+
65
+
66
+ class Post
67
+
68
+ property :title, String
69
+ property :body, Text
70
+
71
+ has n, :comments
72
+ end
63
73
  ```
64
74
 
65
75
  You can test this like so:
@@ -75,15 +85,15 @@ context "User Model" do
75
85
  asserts_topic.has_property :monkey, 'Boolean', :default => false
76
86
  asserts_topic.has_property :name, 'String', :default => 'monkey', :required => true
77
87
 
78
- asserts_topic.has_association :has_n, :comments
88
+ asserts_topic.has_association :has_n, :comments, :through => :posts
79
89
  asserts_topic.has_association :has 1, :address
80
90
  end
81
91
 
82
92
  context "Address Model" do
83
93
  setup { Address }
84
94
 
85
- asserts_topic.has_property :street, String
86
- asserts_topic.has_property :city, String
95
+ asserts_topic.has_property :street, 'String'
96
+ asserts_topic.has_property :city, 'String'
87
97
 
88
98
  asserts_topic.has_association :belongs_to, :user
89
99
  end
@@ -91,11 +101,22 @@ end
91
101
  context "Comment Model" do
92
102
  setup { Comment }
93
103
 
94
- asserts_topic.has_property :title, String
95
- asserts_topic.has_property :body, Text
104
+ asserts_topic.has_property :title, 'String'
105
+ asserts_topic.has_property :body, 'Text'
96
106
 
107
+ asserts_topic.has_association :belongs_to, :post
97
108
  asserts_topic.has_association :belongs_to, :user
98
109
  end
110
+
111
+ context "Post Model" do
112
+ setup { Post }
113
+
114
+ asserts_topic.has_property :title, 'String'
115
+ asserts_topic.has_property :body, 'Text'
116
+
117
+
118
+ asserts_topic.has_association :has_n, :comments
119
+ end
99
120
  ```
100
121
 
101
122
  ## TODO ##
@@ -18,7 +18,16 @@ module Riot
18
18
 
19
19
  return fail(fail_msg) if relationship.nil?
20
20
 
21
- if relationship.class.to_s.include? MAPPINGS[type]
21
+ if options[:through]
22
+ through_type = 'ManyToMany'
23
+ if relationship.through.name == options[:through]
24
+ pass_msg << options_msg
25
+ else
26
+ return fail(fail_msg + options_msg)
27
+ end
28
+ end
29
+
30
+ if relationship.class.to_s.include?(through_type || MAPPINGS[type])
22
31
  pass_msg << type_msg
23
32
  else
24
33
  return fail(fail_msg + type_msg)
@@ -1,5 +1,5 @@
1
1
  module Riot
2
2
  module Datamapper
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -37,15 +37,23 @@ context "has_association macro" do
37
37
  Riot::DataMapper::HasAssociation.new.evaluate(Post,:has_n, :comments).first
38
38
  end.equals :pass
39
39
 
40
- asserts "that it fails when the model has n :foos" do
40
+ asserts "that it fails when the model does not has n :foos" do
41
41
  Riot::DataMapper::HasAssociation.new.evaluate(Post,:has_n, :foos).first
42
42
  end.equals :fail
43
43
 
44
+ asserts "that it passes when the model has n :users, :through => :comments" do
45
+ Riot::DataMapper::HasAssociation.new.evaluate(Post,:has_n, :users, :through => :comments).first
46
+ end.equals :pass
47
+
48
+ asserts "that it fails when the model does not has n :users, :through => :bubbles" do
49
+ Riot::DataMapper::HasAssociation.new.evaluate(Post,:has_n, :users, :through => :bubbles).first
50
+ end.equals :fail
51
+
44
52
  asserts "that it passes when the model belongs_to :post" do
45
53
  Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :post).first
46
54
  end.equals :pass
47
55
 
48
- asserts "that it fails when the model belongs_to :foo" do
56
+ asserts "that it fails when the model does not belongs_to :foo" do
49
57
  Riot::DataMapper::HasAssociation.new.evaluate(Comment, :belongs_to, :foo).first
50
58
  end.equals :fail
51
59
 
@@ -53,7 +61,7 @@ context "has_association macro" do
53
61
  Riot::DataMapper::HasAssociation.new.evaluate(User, :has_1, :comment).first
54
62
  end.equals :pass
55
63
 
56
- asserts "that it passes when the model has 1 :foo" do
64
+ asserts "that it passes when the model does not has 1 :foo" do
57
65
  Riot::DataMapper::HasAssociation.new.evaluate(User, :has_1, :foo).first
58
66
  end.equals :fail
59
67
 
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.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Arthur Chiu