-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
relationships_spec.rb
70 lines (57 loc) · 2.21 KB
/
relationships_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require File.join(File.dirname(__FILE__), "spec_helper")
#__END__
# class Post < Sequel::Model
# relationships do
# has :one, :blog, :required => true, :normalized => false # uses a blog_id field, which cannot be null, in the Post model
# has :one, :account # uses a join table called accounts_posts to link the post with it's account.
# has :many, :comments # uses a comments_posts join table
# has :many, :authors, :required => true # authors_posts join table, requires at least one author
# end
# end
class User < Sequel::Model; end
describe Sequel::Model, "relationships" do
describe "has" do
it "should allow for arity :one with options"
it "should allow for arity :many with options"
it "should raise an error Sequel::Error, \"Arity must be specified {:one, :many}.\" if arity was not specified."
end
describe "has_one" do
it "should pass arguments to has :one" do
User.should_receive(:has).with(:one, :boss, {}).and_return(true)
User.send(:has_one, :boss)
end
end
describe "has_many" do
it "should pass arguments to has :many" do
User.should_receive(:has).with(:many, :addresses, {}).and_return(true)
User.send(:has_many, :addresses)
end
end
describe "belongs_to" do
it "should pass arguments to has :one" do
@belongs_to_relationship = mock(Sequel::Model::BelongsToRelationship)
@belongs_to_relationship.should_receive(:create)
Sequel::Model::BelongsToRelationship.should_receive(:new).with(User, :boss, {}).and_return(@belongs_to_relationship)
User.send(:belongs_to, :boss)
end
end
describe "has_relationships?" do
end
describe "relationships block" do
it "should store the relationship" do
User.should_receive(:has).with(:one, :boss).and_return(true)
class User
relationships do
has :one, :boss
end
end
# User.model_relationships.should eql(?)
end
it "should create relationship methods on the model"
it "should allow for has :one relationship"
it "should allow for has :many relationship"
it "should allow for has_one relationship"
it "should allow for has_many relationship"
it "should allow for belongs_to"
end
end