frozen_record 0.24.1 → 0.25.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: b99597156ea028c8d0cbd66024b901d55a5e26679030266367caa8ec81353946
4
- data.tar.gz: 12e4756a7a49d32010298b4320f447d9b18afd76efe969a1f3a32e7d890592de
3
+ metadata.gz: d2be87eaecead5b4f1d4c5e941d48fcd9be163c56f2c9b988ec4d6ff7ea84757
4
+ data.tar.gz: 0a4a51c609251f3a46ba49e16f85b1d27ce5e52581fb70bd605c8585b1f62fa8
5
5
  SHA512:
6
- metadata.gz: fcb9c7aa9c820dfa50b431d36bef98d39488be55fa034edaed7aefde063a919134af0d945e3233ca5a6efbc3c3798245a5ea5741b5ae1f4d8dad1b0189b1bf7e
7
- data.tar.gz: df184ce79d274a9fe8a6fcb70c9548bb18f17c1e8da143c88d2ab9f2aedec746314a21ee2e591e191fd248f8d5e332dfdcc379f316d09fcb070a5284724f43ad
6
+ metadata.gz: 4326747e566bdb03b700dd5bb8164b550f8d339991754cebeb2a5414f8858a4bb19c074ac2231d4e978be881ed0ff87611c107c69bbc2a21ba498b7d3eb563eb
7
+ data.tar.gz: f73715f137336bada8a8aad2a3be9d6b4cf87f4de9dae6c2b77463201f7a3e510ae6c7491d9957db9c7d2b6df8280576e7e896eb8bf28b661bff02d32d4634f5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Unreleased
2
2
 
3
+ # v0.25.0
4
+
5
+ - Disable max_records_scan checks when loading records.
6
+ - Add `FrozenRecord::Base.with_max_record_scan` for more easily allowing larger amount in specific tests.
7
+
3
8
  # v0.24.1
4
9
 
5
10
  - Fix index selection not applying some restrictions.
@@ -45,6 +45,14 @@ module FrozenRecord
45
45
  end
46
46
 
47
47
  class << self
48
+ def with_max_records_scan(value)
49
+ previous_max_records_scan = max_records_scan
50
+ self.max_records_scan = value
51
+ yield
52
+ ensure
53
+ self.max_records_scan = previous_max_records_scan
54
+ end
55
+
48
56
  alias_method :set_default_attributes, :default_attributes=
49
57
  private :set_default_attributes
50
58
  def default_attributes=(default_attributes)
@@ -148,7 +156,7 @@ module FrozenRecord
148
156
  end
149
157
  @attributes = list_attributes(records).freeze
150
158
  define_attribute_methods(@attributes.to_a)
151
- records = records.map { |r| load(r) }.freeze
159
+ records = with_max_records_scan(nil) { records.map { |r| load(r) }.freeze }
152
160
  index_definitions.values.each { |index| index.build(records) }
153
161
  records
154
162
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrozenRecord
4
- VERSION = '0.24.1'
4
+ VERSION = '0.25.0'
5
5
  end
@@ -0,0 +1,13 @@
1
+ <% 100.times.map { |i| "plan_#{i}"}.each do |plan_name| %>
2
+ <% ["base", "online", "retail"].each do |type| %>
3
+ <% [nil, "USD", "EUR", "GBP", "JPY"].each do |currency| %>
4
+ <% ["monthly", "annual", "biennial", "triennial"].each do |period| %>
5
+ - plan_name: <%= plan_name %>
6
+ type: <%= type %>
7
+ period: <%= period %>
8
+ currency: <%= currency %>
9
+ amount: 10.0
10
+ <% end %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
data/spec/scope_spec.rb CHANGED
@@ -476,17 +476,28 @@ describe 'querying' do
476
476
 
477
477
  context 'when max_records_scan is set' do
478
478
 
479
- around :each do |example|
480
- FrozenRecord::Base.max_records_scan = 1
481
- example.run
482
- FrozenRecord::Base.max_records_scan = nil
483
- end
484
-
485
479
  it 'raises on slow queries' do
486
480
  expect {
487
- Country.where(king: "Louis").to_a
481
+ FrozenRecord::Base.with_max_records_scan(1) do
482
+ Country.where(king: "Louis").to_a
483
+ end
488
484
  }.to raise_error(FrozenRecord::SlowQuery)
489
485
  end
490
486
 
487
+ it 'is accurate' do
488
+ FrozenRecord::Base.with_max_records_scan(60) do
489
+ expect(Price.count).to be == 6_000
490
+
491
+ Price.where(plan_name: "plan_24", currency: [nil, "EUR"], period: "monthly", type: "base").each do |price|
492
+ expect(price.plan_name).to be == "plan_24"
493
+ unless price.currency.nil?
494
+ expect(price.currency).to be == "EUR"
495
+ end
496
+ expect(price.period).to be == "monthly"
497
+ expect(price.type).to be == "base"
498
+ end
499
+ end
500
+ end
501
+
491
502
  end
492
503
  end
@@ -0,0 +1,13 @@
1
+ class Price < FrozenRecord::Base
2
+ add_index :plan_name
3
+ add_index :currency
4
+ end
5
+
6
+ module Compact
7
+ class Price < ::Price
8
+ include FrozenRecord::Compact
9
+ def self.file_path
10
+ superclass.file_path
11
+ end
12
+ end
13
+ end
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.24.1
4
+ version: 0.25.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: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -105,6 +105,7 @@ files:
105
105
  - spec/fixtures/cars.yml
106
106
  - spec/fixtures/continents.yml.erb
107
107
  - spec/fixtures/countries.yml.erb
108
+ - spec/fixtures/prices.yml.erb
108
109
  - spec/fixtures/test_helper/continents.yml.erb
109
110
  - spec/fixtures/test_helper/countries.yml.erb
110
111
  - spec/frozen_record_spec.rb
@@ -115,6 +116,7 @@ files:
115
116
  - spec/support/car.rb
116
117
  - spec/support/continent.rb
117
118
  - spec/support/country.rb
119
+ - spec/support/price.rb
118
120
  - spec/test_helper_spec.rb
119
121
  homepage: https://github.com/byroot/frozen_record
120
122
  licenses:
@@ -144,6 +146,7 @@ test_files:
144
146
  - spec/fixtures/cars.yml
145
147
  - spec/fixtures/continents.yml.erb
146
148
  - spec/fixtures/countries.yml.erb
149
+ - spec/fixtures/prices.yml.erb
147
150
  - spec/fixtures/test_helper/continents.yml.erb
148
151
  - spec/fixtures/test_helper/countries.yml.erb
149
152
  - spec/frozen_record_spec.rb
@@ -154,4 +157,5 @@ test_files:
154
157
  - spec/support/car.rb
155
158
  - spec/support/continent.rb
156
159
  - spec/support/country.rb
160
+ - spec/support/price.rb
157
161
  - spec/test_helper_spec.rb