mincer 0.2.9 → 0.2.11

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
  SHA1:
3
- metadata.gz: cd01b7eba5a56472f7840a781735379e72aa6a9d
4
- data.tar.gz: 5d7b4304379f67a8e26aea2b6e8de23cbe8935f4
3
+ metadata.gz: 75beab8a1ff5a1cb3050b90da354ff7f35015a2c
4
+ data.tar.gz: f21249f540044374eab84600f51d4a3aeb93fd55
5
5
  SHA512:
6
- metadata.gz: 510c437475a7b9519bab079059b4c3a2e62c6bccf0bd6dedb2971b09686afb8f3d38ce9a938c656844ab7c1ecd11b9e8d10d641d778053ee1ceaf7e72bb982f3
7
- data.tar.gz: 1196d1f63d793e851b6ae42e4fbcf16379b25b8613879def5f4e5622f675d4f004aec30bd5ef042125adf37772ff44f36473a3d8dd798b4bb7b027bd2102624f
6
+ metadata.gz: fb1fa9dd8f0feb642d7d670c6269de05429357be671ad5fef8f7af9af56d54912372f1caa917538166119ded1a030319553d49f3611985480d8e54198d80e13f
7
+ data.tar.gz: d4693f19a4c5718d2c3f71dfa8f8f686a7cafa463f049fc0a6355a4ecdeef0eeb37bf484e330bfd50b38c0ca53271c2646bb1a82ade179cf634f542ea31878c7
@@ -30,7 +30,7 @@ module Mincer
30
30
  end
31
31
 
32
32
  def per_page
33
- @args[::Mincer.config.pagination.per_page_param_name]
33
+ @mincer.class.default_per_page || @args[::Mincer.config.pagination.per_page_param_name]
34
34
  end
35
35
  end
36
36
 
@@ -41,6 +41,14 @@ module Mincer
41
41
  def skip_pagination!
42
42
  active_processors.delete(Mincer::Processors::Pagination::Processor)
43
43
  end
44
+
45
+ def paginate_defaults(options = {})
46
+ @default_per_page = options[:per_page] if options[:per_page]
47
+ end
48
+
49
+ def default_per_page
50
+ @default_per_page
51
+ end
44
52
  end
45
53
  end
46
54
 
@@ -13,7 +13,8 @@ module Mincer
13
13
 
14
14
  def to_json
15
15
  if dump_supported?
16
- Mincer.connection.execute(json_query).first['json']
16
+ result = Mincer.connection.execute(json_query).first['json']
17
+ @options[:singularize] ? (result[1..-2].presence || '{}') : result
17
18
  else
18
19
  warn 'To dump data to json with postgres you need to use postgres server version >= 9.2'
19
20
  end
@@ -19,7 +19,14 @@ module Mincer
19
19
 
20
20
  def apply_pg_search(relation, args)
21
21
  rel = relation.where(conditions(args))
22
- (rank = rank(args)) ? rel.reorder(rank) : rel
22
+ rank = rank(args)
23
+ if rank.blank?
24
+ rel
25
+ elsif @mincer.default_sorting
26
+ rel.reorder(rank)
27
+ else
28
+ rel.order(rank)
29
+ end
23
30
  end
24
31
 
25
32
  def conditions(args)
@@ -19,9 +19,11 @@ module Mincer
19
19
  private
20
20
 
21
21
  def document_for(search_statement)
22
+ sanitizers = search_statement.sanitizers(:document)
22
23
  arel_group do
23
24
  documents = search_statement.columns.map do |search_column|
24
- Arel.sql(search_column + '::text[]')
25
+ sanitized_term = sanitizers.any? ? sanitize_column("#{search_column}::text", sanitizers).to_sql : search_column
26
+ Arel.sql(sanitized_term + '::text[]')
25
27
  end
26
28
  join_expressions(documents, '||')
27
29
  end
@@ -9,7 +9,9 @@ module Mincer
9
9
  def apply
10
10
  sorting_sting = sort_string
11
11
  if sorting_sting.present?
12
- @mincer.sort_attribute, @mincer.sort_order = sort_attr.to_s, order_attr.to_s
12
+ @mincer.sort_attribute = (sort_attr || default_sort).to_s
13
+ @mincer.sort_order = (order_attr || default_order).to_s
14
+ @mincer.default_sorting = sort_attr.blank? && order_attr.blank?
13
15
  @relation.order(sorting_sting)
14
16
  else
15
17
  @relation
@@ -21,11 +23,11 @@ module Mincer
21
23
  end
