forty_facets 0.1.9.0 → 0.1.9.1

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: ad48e8c4f2338a87b29236fd94806a15f82da882ab7c754407cdb1795f608d15
4
- data.tar.gz: e19407ae762c613e784f8ebfb9e802d4398aa38520ef3b942016d50926cf70ca
3
+ metadata.gz: 69545229909e0d3d59609f54cd23590099dc656eb9c0450e38ec28ea23001edd
4
+ data.tar.gz: c883ef1c6c6744a0066d006bed2ffe9810e32fadb0f0677f5b98d66564bd1e0e
5
5
  SHA512:
6
- metadata.gz: 9165e142d34aac61ce38eaac7efa70db5172496494e48082b5a9882345ba113850f2bda7ff066c2d7df76557555e59acf0b7286dd6f1e5d6b1e4d2eeb4473ee1
7
- data.tar.gz: 005ef2414ddcadcf8c53d176f887386c17de905cf6f27a2ca03b9b90f5b326020cfce26fb062475ffdddf62c6f1a30e4ab79924f36c474fd47e308042a2d9ca7
6
+ metadata.gz: 669f899ed5ec16ada4907272603db2c9bbcd6a27b42555a80aaafc841c2eed0863452905ae72753b35652159a40a4fdd5c42931e780ed04a58f4dd9a0fdd975a
7
+ data.tar.gz: 3af3637c333eafe0723e8f695abcb0c1385c37bb089ac285375ea38b4975f7f1bec3e6381b1cfc53b53f280462d0aa4f52e23928b7ca47b199a22861b5ea1c2e
@@ -25,7 +25,7 @@ module FortyFacets
25
25
 
26
26
  class AssociationFacetFilter < FacetFilter
27
27
  def selected
28
- @selected ||= definition.association.klass.find(Array.wrap(values).reject(&:blank?))
28
+ @selected ||= definition.association.klass.unscoped.find(Array.wrap(values).reject(&:blank?))
29
29
  end
30
30
 
31
31
  def remove(entity)
@@ -101,7 +101,7 @@ module FortyFacets
101
101
  query = "#{my_column} AS foreign_id, count(#{my_column}) AS occurrences"
102
102
  counts = without.result(skip_ordering: true).distinct.joins(definition.joins).select(query).group(my_column)
103
103
  counts.includes_values = []
104
- entities_by_id = definition.association.klass.find(counts.map(&:foreign_id)).group_by(&:id)
104
+ entities_by_id = definition.association.klass.unscoped.find(counts.map(&:foreign_id)).group_by(&:id)
105
105
 
106
106
  facet = counts.map do |count|
107
107
  facet_entity = entities_by_id[count.foreign_id].first
@@ -138,7 +138,7 @@ module FortyFacets
138
138
  .select("#{my_column} as foreign_id, count(#{my_column}) as occurrences")
139
139
  .group(my_column)
140
140
  counts.includes_values = []
141
- entities_by_id = definition.association.klass.find(counts.map(&:foreign_id)).group_by(&:id)
141
+ entities_by_id = definition.association.klass.unscoped.find(counts.map(&:foreign_id)).group_by(&:id)
142
142
 
143
143
  facet = counts.map do |count|
144
144
  facet_entity = entities_by_id[count.foreign_id].first
@@ -1,3 +1,3 @@
1
1
  module FortyFacets
2
- VERSION = "0.1.9.0"
2
+ VERSION = "0.1.9.1"
3
3
  end
@@ -14,6 +14,7 @@ ActiveRecord::Schema.define do
14
14
  t.string :status
15
15
  t.string :name
16
16
  t.string :description
17
+ t.datetime :deleted_at
17
18
  end
18
19
 
19
20
  create_table :producers do |t|
@@ -79,10 +80,13 @@ end
79
80
  class Studio < ActiveRecord::Base
80
81
  belongs_to :country
81
82
  has_and_belongs_to_many :producers
83
+
84
+ default_scope ->{ where(deleted_at: nil) }
85
+ scope :with_deleted, ->{ unscope(where: :deleted_at) }
82
86
  end
83
87
 
84
88
  class Movie < ActiveRecord::Base
85
- belongs_to :studio
89
+ belongs_to :studio, ->{ with_deleted }
86
90
  has_and_belongs_to_many :genres
87
91
  has_and_belongs_to_many :actors
88
92
  has_and_belongs_to_many :writers
@@ -2,8 +2,9 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
4
  require "minitest/autorun"
5
+ require 'test_helper'
5
6
  require 'logger'
6
- #require 'byebug'# travis doenst like byebug
7
+ # require 'byebug'# travis doenst like byebug
7
8
  require_relative '../lib/forty_facets'
8
9
 
9
10
  #silence_warnings do
@@ -192,6 +193,20 @@ class SmokeTest < Minitest::Test
192
193
  assert_equal movies_with_studio.size, first_facet_value.count
193
194
  end
194
195
 
196
+ def test_belongs_to_filter_with_default_scope
197
+ wrap_in_db_transaction do
198
+ deleted_studio = Studio.create!(name: 'Deleted studio', status: 'active')
199
+ movie = Movie.create!(studio: deleted_studio)
200
+ deleted_studio.update!(deleted_at: Time.now)
201
+
202
+ blank_search = MovieSearch.new
203
+
204
+ assert_equal(
205
+ 5, blank_search.filter(:studio).facet.length
206
+ )
207
+ end
208
+ end
209
+
195
210
  def test_sort_by_proc
196
211
  blank_search = MovieSearch.new
197
212
  facet_entities = blank_search.filter(:year).facet.map(&:entity)
@@ -0,0 +1,8 @@
1
+ class Minitest::Test
2
+ def wrap_in_db_transaction(&block)
3
+ ActiveRecord::Base.transaction do
4
+ yield
5
+ raise ActiveRecord::Rollback
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forty_facets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9.0
4
+ version: 0.1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Axel Tetzlaff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-11 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.7.6
164
+ rubygems_version: 3.0.6
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: Library for building facet searches for active_record models