active_mocker 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_hash/ar_api.rb +8 -0
- data/lib/active_mocker/version.rb +1 -1
- data/spec/lib/active_mocker/base_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 613f38220c1c399f17a225afae1041c1694bb982
|
4
|
+
data.tar.gz: c645aa726a86296a7239fe1c173c37852a68b398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee293efab67128df025c0d0c3810a69a2d533b78e10d6ab3ee42d491be09b23fb24718438f795000b1893a0e2c8f0d9bae8fc067b5119bec5fd0832704ccd86
|
7
|
+
data.tar.gz: da922d7734e9b34e1edc048ddf3e6203a863bf996203761b22ed19ed353ae23e97c8678ce553abf813a024506ae72574dd272cc765c9c46b575072a153777482
|
data/lib/active_hash/ar_api.rb
CHANGED
@@ -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
|
@@ -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
|