couch_potato 1.21.0 → 1.22.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0460baa84b2605f60a5a954e246a9c839171b0f125e5bca929abf9e40a736bad
4
- data.tar.gz: b5ce4755ab00575bb348bdabedc678d9aad45a42469e202ce991e7f55d7aedd4
3
+ metadata.gz: 9d8263b3487e2591fa53b3f19f6c7363bfa0d9478d449098d1bc2eee29b90ee7
4
+ data.tar.gz: 6ab3f176e570bcc2f94f531ba7248cd7bcfdd2a2bde2cf5f13b0fffd077a7dbd
5
5
  SHA512:
6
- metadata.gz: c8c46fa595c3dbfb5d8f6d8206c3f250c2dd955f1df26ec0865abdb60c3f7294474f9579328a57c4d03db33f1050bb893024847e799715010abdf029aebcf357
7
- data.tar.gz: 4aea25697ff53ef8cffa72a3ca41c864abe1d1e62d539c634a2299679d86311872ad4efce1c14cf356b04131082ec50b8fc2bc0f1700a80e1a6bdc39cf0e7d28
6
+ metadata.gz: 4f59675db667b580551a53f1a7e978d0f860f2cfad4b7aae58676d59679f84664e45544a38b39d501851d6a76752e097e3912fb3e15f4e5220621b8653c44f0b
7
+ data.tar.gz: 90c43f70f518f38e325066435b5b5ad3051df392a91399707fc814bb88615bbf90a9eada713781aa20fe5fde73a79730462a22eb8fc1da725218e16f560ba610
@@ -0,0 +1,2 @@
1
+ [native_query_servers]
2
+ enable_erlang_query_server = true
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "Ruby 3.4",
3
+ "dockerComposeFile": "docker-compose.yml",
4
+ "service": "app",
5
+ "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
6
+ "remoteUser": "vscode",
7
+ "containerEnv": {
8
+ "DATABASE": "http://admin:admin@127.0.0.1:5984/couch_potato_test"
9
+ },
10
+ "features": {
11
+ "ghcr.io/devcontainers/features/common-utils:2": {
12
+ "username": "vscode",
13
+ "userUid": "1000",
14
+ "userGid": "1000"
15
+ },
16
+ "ghcr.io/devcontainers/features/node:1": {}
17
+ }
18
+ }
@@ -0,0 +1,26 @@
1
+ services:
2
+ app:
3
+ image: ruby:3.4
4
+ volumes:
5
+ - ../..:/workspaces:z
6
+ command: sleep infinity
7
+ network_mode: service:couchdb
8
+ depends_on:
9
+ - couchdb
10
+
11
+ couchdb:
12
+ image: couchdb:3
13
+ restart: unless-stopped
14
+ entrypoint:
15
+ - /bin/bash
16
+ - -c
17
+ - cp /tmp/erlang-query-server.ini /opt/couchdb/etc/local.d/erlang-query-server.ini && exec tini -- /docker-entrypoint.sh /opt/couchdb/bin/couchdb
18
+ environment:
19
+ COUCHDB_USER: admin
20
+ COUCHDB_PASSWORD: admin
21
+ volumes:
22
+ - couchdb-data:/opt/couchdb/data
23
+ - ./couchdb/erlang-query-server.ini:/tmp/erlang-query-server.ini:ro,z
24
+
25
+ volumes:
26
+ couchdb-data:
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Changes
2
2
 
3
+ # 1.22.00
4
+
5
+ - support `Database#first` / `#first!` for flex views
6
+
3
7
  # 1.21.0
4
8
 
5
9
  - add railties 8.1, Ruby 3.4 to CI
data/couch_potato.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency 'activemodel', ['>= 7.2', '< 8.2']
17
17
  s.add_dependency 'couchrest', '~>2.0.0'
18
18
  s.add_dependency 'json', '~> 2.3'
19
+ s.add_dependency 'ostruct'
19
20
 
20
21
  s.add_development_dependency 'rake', '~>12.0'
21
22
  s.add_development_dependency 'rspec', '~>3.12.0'
@@ -96,7 +96,8 @@ module CouchPotato
96
96
  # returns the first result from a #view query or nil
97
97
  def first(spec)
98
98
  spec.view_parameters = spec.view_parameters.merge({ limit: 1 })
99
- view(spec).first
99
+ result = view(spec)
100
+ flex_view?(spec) ? result.docs.first : result.first
100
101
  end
101
102
 
102
103
  # returns th first result from a #view or raises CouchPotato::NotFound
@@ -240,6 +241,10 @@ module CouchPotato
240
241
 
241
242
  private
242
243
 
244
+ def flex_view?(spec)
245
+ spec.is_a?(CouchPotato::View::FlexViewSpec)
246
+ end
247
+
243
248
  def copy_clear_cache_proc
