search_object 1.2.2 → 1.2.3

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: 5f55c0e518e6eb83f63ca7670605b85c7caf3a3736b070759edd7e76688b85ec
4
- data.tar.gz: 8435ace3621b80b7b146f9cb78f7586036fb6e849ce660844bbd0f49e4a8d3ec
3
+ metadata.gz: 185c2ec2237293e6a214c921457a18ef221402c395a74c66a774d2f8e2b4e12b
4
+ data.tar.gz: 81dcfc6e5bfc8a3499cf24f37be6d2dd2fac23bdd6da39162a24ef66c20063bb
5
5
  SHA512:
6
- metadata.gz: 55a03c93e854a7de0aa2412a071a031219105131a036ca96c20f351ff5989566e278ee76b18d776adbed3d553f633ffd03158318667efef235a75748bfebb79c
7
- data.tar.gz: 568572db3450627999c39fc0e5304f52dc06bb49cad958fe8f19e8506e17bfd6684b599a64027d91dcdc426f632454ccff89b4123510b624231b5434823fa04e
6
+ metadata.gz: 2f66341b1d6e542396ac8930b3b29eba4124081e4e9e08d208208667856c80253ca6c33136afca304a47e2a2bbff03b4202170acd71e1da012058b0aaa05b144
7
+ data.tar.gz: 1af8e023f69d4f30217a259018c6a866fb65ec26bf904ccbd28331cf62aa2bfce54cf937d8f9af24c30e2aa7a817eac0e7d51a9fcae6eb4f24fc737794eeea20
data/.rubocop.yml CHANGED
@@ -7,15 +7,15 @@ AllCops:
7
7
  - search_object.gemspec
8
8
 
9
9
  # Disables "Line is too long"
10
- LineLength:
10
+ Metrics/LineLength:
11
11
  Enabled: false
12
12
 
13
13
  # Disables Module has too many lines
14
- ModuleLength:
14
+ Metrics/ModuleLength:
15
15
  Enabled: false
16
16
 
17
17
  # Disables "Missing top-level class documentation comment"
18
- Documentation:
18
+ Style/Documentation:
19
19
  Enabled: false
20
20
 
21
21
  # Disables "Use each_with_object instead of inject"
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
3
  - 2.3
4
+ - 2.4
5
+ - 2.6
5
6
  script:
6
7
  - bundle exec rubocop
7
8
  - bundle exec rspec spec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.2.3
4
+
5
+ * __[fix]__ convert enum values to strings (@Postmodum37)
3
6
 
4
7
  ## Version 1.2.2
5
8
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in search_object.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
data/example/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'rails', '5.0.1'
data/example/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
5
 
4
- require File.expand_path('../config/application', __FILE__)
6
+ require File.expand_path('config/application', __dir__)
5
7
 
6
8
  Example::Application.load_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  protect_from_forgery with: :exception
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PostsController < ApplicationController
2
4
  def index
3
5
  @search = PostSearch.new filters: params[:f], page: params[:page], per_page: params[:per_page]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Post < ActiveRecord::Base
2
4
  belongs_to :user
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PostSearch
2
4
  include SearchObject.module(:model, :sorting, :will_paginate, :enum)
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
4
  has_many :posts
3
5
 
data/example/bin/bundle CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
5
  load Gem.bin_path('bundler', 'bundle')
data/example/bin/rails CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
5
  require_relative '../config/boot'
4
6
  require 'rails/commands'
data/example/bin/rake CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require_relative '../config/boot'
3
5
  require 'rake'
4
6
  Rake.application.run
data/example/config.ru CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
5
  require ::File.expand_path('../config/environment', __FILE__)
@@ -1,4 +1,4 @@
1
- # rubocop:disable Lint/UselessAssignment:%s
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -11,11 +11,11 @@ describe PostSearch do
11
11
 
12
12
  def create(attributes = {})
13
13
  Post.create! attributes.reverse_merge(
14
- user: user,
15
- title: 'Title',
16
- body: 'Body',
17
- category_name: 'Tech',
18
- published: true
14
+ user: user,
15
+ title: 'Title',
16
+ body: 'Body',
17
+ category_name: 'Tech',
18
+ published: true
19
19
  )
20
20
  end
21
21
 
@@ -24,29 +24,29 @@ describe PostSearch do
24
24
  end
25
25
 
26
26
  it 'can search by category name' do
27
- post = create category_name: 'Personal'
28
- other = create category_name: 'Other'
27
+ post = create category_name: 'Personal'
28
+ _other = create category_name: 'Other'
29
29
 
30
30
  expect_search(category_name: 'Personal').to eq [post]
31
31
  end
32
32
 
33
33
  it 'can search by user_id' do
34
- post = create user: create_user
35
- other = create user: create_user
34
+ post = create user: create_user
35
+ _other = create user: create_user
36
36
 
