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.
- checksums.yaml +7 -0
- data/giga-pure-kit.gemspec +12 -0
- data/ransack-4.4.1/LICENSE +20 -0
- data/ransack-4.4.1/README.md +101 -0
- data/ransack-4.4.1/lib/polyamorous/activerecord/join_association.rb +218 -0
- data/ransack-4.4.1/lib/polyamorous/activerecord/join_association_7_2.rb +55 -0
- data/ransack-4.4.1/lib/polyamorous/activerecord/join_dependency.rb +102 -0
- data/ransack-4.4.1/lib/polyamorous/activerecord/reflection.rb +11 -0
- data/ransack-4.4.1/lib/polyamorous/join.rb +70 -0
- data/ransack-4.4.1/lib/polyamorous/polyamorous.rb +27 -0
- data/ransack-4.4.1/lib/polyamorous/swapping_reflection_class.rb +11 -0
- data/ransack-4.4.1/lib/polyamorous/tree_node.rb +7 -0
- data/ransack-4.4.1/lib/ransack/active_record.rb +14 -0
- data/ransack-4.4.1/lib/ransack/adapters/active_record/base.rb +152 -0
- data/ransack-4.4.1/lib/ransack/adapters/active_record/context.rb +373 -0
- data/ransack-4.4.1/lib/ransack/configuration.rb +209 -0
- data/ransack-4.4.1/lib/ransack/constants.rb +176 -0
- data/ransack-4.4.1/lib/ransack/context.rb +190 -0
- data/ransack-4.4.1/lib/ransack/helpers/form_builder.rb +277 -0
- data/ransack-4.4.1/lib/ransack/helpers/form_helper.rb +311 -0
- data/ransack-4.4.1/lib/ransack/helpers.rb +2 -0
- data/ransack-4.4.1/lib/ransack/invalid_search_error.rb +3 -0
- data/ransack-4.4.1/lib/ransack/locale/ar.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/az.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/bg.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/ca.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/cs.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/da.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/de.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/el.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/en.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/es.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/fa.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/fi.yml +71 -0
- data/ransack-4.4.1/lib/ransack/locale/fr.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/hu.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/id.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/it.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/ja.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/ko.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/nl.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/pt-BR.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/ro.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/ru.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/sk.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/sv.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/tr.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/uk.yml +72 -0
- data/ransack-4.4.1/lib/ransack/locale/zh-CN.yml +70 -0
- data/ransack-4.4.1/lib/ransack/locale/zh-TW.yml +70 -0
- data/ransack-4.4.1/lib/ransack/naming.rb +58 -0
- data/ransack-4.4.1/lib/ransack/nodes/attribute.rb +59 -0
- data/ransack-4.4.1/lib/ransack/nodes/bindable.rb +52 -0
- data/ransack-4.4.1/lib/ransack/nodes/condition.rb +399 -0
- data/ransack-4.4.1/lib/ransack/nodes/grouping.rb +206 -0
- data/ransack-4.4.1/lib/ransack/nodes/node.rb +34 -0
- data/ransack-4.4.1/lib/ransack/nodes/sort.rb +54 -0
- data/ransack-4.4.1/lib/ransack/nodes/value.rb +115 -0
- data/ransack-4.4.1/lib/ransack/predicate.rb +75 -0
- data/ransack-4.4.1/lib/ransack/ransacker.rb +24 -0
- data/ransack-4.4.1/lib/ransack/search.rb +195 -0
- data/ransack-4.4.1/lib/ransack/translate.rb +156 -0
- data/ransack-4.4.1/lib/ransack/version.rb +3 -0
- data/ransack-4.4.1/lib/ransack/visitor.rb +87 -0
- data/ransack-4.4.1/lib/ransack.rb +33 -0
- data/ransack-4.4.1/spec/console.rb +13 -0
- data/ransack-4.4.1/spec/factories/articles.rb +7 -0
- data/ransack-4.4.1/spec/factories/comments.rb +7 -0
- data/ransack-4.4.1/spec/factories/notes.rb +13 -0
- data/ransack-4.4.1/spec/factories/people.rb +10 -0
- data/ransack-4.4.1/spec/factories/tags.rb +5 -0
- data/ransack-4.4.1/spec/helpers/polyamorous_helper.rb +13 -0
- data/ransack-4.4.1/spec/helpers/ransack_helper.rb +9 -0
- data/ransack-4.4.1/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/ransack-4.4.1/spec/polyamorous/join_association_spec.rb +29 -0
- data/ransack-4.4.1/spec/polyamorous/join_dependency_spec.rb +80 -0
- data/ransack-4.4.1/spec/polyamorous/join_spec.rb +19 -0
- data/ransack-4.4.1/spec/ransack/adapters/active_record/base_spec.rb +943 -0
- data/ransack-4.4.1/spec/ransack/adapters/active_record/context_spec.rb +219 -0
- data/ransack-4.4.1/spec/ransack/configuration_spec.rb +201 -0
- data/ransack-4.4.1/spec/ransack/helpers/form_builder_spec.rb +169 -0
- data/ransack-4.4.1/spec/ransack/helpers/form_helper_spec.rb +1075 -0
- data/ransack-4.4.1/spec/ransack/invalid_search_error_spec.rb +27 -0
- data/ransack-4.4.1/spec/ransack/nodes/condition_spec.rb +333 -0
- data/ransack-4.4.1/spec/ransack/nodes/grouping_spec.rb +111 -0
- data/ransack-4.4.1/spec/ransack/nodes/value_spec.rb +126 -0
- data/ransack-4.4.1/spec/ransack/predicate_spec.rb +504 -0
- data/ransack-4.4.1/spec/ransack/ransacker_spec.rb +69 -0
- data/ransack-4.4.1/spec/ransack/search_spec.rb +821 -0
- data/ransack-4.4.1/spec/ransack/translate_spec.rb +16 -0
- data/ransack-4.4.1/spec/spec_helper.rb +52 -0
- data/ransack-4.4.1/spec/support/en.yml +18 -0
- data/ransack-4.4.1/spec/support/schema.rb +419 -0
- 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,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,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,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,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
|