ransack 1.7.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +16 -48
- data/CHANGELOG.md +409 -26
- data/CONTRIBUTING.md +48 -20
- data/Gemfile +9 -13
- data/README.md +352 -92
- data/Rakefile +6 -25
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +2 -0
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +2 -0
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +32 -0
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +112 -0
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +32 -0
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +113 -0
- data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +31 -0
- data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +57 -0
- data/lib/polyamorous/join.rb +70 -0
- data/lib/polyamorous/swapping_reflection_class.rb +11 -0
- data/lib/polyamorous/tree_node.rb +7 -0
- data/lib/polyamorous.rb +25 -0
- data/lib/ransack/adapters/active_record/base.rb +23 -2
- data/lib/ransack/adapters/active_record/context.rb +210 -135
- data/lib/ransack/adapters/active_record/ransack/constants.rb +53 -53
- data/lib/ransack/adapters/active_record/ransack/context.rb +11 -15
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +33 -30
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
- data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
- data/lib/ransack/adapters/active_record.rb +11 -10
- data/lib/ransack/adapters.rb +45 -23
- data/lib/ransack/configuration.rb +91 -4
- data/lib/ransack/constants.rb +14 -26
- data/lib/ransack/context.rb +29 -18
- data/lib/ransack/helpers/form_builder.rb +27 -12
- data/lib/ransack/helpers/form_helper.rb +75 -70
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +70 -0
- data/lib/ransack/locale/bg.yml +70 -0
- data/lib/ransack/locale/da.yml +70 -0
- data/lib/ransack/locale/el.yml +70 -0
- data/lib/ransack/locale/id.yml +70 -0
- data/lib/ransack/locale/it.yml +70 -0
- data/lib/ransack/locale/ja.yml +70 -0
- data/lib/ransack/locale/nl.yml +4 -4
- data/lib/ransack/locale/pt-BR.yml +70 -0
- data/lib/ransack/locale/ru.yml +70 -0
- data/lib/ransack/locale/tr.yml +70 -0
- data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
- data/lib/ransack/locale/zh-TW.yml +70 -0
- data/lib/ransack/nodes/attribute.rb +5 -2
- data/lib/ransack/nodes/bindable.rb +18 -6
- data/lib/ransack/nodes/condition.rb +77 -28
- data/lib/ransack/nodes/grouping.rb +16 -10
- data/lib/ransack/nodes/sort.rb +9 -5
- data/lib/ransack/nodes/value.rb +74 -68
- data/lib/ransack/nodes.rb +1 -1
- data/lib/ransack/predicate.rb +15 -19
- data/lib/ransack/search.rb +14 -7
- data/lib/ransack/translate.rb +3 -3
- data/lib/ransack/version.rb +1 -1
- data/lib/ransack/visitor.rb +1 -12
- data/lib/ransack.rb +7 -7
- data/logo/ransack-h.png +0 -0
- data/logo/ransack-h.svg +34 -0
- data/logo/ransack-v.png +0 -0
- data/logo/ransack-v.svg +34 -0
- data/logo/ransack.png +0 -0
- data/logo/ransack.svg +21 -0
- data/ransack.gemspec +9 -10
- data/spec/console.rb +4 -0
- data/spec/helpers/polyamorous_helper.rb +24 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +365 -74
- data/spec/ransack/adapters/active_record/context_spec.rb +14 -19
- data/spec/ransack/configuration_spec.rb +87 -14
- data/spec/ransack/helpers/form_builder_spec.rb +2 -11
- data/spec/ransack/helpers/form_helper_spec.rb +481 -113
- data/spec/ransack/join_association_spec.rb +28 -0
- data/spec/ransack/join_dependency_spec.rb +86 -0
- data/spec/ransack/join_spec.rb +19 -0
- data/spec/ransack/nodes/condition_spec.rb +24 -0
- data/spec/ransack/nodes/grouping_spec.rb +56 -0
- data/spec/ransack/predicate_spec.rb +27 -5
- data/spec/ransack/search_spec.rb +84 -70
- data/spec/spec_helper.rb +4 -0
- data/spec/support/schema.rb +86 -41
- metadata +60 -81
- data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
- data/lib/ransack/adapters/active_record/3.0/context.rb +0 -201
- data/lib/ransack/adapters/active_record/3.1/context.rb +0 -215
- data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
- data/lib/ransack/adapters/active_record/compat.rb +0 -14
- data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
- data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
- data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
- data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
- data/lib/ransack/adapters/mongoid/base.rb +0 -130
- data/lib/ransack/adapters/mongoid/context.rb +0 -208
- data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
- data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
- data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
- data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
- data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
- data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
- data/lib/ransack/adapters/mongoid/table.rb +0 -35
- data/lib/ransack/adapters/mongoid.rb +0 -13
- data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
- data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
- data/spec/mongoid/configuration_spec.rb +0 -102
- data/spec/mongoid/dependencies_spec.rb +0 -8
- data/spec/mongoid/helpers/ransack_helper.rb +0 -11
- data/spec/mongoid/nodes/condition_spec.rb +0 -34
- data/spec/mongoid/nodes/grouping_spec.rb +0 -13
- data/spec/mongoid/predicate_spec.rb +0 -155
- data/spec/mongoid/search_spec.rb +0 -446
- data/spec/mongoid/support/mongoid.yml +0 -6
- data/spec/mongoid/support/schema.rb +0 -128
- data/spec/mongoid/translate_spec.rb +0 -14
- data/spec/mongoid_spec_helper.rb +0 -59
- data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'mongoid'
|
2
|
-
|
3
|
-
Mongoid.load!(File.expand_path("../mongoid.yml", __FILE__), :test)
|
4
|
-
|
5
|
-
class Person
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::Timestamps
|
8
|
-
|
9
|
-
field :name, type: String
|
10
|
-
field :email, type: String
|
11
|
-
field :only_search, type: String
|
12
|
-
field :only_sort, type: String
|
13
|
-
field :only_admin, type: String
|
14
|
-
field :salary, type: Integer
|
15
|
-
field :awesome, type: Boolean, default: false
|
16
|
-
|
17
|
-
belongs_to :parent, :class_name => 'Person', inverse_of: :children
|
18
|
-
has_many :children, :class_name => 'Person', inverse_of: :parent
|
19
|
-
|
20
|
-
has_many :articles
|
21
|
-
has_many :comments
|
22
|
-
|
23
|
-
# has_many :authored_article_comments, :through => :articles,
|
24
|
-
# :source => :comments, :foreign_key => :person_id
|
25
|
-
|
26
|
-
has_many :notes, :as => :notable
|
27
|
-
|
28
|
-
default_scope -> { order(id: :desc) }
|
29
|
-
|
30
|
-
scope :restricted, lambda { where(restricted: 1) }
|
31
|
-
scope :active, lambda { where(active: 1) }
|
32
|
-
scope :over_age, lambda { |y| where(:age.gt => y) }
|
33
|
-
|
34
|
-
ransacker :reversed_name, :formatter => proc { |v| v.reverse } do |parent|
|
35
|
-
parent.table[:name]
|
36
|
-
end
|
37
|
-
|
38
|
-
ransacker :doubled_name do |parent|
|
39
|
-
# Arel::Nodes::InfixOperation.new(
|
40
|
-
# '||', parent.table[:name], parent.table[:name]
|
41
|
-
# )
|
42
|
-
parent.table[:name]
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.ransackable_attributes(auth_object = nil)
|
46
|
-
if auth_object == :admin
|
47
|
-
all_ransackable_attributes - ['only_sort']
|
48
|
-
else
|
49
|
-
all_ransackable_attributes - ['only_sort', 'only_admin']
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.ransortable_attributes(auth_object = nil)
|
54
|
-
if auth_object == :admin
|
55
|
-
all_ransackable_attributes - ['only_search']
|
56
|
-
else
|
57
|
-
all_ransackable_attributes - ['only_search', 'only_admin']
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Article
|
63
|
-
include Mongoid::Document
|
64
|
-
|
65
|
-
field :title, type: String
|
66
|
-
field :body, type: String
|
67
|
-
|
68
|
-
belongs_to :person
|
69
|
-
has_many :comments
|
70
|
-
# has_and_belongs_to_many :tags
|
71
|
-
has_many :notes, :as => :notable
|
72
|
-
end
|
73
|
-
|
74
|
-
module Namespace
|
75
|
-
class Article < ::Article
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Comment
|
81
|
-
include Mongoid::Document
|
82
|
-
|
83
|
-
field :body, type: String
|
84
|
-
|
85
|
-
|
86
|
-
belongs_to :article
|
87
|
-
belongs_to :person
|
88
|
-
end
|
89
|
-
|
90
|
-
class Tag
|
91
|
-
include Mongoid::Document
|
92
|
-
|
93
|
-
field :name, type: String
|
94
|
-
|
95
|
-
# has_and_belongs_to_many :articles
|
96
|
-
end
|
97
|
-
|
98
|
-
class Note
|
99
|
-
include Mongoid::Document
|
100
|
-
|
101
|
-
field :note, type: String
|
102
|
-
|
103
|
-
belongs_to :notable, :polymorphic => true
|
104
|
-
end
|
105
|
-
|
106
|
-
module Schema
|
107
|
-
def self.create
|
108
|
-
10.times do
|
109
|
-
person = Person.make.save!
|
110
|
-
Note.make.save!(:notable => person)
|
111
|
-
3.times do
|
112
|
-
article = Article.create!(:person => person)
|
113
|
-
3.times do
|
114
|
-
# article.tags = [Tag.make.save!, Tag.make.save!, Tag.make.save!]
|
115
|
-
end
|
116
|
-
Note.create.save!(:notable => article)
|
117
|
-
10.times do
|
118
|
-
Comment.create.save!(:article => article, :person => person)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
Comment.create!(
|
124
|
-
:body => 'First post!',
|
125
|
-
:article => Article.create!(:title => 'Hello, world!')
|
126
|
-
)
|
127
|
-
end
|
128
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'mongoid_spec_helper'
|
2
|
-
|
3
|
-
module Ransack
|
4
|
-
describe Translate do
|
5
|
-
|
6
|
-
describe '.attribute' do
|
7
|
-
it 'translate namespaced attribute like AR does' do
|
8
|
-
ar_translation = ::Namespace::Article.human_attribute_name(:title)
|
9
|
-
ransack_translation = Ransack::Translate.attribute(:title, :context => ::Namespace::Article.search.context)
|
10
|
-
expect(ransack_translation).to eq ar_translation
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/spec/mongoid_spec_helper.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'machinist/object'
|
2
|
-
require 'sham'
|
3
|
-
require 'faker'
|
4
|
-
require 'pry'
|
5
|
-
require 'mongoid'
|
6
|
-
require 'ransack'
|
7
|
-
|
8
|
-
I18n.enforce_available_locales = false
|
9
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
10
|
-
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'support', '*.yml')]
|
11
|
-
|
12
|
-
Dir[File.expand_path('../{mongoid/helpers,mongoid/support,blueprints}/*.rb', __FILE__)]
|
13
|
-
.each do |f|
|
14
|
-
require f
|
15
|
-
end
|
16
|
-
|
17
|
-
Sham.define do
|
18
|
-
name { Faker::Name.name }
|
19
|
-
title { Faker::Lorem.sentence }
|
20
|
-
body { Faker::Lorem.paragraph }
|
21
|
-
salary { |index| 30000 + (index * 1000) }
|
22
|
-
tag_name { Faker::Lorem.words(3).join(' ') }
|
23
|
-
note { Faker::Lorem.words(7).join(' ') }
|
24
|
-
only_admin { Faker::Lorem.words(3).join(' ') }
|
25
|
-
only_search { Faker::Lorem.words(3).join(' ') }
|
26
|
-
only_sort { Faker::Lorem.words(3).join(' ') }
|
27
|
-
notable_id { |id| id }
|
28
|
-
end
|
29
|
-
|
30
|
-
RSpec.configure do |config|
|
31
|
-
config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior'
|
32
|
-
|
33
|
-
config.before(:suite) do
|
34
|
-
puts '=' * 80
|
35
|
-
connection_name = Mongoid.default_session.inspect
|
36
|
-
puts "Running specs against #{connection_name}, Mongoid #{
|
37
|
-
Mongoid::VERSION}, Moped #{Moped::VERSION} and Origin #{Origin::VERSION}..."
|
38
|
-
puts '=' * 80
|
39
|
-
Schema.create
|
40
|
-
end
|
41
|
-
|
42
|
-
config.before(:all) { Sham.reset(:before_all) }
|
43
|
-
config.before(:each) { Sham.reset(:before_each) }
|
44
|
-
|
45
|
-
config.include RansackHelper
|
46
|
-
end
|
47
|
-
|
48
|
-
RSpec::Matchers.define :be_like do |expected|
|
49
|
-
match do |actual|
|
50
|
-
actual.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip ==
|
51
|
-
expected.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
RSpec::Matchers.define :have_attribute_method do |expected|
|
56
|
-
match do |actual|
|
57
|
-
actual.attribute_method?(expected)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
rails = ::ActiveRecord::VERSION::STRING.first(3)
|
3
|
-
|
4
|
-
if %w(3.2 4.0 4.1).include?(rails) || rails == '3.1' && RUBY_VERSION < '2.2'
|
5
|
-
describe 'Ransack' do
|
6
|
-
it 'can be required without errors' do
|
7
|
-
output = `bundle exec ruby -e "require 'ransack'" 2>&1`
|
8
|
-
expect(output).to be_empty
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
=end
|