ransack 2.0.0 → 2.0.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: 35bd0ff11964ff0c0308e7b663a3284510e7f5da71f6799bf061992b6515b616
4
- data.tar.gz: 415ef127b34f85c7fdcf48e1f66f764d060cefacfa3a9a3d013688ecc38a07da
3
+ metadata.gz: 1e44db6020449735b694bd18943195f6e7cdd3597a8dc776d22a54114b4b9273
4
+ data.tar.gz: cdcb6ef8b863873fcaa7c2067cb20636c4e856e27f431488978201a310023f45
5
5
  SHA512:
6
- metadata.gz: 56239015bf48bc38842fa9f09325a04dc047299c0f17da8429a9a1ea95cf3aedf9d07117da157cc036a8fb8280d2925cf318b62a7b66b8a99acaa8d8a48e4b30
7
- data.tar.gz: 574ac22523e67dddce34c18a929a9624cde30de3c14e2c53d6476c8136f48541879c1fd4b89467786e3f128327f79f4b6617561de7d11d5fbf6f6e888d37a212
6
+ metadata.gz: ded22ffb680b2a358ee72ab348b8f9debc7f2c927c878ec5a4ad872b552b715e561e9b0aac188d874c67cce70f6463d62b3be7655e46900a706214d58d69fa88
7
+ data.tar.gz: 6f45114a54ef6f83cbd99780ba432069cf4111c4b9d2294141f238526655edc1cb035422705565389e4c60f75666716d8fd201887f7ca9fd90c92314bbb3b9e6
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## Version 2.0.1 - 2018-08-18
6
+
7
+ * Don't return association if table is nil
8
+ PR [952](https://github.com/activerecord-hackery/ransack/pull/952)
9
+
10
+ *Christian Gregg*
11
+
5
12
  ## Version 2.0.0 - 2018-08-09
6
13
 
7
14
  * Add support for Active Record 5.2.1
data/README.md CHANGED
@@ -27,11 +27,12 @@ instead.
27
27
  If you're viewing this at
28
28
  [github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
29
29
  you're reading the documentation for the master branch with the latest features.
30
- [View documentation for the last release (1.8.8).](https://github.com/activerecord-hackery/ransack/tree/v1.8.8)
30
+ [View documentation for the last release (2.0.0).](https://github.com/activerecord-hackery/ransack/tree/v2.0.0)
31
31
 
32
32
  ## Getting started
33
33
 
34
- Ransack is compatible with Rails 4.2 and 5.0, 5.1 and 5.2 on Ruby 2.2 and later.
34
+ Ransack is compatible with Rails 5.0, 5.1 and 5.2 on Ruby 2.2 and later.
35
+ If you are using Rails <5.0 use the 1.8 line of Ransack.
35
36
  If you are using Ruby 1.8 or an earlier JRuby and run into compatibility
36
37
  issues, you can use an earlier version of Ransack, say, up to 1.3.0.
37
38
 
@@ -20,13 +20,6 @@ module Polyamorous
20
20
  end
21
21
  end
22
22
 
23
- # Reference: https://github.com/rails/rails/commit/9b15db5
24
- # NOTE: Not sure we still need it?
25
- #
26
- def ==(other)
27
- base_klass == other.base_klass
28
- end
29
-
30
23
  def build_constraint(klass, table, key, foreign_table, foreign_key)
31
24
  if reflection.polymorphic?
32
25
  super(klass, table, key, foreign_table, foreign_key)
@@ -30,24 +30,6 @@ module Polyamorous
30
30
  end
31
31
  end
32
32
 
33
- def find_join_association_respecting_polymorphism(reflection, parent, klass)
34
- if association = parent.children.find { |j| j.reflection == reflection }
35
- unless reflection.polymorphic?
36
- association
37
- else
38
- association if association.base_klass == klass
39
- end
40
- end
41
- end
42
-
43
- def build_join_association_respecting_polymorphism(reflection, parent, klass)
44
- if reflection.polymorphic? && klass
45
- JoinAssociation.new(reflection, self, klass)
46
- else
47
- JoinAssociation.new(reflection, self)
48
- end
49
- end
50
-
51
33
  # Replaces ActiveRecord::Associations::JoinDependency#join_constraints
52
34
  #
53
35
  # This internal method was changed in Rails 5.0 by commit
@@ -20,13 +20,6 @@ module Polyamorous
20
20
  end
21
21
  end
22
22
 
23
- # Reference: https://github.com/rails/rails/commit/9b15db5
24
- # NOTE: Not sure we still need it?
25
- #
26
- def ==(other)
27
- base_klass == other.base_klass
28
- end
29
-
30
23
  def build_constraint(klass, table, key, foreign_table, foreign_key)
31
24
  if reflection.polymorphic?
32
25
  super(klass, table, key, foreign_table, foreign_key)
@@ -30,24 +30,6 @@ module Polyamorous
30
30
  end
31
31
  end
32
32
 
33
- def find_join_association_respecting_polymorphism(reflection, parent, klass)
34
- if association = parent.children.find { |j| j.reflection == reflection }
35
- unless reflection.polymorphic?
36
- association
37
- else
38
- association if association.base_klass == klass
39
- end
40
- end
41
- end
42
-
43
- def build_join_association_respecting_polymorphism(reflection, parent, klass)
44
- if reflection.polymorphic? && klass
45
- JoinAssociation.new(reflection, self, alias_tracker, klass)
46
- else
47
- JoinAssociation.new(reflection, self, alias_tracker)
48
- end
49
- end
50
-
51
33
  # Replaces ActiveRecord::Associations::JoinDependency#join_constraints
52
34
  #
53
35
  # This internal method was changed in Rails 5.0 by commit
@@ -19,13 +19,6 @@ module Polyamorous
19
19
  end
20
20
  end
21
21
 
22
- # Reference: https://github.com/rails/rails/commit/9b15db5
23
- # NOTE: Not sure we still need it?
24
- #
25
- def ==(other)
26
- base_klass == other.base_klass
27
- end
28
-
29
22
  def build_constraint(klass, table, key, foreign_table, foreign_key)
30
23
  if reflection.polymorphic?
31
24
  super(klass, table, key, foreign_table, foreign_key)
@@ -30,24 +30,6 @@ module Polyamorous
30
30
  end
31
31
  end
32
32
 
33
- def find_join_association_respecting_polymorphism(reflection, parent, klass)
34
- if association = parent.children.find { |j| j.reflection == reflection }
35
- unless reflection.polymorphic?
36
- association
37
- else
38
- association if association.base_klass == klass
39
- end
40
- end
41
- end
42
-
43
- def build_join_association_respecting_polymorphism(reflection, parent, klass)
44
- if reflection.polymorphic? && klass
45
- JoinAssociation.new(reflection, self, klass)
46
- else
47
- JoinAssociation.new(reflection, self)
48
- end
49
- end
50
-
51
33
  module ClassMethods
52
34
  # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
53
35
  #
@@ -268,7 +268,7 @@ module Ransack
268
268
 
269
269
  def find_association(name, parent = @base, klass = nil)
270
270
  @join_dependency.instance_variable_get(:@join_root).children.detect do |assoc|
271
- assoc.reflection.name == name &&
271
+ assoc.reflection.name == name && assoc.table &&
272
272
  (@associations_pot.empty? || @associations_pot[assoc] == parent || !@associations_pot.key?(assoc)) &&
273
273
  (!klass || assoc.reflection.klass == klass)
274
274
  end
@@ -0,0 +1,70 @@
1
+ ru:
2
+ ransack:
3
+ search: "Поиск"
4
+ predicate: "predicate"
5
+ and: "и"
6
+ or: "или"
7
+ any: "любое"
8
+ all: "все"
9
+ combinator: "combinator"
10
+ attribute: "аттрибут"
11
+ value: "значение"
12
+ condition: "условие"
13
+ sort: "сортировка"
14
+ asc: "по возрастанию"
15
+ desc: "по убыванию"
16
+ predicates:
17
+ eq: "равный"
18
+ eq_any: "равный любому"
19
+ eq_all: "равный всем"
20
+ not_eq: "не равный любому"
21
+ not_eq_any: "не равный любому"
22
+ not_eq_all: "не равный всем"
23
+ matches: "совпадение"
24
+ matches_any: "совпадение любому"
25
+ matches_all: "совпадение всем"
26
+ does_not_match: "не совпадение"
27
+ does_not_match_any: "не совпадение любому"
28
+ does_not_match_all: "не совпадение всем"
29
+ lt: "меньше чем"
30
+ lt_any: "меньше чем любое"
31
+ lt_all: "меньше чем все"
32
+ lteq: "меньше чем или равен"
33
+ lteq_any: "меньше чем или равен любому"
34
+ lteq_all: "меньше чем или равен всем"
35
+ gt: "больше чем"
36
+ gt_any: "больше чем любое"
37
+ gt_all: "больше чем все"
38
+ gteq: "больше чем или равен"
39
+ gteq_any: "больше чем или равен любому"
40
+ gteq_all: "больше чем или равен всем"
41
+ in: "в"
42
+ in_any: "в любом из"
43
+ in_all: "во всех"
44
+ not_in: "нет в"
45
+ not_in_any: "не в каком из"
46
+ not_in_all: "нет во всех"
47
+ cont: "содержит"
48
+ cont_any: "содержит любое"
49
+ cont_all: "содержит все"
50
+ not_cont: "не содержит"
51
+ not_cont_any: "не содержит любое"
52
+ not_cont_all: "не содержит все"
53
+ start: "начинается с"
54
+ start_any: "начинается с любого"
55
+ start_all: "начинается с всего"
56
+ not_start: "не начинается с"
57
+ not_start_any: "не начинается с любого"
58
+ not_start_all: "не начинается со всего"
59
+ end: "кончается с"
60
+ end_any: "кончается с любого"
61
+ end_all: "кончается со всего"
62
+ not_end: "не кончается с"
63
+ not_end_any: "не кончается с любого"
64
+ not_end_all: "не кончается со всего"
65
+ 'true': "верно"
66
+ 'false': "не верно"
67
+ present: "настоящее"
68
+ blank: "пусто"
69
+ 'null': "нулевой"
70
+ not_null: "не нулевой"
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -3,34 +3,13 @@ require 'spec_helper'
3
3
  module Polyamorous
4
4
  describe JoinAssociation do
5
5
 
6
- join_base, join_association_args, polymorphic = [:join_root, 'parent.children', 'reflection.options[:polymorphic]']
7
-
8
6
  let(:join_dependency) { new_join_dependency Note, {} }
9
7
  let(:reflection) { Note.reflect_on_association(:notable) }
10
- let(:parent) { join_dependency.send(join_base) }
8
+ let(:parent) { join_dependency.send(:join_root) }
11
9
  let(:join_association) {
12
- eval("new_join_association(reflection, #{join_association_args}, Article)")
13
- }
14
-
15
- subject {
16
- join_dependency.build_join_association_respecting_polymorphism(
17
- reflection, parent, Person
18
- )
10
+ new_join_association(reflection, parent.children, Article)
19
11
  }
20
12
 
21
- it 'respects polymorphism on equality test' do
22
- expect(subject).to eq(
23
- join_dependency.build_join_association_respecting_polymorphism(
24
- reflection, parent, Person
25
- )
26
- )
27
- expect(subject).not_to eq(
28
- join_dependency.build_join_association_respecting_polymorphism(
29
- reflection, parent, Article
30
- )
31
- )
32
- end
33
-
34
13
  it 'leaves the orginal reflection intact for thread safety' do
35
14
  reflection.instance_variable_set(:@klass, Article)
36
15
  join_association
@@ -43,7 +22,7 @@ module Polyamorous
43
22
  end
44
23
 
45
24
  it 'sets the polymorphic option to true after initializing' do
46
- expect(join_association.instance_eval(polymorphic)).to be true
25
+ expect(join_association.reflection.options[:polymorphic]).to be true
47
26
  end
48
27
  end
49
28
  end
@@ -3,32 +3,30 @@ require 'spec_helper'
3
3
  module Polyamorous
4
4
  describe JoinDependency do
5
5
 
6
- method, join_associations, join_base = :instance_eval, 'join_root.drop(1)', :join_root
7
-
8
6
  context 'with symbol joins' do
9
7
  subject { new_join_dependency Person, articles: :comments }
10
8
 
11
- specify { expect(subject.send(method, join_associations).size)
9
+ specify { expect(subject.send(:join_root).drop(1).size)
12
10
  .to eq(2) }
13
- specify { expect(subject.send(method, join_associations).map(&:join_type))
11
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
14
12
  .to be_all { Polyamorous::InnerJoin } }
15
13
  end
16
14
 
17
15
  context 'with has_many :through association' do
18
16
  subject { new_join_dependency Person, :authored_article_comments }
19
17
 
20
- specify { expect(subject.send(method, join_associations).size)
18
+ specify { expect(subject.send(:join_root).drop(1).size)
21
19
  .to eq 1 }
22
- specify { expect(subject.send(method, join_associations).first.table_name)
20
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
23
21
  .to eq 'comments' }
24
22
  end
25
23
 
26
24
  context 'with outer join' do
27
25
  subject { new_join_dependency Person, new_join(:articles, :outer) }
28
26
 
29
- specify { expect(subject.send(method, join_associations).size)
27
+ specify { expect(subject.send(:join_root).drop(1).size)
30
28
  .to eq 1 }
31
- specify { expect(subject.send(method, join_associations).first.join_type)
29
+ specify { expect(subject.send(:join_root).drop(1).first.join_type)
32
30
  .to eq Polyamorous::OuterJoin }
33
31
  end
34
32
 
@@ -36,45 +34,36 @@ module Polyamorous
36
34
  subject { new_join_dependency Person,
37
35
  new_join(:articles, :outer) => new_join(:comments, :outer) }
38
36
 
39
- specify { expect(subject.send(method, join_associations).size)
37
+ specify { expect(subject.send(:join_root).drop(1).size)
40
38
  .to eq 2 }
41
- specify { expect(subject.send(method, join_associations).map(&:join_type))
39
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
42
40
  .to eq [Polyamorous::OuterJoin, Polyamorous::OuterJoin] }
43
- specify { expect(subject.send(method, join_associations).map(&:join_type))
41
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
44
42
  .to be_all { Polyamorous::OuterJoin } }
45
43
  end
46
44
 
47
45
  context 'with polymorphic belongs_to join' do
48
46
  subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
49
47
 
50
- specify { expect(subject.send(method, join_associations).size)
48
+ specify { expect(subject.send(:join_root).drop(1).size)
51
49
  .to eq 1 }
52
- specify { expect(subject.send(method, join_associations).first.join_type)
50
+ specify { expect(subject.send(:join_root).drop(1).first.join_type)
53
51
  .to eq Polyamorous::InnerJoin }
54
- specify { expect(subject.send(method, join_associations).first.table_name)
52
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
55
53
  .to eq 'people' }
56
-
57
- it 'finds a join association respecting polymorphism' do
58
- parent = subject.send(join_base)
59
- reflection = Note.reflect_on_association(:notable)
60
-
61
- expect(subject.find_join_association_respecting_polymorphism(
62
- reflection, parent, Person))
63
- .to eq subject.send(method, join_associations).first
64
- end
65
54
  end
66
55
 
67
56
  context 'with polymorphic belongs_to join and nested symbol join' do
68
57
  subject { new_join_dependency Note,
69
58
  new_join(:notable, :inner, Person) => :comments }
70
59
 
71
- specify { expect(subject.send(method, join_associations).size)
60
+ specify { expect(subject.send(:join_root).drop(1).size)
72
61
  .to eq 2 }
73
- specify { expect(subject.send(method, join_associations).map(&:join_type))
62
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
74
63
  .to be_all { Polyamorous::InnerJoin } }
75
- specify { expect(subject.send(method, join_associations).first.table_name)
64
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
76
65
  .to eq 'people' }
77
- specify { expect(subject.send(method, join_associations)[1].table_name)
66
+ specify { expect(subject.send(:join_root).drop(1)[1].table_name)
78
67
  .to eq 'comments' }
79
68
  end
80
69
 
@@ -316,6 +316,11 @@ module Ransack
316
316
  .to eq s.result(distinct: true).send(all_or_load)
317
317
  end
318
318
 
319
+ it 'evaluates joins with belongs_to join' do
320
+ s = Person.joins(:parent).ransack(parent_name_eq: 'Ernie').result(distinct: true)
321
+ expect(s).to be_an ActiveRecord::Relation
322
+ end
323
+
319
324
  private
320
325
 
321
326
  def remove_quotes_and_backticks(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-08-09 00:00:00.000000000 Z
14
+ date: 2018-08-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: actionpack
@@ -229,6 +229,7 @@ files:
229
229
  - lib/ransack/locale/nl.yml
230
230
  - lib/ransack/locale/pt-BR.yml
231
231
  - lib/ransack/locale/ro.yml
232
+ - lib/ransack/locale/ru.yml
232
233
  - lib/ransack/locale/tr.yml
233
234
  - lib/ransack/locale/zh-CN.yml
234
235
  - lib/ransack/locale/zh-TW.yml