Skip to content

Commit

Permalink
fix error that occurs when specifying multiple condition in bgeigie_i…
Browse files Browse the repository at this point in the history
…mpors#index (#987)

`ActiveRecord::Relation` has method called `filter` that is from `Enumerable#filter` of ruby standard library
  • Loading branch information
eitoball authored Dec 7, 2022
1 parent e524cfd commit d5e75ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/bgeigie_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BgeigieImportsController < ApplicationController # rubocop:disable Metrics
before_action :require_moderator, only: %i(approve fixdrive send_email resolve)

has_scope :q do |_controller, scope, value|
scope.filter(value)
scope.filter_by_text_fields(value)
end

has_scope :by_status
Expand Down
2 changes: 1 addition & 1 deletion app/models/bgeigie_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BgeigieImport < MeasurementImport # rubocop:disable Metrics/ClassLength
measurements_added
)

def self.filter(query)
def self.filter_by_text_fields(query)
where("lower(name) LIKE :query
OR lower(source) LIKE :query
OR lower(description) LIKE :query
Expand Down
11 changes: 11 additions & 0 deletions spec/models/bgeigie_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
RSpec.describe BgeigieImport do
let(:user) { Fabricate(:user) }

describe '.filter_by_text_fields' do
context 'with ActiveRecord::Relation' do
let(:relation) { described_class.order(:created_at) }

it 'should not raise error' do
expect { relation.filter_by_text_fields('_text_') }
.not_to raise_error
end
end
end

describe '#initialize' do
it 'should set subtype to "None" by default' do
expect(described_class.new.subtype).to eq('None')
Expand Down

0 comments on commit d5e75ce

Please sign in to comment.