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 +4 -4
- data/lib/frozen_record/base.rb +1 -1
- data/lib/frozen_record/scope.rb +8 -0
- data/lib/frozen_record/version.rb +1 -1
- data/spec/scope_spec.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5bf57cf0db1528c16e891539181a4a5656be02
|
4
|
+
data.tar.gz: b956af651e5cfd433e5dd34d8587b47f0df5da74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b16b551e331aa03982c77b380a7ed8481c81b75a7447c4fd21a491dec9872d773bc00f45b6678d47ae4dfbde8ac1bff303a507a4fbd30f3aaa7d8f63f145cd
|
7
|
+
data.tar.gz: 1774b28d79b17b87244c73b608a9981219d90c0448ebfa625e6adbc451e43dad057fd77afb33fcff0e1d42b29bc7c4199faa9282819f07354f5e6cd65e151c9e
|
data/lib/frozen_record/base.rb
CHANGED
@@ -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
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|