giga-pure-kit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of giga-pure-kit might be problematic. Click here for more details.

Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/giga-pure-kit.gemspec +12 -0
  3. data/ransack-4.4.1/LICENSE +20 -0
  4. data/ransack-4.4.1/README.md +101 -0
  5. data/ransack-4.4.1/lib/polyamorous/activerecord/join_association.rb +218 -0
  6. data/ransack-4.4.1/lib/polyamorous/activerecord/join_association_7_2.rb +55 -0
  7. data/ransack-4.4.1/lib/polyamorous/activerecord/join_dependency.rb +102 -0
  8. data/ransack-4.4.1/lib/polyamorous/activerecord/reflection.rb +11 -0
  9. data/ransack-4.4.1/lib/polyamorous/join.rb +70 -0
  10. data/ransack-4.4.1/lib/polyamorous/polyamorous.rb +27 -0
  11. data/ransack-4.4.1/lib/polyamorous/swapping_reflection_class.rb +11 -0
  12. data/ransack-4.4.1/lib/polyamorous/tree_node.rb +7 -0
  13. data/ransack-4.4.1/lib/ransack/active_record.rb +14 -0
  14. data/ransack-4.4.1/lib/ransack/adapters/active_record/base.rb +152 -0
  15. data/ransack-4.4.1/lib/ransack/adapters/active_record/context.rb +373 -0
  16. data/ransack-4.4.1/lib/ransack/configuration.rb +209 -0
  17. data/ransack-4.4.1/lib/ransack/constants.rb +176 -0
  18. data/ransack-4.4.1/lib/ransack/context.rb +190 -0
  19. data/ransack-4.4.1/lib/ransack/helpers/form_builder.rb +277 -0
  20. data/ransack-4.4.1/lib/ransack/helpers/form_helper.rb +311 -0
  21. data/ransack-4.4.1/lib/ransack/helpers.rb +2 -0
  22. data/ransack-4.4.1/lib/ransack/invalid_search_error.rb +3 -0
  23. data/ransack-4.4.1/lib/ransack/locale/ar.yml +70 -0
  24. data/ransack-4.4.1/lib/ransack/locale/az.yml +70 -0
  25. data/ransack-4.4.1/lib/ransack/locale/bg.yml +70 -0
  26. data/ransack-4.4.1/lib/ransack/locale/ca.yml +70 -0
  27. data/ransack-4.4.1/lib/ransack/locale/cs.yml +70 -0
  28. data/ransack-4.4.1/lib/ransack/locale/da.yml +70 -0
  29. data/ransack-4.4.1/lib/ransack/locale/de.yml +70 -0
  30. data/ransack-4.4.1/lib/ransack/locale/el.yml +70 -0
  31. data/ransack-4.4.1/lib/ransack/locale/en.yml +70 -0
  32. data/ransack-4.4.1/lib/ransack/locale/es.yml +70 -0
  33. data/ransack-4.4.1/lib/ransack/locale/fa.yml +70 -0
  34. data/ransack-4.4.1/lib/ransack/locale/fi.yml +71 -0
  35. data/ransack-4.4.1/lib/ransack/locale/fr.yml +70 -0
  36. data/ransack-4.4.1/lib/ransack/locale/hu.yml +70 -0
  37. data/ransack-4.4.1/lib/ransack/locale/id.yml +70 -0
  38. data/ransack-4.4.1/lib/ransack/locale/it.yml +70 -0
  39. data/ransack-4.4.1/lib/ransack/locale/ja.yml +70 -0
  40. data/ransack-4.4.1/lib/ransack/locale/ko.yml +70 -0
  41. data/ransack-4.4.1/lib/ransack/locale/nl.yml +70 -0
  42. data/ransack-4.4.1/lib/ransack/locale/pt-BR.yml +70 -0
  43. data/ransack-4.4.1/lib/ransack/locale/ro.yml +70 -0
  44. data/ransack-4.4.1/lib/ransack/locale/ru.yml +70 -0
  45. data/ransack-4.4.1/lib/ransack/locale/sk.yml +70 -0
  46. data/ransack-4.4.1/lib/ransack/locale/sv.yml +70 -0
  47. data/ransack-4.4.1/lib/ransack/locale/tr.yml +70 -0
  48. data/ransack-4.4.1/lib/ransack/locale/uk.yml +72 -0
  49. data/ransack-4.4.1/lib/ransack/locale/zh-CN.yml +70 -0
  50. data/ransack-4.4.1/lib/ransack/locale/zh-TW.yml +70 -0
  51. data/ransack-4.4.1/lib/ransack/naming.rb +58 -0
  52. data/ransack-4.4.1/lib/ransack/nodes/attribute.rb +59 -0
  53. data/ransack-4.4.1/lib/ransack/nodes/bindable.rb +52 -0
  54. data/ransack-4.4.1/lib/ransack/nodes/condition.rb +399 -0
  55. data/ransack-4.4.1/lib/ransack/nodes/grouping.rb +206 -0
  56. data/ransack-4.4.1/lib/ransack/nodes/node.rb +34 -0
  57. data/ransack-4.4.1/lib/ransack/nodes/sort.rb +54 -0
  58. data/ransack-4.4.1/lib/ransack/nodes/value.rb +115 -0
  59. data/ransack-4.4.1/lib/ransack/predicate.rb +75 -0
  60. data/ransack-4.4.1/lib/ransack/ransacker.rb +24 -0
  61. data/ransack-4.4.1/lib/ransack/search.rb +195 -0
  62. data/ransack-4.4.1/lib/ransack/translate.rb +156 -0
  63. data/ransack-4.4.1/lib/ransack/version.rb +3 -0
  64. data/ransack-4.4.1/lib/ransack/visitor.rb +87 -0
  65. data/ransack-4.4.1/lib/ransack.rb +33 -0
  66. data/ransack-4.4.1/spec/console.rb +13 -0
  67. data/ransack-4.4.1/spec/factories/articles.rb +7 -0
  68. data/ransack-4.4.1/spec/factories/comments.rb +7 -0
  69. data/ransack-4.4.1/spec/factories/notes.rb +13 -0
  70. data/ransack-4.4.1/spec/factories/people.rb +10 -0
  71. data/ransack-4.4.1/spec/factories/tags.rb +5 -0
  72. data/ransack-4.4.1/spec/helpers/polyamorous_helper.rb +13 -0
  73. data/ransack-4.4.1/spec/helpers/ransack_helper.rb +9 -0
  74. data/ransack-4.4.1/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  75. data/ransack-4.4.1/spec/polyamorous/join_association_spec.rb +29 -0
  76. data/ransack-4.4.1/spec/polyamorous/join_dependency_spec.rb +80 -0
  77. data/ransack-4.4.1/spec/polyamorous/join_spec.rb +19 -0
  78. data/ransack-4.4.1/spec/ransack/adapters/active_record/base_spec.rb +943 -0
  79. data/ransack-4.4.1/spec/ransack/adapters/active_record/context_spec.rb +219 -0
  80. data/ransack-4.4.1/spec/ransack/configuration_spec.rb +201 -0
  81. data/ransack-4.4.1/spec/ransack/helpers/form_builder_spec.rb +169 -0
  82. data/ransack-4.4.1/spec/ransack/helpers/form_helper_spec.rb +1075 -0
  83. data/ransack-4.4.1/spec/ransack/invalid_search_error_spec.rb +27 -0
  84. data/ransack-4.4.1/spec/ransack/nodes/condition_spec.rb +333 -0
  85. data/ransack-4.4.1/spec/ransack/nodes/grouping_spec.rb +111 -0
  86. data/ransack-4.4.1/spec/ransack/nodes/value_spec.rb +126 -0
  87. data/ransack-4.4.1/spec/ransack/predicate_spec.rb +504 -0
  88. data/ransack-4.4.1/spec/ransack/ransacker_spec.rb +69 -0
  89. data/ransack-4.4.1/spec/ransack/search_spec.rb +821 -0
  90. data/ransack-4.4.1/spec/ransack/translate_spec.rb +16 -0
  91. data/ransack-4.4.1/spec/spec_helper.rb +52 -0
  92. data/ransack-4.4.1/spec/support/en.yml +18 -0
  93. data/ransack-4.4.1/spec/support/schema.rb +419 -0
  94. metadata +133 -0
