contentful_model 1.2.0 → 1.3.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
  SHA256:
3
- metadata.gz: 95936de4fccef8852abcdd2d2e1053f73210d3026add835f392287681eb570cf
4
- data.tar.gz: ad3a0a352825eeea13e7a3661a63dc2c4c251ad61d8a8c58953c425a67f90f34
3
+ metadata.gz: 9698f899467e305668facbe2f839511aeeb471da81fb65b7d73c6328afe55c70
4
+ data.tar.gz: 91cc79dd66f213c21fbc63c25d537896c68ab27702295176e5f29b8fa55cc03e
5
5
  SHA512:
6
- metadata.gz: 98eef95a34aa622730863c966a4631669ff24ada5d0f7aa9e325a000c7d2ff3e91e19d67aa4f37fab9d00d4978865c6b69b6e4449a73ceca2824624315d4873a
7
- data.tar.gz: 81c0e9a361ee70ffc23007f86fe5555ea1aaba2a0cd622813766fb20d8fa9548fb09065cd235cf8933a64f0b4453f226e6da79aa1ab7869fd02091417fcafc27
6
+ metadata.gz: 52e15d3939439beebbb265847d1493ce3d01bc96f67f62adc95403bd7f432bd5977702595233ac17c218dda6473fe16f943595ad610094152e0001c5db5e5225
7
+ data.tar.gz: 783982e1384ff5f304a2bdce4cedafc1068e04ca72caeeb58d382180e1b1e66a823689cdbc9373f33b73158fece47030cda336b29cf4f7435d333ddbeffa9f12
@@ -1,4 +1,5 @@
1
1
  module ContentfulModel
2
2
  class AssociationError < StandardError; end
3
3
  class VersionMismatchError < StandardError; end
4
+ class NotFoundError < StandardError; end
4
5
  end
@@ -22,6 +22,10 @@ module ContentfulModel
22
22
  all.load
23
23
  end
24
24
 
25
+ def load!
26
+ all.load!
27
+ end
28
+
25
29
  def first
26
30
  query.first
27
31
  end
@@ -159,6 +159,10 @@ module ContentfulModel
159
159
  end
160
160
  alias load execute
161
161
 
162
+ def load!
163
+ load.presence || raise(NotFoundError)
164
+ end
165
+
162
166
  def client
163
167
  @client ||= @referenced_class.client
164
168
  end
@@ -1,3 +1,3 @@
1
1
  module ContentfulModel
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -93,6 +93,22 @@ describe ContentfulModel::Query do
93
93
  end
94
94
  end
95
95
 
96
+ describe '#load!' do
97
+ it 'raises an error when response is empty' do
98
+ vcr('query/empty') {
99
+ expect { subject.load! }.to raise_error ContentfulModel::NotFoundError
100
+ }
101
+ end
102
+
103
+ it 'returns items when response is not empty' do
104
+ query = described_class.new(Cat, 'sys.id' => 'nyancat')
105
+ vcr('nyancat') {
106
+ entries = query.load!
107
+ expect(entries.first.id).to eq 'nyancat'
108
+ }
109
+ end
110
+ end
111
+
96
112
  describe '#discover_includes' do
97
113
  it 'defaults to 1 for a class without associations' do
98
114
  query = described_class.new(Cat)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (David Litvak Bruno)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-11 00:00:00.000000000 Z
12
+ date: 2020-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: contentful