ransack 1.8.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +12 -3
  4. data/CHANGELOG.md +29 -5
  5. data/Gemfile +1 -9
  6. data/README.md +16 -25
  7. data/Rakefile +1 -22
  8. data/lib/polyamorous.rb +5 -18
  9. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +2 -2
  10. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +2 -2
  11. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +38 -0
  12. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +75 -0
  13. data/lib/ransack/adapters/active_record.rb +0 -9
  14. data/lib/ransack/adapters/active_record/base.rb +8 -0
  15. data/lib/ransack/adapters/active_record/context.rb +118 -182
  16. data/lib/ransack/adapters/active_record/ransack/context.rb +1 -8
  17. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  18. data/lib/ransack/constants.rb +1 -1
  19. data/lib/ransack/context.rb +4 -0
  20. data/lib/ransack/nodes/value.rb +1 -1
  21. data/lib/ransack/search.rb +1 -1
  22. data/lib/ransack/version.rb +1 -1
  23. data/ransack.gemspec +4 -3
  24. data/spec/helpers/polyamorous_helper.rb +7 -9
  25. data/spec/ransack/adapters/active_record/base_spec.rb +35 -0
  26. data/spec/ransack/adapters/active_record/context_spec.rb +3 -6
  27. data/spec/ransack/helpers/form_builder_spec.rb +3 -15
  28. data/spec/ransack/helpers/form_helper_spec.rb +11 -99
  29. data/spec/ransack/join_association_spec.rb +1 -6
  30. data/spec/ransack/join_dependency_spec.rb +1 -6
  31. data/spec/ransack/search_spec.rb +2 -2
  32. data/spec/support/schema.rb +3 -21
  33. metadata +10 -83
  34. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_association.rb +0 -76
  35. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_dependency.rb +0 -96
  36. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_association.rb +0 -2
  37. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_dependency.rb +0 -4
  38. data/lib/polyamorous/activerecord_4.1_ruby_2/join_association.rb +0 -2
  39. data/lib/polyamorous/activerecord_4.1_ruby_2/join_dependency.rb +0 -3
  40. data/lib/polyamorous/activerecord_4.1_ruby_2/make_polyamorous_inner_joins.rb +0 -14
  41. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_association.rb +0 -46
  42. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb +0 -87
  43. data/lib/polyamorous/activerecord_4.2_ruby_2/join_association.rb +0 -2
  44. data/lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb +0 -24
  45. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -173
  46. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
  47. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
  48. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  49. data/lib/ransack/adapters/mongoid.rb +0 -15
  50. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  51. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  52. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  53. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  54. data/lib/ransack/adapters/mongoid/base.rb +0 -134
  55. data/lib/ransack/adapters/mongoid/context.rb +0 -212
  56. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  57. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  58. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -59
  59. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -22
  60. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  61. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -18
  62. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  63. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
  64. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  65. data/spec/mongoid/configuration_spec.rb +0 -162
  66. data/spec/mongoid/dependencies_spec.rb +0 -8
  67. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  68. data/spec/mongoid/nodes/condition_spec.rb +0 -49
  69. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  70. data/spec/mongoid/predicate_spec.rb +0 -155
  71. data/spec/mongoid/search_spec.rb +0 -445
  72. data/spec/mongoid/support/mongoid.yml +0 -11
  73. data/spec/mongoid/support/schema.rb +0 -135
  74. data/spec/mongoid/translate_spec.rb +0 -14
  75. data/spec/mongoid_spec_helper.rb +0 -63
  76. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,135 +0,0 @@