@@ -0,0 +1,156 @@
1
+ require 'i18n'
2
+
3
+ I18n.load_path += Dir[
4
+ File.join(File.dirname(__FILE__), 'locale'.freeze, '*.yml'.freeze)
5
+ ]
6
+
7
+ module Ransack
8
+ module Translate
9
+ class << self
10
+ def word(key, options = {})
11
+ I18n.translate(:"ransack.#{key}", default: key.to_s)
12
+ end
13
+
14
+ def predicate(key, options = {})
15
+ I18n.translate(:"ransack.predicates.#{key}", default: key.to_s)
16
+ end
17
+
18
+ def attribute(key, options = {})
19
+ unless context = options.delete(:context)
20
+ raise ArgumentError, "A context is required to translate attributes"
21
+ end
22
+
23
+ original_name = key.to_s
24
+ base_class = context.klass
25
+ base_ancestors = base_class.ancestors.select {
26
+ |x| x.respond_to?(:model_name)
27
+ }
28
+ attributes_str = original_name.dup # will be modified by ⬇
29
+ predicate = Predicate.detect_and_strip_from_string!(attributes_str)
30
+ attribute_names = attributes_str.split(/_and_|_or_/)
31
+ combinator = attributes_str =~ /_and_/ ? :and : :or
32
+ defaults = base_ancestors.map do |klass|
33
+ "ransack.attributes.#{i18n_key(klass)}.#{original_name}".to_sym
34
+ end
35
+ defaults << options.delete(:default) if options[:default]
36
+
37
+ translated_names = attribute_names.map do |name|
38
+ attribute_name(context, name, options[:include_associations])
39
+ end
40
+
41
+ interpolations = {
42
+ attributes: translated_names.join(" #{Translate.word(combinator)} ")
43
+ }
44
+
45
+ if predicate
46
+ defaults << "%{attributes} %{predicate}".freeze
47
+ interpolations[:predicate] = Translate.predicate(predicate)
48
+ else
49
+ defaults << "%{attributes}".freeze
50
+ end
51
+
52
+ options.reverse_merge! count: 1, default: defaults
53
+ I18n.translate(defaults.shift, **options.merge(interpolations))
54
+ end
55
+
56
+ def association(key, options = {})
57
+ unless context = options.delete(:context)
58
+ raise ArgumentError, "A context is required to translate associations"
59
+ end
60
+
61
+ defaults =
62
+ if key.blank?
63
+ [:"ransack.models.#{i18n_key(context.klass)}",
64
+ :"#{context.klass.i18n_scope}.models.#{i18n_key(context.klass)}"]
65
+ else
66
+ [:"ransack.associations.#{i18n_key(context.klass)}.#{key}"]
67
+ end
68
+ defaults << context.traverse(key).model_name.human
69
+ options = { count: 1, default: defaults }
70
+ I18n.translate(defaults.shift, **options)
71
+ end
72
+
73
+ private
74
+
75
+ def attribute_name(context, name, include_associations = nil)
76
+ @context, @name = context, name
77
+ @assoc_path = context.association_path(name)
78
+ @attr_name = @name.sub(/^#{@assoc_path}_/, ''.freeze)
79
+ associated_class = @context.traverse(@assoc_path) if @assoc_path.present?
80
+ @include_associated = include_associations && associated_class
81
+
82
+ defaults = default_attribute_name << fallback_args
83
+ options = { count: 1, default: defaults }
84
+ interpolations = build_interpolations(associated_class)
85
+
86
+ I18n.translate(defaults.shift, **options.merge(interpolations))
87
+ end
88
+
89
+ def default_attribute_name
90
+ ["ransack.attributes.#{i18n_key(@context.klass)}.#{@name}".to_sym]
91
+ end
92
+
93
+ def fallback_args
94
+ if @include_associated
95
+ '%{association_name} %{attr_fallback_name}'.freeze
96
+ else
97
+ '%{attr_fallback_name}'.freeze
98
+ end
99
+ end
100
+
101
+ def build_interpolations(associated_class)
102
+ {
103
+ attr_fallback_name: attr_fallback_name(associated_class),
104
+ association_name: association_name
105
+ }.reject { |_, value| value.nil? }
106
+ end
107
+
108
+ def attr_fallback_name(associated_class)
109
+ I18n.t(
110
+ :"ransack.attributes.#{fallback_class(associated_class)}.#{@attr_name}",
111
+ default: default_interpolation(associated_class)
112
+ )
113
+ end
114
+
115
+ def fallback_class(associated_class)
116
+ i18n_key(associated_class || @context.klass)
117
+ end
118
+
119
+ def association_name
120
+ association(@assoc_path, context: @context) if @include_associated
121
+ end
122
+
123
+ def default_interpolation(associated_class)
124
+ [
125
+ associated_attribute(associated_class),
126
+ ".attributes.#{@attr_name}".to_sym,
127
+ @attr_name.humanize
128
+ ].flatten
129
+ end
130
+
131
+ def associated_attribute(associated_class)
132
+ if associated_class
133
+ translated_attribute(associated_class)
134
+ else
135
+ translated_ancestor_attributes
136
+ end
137
+ end
138
+
139
+ def translated_attribute(associated_class)
140
+ key = "#{associated_class.i18n_scope}.attributes.#{
141
+ i18n_key(associated_class)}.#{@attr_name}"
142
+ ["#{key}.one".to_sym, key.to_sym]
143
+ end
144
+
145
+ def translated_ancestor_attributes
146
+ @context.klass.ancestors
147
+ .select { |ancestor| ancestor.respond_to?(:model_name) }
148
+ .map { |ancestor| translated_attribute(ancestor) }
149
+ end
150
+
151
+ def i18n_key(klass)
152
+ klass.model_name.i18n_key
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,3 @@
1
+ module Ransack
2
+ VERSION = '4.4.1'
3
+ end
@@ -0,0 +1,87 @@
1
+ module Ransack
2
+ class Visitor
3
+
4
+ def accept(object)
5
+ visit(object)
6
+ end
7
+
8
+ def can_accept?(object)
9
+ respond_to? DISPATCH[object.class]
10
+ end
11
+
12
+ def visit_Array(object)
13
+ object.map { |o| accept(o) }.compact
14
+ end
15
+
16
+ def visit_Ransack_Nodes_Condition(object)
17
+ object.arel_predicate if object.valid?
18
+ end
19
+
20
+ def visit_Ransack_Nodes_Grouping(object)
21
+ if object.combinator == Constants::OR
22
+ visit_or(object)
23
+ else
24
+ visit_and(object)
25
+ end
26
+ end
27
+
28
+ def visit_and(object)
29
+ nodes = object.values.map { |o| accept(o) }.compact
30
+ return nil unless nodes.size > 0
31
+
32
+ if nodes.size > 1
33
+ Arel::Nodes::Grouping.new(Arel::Nodes::And.new(nodes))
34
+ else
35
+ nodes.first
36
+ end
37
+ end
38
+
39
+ def visit_or(object)
40
+ nodes = object.values.map { |o| accept(o) }.compact
41
+ nodes.inject(&:or)
42
+ end
43
+
44
+ def quoted?(object)
45
+ case object
46
+ when Arel::Nodes::SqlLiteral, Bignum, Fixnum
47
+ false
48
+ else
49
+ true
50
+ end
51
+ end
52
+
53
+ def visit(object)
54
+ send(DISPATCH[object.class], object)
55
+ end
56
+
57
+ def visit_Ransack_Nodes_Sort(object)
58
+ if object.valid?
59
+ if object.attr.is_a?(Arel::Attributes::Attribute)
60
+ object.attr.send(object.dir)
61
+ else
62
+ ordered(object)
63
+ end
64
+ else
65
+ scope_name = :"sort_by_#{object.name}_#{object.dir}"
66
+ scope_name if object.context.object.respond_to?(scope_name)
67
+ end
68
+ end
69
+
70
+ DISPATCH = Hash.new do |hash, klass|
71
+ hash[klass] = "visit_#{
72
+ klass.name.gsub(Constants::TWO_COLONS, Constants::UNDERSCORE)
73
+ }"
74
+ end
75
+
76
+ private
77
+
78
+ def ordered(object)
79
+ case object.dir
80
+ when 'asc'.freeze
81
+ Arel::Nodes::Ascending.new(object.attr)
82
+ when 'desc'.freeze
83
+ Arel::Nodes::Descending.new(object.attr)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,33 @@
1
+ require 'active_support/dependencies/autoload'
2
+ require 'active_support/deprecation'
3
+ require 'active_support/deprecator'
4
+
5
+ require 'active_support/core_ext'
6
+ require 'ransack/configuration'
7
+ require 'polyamorous/polyamorous'
8
+
9
+ module Ransack
10
+ extend Configuration
11
+ class UntraversableAssociationError < StandardError; end
12
+ end
13
+
14
+ Ransack.configure do |config|
15
+ Ransack::Constants::AREL_PREDICATES.each do |name|
16
+ config.add_predicate name, arel_predicate: name
17
+ end
18
+ Ransack::Constants::DERIVED_PREDICATES.each do |args|
19
+ config.add_predicate(*args)
20
+ end
21
+ end
22
+
23
+ require 'ransack/search'
24
+ require 'ransack/ransacker'
25
+ require 'ransack/translate'
26
+ require 'ransack/active_record'
27
+ require 'ransack/context'
28
+ require 'ransack/version'
29
+
30
+ ActiveSupport.on_load(:action_controller) do
31
+ require 'ransack/helpers'
32
+ ActionController::Base.helper Ransack::Helpers::FormHelper
33
+ end
@@ -0,0 +1,13 @@
1
+ Bundler.setup
2
+ require 'factory_bot'
3
+ require 'faker'
4
+ require 'ransack'
5
+
6
+ Dir[File.expand_path('../../spec/{helpers,support,factories}/*.rb', __FILE__)]
7
+ .each do |f|
8
+ require f
9
+ end
10
+
11
+ Faker::Config.random = Random.new(0)
12
+
13
+ Schema.create
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :article do
3
+ association :person
4
+ title { Faker::Lorem.sentence }
5
+ body { Faker::Lorem.paragraph }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :comment do
3
+ association :article
4
+ association :person
5
+ body { Faker::Lorem.paragraph }
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :note do
3
+ note { Faker::Lorem.words(number: 7).join(' ') }
4
+
5
+ trait :for_person do
6
+ association :notable, factory: :person
7
+ end
8
+
9
+ trait :for_article do
10
+ association :notable, factory: :article
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :person do
3
+ name { Faker::Name.name }
4
+ email { "test@example.com" }
5
+ sequence(:salary) { |n| 30000 + (n * 1000) }
6
+ only_sort { Faker::Lorem.words(number: 3).join(' ') }
7
+ only_search { Faker::Lorem.words(number: 3).join(' ') }
8
+ only_admin { Faker::Lorem.words(number: 3).join(' ') }
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :tag do
3
+ name { Faker::Lorem.words(number: 3).join(' ') }
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module PolyamorousHelper
2
+ def new_join_association(reflection, children, klass)
3
+ Polyamorous::JoinAssociation.new reflection, children, klass
4
+ end
5
+
6
+ def new_join_dependency(klass, associations = {})
7
+ Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
8
+ end
9
+
10
+ def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
11
+ Polyamorous::Join.new name, type, klass
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module RansackHelper
2
+ def quote_table_name(table)
3
+ ActiveRecord::Base.connection.quote_table_name(table)
4
+ end
5
+
6
+ def quote_column_name(column)
7
+ ActiveRecord::Base.connection.quote_column_name(column)
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Polyamorous
4
+ describe "ActiveRecord Compatibility" do
5
+ it 'works with self joins and includes' do
6
+ trade_account = Account.create!
7
+ Account.create!(trade_account: trade_account)
8
+
9
+ accounts = Account.joins(:trade_account).includes(:trade_account, :agent_account)
10
+ account = accounts.first
11
+
12
+ expect(account.agent_account).to be_nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Polyamorous
4
+ describe JoinAssociation do
5
+ let(:join_dependency) { new_join_dependency Note, {} }
6
+ let(:reflection) { Note.reflect_on_association(:notable) }
7
+ let(:parent) { join_dependency.send(:join_root) }
8
+ let(:join_association) {
9
+ new_join_association(reflection, parent.children, Article)
10
+ }
11
+
12
+ subject { new_join_association(reflection, parent.children, Person) }
13
+
14
+ it 'leaves the original reflection intact for thread safety' do
15
+ reflection.instance_variable_set(:@klass, Article)
16
+ join_association
17
+ .swapping_reflection_klass(reflection, Person) do |new_reflection|
18
+ expect(new_reflection.options).not_to equal reflection.options
19
+ expect(new_reflection.options).not_to have_key(:polymorphic)
20
+ expect(new_reflection.klass).to eq(Person)
21
+ expect(reflection.klass).to eq(Article)
22
+ end
23
+ end
24
+
25
+ it 'sets the polymorphic option to true after initializing' do
26
+ expect(join_association.reflection.options[:polymorphic]).to be true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ module Polyamorous
4
+ describe JoinDependency do
5
+ context 'with symbol joins' do
6
+ subject { new_join_dependency Person, articles: :comments }
7
+
8
+ specify { expect(subject.send(:join_root).drop(1).size)
9
+ .to eq(2) }
10
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
11
+ .to eq [Polyamorous::InnerJoin] }
12
+ end
13
+
14
+ context 'with has_many :through association' do
15
+ subject { new_join_dependency Person, :authored_article_comments }
16
+
17
+ specify { expect(subject.send(:join_root).drop(1).size)
18
+ .to eq 1 }
19
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
20
+ .to eq 'comments' }
21
+ end
22
+
23
+ context 'with outer join' do
24
+ subject { new_join_dependency Person, new_join(:articles, :outer) }
25
+
26
+ specify { expect(subject.send(:join_root).drop(1).size)
27
+ .to eq 1 }
28
+ specify { expect(subject.send(:join_root).drop(1).first.join_type)
29
+ .to eq Polyamorous::OuterJoin }
30
+ end
31
+
32
+ context 'with nested outer joins' do
33
+ subject { new_join_dependency Person,
34
+ new_join(:articles, :outer) => new_join(:comments, :outer) }
35
+
36
+ specify { expect(subject.send(:join_root).drop(1).size)
37
+ .to eq 2 }
38
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
39
+ .to eq [Polyamorous::OuterJoin, Polyamorous::OuterJoin] }
40
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
41
+ .to eq [Polyamorous::OuterJoin] }
42
+ end
43
+
44
+ context 'with polymorphic belongs_to join' do
45
+ subject { new_join_dependency Note, new_join(:notable, :inner, Person) }
46
+
47
+ specify { expect(subject.send(:join_root).drop(1).size)
48
+ .to eq 1 }
49
+ specify { expect(subject.send(:join_root).drop(1).first.join_type)
50
+ .to eq Polyamorous::InnerJoin }
51
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
52
+ .to eq 'people' }
53
+ end
54
+
55
+ context 'with polymorphic belongs_to join and nested symbol join' do
56
+ subject { new_join_dependency Note,
57
+ new_join(:notable, :inner, Person) => :comments }
58
+
59
+ specify { expect(subject.send(:join_root).drop(1).size)
60
+ .to eq 2 }
61
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
62
+ .to eq [Polyamorous::InnerJoin] }
63
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
64
+ .to eq 'people' }
65
+ specify { expect(subject.send(:join_root).drop(1)[1].table_name)
66
+ .to eq 'comments' }
67
+ end
68
+
69
+ context 'with polymorphic belongs_to join and nested join' do
70
+ subject { new_join_dependency Note,
71
+ new_join(:notable, :outer, Person) => :comments }
72
+ specify { expect(subject.send(:join_root).drop(1).size).to eq 2 }
73
+ specify { expect(subject.send(:join_root).drop(1).map(&:join_type)).to eq [Polyamorous::OuterJoin, Polyamorous::InnerJoin] }
74
+ specify { expect(subject.send(:join_root).drop(1).first.table_name)
75
+ .to eq 'people' }
76
+ specify { expect(subject.send(:join_root).drop(1)[1].table_name)
77
+ .to eq 'comments' }
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Polyamorous
4
+ describe Join do
5
+ it 'is a tree node' do
6
+ join = new_join(:articles, :outer)
7
+ expect(join).to be_kind_of(TreeNode)
8
+ end
9
+
10
+ it 'can be added to a tree' do
11
+ join = new_join(:articles, :outer)
12
+
13
+ tree_hash = {}
14
+ join.add_to_tree(tree_hash)
15
+
16
+ expect(tree_hash[join]).to be {}
17
+ end
18
+ end
19
+ end