frozen_record 0.1.3 → 0.2.0

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: c789eb24300d5ed1ad38c6e5e97a113456436e4f
4
- data.tar.gz: 6984bcf978e209e3fd3c0f3a0b53a5aac9228449
3
+ metadata.gz: 3d5bf57cf0db1528c16e891539181a4a5656be02
4
+ data.tar.gz: b956af651e5cfd433e5dd34d8587b47f0df5da74
5
5
  SHA512:
6
- metadata.gz: c90cbe7410bf3e7da6a652e61c677ba35bce7993f14782337094b15015350584781df430d2e111b6027dc3edd979c9b64d1af003488ee6d42e178868b66259dd
7
- data.tar.gz: 6c6d7524d6ab890ffb4816599c45b3482c972036446abe94747687c99fab969f527ad6abe9abf5e4120ad81fb6277465fc12a232985031a1efe13f3a0541e080
6
+ metadata.gz: f5b16b551e331aa03982c77b380a7ed8481c81b75a7447c4fd21a491dec9872d773bc00f45b6678d47ae4dfbde8ac1bff303a507a4fbd30f3aaa7d8f63f145cd
7
+ data.tar.gz: 1774b28d79b17b87244c73b608a9981219d90c0448ebfa625e6adbc451e43dad057fd77afb33fcff0e1d42b29bc7c4199faa9282819f07354f5e6cd65e151c9e
@@ -47,7 +47,7 @@ module FrozenRecord
47
47
  store[:scope] = scope
48
48
  end
49
49
 
50
- delegate :find, :find_by_id, :where, :first, :first!, :last, :last!, :pluck, :order, :limit, :offset,
50
+ delegate :find, :find_by_id, :find_by, :find_by!, :where, :first, :first!, :last, :last!, :pluck, :order, :limit, :offset,
51
51
  :minimum, :maximum, :average, :sum, to: :current_scope
52
52
 
53
53
  def file_path
@@ -37,6 +37,14 @@ module FrozenRecord
37
37
  find_by_id(id) or raise RecordNotFound, "Couldn't find a record with ID = #{id.inspect}"
38
38
  end
39
39
 
40
+ def find_by(criterias)
41
+ where(criterias).first
42
+ end
43
+
44
+ def find_by!(criterias)
45
+ where(criterias).first!
46
+ end
47
+
40
48
  def first!
41
49
  first or raise RecordNotFound, "No record matched"
42
50
  end
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
data/spec/scope_spec.rb CHANGED
@@ -104,6 +104,35 @@ describe 'querying' do
104
104
 
105
105
  end
106
106
 
107
+ describe '.find_by' do
108
+
109
+ it 'returns the first matching record' do
110
+ country = Country.find_by(name: 'France', density: 116)
111
+ expect(country.name).to be == 'France'
112
+ end
113
+
114
+ it 'returns nil if no records match' do
115
+ country = Country.find_by(name: 'England', density: 116)
116
+ expect(country).to be_nil
117
+ end
118
+
119
+ end
120
+
121
+ describe '.find_by!' do
122
+
123
+ it 'returns the first matching record' do
124
+ country = Country.find_by!(name: 'France', density: 116)
125
+ expect(country.name).to be == 'France'
126
+ end
127
+
128
+ it 'returns nil if no records match' do
129
+ expect {
130
+ Country.find_by!(name: 'England', density: 116)
131
+ }.to raise_error(FrozenRecord::RecordNotFound)
132
+ end
133
+
134
+ end
135
+
107
136
  describe 'dynamic_matchers' do
108
137
 
109
138
  it 'returns the first matching record' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frozen_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-25 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel