Skip to content

Commit

Permalink
Refactored upgly iteration to inject
Browse files Browse the repository at this point in the history
  • Loading branch information
mhennemeyer committed Nov 5, 2008
1 parent 09ef258 commit 3daa8be
Show file tree
Hide file tree
Showing 2 changed files with 359 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/existence_validated.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
def existence_validated(assocs=[], options={})
assocs = [assocs] unless assocs.respond_to?(:each)
hash ||= {}
assocs.each do |assoc|
assocs.inject({}) do |memo, assoc|
unless options.has_key?(assoc) && options[assoc] == nil
klass = assoc.to_s.camelize.constantize
mock = options[assoc] || mock_model(klass)
klass.should_receive(:exists?).any_number_of_times.and_return do |fk|
fk ? true : false
end
hash.update({
memo.update({
assoc.to_s.concat("_id").to_sym => mock.id,
assoc => mock
})
end
end || {}
end
hash
end
Loading

0 comments on commit 3daa8be

Please sign in to comment.