37
37
  expect_search(user_id: post.user_id).to eq [post]
38
38
  end
39
39
 
40
40
  it 'can search by title' do
41
- post = create title: 'Title'
42
- other = create title: 'Other'
41
+ post = create title: 'Title'
42
+ _other = create title: 'Other'
43
43
 
44
44
  expect_search(title: 'itl').to eq [post]
45
45
  end
46
46
 
47
47
  it 'can search by published' do
48
- post = create published: true
49
- other = create published: false
48
+ post = create published: true
49
+ _other = create published: false
50
50
 
51
51
  expect_search(published: true).to eq [post]
52
52
  end
@@ -54,21 +54,21 @@ describe PostSearch do
54
54
  it 'can search by term' do
55
55
  post_with_body = create body: 'pattern'
56
56
  post_with_title = create title: 'pattern'
57
- other = create
57
+ _other = create
58
58
 
59
59
  expect_search(term: 'pattern').to eq [post_with_title, post_with_body]
60
60
  end
61
61
 
62
62
  it 'can search by created after' do
63
- post = create created_at: 1.month.ago
64
- other = create created_at: 3.month.ago
63
+ post = create created_at: 1.month.ago
64
+ _other = create created_at: 3.month.ago
65
65
 
66
66
  expect_search(created_after: 2.month.ago.strftime('%Y-%m-%d')).to eq [post]
67
67
  end
68
68
 
69
69
  it 'can search by created before' do
70
- post = create created_at: 3.month.ago
71
- other = create created_at: 1.month.ago
70
+ post = create created_at: 3.month.ago
71
+ _other = create created_at: 1.month.ago
72
72
 
73
73
  expect_search(created_before: 2.month.ago.strftime('%Y-%m-%d')).to eq [post]
74
74
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
4
  ENV['RAILS_ENV'] ||= 'test'
3
5
 
4
- require File.expand_path('../../config/environment', __FILE__)
6
+ require File.expand_path('../config/environment', __dir__)
5
7
  require 'rspec/rails'
6
8
 
7
9
  # Requires supporting ruby files with custom matchers and macros, etc,
@@ -7,7 +7,7 @@ module SearchObject
7
7
  base.instance_eval do
8
8
  @config = {
9
9
  defaults: {},
10
- options: {}
10
+ options: {}
11
11
  }
12
12
  end
13
13
  end
@@ -32,9 +32,7 @@ module SearchObject
32
32
  def apply_filter(object:, option:, enums:, scope:, value:)
33
33
  return if value.nil? || value == ''
34
34
 
35
- unless enums.include? value
36
- return handle_invalid_value(object: object, option: option, enums: enums, scope: scope, value: value)
37
- end
35
+ return handle_invalid_value(object: object, option: option, enums: enums, scope: scope, value: value) unless enums.include? value.to_s
38
36
 
39
37
  object.send("apply_#{Helper.underscore(option)}_with_#{Helper.underscore(value)}", scope)
40
38
  end
@@ -43,8 +41,7 @@ module SearchObject
43
41
  specific = "handle_invalid_#{option}"
44
42
  return object.send(specific, scope, value) if object.respond_to? specific, true
45
43
 
46
- catch_all = 'handle_invalid_enum'
47
- return object.send(catch_all, option, scope, value) if object.respond_to? catch_all, true
44
+ return object.handle_invalid_enum(option, scope, value) if object.respond_to? :handle_invalid_enum, true
48
45
 
49
46
  raise InvalidEnumValueError.new(option, enums, value)
50
47
  end
@@ -28,17 +28,20 @@ module SearchObject
28
28
 
29
29
  module ClassMethods
30
30
  def per_page(number)
31
- raise InvalidNumberError.new('Per page', number) unless number > 0
31
+ raise InvalidNumberError.new('Per page', number) unless number.positive?
32
+
32
33
  config[:per_page] = number
33
34
  end
34
35
 
35
36
  def min_per_page(number)
36
- raise InvalidNumberError.new('Min per page', number) unless number > 0
37
+ raise InvalidNumberError.new('Min per page', number) unless number.positive?
38
+
37
39
  config[:min_per_page] = number
38
40
  end
39
41
 
40
42
  def max_per_page(number)
41
- raise InvalidNumberError.new('Max per page', number) unless number > 0
43
+ raise InvalidNumberError.new('Max per page', number) unless number.positive?
44
+
42
45
  config[:max_per_page] = number
43
46
  end
44
47
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SearchObject
4
- VERSION = '1.2.2'.freeze
4
+ VERSION = '1.2.3'
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.13"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency 'rspec', '~> 3.5'
24
24
  spec.add_development_dependency 'rspec-mocks', '~> 3.5'
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'will_paginate'
30
30
  spec.add_development_dependency 'kaminari'
31
31
  spec.add_development_dependency 'kaminari-activerecord'
