ransack 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -4
  3. data/CONTRIBUTING.md +12 -4
  4. data/Gemfile +4 -5
  5. data/README.md +160 -55
  6. data/lib/ransack.rb +1 -1
  7. data/lib/ransack/adapters/active_record/3.0/context.rb +16 -0
  8. data/lib/ransack/adapters/active_record/3.1/context.rb +24 -0
  9. data/lib/ransack/adapters/active_record/base.rb +6 -0
  10. data/lib/ransack/adapters/active_record/context.rb +49 -1
  11. data/lib/ransack/configuration.rb +23 -6
  12. data/lib/ransack/constants.rb +46 -45
  13. data/lib/ransack/context.rb +19 -2
  14. data/lib/ransack/helpers/form_builder.rb +5 -4
  15. data/lib/ransack/helpers/form_helper.rb +34 -14
  16. data/lib/ransack/locale/hu.yml +70 -0
  17. data/lib/ransack/locale/nl.yml +70 -0
  18. data/lib/ransack/nodes/attribute.rb +2 -2
  19. data/lib/ransack/nodes/condition.rb +29 -12
  20. data/lib/ransack/nodes/grouping.rb +6 -6
  21. data/lib/ransack/nodes/node.rb +1 -1
  22. data/lib/ransack/nodes/value.rb +1 -1
  23. data/lib/ransack/predicate.rb +4 -5
  24. data/lib/ransack/ransacker.rb +1 -1
  25. data/lib/ransack/search.rb +39 -13
  26. data/lib/ransack/translate.rb +7 -8
  27. data/lib/ransack/version.rb +1 -1
  28. data/ransack.gemspec +5 -5
  29. data/spec/ransack/adapters/active_record/base_spec.rb +78 -35
  30. data/spec/ransack/adapters/active_record/context_spec.rb +58 -15
  31. data/spec/ransack/configuration_spec.rb +18 -18
  32. data/spec/ransack/dependencies_spec.rb +1 -1
  33. data/spec/ransack/helpers/form_builder_spec.rb +29 -29
  34. data/spec/ransack/helpers/form_helper_spec.rb +14 -1
  35. data/spec/ransack/nodes/condition_spec.rb +21 -2
  36. data/spec/ransack/predicate_spec.rb +49 -9
  37. data/spec/ransack/search_spec.rb +178 -143
  38. data/spec/ransack/translate_spec.rb +1 -1
  39. data/spec/spec_helper.rb +1 -0
  40. data/spec/support/schema.rb +26 -21
  41. metadata +15 -11
@@ -7,7 +7,7 @@ module Ransack
7
7
  it 'translate namespaced attribute like AR does' do
8
8
  ar_translation = ::Namespace::Article.human_attribute_name(:title)
9
9
  ransack_translation = Ransack::Translate.attribute(:title, :context => ::Namespace::Article.search.context)
10
- ransack_translation.should eq ar_translation
10
+ expect(ransack_translation).to eq ar_translation
11
11
  end
12
12
  end
13
13
  end
@@ -3,6 +3,7 @@ require 'sham'
3
3
  require 'faker'
4
4
  require 'ransack'
5
5
 
6
+ I18n.enforce_available_locales = false
6
7
  Time.zone = 'Eastern Time (US & Canada)'
7
8
  I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'support', '*.yml')]
8
9
 
@@ -28,15 +28,19 @@ class Person < ActiveRecord::Base
28
28
  else
29
29
  default_scope { order(id: :desc) }
30
30
  end
31
- belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
32
- has_many :children, class_name: 'Person', foreign_key: :parent_id
31
+ belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
32
+ has_many :children, :class_name => 'Person', :foreign_key => :parent_id
33
33
  has_many :articles
34
34
  has_many :comments
35
- has_many :authored_article_comments, through: :articles,
36
- source: :comments, foreign_key: :person_id
37
- has_many :notes, as: :notable
35
+ has_many :authored_article_comments, :through => :articles,
36
+ :source => :comments, :foreign_key => :person_id
37
+ has_many :notes, :as => :notable
38
38
 
39
- ransacker :reversed_name, formatter: proc { |v| v.reverse } do |parent|
39
+ scope :restricted, lambda { where("restricted = 1") }
40
+ scope :active, lambda { where("active = 1") }
41
+ scope :over_age, lambda { |y| where(["age > ?", y]) }
42
+
43
+ ransacker :reversed_name, :formatter => proc { |v| v.reverse } do |parent|
40
44
  parent.table[:name]
41
45
  end
42
46
 
@@ -80,10 +84,10 @@ class Person < ActiveRecord::Base
80
84
  end
81
85
 
82
86
  class Article < ActiveRecord::Base
83
- belongs_to :person
84
- has_many :comments
87
+ belongs_to :person
88
+ has_many :comments
85
89
  has_and_belongs_to_many :tags
86
- has_many :notes, as: :notable
90
+ has_many :notes, :as => :notable
87
91
  end
88
92
 
89
93
  module Namespace
@@ -108,7 +112,7 @@ class Tag < ActiveRecord::Base
108
112
  end
109
113
 
110
114
  class Note < ActiveRecord::Base
111
- belongs_to :notable, polymorphic: true
115
+ belongs_to :notable, :polymorphic => true
112
116
  end
113
117
 
114
118
  module Schema
@@ -116,7 +120,7 @@ module Schema
116
120
  ActiveRecord::Migration.verbose = false
117
121
 
118
122
  ActiveRecord::Schema.define do