22
24
 
23
25
  def sort_attr
24
- (@mincer.send(:allowed_sort_attributes).include?(sort) && sort) || default_sort
26
+ (@mincer.send(:allowed_sort_attributes).include?(sort) && sort)
25
27
  end
26
28
 
27
29
  def order_attr
28
- (%w{asc desc}.include?(order.try(:downcase)) && order) || default_order
30
+ (%w{asc desc}.include?(order.try(:downcase)) && order)
29
31
  end
30
32
 
31
33
  def sort
@@ -52,7 +54,7 @@ module Mincer
52
54
 
53
55
  included do
54
56
  # Used in view helpers
55
- attr_accessor :sort_attribute, :sort_order
57
+ attr_accessor :sort_attribute, :sort_order, :default_sorting
56
58
  end
57
59
 
58
60
  module ClassMethods
@@ -1,7 +1,7 @@
1
1
  module Mincer
2
2
 
3
3
  def self.version
4
- Gem::Version.new '0.2.9'
4
+ Gem::Version.new '0.2.11'
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
@@ -49,7 +49,7 @@ describe ::Mincer::PgSearch::SearchEngines::Array do
49
49
  it 'generates search condition with two columns, two terms and option "ignore_accent" set to true ' do
50
50
  search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:array], ignore_accent: true)
51
51
  search_engine = search_engine_class.new({ pattern: 'search word' }, [search_statement1])
52
- search_engine.conditions.to_sql.should == %{(("records"."text"::text[] || "records"."text2"::text[]) @> ARRAY[unaccent('search'),unaccent('word')])}
52
+ search_engine.conditions.to_sql.should == %{((unaccent("records"."text"::text)::text[] || unaccent("records"."text2"::text)::text[]) @> ARRAY[unaccent('search'),unaccent('word')])}
53
53
  end
54
54
 
55
55
  #TODO: sanitizer can not be set on array columns since we ned to unpack an reconstruct those arrays. Find a solution
@@ -62,7 +62,7 @@ describe ::Mincer::PgSearch::SearchEngines::Array do
62
62
  it 'generates search condition with two columns, two terms and option "ignore_accent" and "ignore_case" set to true ' do
63
63
  search_statement1 = search_statement_class.new(['"records"."text"', '"records"."text2"'], engines: [:array], ignore_accent: true, ignore_case: true)
64
64
  search_engine = search_engine_class.new({ pattern: 'search word' }, [search_statement1])
65
- search_engine.conditions.to_sql.should == %{(("records"."text"::text[] || "records"."text2"::text[]) @> ARRAY[unaccent(lower('search')),unaccent(lower('word'))])}
65
+ search_engine.conditions.to_sql.should == %{((unaccent(lower("records"."text"::text))::text[] || unaccent(lower("records"."text2"::text))::text[]) @> ARRAY[unaccent(lower('search')),unaccent(lower('word'))])}
66
66
  end
67
67
 
68
68
  it 'generates search condition with one column, one term, two statements and no options' do
@@ -58,6 +58,30 @@ describe ::Mincer::Processors::Sorting::Processor do
58
58
  end
59
59
  end
60
60
 
61
+ context 'when sort and order is not given in params' do
62
+ it 'sets @mincer.default_sorting to true' do
63
+ subject = Class.new(Mincer::Base)
64
+ query = subject.new(ActiveRecordModel, { })
65
+ expect(query.default_sorting).to eq(true)
66
+ end
67
+ end
68
+
69
+ context 'when sort is given in params' do
70
+ it 'sets @mincer.default_sorting to false' do
71
+ subject = Class.new(Mincer::Base)
72
+ query = subject.new(ActiveRecordModel, { 'sort' => 'text' })
73
+ expect(query.default_sorting).to eq(false)
74
+ end
75
+ end
76
+
77
+ context 'when order is given in params' do
78
+ it 'sets @mincer.default_sorting to false' do
79
+ subject = Class.new(Mincer::Base)
80
+ query = subject.new(ActiveRecordModel, { 'order' => 'asc' })
81
+ expect(query.default_sorting).to eq(false)
82
+ end
83
+ end
84
+
61
85
  describe 'sorting with basic model with defaults changed' do
62
86
  it 'sorts by default attributes(id) abd order(ASC) when nothing passed to args' do
63
87
  subject = Class.new(Mincer::Base) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mincer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Krasinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.4.5.1
199
+ rubygems_version: 2.5.1
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: ActiveRecord::Relation wrapper for pagination, order, json, search, cache_digest