/
proxy.rb
75 lines (65 loc) · 1.74 KB
/
proxy.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
module FactoryGirl
class Proxy #:nodoc:
attr_reader :callbacks
def initialize(klass)
@callbacks = {}
end
def get(attribute)
end
def set(attribute, value, ignored = false)
end
def associate(name, factory, attributes)
end
def add_callback(callback)
@callbacks[callback.name] ||= []
@callbacks[callback.name] << callback
end
def run_callbacks(name)
if @callbacks[name]
@callbacks[name].each do |callback|
callback.run(@instance, self)
end
end
end
# Generates an association using the current build strategy.
#
# Arguments:
# name: (Symbol)
# The name of the factory that should be used to generate this
# association.
# attributes: (Hash)
# A hash of attributes that should be overridden for this association.
#
# Returns:
# The generated association for the current build strategy. Note that
# associations are not generated for the attributes_for strategy. Returns
# nil in this case.
#
# Example:
#
# factory :user do
# # ...
# end
#
# factory :post do
# # ...
# author { |post| post.association(:user, :name => 'Joe') }
# end
#
# # Builds (but doesn't save) a Post and a User
# FactoryGirl.build(:post)
#
# # Builds and saves a User, builds a Post, assigns the User to the
# # author association, and saves the Post.
# FactoryGirl.create(:post)
#
def association(name, overrides = {})
end
def method_missing(method, *args, &block)
get(method)
end
def result(to_create)
raise NotImplementedError, "Strategies must return a result"
end
end
end