This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a simple refactoring exercise. | |
# | |
# What to do? | |
# | |
# 1. Look at the code of the class CorrectAnswerBehavior | |
# 2. Try to see what it does by running `ruby refactoring_example.rb` | |
# 3. Record characterisation tests by running `ruby refactoring_example.rb --record` | |
# 4. Make the code beautiful;) | |
# 5. You are allowed to modify only the code between markers (REFACTORING START/REFACTORING END). | |
# 6. Test must pass! You can run them with command `ruby refactoring_example.rb --test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveModel | |
class Errors | |
def error_types | |
@_error_types ||= Hash.new { |hash, key| hash[key] = [] } | |
end | |
def add_with_save_names(attribute, message = nil, options = {}) | |
message ||= :invalid | |
message = message.call if message.is_a?(Proc) | |
error_types[attribute] << message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For Mongoid 2.4.x: | |
collection = Mongoid.master.collections("libraries") | |
collection.find({ user_id: current_user.id }, fields: { documents: 1 }).entries.to_json | |
For Mongoid 3.x: | |
Library.collection.find({ user_id: current_user.id }).select(documents: 1).to_json |