forked from mongodb/mongoid
/
many_spec.rb
101 lines (73 loc) · 1.88 KB
/
many_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require "spec_helper"
describe Mongoid::Relations::Referenced::Many do
describe ".builder" do
let(:builder_klass) do
Mongoid::Relations::Builders::Referenced::Many
end
let(:document) do
stub
end
let(:metadata) do
stub(:extension? => false)
end
it "returns the embedded in builder" do
described_class.builder(metadata, document).should
be_a_kind_of(builder_klass)
end
end
describe ".embedded?" do
it "returns false" do
described_class.should_not be_embedded
end
end
describe ".foreign_key_suffix" do
it "returns _id" do
described_class.foreign_key_suffix.should == "_id"
end
end
describe ".macro" do
it "returns references_many" do
described_class.macro.should == :references_many
end
end
describe "#respond_to?" do
let(:person) do
Person.new
end
let(:posts) do
person.posts
end
Array.public_instance_methods.each do |method|
context "when checking #{method}" do
it "returns true" do
posts.respond_to?(method).should be_true
end
end
end
Mongoid::Relations::Referenced::Many.public_instance_methods.each do |method|
context "when checking #{method}" do
it "returns true" do
posts.respond_to?(method).should be_true
end
end
end
Post.scopes.keys.each do |method|
context "when checking #{method}" do
it "returns true" do
posts.respond_to?(method).should be_true
end
end
end
end
describe ".stores_foreign_key?" do
it "returns false" do
described_class.stores_foreign_key?.should == false
end
end
describe ".valid_options" do
it "returns the valid options" do
described_class.valid_options.should ==
[ :as, :autosave, :dependent, :foreign_key, :order ]
end
end
end