119
- create_table :people, force: true do |t|
123
+ create_table :people, :force => true do |t|
120
124
  t.integer :parent_id
121
125
  t.string :name
122
126
  t.string :email
@@ -128,28 +132,28 @@ module Schema
128
132
  t.timestamps
129
133
  end
130
134
 
131
- create_table :articles, force: true do |t|
135
+ create_table :articles, :force => true do |t|
132
136
  t.integer :person_id
133
137
  t.string :title
134
138
  t.text :body
135
139
  end
136
140
 
137
- create_table :comments, force: true do |t|
141
+ create_table :comments, :force => true do |t|
138
142
  t.integer :article_id
139
143
  t.integer :person_id
140
144
  t.text :body
141
145
  end
142
146
 
143
- create_table :tags, force: true do |t|
147
+ create_table :tags, :force => true do |t|
144
148
  t.string :name
145
149
  end
146
150
 
147
- create_table :articles_tags, force: true, id: false do |t|
151
+ create_table :articles_tags, :force => true, :id => false do |t|
148
152
  t.integer :article_id
149
153
  t.integer :tag_id
150
154
  end
151
155
 
152
- create_table :notes, force: true do |t|
156
+ create_table :notes, :force => true do |t|
153
157
  t.integer :notable_id
154
158
  t.string :notable_type
155
159
  t.string :note
@@ -159,21 +163,22 @@ module Schema
159
163
 
160
164
  10.times do
161
165
  person = Person.make
162
- Note.make(notable: person)
166
+ Note.make(:notable => person)
163
167
  3.times do
164
- article = Article.make(person: person)
168
+ article = Article.make(:person => person)
165
169
  3.times do
166
170
  article.tags = [Tag.make, Tag.make, Tag.make]
167
171
  end
168
- Note.make(notable: article)
172
+ Note.make(:notable => article)
169
173
  10.times do
170
- Comment.make(article: article, person: person)
174
+ Comment.make(:article => article, :person => person)
171
175
  end
172
176
  end
173
177
  end
174
178
 
175
179
  Comment.make(
176
- body: 'First post!', article: Article.make(title: 'Hello, world!')
180
+ :body => 'First post!',
181
+ :article => Article.make(:title => 'Hello, world!')
177
182
  )
178
183
  end
179
184
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
8
8
  - Ryan Bigg
9
+ - Jon Atack
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-04-30 00:00:00.000000000 Z
13
+ date: 2014-08-23 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: actionpack
@@ -73,28 +74,28 @@ dependencies:
73
74
  requirements:
74
75
  - - "~>"
75
76
  - !ruby/object:Gem::Version
76
- version: 1.0.0
77
+ version: '1.1'
77
78
  type: :runtime
78
79
  prerelease: false
79
80
  version_requirements: !ruby/object:Gem::Requirement
80
81
  requirements:
81
82
  - - "~>"
82
83
  - !ruby/object:Gem::Version
83
- version: 1.0.0
84
+ version: '1.1'
84
85
  - !ruby/object:Gem::Dependency
85
86
  name: rspec
86
87
  requirement: !ruby/object:Gem::Requirement
87
88
  requirements:
88
89
  - - "~>"
89
90
  - !ruby/object:Gem::Version
90
- version: 2.8.0
91
+ version: 2.14.0
91
92
  type: :development
92
93
  prerelease: false
93
94
  version_requirements: !ruby/object:Gem::Requirement
94
95
  requirements:
95
96
  - - "~>"
96
97
  - !ruby/object:Gem::Version
97
- version: 2.8.0
98
+ version: 2.14.0
98
99
  - !ruby/object:Gem::Dependency
99
100
  name: machinist
100
101
  requirement: !ruby/object:Gem::Requirement
@@ -141,16 +142,16 @@ dependencies:
141
142
  name: pg
142
143
  requirement: !ruby/object:Gem::Requirement
143
144
  requirements:
144
- - - '='
145
+ - - ">="
145
146
  - !ruby/object:Gem::Version
146
- version: 0.17.0
147
+ version: '0'
147
148
  type: :development
148
149
  prerelease: false
149
150
  version_requirements: !ruby/object:Gem::Requirement
150
151
  requirements:
151
- - - '='
152
+ - - ">="
152
153
  - !ruby/object:Gem::Version
153
- version: 0.17.0
154
+ version: '0'
154
155
  - !ruby/object:Gem::Dependency
155
156
  name: mysql2
156
157
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +185,7 @@ description: Ransack is the successor to the MetaSearch gem. It improves and exp
184
185
  email:
185
186
  - ernie@erniemiller.org
186
187
  - radarlistener@gmail.com
188
+ - jonnyatack@gmail.com
187
189
  executables: []
188
190
  extensions: []
189
191
  extra_rdoc_files: []
@@ -214,6 +216,8 @@ files:
214
216
  - lib/ransack/locale/en.yml
215
217
  - lib/ransack/locale/es.yml
216
218
  - lib/ransack/locale/fr.yml
219
+ - lib/ransack/locale/hu.yml
220
+ - lib/ransack/locale/nl.yml
217
221
  - lib/ransack/locale/zh.yml
218
222
  - lib/ransack/naming.rb
219
223
  - lib/ransack/nodes.rb
@@ -272,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
276
  version: '0'
273
277
  requirements: []
274
278
  rubyforge_project: ransack
275
- rubygems_version: 2.2.0
279
+ rubygems_version: 2.4.1
276
280
  signing_key:
277
281
  specification_version: 4
278
282
  summary: Object-based searching for ActiveRecord (currently).