ransack 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +40 -22
- data/CHANGELOG.md +176 -27
- data/CONTRIBUTING.md +30 -19
- data/Gemfile +8 -3
- data/README.md +131 -58
- data/Rakefile +5 -2
- data/lib/ransack.rb +10 -5
- data/lib/ransack/adapters.rb +43 -23
- data/lib/ransack/adapters/active_record.rb +2 -2
- data/lib/ransack/adapters/active_record/3.0/compat.rb +5 -5
- data/lib/ransack/adapters/active_record/3.0/context.rb +5 -3
- data/lib/ransack/adapters/active_record/3.1/context.rb +1 -4
- data/lib/ransack/adapters/active_record/base.rb +12 -1
- data/lib/ransack/adapters/active_record/context.rb +148 -55
- data/lib/ransack/adapters/active_record/ransack/constants.rb +53 -53
- data/lib/ransack/adapters/active_record/ransack/context.rb +3 -1
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +20 -28
- data/lib/ransack/adapters/mongoid/base.rb +21 -6
- data/lib/ransack/adapters/mongoid/context.rb +9 -5
- data/lib/ransack/configuration.rb +24 -3
- data/lib/ransack/constants.rb +11 -22
- data/lib/ransack/context.rb +20 -13
- data/lib/ransack/helpers/form_builder.rb +5 -6
- data/lib/ransack/helpers/form_helper.rb +50 -69
- data/lib/ransack/locale/da.yml +70 -0
- data/lib/ransack/locale/id.yml +70 -0
- data/lib/ransack/locale/ja.yml +70 -0
- data/lib/ransack/locale/pt-BR.yml +70 -0
- data/lib/ransack/locale/{zh.yml → zh-CN.yml} +1 -1
- data/lib/ransack/locale/zh-TW.yml +70 -0
- data/lib/ransack/nodes.rb +1 -1
- data/lib/ransack/nodes/attribute.rb +4 -1
- data/lib/ransack/nodes/bindable.rb +18 -6
- data/lib/ransack/nodes/condition.rb +58 -28
- data/lib/ransack/nodes/grouping.rb +15 -4
- data/lib/ransack/nodes/sort.rb +9 -5
- data/lib/ransack/predicate.rb +6 -2
- data/lib/ransack/search.rb +6 -5
- data/lib/ransack/translate.rb +2 -2
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +4 -4
- data/spec/mongoid/adapters/mongoid/base_spec.rb +20 -1
- data/spec/mongoid/nodes/condition_spec.rb +15 -0
- data/spec/mongoid/support/mongoid.yml +5 -0
- data/spec/mongoid/support/schema.rb +4 -0
- data/spec/mongoid_spec_helper.rb +13 -9
- data/spec/ransack/adapters/active_record/base_spec.rb +249 -71
- data/spec/ransack/adapters/active_record/context_spec.rb +16 -18
- data/spec/ransack/helpers/form_builder_spec.rb +5 -2
- data/spec/ransack/helpers/form_helper_spec.rb +84 -14
- data/spec/ransack/nodes/condition_spec.rb +24 -0
- data/spec/ransack/nodes/grouping_spec.rb +56 -0
- data/spec/ransack/predicate_spec.rb +5 -5
- data/spec/ransack/search_spec.rb +79 -70
- data/spec/support/schema.rb +43 -29
- metadata +17 -12
data/spec/support/schema.rb
CHANGED
@@ -25,23 +25,30 @@ else
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class Person < ActiveRecord::Base
|
28
|
-
if ActiveRecord::VERSION::MAJOR == 3
|
28
|
+
if ::ActiveRecord::VERSION::MAJOR == 3
|
29
29
|
default_scope order('id DESC')
|
30
30
|
else
|
31
31
|
default_scope { order(id: :desc) }
|
32
32
|
end
|
33
|
-
belongs_to :parent, :
|
34
|
-
has_many :children, :
|
33
|
+
belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
|
34
|
+
has_many :children, class_name: 'Person', foreign_key: :parent_id
|
35
35
|
has_many :articles
|
36
36
|
if ActiveRecord::VERSION::MAJOR == 3
|
37
|
-
|
37
|
+
if RUBY_VERSION >= '2.3'
|
38
|
+
has_many :published_articles, class_name: "Article",
|
39
|
+
conditions: "published = 't'"
|
40
|
+
else
|
41
|
+
has_many :published_articles, class_name: "Article",
|
42
|
+
conditions: { published: true }
|
43
|
+
end
|
38
44
|
else
|
39
|
-
has_many :published_articles, ->{ where(published: true) },
|
45
|
+
has_many :published_articles, ->{ where(published: true) },
|
46
|
+
class_name: "Article"
|
40
47
|
end
|
41
48
|
has_many :comments
|
42
|
-
has_many :authored_article_comments, :
|
43
|
-
:
|
44
|
-
has_many :notes, :
|
49
|
+
has_many :authored_article_comments, through: :articles,
|
50
|
+
source: :comments, foreign_key: :person_id
|
51
|
+
has_many :notes, as: :notable
|
45
52
|
|
46
53
|
scope :restricted, lambda { where("restricted = 1") }
|
47
54
|
scope :active, lambda { where("active = 1") }
|
@@ -50,7 +57,12 @@ class Person < ActiveRecord::Base
|
|
50
57
|
of_age ? where("age >= ?", 18) : where("age < ?", 18)
|
51
58
|
}
|
52
59
|
|
53
|
-
|
60
|
+
alias_attribute :full_name, :name
|
61
|
+
|
62
|
+
ransack_alias :term, :name_or_email
|
63
|
+
ransack_alias :daddy, :parent_name
|
64
|
+
|
65
|
+
ransacker :reversed_name, formatter: proc { |v| v.reverse } do |parent|
|
54
66
|
parent.table[:name]
|
55
67
|
end
|
56
68
|
|
@@ -84,14 +96,15 @@ class Person < ActiveRecord::Base
|
|
84
96
|
GROUP BY articles.person_id
|
85
97
|
)
|
86
98
|
SQL
|
99
|
+
.squish
|
87
100
|
Arel.sql(query)
|
88
101
|
end
|
89
102
|
|
90
103
|
def self.ransackable_attributes(auth_object = nil)
|
91
104
|
if auth_object == :admin
|
92
|
-
|
105
|
+
super - ['only_sort']
|
93
106
|
else
|
94
|
-
|
107
|
+
super - ['only_sort', 'only_admin']
|
95
108
|
end
|
96
109
|
end
|
97
110
|
|
@@ -102,16 +115,17 @@ class Person < ActiveRecord::Base
|
|
102
115
|
column_names + _ransackers.keys - ['only_search', 'only_admin']
|
103
116
|
end
|
104
117
|
end
|
105
|
-
|
106
118
|
end
|
107
119
|
|
108
120
|
class Article < ActiveRecord::Base
|
109
121
|
belongs_to :person
|
110
122
|
has_many :comments
|
111
123
|
has_and_belongs_to_many :tags
|
112
|
-
has_many :notes, :
|
124
|
+
has_many :notes, as: :notable
|
113
125
|
|
114
|
-
|
126
|
+
alias_attribute :content, :body
|
127
|
+
|
128
|
+
if ::ActiveRecord::VERSION::STRING >= '3.1'
|
115
129
|
default_scope { where("'default_scope' = 'default_scope'") }
|
116
130
|
else # Rails 3.0 does not accept a block
|
117
131
|
default_scope where("'default_scope' = 'default_scope'")
|
@@ -146,7 +160,7 @@ class Tag < ActiveRecord::Base
|
|
146
160
|
end
|
147
161
|
|
148
162
|
class Note < ActiveRecord::Base
|
149
|
-
belongs_to :notable, :
|
163
|
+
belongs_to :notable, polymorphic: true
|
150
164
|
end
|
151
165
|
|
152
166
|
module Schema
|
@@ -154,7 +168,7 @@ module Schema
|
|
154
168
|
ActiveRecord::Migration.verbose = false
|
155
169
|
|
156
170
|
ActiveRecord::Schema.define do
|
157
|
-
create_table :people, :
|
171
|
+
create_table :people, force: true do |t|
|
158
172
|
t.integer :parent_id
|
159
173
|
t.string :name
|
160
174
|
t.string :email
|
@@ -171,7 +185,7 @@ module Schema
|
|
171
185
|
t.timestamps null: false
|
172
186
|
end
|
173
187
|
|
174
|
-
create_table :articles, :
|
188
|
+
create_table :articles, force: true do |t|
|
175
189
|
t.integer :person_id
|
176
190
|
t.string :title
|
177
191
|
t.text :subject_header
|
@@ -179,28 +193,28 @@ module Schema
|
|
179
193
|
t.boolean :published, default: true
|
180
194
|
end
|
181
195
|
|
182
|
-
create_table :comments, :
|
196
|
+
create_table :comments, force: true do |t|
|
183
197
|
t.integer :article_id
|
184
198
|
t.integer :person_id
|
185
199
|
t.text :body
|
186
200
|
end
|
187
201
|
|
188
|
-
create_table :tags, :
|
202
|
+
create_table :tags, force: true do |t|
|
189
203
|
t.string :name
|
190
204
|
end
|
191
205
|
|
192
|
-
create_table :articles_tags, :
|
206
|
+
create_table :articles_tags, force: true, id: false do |t|
|
193
207
|
t.integer :article_id
|
194
208
|
t.integer :tag_id
|
195
209
|
end
|
196
210
|
|
197
|
-
create_table :notes, :
|
211
|
+
create_table :notes, force: true do |t|
|
198
212
|
t.integer :notable_id
|
199
213
|
t.string :notable_type
|
200
214
|
t.string :note
|
201
215
|
end
|
202
216
|
|
203
|
-
create_table :recommendations, :
|
217
|
+
create_table :recommendations, force: true do |t|
|
204
218
|
t.integer :person_id
|
205
219
|
t.integer :target_person_id
|
206
220
|
t.integer :article_id
|
@@ -209,22 +223,22 @@ module Schema
|
|
209
223
|
|
210
224
|
10.times do
|
211
225
|
person = Person.make
|
212
|
-
Note.make(:
|
226
|
+
Note.make(notable: person)
|
213
227
|
3.times do
|
214
|
-
article = Article.make(:
|
228
|
+
article = Article.make(person: person)
|
215
229
|
3.times do
|
216
230
|
article.tags = [Tag.make, Tag.make, Tag.make]
|
217
231
|
end
|
218
|
-
Note.make(:
|
232
|
+
Note.make(notable: article)
|
219
233
|
10.times do
|
220
|
-
Comment.make(:
|
234
|
+
Comment.make(article: article, person: person)
|
221
235
|
end
|
222
236
|
end
|
223
237
|
end
|
224
238
|
|
225
239
|
Comment.make(
|
226
|
-
:
|
227
|
-
:
|
228
|
-
|
240
|
+
body: 'First post!',
|
241
|
+
article: Article.make(title: 'Hello, world!')
|
242
|
+
)
|
229
243
|
end
|
230
244
|
end
|
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: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -74,28 +74,28 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '1.
|
77
|
+
version: '1.3'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '1.
|
84
|
+
version: '1.3'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: rspec
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
89
|
- - "~>"
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version: '
|
91
|
+
version: '3'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version: '
|
98
|
+
version: '3'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: machinist
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,28 +158,28 @@ dependencies:
|
|
158
158
|
requirements:
|
159
159
|
- - '='
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version: 0.3.
|
161
|
+
version: 0.3.20
|
162
162
|
type: :development
|
163
163
|
prerelease: false
|
164
164
|
version_requirements: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
166
|
- - '='
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version: 0.3.
|
168
|
+
version: 0.3.20
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: pry
|
171
171
|
requirement: !ruby/object:Gem::Requirement
|
172
172
|
requirements:
|
173
173
|
- - '='
|
174
174
|
- !ruby/object:Gem::Version
|
175
|
-
version: 0.
|
175
|
+
version: '0.10'
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
178
|
version_requirements: !ruby/object:Gem::Requirement
|
179
179
|
requirements:
|
180
180
|
- - '='
|
181
181
|
- !ruby/object:Gem::Version
|
182
|
-
version: 0.
|
182
|
+
version: '0.10'
|
183
183
|
description: Ransack is the successor to the MetaSearch gem. It improves and expands
|
184
184
|
upon MetaSearch's functionality, but does not have a 100%-compatible API.
|
185
185
|
email:
|
@@ -234,14 +234,19 @@ files:
|
|
234
234
|
- lib/ransack/helpers/form_builder.rb
|
235
235
|
- lib/ransack/helpers/form_helper.rb
|
236
236
|
- lib/ransack/locale/cs.yml
|
237
|
+
- lib/ransack/locale/da.yml
|
237
238
|
- lib/ransack/locale/de.yml
|
238
239
|
- lib/ransack/locale/en.yml
|
239
240
|
- lib/ransack/locale/es.yml
|
240
241
|
- lib/ransack/locale/fr.yml
|
241
242
|
- lib/ransack/locale/hu.yml
|
243
|
+
- lib/ransack/locale/id.yml
|
244
|
+
- lib/ransack/locale/ja.yml
|
242
245
|
- lib/ransack/locale/nl.yml
|
246
|
+
- lib/ransack/locale/pt-BR.yml
|
243
247
|
- lib/ransack/locale/ro.yml
|
244
|
-
- lib/ransack/locale/zh.yml
|
248
|
+
- lib/ransack/locale/zh-CN.yml
|
249
|
+
- lib/ransack/locale/zh-TW.yml
|
245
250
|
- lib/ransack/naming.rb
|
246
251
|
- lib/ransack/nodes.rb
|
247
252
|
- lib/ransack/nodes/attribute.rb
|
@@ -312,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
312
317
|
version: '0'
|
313
318
|
requirements: []
|
314
319
|
rubyforge_project: ransack
|
315
|
-
rubygems_version: 2.4
|
320
|
+
rubygems_version: 2.6.4
|
316
321
|
signing_key:
|
317
322
|
specification_version: 4
|
318
323
|
summary: Object-based searching for Active Record and Mongoid (currently).
|