Module: ActiveMock::Creators
- Included in:
- Base
- Defined in:
- lib/active_mock/creators.rb
Instance Method Summary collapse
- #create(attributes = {}, &block) ⇒ Object (also: #create!)
- #find_or_create_by(attributes) ⇒ Object
- #find_or_initialize_by(attributes) ⇒ Object
Instance Method Details
#create(attributes = {}, &block) ⇒ Object Also known as: create!
4 5 6 7 8 9 10 |
# File 'lib/active_mock/creators.rb', line 4 def create(attributes = {}, &block) record = new record.save record.send(:set_properties, attributes) unless block_given? record.send(:set_properties_block, attributes, &block) if block_given? record end |
#find_or_create_by(attributes) ⇒ Object
14 15 16 |
# File 'lib/active_mock/creators.rb', line 14 def find_or_create_by(attributes) find_by(attributes) || create(attributes) end |
#find_or_initialize_by(attributes) ⇒ Object
18 19 20 |
# File 'lib/active_mock/creators.rb', line 18 def find_or_initialize_by(attributes) find_by(attributes) || new(attributes) end |