244
249
  lambda { |db|
245
250
  next unless cache
@@ -1,4 +1,4 @@
1
1
  module CouchPotato
2
- VERSION = '1.21.0'.freeze
2
+ VERSION = '1.22.0'.freeze
3
3
  RSPEC_VERSION = '4.2.0'.freeze
4
4
  end
@@ -98,6 +98,11 @@ module CouchPotato
98
98
  delegate :view_name, :view_parameters, :design_document, :map_function,
99
99
  :reduce_function, :language, to: :view_spec_delegate
100
100
 
101
+ def view_parameters=(params)
102
+ @view_parameters = params
103
+ @view_spec_delegate.view_parameters = params if @view_spec_delegate
104
+ end
105
+
101
106
  def process_results(results)
102
107
  results = Results.new(results)
103
108
  results.extend @extend_results_module if @extend_results_module
@@ -414,6 +414,85 @@ describe CouchPotato::Database, 'first!' do
414
414
  end
415
415
  end
416
416
 
417
+ describe CouchPotato::Database, 'first with flex view' do
418
+ before(:each) do
419
+ @couchrest_db = double('couchrest db').as_null_object
420
+ @db = CouchPotato::Database.new(@couchrest_db)
421
+ @doc = double('doc')
422
+ @view_parameters = { include_docs: true }
423
+ @results = instance_double(CouchPotato::View::FlexViewSpec::Results, docs: [@doc])
424
+ allow(@results).to receive(:database=)
425
+ @spec = instance_double(
426
+ CouchPotato::View::FlexViewSpec,
427
+ klass: 'FlexFirstModel',
428
+ view_name: 'by_name',
429
+ design_document: 'flex_first_model',
430
+ map_function: 'map',
431
+ reduce_function: nil,
432
+ language: :javascript,
433
+ process_results: @results
434
+ )
435
+ allow(@spec).to receive(:view_parameters) { @view_parameters }
436
+ allow(@spec).to receive(:view_parameters=) { |params| @view_parameters = params }
437
+ allow(@spec).to receive(:is_a?).with(CouchPotato::View::FlexViewSpec).and_return(true)
438
+ allow(CouchPotato::View::ViewQuery).to receive_messages(
439
+ new: double('view query', query_view!: { 'rows' => [{ 'doc' => @doc }] })
440
+ )
441
+ end
442
+
443
+ it 'returns the first doc from a flex view' do
444
+ expect(@db.first(@spec)).to eq(@doc)
445
+ end
446
+
447
+ it 'returns nil if there are no docs' do
448
+ allow(@results).to receive(:docs).and_return([])
449
+ expect(@db.first(@spec)).to be_nil
450
+ end
451
+
452
+ it 'sets limit: 1 on the view parameters' do
453
+ @db.first(@spec)
454
+ expect(@view_parameters[:limit]).to eq(1)
455
+ end
456
+ end
457
+
458
+ describe CouchPotato::Database, 'first! with flex view' do
459
+ before(:each) do
460
+ @couchrest_db = double('couchrest db').as_null_object
461
+ @db = CouchPotato::Database.new(@couchrest_db)
462
+ @doc = double('doc')
463
+ @view_parameters = { include_docs: true }
464
+ @results = instance_double(CouchPotato::View::FlexViewSpec::Results, docs: [@doc])
465
+ allow(@results).to receive(:database=)
466
+ @spec = instance_double(
467
+ CouchPotato::View::FlexViewSpec,
468
+ klass: 'FlexFirstBangModel',
469
+ view_name: 'by_name',
470
+ design_document: 'flex_first_bang_model',
471
+ map_function: 'map',
472
+ reduce_function: nil,
473
+ language: :javascript,
474
+ process_results: @results
475
+ )
476
+ allow(@spec).to receive(:view_parameters) { @view_parameters }
477
+ allow(@spec).to receive(:view_parameters=) { |params| @view_parameters = params }
478
+ allow(@spec).to receive(:is_a?).with(CouchPotato::View::FlexViewSpec).and_return(true)
479
+ allow(CouchPotato::View::ViewQuery).to receive_messages(
480
+ new: double('view query', query_view!: { 'rows' => [{ 'doc' => @doc }] })
481
+ )
482
+ end
483
+
484
+ it 'returns the first doc from a flex view' do
485
+ expect(@db.first!(@spec)).to eq(@doc)
486
+ end
487
+
488
+ it 'raises an error if there are no docs' do
489
+ allow(@results).to receive(:docs).and_return([])
490
+ expect do
491
+ @db.first!(@spec)
492
+ end.to raise_error(CouchPotato::NotFound)
493
+ end
494
+ end
495
+
417
496
  describe CouchPotato::Database, 'view' do
418
497
  before(:each) do
419
498
  @couchrest_db = double('couchrest db').as_null_object
@@ -41,4 +41,19 @@ RSpec.describe CouchPotato::View::FlexViewSpec::Results, '#docs' do
41
41
 
42
42
  it 'returns the docs' do
43
43
  end
44
+ end
45
+
46
+ RSpec.describe CouchPotato::View::FlexViewSpec, '#view_parameters=' do
47
+ it 'updates view parameters on the delegate' do
48
+ klass = Class.new do
49
+ def self.name
50
+ 'FlexViewParamsModel'
51
+ end
52
+ end
53
+ spec = CouchPotato::View::FlexViewSpec.new(klass, 'by_x', { key: :x }, {})
54
+
55
+ spec.view_parameters = spec.view_parameters.merge(limit: 1)
56
+
57
+ expect(spec.view_parameters[:limit]).to eq(1)
58
+ end
44
59
  end
data/spec/views_spec.rb CHANGED
@@ -345,6 +345,26 @@ describe 'views' do
345
345
 
346
346
  expect(custom).to eq([100, 200])
347
347
  end
348
+
349
+ it 'returns the first doc via Database#first' do
350
+ @db.save_document Build.new(id: 'b1', time: '1')
351
+ @db.save_document Build.new(id: 'b2', time: '2')
352
+
353
+ doc = @db.first(Build.flex_with_key(include_docs: true))
354
+
355
+ expect(doc).to be_a(Build)
356
+ expect(doc.id).to eq('b1')
357
+ end
358
+
359
+ it 'returns nil from Database#first when there are no results' do
360
+ expect(@db.first(Build.flex_with_key(include_docs: true))).to be_nil
361
+ end
362
+
363
+ it 'raises from Database#first! when there are no results' do
364
+ expect do
365
+ @db.first!(Build.flex_with_key(include_docs: true))
366
+ end.to raise_error(CouchPotato::NotFound)
367
+ end
348
368
  end
349
369
 
350
370
  describe 'inherited views' do
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.0
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-01-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activemodel
@@ -58,6 +57,20 @@ dependencies:
58
57
  - - "~>"
59
58
  - !ruby/object:Gem::Version
60
59
  version: '2.3'
60
+ - !ruby/object:Gem::Dependency
61
+ name: ostruct
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
61
74
  - !ruby/object:Gem::Dependency
62
75
  name: rake
63
76
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +133,9 @@ executables: []
120
133
  extensions: []
121
134
  extra_rdoc_files: []
122
135
  files:
136
+ - ".devcontainer/couchdb/erlang-query-server.ini"
137
+ - ".devcontainer/devcontainer.json"
138
+ - ".devcontainer/docker-compose.yml"
123
139
  - ".github/workflows/ruby.yml"
124
140
  - ".gitignore"
125
141
  - CHANGES.md
@@ -216,7 +232,6 @@ files:
216
232
  homepage: http://github.com/langalex/couch_potato
217
233
  licenses: []
218
234
  metadata: {}
219
- post_install_message:
220
235
  rdoc_options: []
221
236
  require_paths:
222
237
  - lib
@@ -231,52 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
246
  - !ruby/object:Gem::Version
232
247
  version: '0'
233
248
  requirements: []
234
- rubygems_version: 3.4.7
235
- signing_key:
249
+ rubygems_version: 3.6.9
236
250
  specification_version: 4
237
251
  summary: Ruby persistence layer for CouchDB
238
- test_files:
239
- - spec/attachments_spec.rb
240
- - spec/callbacks_spec.rb
241
- - spec/conflict_handling_spec.rb
242
- - spec/create_spec.rb
243
- - spec/default_property_spec.rb
244
- - spec/destroy_spec.rb
245
- - spec/fixtures/address.rb
246
- - spec/fixtures/person.rb
247
- - spec/property_spec.rb
248
- - spec/rails_spec.rb
249
- - spec/railtie_spec.rb
250
- - spec/reload_spec.rb
251
- - spec/revisions_spec.rb
252
- - spec/single_design_document_spec.rb
253
- - spec/spec.opts
254
- - spec/spec_helper.rb
255
- - spec/unit/active_model_compliance_spec.rb
256
- - spec/unit/attributes_spec.rb
257
- - spec/unit/base_view_spec_spec.rb
258
- - spec/unit/caching_spec.rb
259
- - spec/unit/callbacks_spec.rb
260
- - spec/unit/couch_potato_spec.rb
261
- - spec/unit/create_spec.rb
262
- - spec/unit/custom_view_spec_spec.rb
263
- - spec/unit/custom_views_spec.rb
264
- - spec/unit/database_spec.rb
265
- - spec/unit/date_spec.rb
266
- - spec/unit/dirty_attributes_spec.rb
267
- - spec/unit/flex_view_spec_spec.rb
268
- - spec/unit/forbidden_attributes_protection_spec.rb
269
- - spec/unit/initialize_spec.rb
270
- - spec/unit/json_spec.rb
271
- - spec/unit/model_view_spec_spec.rb
272
- - spec/unit/persistence_spec.rb
273
- - spec/unit/properties_view_spec_spec.rb
274
- - spec/unit/rspec_stub_db_spec.rb
275
- - spec/unit/string_spec.rb
276
- - spec/unit/time_spec.rb
277
- - spec/unit/validation_spec.rb
278
- - spec/unit/view_query_spec.rb
279
- - spec/update_spec.rb
280
- - spec/validation_context_spec.rb
281
- - spec/view_updates_spec.rb
282
- - spec/views_spec.rb
252
+ test_files: []