1
- require 'mongoid'
2
-
3
- Mongoid.load!(File.expand_path("../mongoid.yml", __FILE__), :test)
4
- Mongo::Logger.logger.level = Logger::WARN if defined?(Mongo)
5
- Mongoid.purge!
6
-
7
- class Person
8
- include Mongoid::Document
9
- include Mongoid::Timestamps
10
-
11
- field :name, type: String
12
- field :email, type: String
13
- field :only_search, type: String
14
- field :only_sort, type: String
15
- field :only_admin, type: String
16
- field :salary, type: Integer
17
- field :awesome, type: Boolean, default: false
18
-
19
- belongs_to :parent, :class_name => 'Person', inverse_of: :children
20
- has_many :children, :class_name => 'Person', inverse_of: :parent
21
-
22
- has_many :articles
23
- has_many :comments
24
-
25
- ransack_alias :term, :name_or_email
26
-
27
- # has_many :authored_article_comments, :through => :articles,
28
- # :source => :comments, :foreign_key => :person_id
29
-
30
- has_many :notes, :as => :notable
31
-
32
- default_scope -> { order(id: :desc) }
33
-
34
- scope :restricted, lambda { where(restricted: 1) }
35
- scope :active, lambda { where(active: 1) }
36
- scope :over_age, lambda { |y| where(:age.gt => y) }
37
-
38
- ransacker :reversed_name, :formatter => proc { |v| v.reverse } do |parent|
39
- parent.table[:name]
40
- end
41
-
42
- ransacker :doubled_name do |parent|
43
- # Arel::Nodes::InfixOperation.new(
44
- # '||', parent.table[:name], parent.table[:name]
45
- # )
46
- parent.table[:name]
47
- end
48
-
49
- def self.ransackable_attributes(auth_object = nil)
50
- if auth_object == :admin
51
- all_ransackable_attributes - ['only_sort']
52
- else
53
- all_ransackable_attributes - ['only_sort', 'only_admin']
54
- end
55
- end
56
-
57
- def self.ransortable_attributes(auth_object = nil)
58
- if auth_object == :admin
59
- all_ransackable_attributes - ['only_search']
60
- else
61
- all_ransackable_attributes - ['only_search', 'only_admin']
62
- end
63
- end
64
- end
65
-
66
- class Musician < Person
67
- end
68
-
69
- class Article
70
- include Mongoid::Document
71
-
72
- field :title, type: String
73
- field :body, type: String
74
-
75
- belongs_to :person
76
- has_many :comments
77
- # has_and_belongs_to_many :tags
78
- has_many :notes, :as => :notable
79
- end
80
-
81
- module Namespace
82
- class Article < ::Article
83
-
84
- end
85
- end
86
-
87
- class Comment
88
- include Mongoid::Document
89
-
90
- field :body, type: String
91
-
92
-
93
- belongs_to :article
94
- belongs_to :person
95
- end
96
-
97
- class Tag
98
- include Mongoid::Document
99
-
100
- field :name, type: String
101
-
102
- # has_and_belongs_to_many :articles
103
- end
104
-
105
- class Note
106
- include Mongoid::Document
107
-
108
- field :note, type: String
109
-
110
- belongs_to :notable, :polymorphic => true
111
- end
112
-
113
- module Schema
114
- def self.create
115
- 10.times do
116
- person = Person.make.save!
117
- Note.make.save!(:notable => person)
118
- 3.times do
119
- article = Article.create!(:person => person)
120
- 3.times do
121
- # article.tags = [Tag.make.save!, Tag.make.save!, Tag.make.save!]
122
- end
123
- Note.create.save!(:notable => article)
124
- 10.times do
125
- Comment.create.save!(:article => article, :person => person)
126
- end
127
- end
128
- end
129
-
130
- Comment.create!(
131
- :body => 'First post!',
132
- :article => Article.create!(:title => 'Hello, world!')
133
- )
134
- end
135
- 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
@@ -1,63 +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',
13
- __FILE__)]
14
- .each { |f| require f }
15
-
16
- Sham.define do
17
- name { Faker::Name.name }
18
- title { Faker::Lorem.sentence }
19
- body { Faker::Lorem.paragraph }
20
- salary { |index| 30000 + (index * 1000) }
21
- tag_name { Faker::Lorem.words(3).join(' ') }
22
- note { Faker::Lorem.words(7).join(' ') }
23
- only_admin { Faker::Lorem.words(3).join(' ') }
24
- only_search { Faker::Lorem.words(3).join(' ') }
25
- only_sort { Faker::Lorem.words(3).join(' ') }
26
- notable_id { |id| id }
27
- end
28
-
29
- RSpec.configure do |config|
30
- config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior'
31
-
32
- config.before(:suite) do
33
- if ENV['DB'] == 'mongoid4'
34
- message = "Running Ransack specs with #{Mongoid.default_session.inspect
35
- }, Mongoid #{Mongoid::VERSION}, Moped #{Moped::VERSION
36
- }, Origin #{Origin::VERSION} and Ruby #{RUBY_VERSION}"
37
- else
38
- message = "Running Ransack specs with #{Mongoid.default_client.inspect
39
- }, Mongoid #{Mongoid::VERSION}, Mongo driver #{Mongo::VERSION}"
40
- end
41
- line = '=' * message.length
42
- puts line, message, line
43
- Schema.create
44
- end
45
-
46
- config.before(:all) { Sham.reset(:before_all) }
47
- config.before(:each) { Sham.reset(:before_each) }
48
-
49
- config.include RansackHelper
50
- end
51
-
52
- RSpec::Matchers.define :be_like do |expected|
53
- match do |actual|
54
- actual.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip ==
55
- expected.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip
56
- end
57
- end
58
-
59
- RSpec::Matchers.define :have_attribute_method do |expected|
60
- match do |actual|
61
- actual.attribute_method?(expected)
62
- end
63
- 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