lib/mongo-fixture.rb in mongo-fixture-0.0.3 vs lib/mongo-fixture.rb in mongo-fixture-0.0.4
- old
+ new
@@ -88,19 +88,20 @@
# Inserts the fixture data into the corresponding collections
def push
check
@data.each do |collection, matrix|
- matrix.each do |element, values|
- begin
- @connection[collection].insert simplify values.to_hash
- @inserted ||= Array.new
- @inserted << collection
- rescue MissingProcessedValueError => m
- rollback
- raise MissingProcessedValueError, "In record '#{element}' to be inserted into '#{collection}', the processed value of field '#{m.field}' is missing, aborting"
+ unless data_was_inserted_in? collection
+ matrix.each do |element, values|
+ begin
+ @connection[collection].insert simplify values.to_hash
+ rescue MissingProcessedValueError => m
+ rollback
+ raise MissingProcessedValueError, "In record '#{element}' to be inserted into '#{collection}', the processed value of field '#{m.field}' is missing, aborting"
+ end
end
+ @inserted << collection
end
end
end
# Simplifies the hash in order to insert it into the database
@@ -126,10 +127,12 @@
end
unless data_was_inserted_in? actual_option
insert_data_for actual_option
end
- the_returned_hash[key] = @connection[actual_option].find( @data[actual_option][value[actual_option].to_sym] ).first[:_id]
+ current_collection = @connection[actual_option]
+ current_data = simplify @data[actual_option][value[actual_option].to_sym]
+ the_returned_hash[key] = current_collection.find(current_data).first["_id"]
end
else
the_returned_hash[key] = value
end
end