32
- spec.add_development_dependency 'rubocop', '0.51.0'
33
- spec.add_development_dependency 'rubocop-rspec', '1.20.1'
32
+ spec.add_development_dependency 'rubocop', '0.75.1'
33
+ spec.add_development_dependency 'rubocop-rspec', '1.36.0'
34
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'active_support/core_ext/object/blank'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'action_controller'
3
5
 
@@ -1,52 +1,61 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'ostruct'
3
5
 
4
6
  module SearchObject
5
7
  module Plugin
6
8
  describe Enum do
7
- class TestSearch
8
- include SearchObject.module(:enum)
9
+ let(:test_search) do
10
+ Class.new do
11
+ include SearchObject.module(:enum)
9
12
 
10
- scope { [1, 2, 3, 4, 5] }
13
+ scope { [1, 2, 3, 4, 5] }
11
14
 
12
- option :filter, enum: %w[odd even]
13
- option :camelCase, enum: %w[someValue]
15
+ option :filter, enum: %w[odd even]
16
+ option :camelCase, enum: %w[someValue]
14
17
 
15
- private
18
+ private
16
19
 
17
- def apply_filter_with_odd(scope)
18
- scope.select(&:odd?)
19
- end
20
+ def apply_filter_with_odd(scope)
21
+ scope.select(&:odd?)
22
+ end
20
23
 
21
- def apply_filter_with_even(scope)
22
- scope.select(&:even?)
23
- end
24
+ def apply_filter_with_even(scope)
25
+ scope.select(&:even?)
26
+ end
24
27
 
25
- def apply_camel_case_with_some_value(_scope)
26
- [1]
27
- end
28
+ def apply_camel_case_with_some_value(_scope)
29
+ [1]
30
+ end
28
31
 
29
- def handle_invalid_filter(_scope, value)
30
- "invalid filter - #{value}"
32
+ def handle_invalid_filter(_scope, value)
33
+ "invalid filter - #{value}"
34
+ end
31
35
  end
32
36
  end
33
37
 
34
38
  it 'can filter by enum values' do
35
- expect(TestSearch.results(filters: { filter: 'odd' })).to eq [1, 3, 5]
36
- expect(TestSearch.results(filters: { filter: 'even' })).to eq [2, 4]
39
+ expect(test_search.results(filters: { filter: 'odd' })).to eq [1, 3, 5]
40
+ expect(test_search.results(filters: { filter: 'even' })).to eq [2, 4]
41
+ end
42
+
43
+ it 'converts input to string' do
44
+ expect(test_search.results(filters: { filter: :odd })).to eq [1, 3, 5]
45
+ expect(test_search.results(filters: { filter: :even })).to eq [2, 4]
37
46
  end
38
47
 
39
48
  it 'ignores blank values' do
40
- expect(TestSearch.results(filters: { filter: nil })).to eq [1, 2, 3, 4, 5]
41
- expect(TestSearch.results(filters: { filter: '' })).to eq [1, 2, 3, 4, 5]
49
+ expect(test_search.results(filters: { filter: nil })).to eq [1, 2, 3, 4, 5]
50
+ expect(test_search.results(filters: { filter: '' })).to eq [1, 2, 3, 4, 5]
42
51
  end
43
52
 
44
53
  it 'handles wrong enum values' do
45
- expect(TestSearch.results(filters: { filter: 'foo' })).to eq 'invalid filter - foo'
54
+ expect(test_search.results(filters: { filter: 'foo' })).to eq 'invalid filter - foo'
46
55
  end
47
56
 
48
57
  it 'underscores method and enum values' do
49
- expect(TestSearch.results(filters: { camelCase: 'someValue' })).to eq [1]
58
+ expect(test_search.results(filters: { camelCase: 'someValue' })).to eq [1]
50
59
  end
51
60
 
52
61
  it 'raises when block is passed with enum option' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper_active_record'
2
4
  require 'kaminari'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  require 'active_support/core_ext/object/blank'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper_active_record'
2
4
 
3
5
  module SearchObject
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper_active_record'
2
4
 
3
5
  module SearchObject
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper_active_record'
2
4
 
3
5
  require 'will_paginate'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'ostruct'
3
5
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
 
3
5
  if ENV['TRAVIS']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'spec_helper'
2
4
  require_relative 'support/paging_shared_example'
3
5
  require 'active_record'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'a paging plugin' do
2
4
  after do
3
5
  Product.delete_all
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radoslav Stankov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-18 00:00:00.000000000 Z
11
+ date: 2019-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -170,28 +170,28 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 0.51.0
173
+ version: 0.75.1
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 0.51.0
180
+ version: 0.75.1
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubocop-rspec
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 1.20.1
187
+ version: 1.36.0
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 1.20.1
194
+ version: 1.36.0
195
195
  description: Search object DSL
196
196
  email:
197
197
  - rstankov@gmail.com