active_mocker 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fb5d2c18e0123bbfcd1e6e34e9ce6f323a29324
4
- data.tar.gz: dbe134929a21a543e9f72ea5ff773bcbb1601f97
3
+ metadata.gz: 613f38220c1c399f17a225afae1041c1694bb982
4
+ data.tar.gz: c645aa726a86296a7239fe1c173c37852a68b398
5
5
  SHA512:
6
- metadata.gz: 1edf9a047d35d844d8382192dce7e368afe325a86adaa825196a4d30082d9171998bb3dcc37e9e97aea70e3fde04a89e95dee15f77a88154367b75d51060382c
7
- data.tar.gz: 20bc1b6439aacc5de848ea444463d9477cbf567a4b67f860f5618a2a7726e1800a8717feda70fe0074b7ecb30a5497778158bdb41f0492209f1f11c5c968560d
6
+ metadata.gz: bee293efab67128df025c0d0c3810a69a2d533b78e10d6ab3ee42d491be09b23fb24718438f795000b1893a0e2c8f0d9bae8fc067b5119bec5fd0832704ccd86
7
+ data.tar.gz: da922d7734e9b34e1edc048ddf3e6203a863bf996203761b22ed19ed353ae23e97c8678ce553abf813a024506ae72574dd272cc765c9c46b575072a153777482
@@ -17,6 +17,14 @@ module ActiveHash
17
17
  module ClassMethods
18
18
  include ARApi::DestroyAll
19
19
  include ARApi::FindBy
20
+
21
+ def find_or_create_by(attributes)
22
+ find_by(attributes) || create(attributes)
23
+ end
24
+
25
+ def find_or_initialize_by(attributes)
26
+ find_by(attributes) || new(attributes)
27
+ end
20
28
  end
21
29
 
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.1.7"
2
+ VERSION = "1.1.8"
3
3
  end
@@ -427,6 +427,25 @@ describe ActiveMocker::Base do
427
427
  expect(mock_class.find_by(first_name: 'dustin')).to eq person
428
428
  end
429
429
 
430
+ it '::find_or_create_by' do
431
+ person = mock_class.find_or_create_by(first_name: 'dustin')
432
+ expect(mock_class.find_by(first_name: 'dustin')).to eq person
433
+ person = mock_class.find_or_create_by(first_name: 'dustin')
434
+ expect(mock_class.count).to eq 1
435
+ end
436
+
437
+ it '::find_or_initialize_by' do
438
+ person = mock_class.find_or_initialize_by(first_name: 'dustin')
439
+ expect(person.persisted?).to eq false
440
+ mock_class.create(first_name: 'dustin')
441
+ person = mock_class.find_or_initialize_by(first_name: 'dustin')
442
+ expect(person.persisted?).to eq true
443
+ end
444
+
445
+ after(:each) do
446
+ mock_class.delete_all
447
+ end
448
+
430
449
  end
431
450
 
432
451
  describe 'false' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler