ransack_wrap 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +18 -0
- data/lib/generators/rails/searcher_generator.rb +2 -0
- data/lib/generators/rails/templates/searcher.rb +1 -1
- data/lib/ransack_wrap.rb +9 -3
- data/lib/ransack_wrap/adapters/active_record.rb +30 -10
- data/lib/ransack_wrap/helpers/form_helper.rb +7 -0
- data/lib/ransack_wrap/railtie.rb +9 -8
- data/lib/ransack_wrap/search.rb +28 -5
- data/lib/ransack_wrap/version.rb +1 -1
- data/ransack_wrap.gemspec +11 -3
- data/spec/blueprints/articles.rb +5 -0
- data/spec/blueprints/comments.rb +5 -0
- data/spec/blueprints/notes.rb +5 -0
- data/spec/blueprints/people.rb +8 -0
- data/spec/blueprints/tags.rb +3 -0
- data/spec/console.rb +23 -0
- data/spec/helpers/person_searcher.rb +13 -0
- data/spec/helpers/ransack_wrap_helper.rb +11 -0
- data/spec/ransack_wrap/dependencies_spec.rb +6 -0
- data/spec/ransack_wrap/search_spec.rb +69 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/support/schema.rb +108 -0
- metadata +115 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ab10eb36103ea6b478e5efd62eb71a3bfe843b9
|
4
|
+
data.tar.gz: ce920eddfcc840d8536be5728cc2e6fde3daafdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48130aa446959608d86ae24f701d3a19b7baf7099d8b379f94aafaee5f118f191aaad51cf6bef92072870c63b93b5960d55ba7e4e87410790831954ca67352b1
|
7
|
+
data.tar.gz: 657e5be0694ce9e0bf8360e4499837e326089390deeb23865f7496713245a4afd8107bb7c90c734225e1c639b1d403213c570e1eca83a9d52d5cc946bc1a9690
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1 +1,19 @@
|
|
1
|
+
# :enddoc:
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |rspec|
|
7
|
+
rspec.rspec_opts = ['--backtrace']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
11
|
+
|
12
|
+
desc "Open an irb session with Ransack and the sample data used in specs"
|
13
|
+
task :console do
|
14
|
+
require 'irb'
|
15
|
+
require 'irb/completion'
|
16
|
+
require 'console'
|
17
|
+
ARGV.clear
|
18
|
+
IRB.start
|
19
|
+
end
|
data/lib/ransack_wrap.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
require "ransack_wrap/version"
|
2
|
+
|
3
|
+
require "active_support/core_ext"
|
4
|
+
require "active_attr"
|
5
|
+
require "ransack"
|
6
|
+
|
2
7
|
require "ransack_wrap/search"
|
3
8
|
require "ransack_wrap/scopes"
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
9
|
+
require "ransack_wrap/adapters/active_record"
|
10
|
+
require "ransack_wrap/helpers"
|
11
|
+
require "ransack_wrap/railtie" if defined?(Rails)
|
7
12
|
|
8
13
|
module RansackWrap
|
9
14
|
# Your code goes here...
|
10
15
|
end
|
11
16
|
|
17
|
+
# :stopdoc:
|
12
18
|
ActionController::Base.helper RansackWrap::Helpers::FormHelper
|
@@ -1,26 +1,46 @@
|
|
1
|
-
require
|
1
|
+
require "active_record"
|
2
2
|
|
3
3
|
module RansackWrap
|
4
|
+
# :stopdoc:
|
4
5
|
module Adapters
|
5
6
|
module ActiveRecord
|
6
7
|
module Base
|
7
|
-
|
8
|
-
send(:searcher_class_for, name).new(self, params)
|
9
|
-
end
|
8
|
+
# :startdoc:
|
10
9
|
|
10
|
+
##
|
11
|
+
# Creates new searcher using RansackWrap::Search subclass for current model.
|
12
|
+
#
|
13
|
+
# In the example below it creates instance of +UserSearcher+ class (which must be defined in +app/searchers/user_searcher.rb)+
|
14
|
+
#
|
15
|
+
# User.wrap_searcher(params[:q])
|
16
|
+
# # => UserSearcher.new
|
11
17
|
def wrap_searcher(params = {})
|
12
|
-
send
|
18
|
+
send(:wrap_searcher_as, name, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Creates new searcher using custom named searcher class.
|
23
|
+
#
|
24
|
+
# In the example below it creates instance of +SharedSearcher+ class (which must be defined in +app/searchers/shared_searcher.rb)+
|
25
|
+
#
|
26
|
+
# User.wrap_searcher(:shared, params[:q])
|
27
|
+
# # => SharedSearcher.new
|
28
|
+
#
|
29
|
+
# :call-seq:
|
30
|
+
# wrap_searcher_as(:name, params = {})
|
31
|
+
# wrap_searcher_as("name", params = {})
|
32
|
+
def wrap_searcher_as(name, params = {})
|
33
|
+
send(:searcher_class_for, name).new(self, params)
|
13
34
|
end
|
14
35
|
|
15
|
-
private
|
36
|
+
private
|
16
37
|
def searcher_class_for(name)
|
17
|
-
name
|
18
|
-
name ||= self.scoped.klass.name
|
19
|
-
name.concat("Searcher").constantize
|
38
|
+
name.to_s.camelize.concat("Searcher").constantize
|
20
39
|
end
|
21
40
|
end
|
22
41
|
end
|
23
42
|
end
|
24
43
|
end
|
25
44
|
|
26
|
-
|
45
|
+
# :stopdoc:
|
46
|
+
ActiveRecord::Base.extend(RansackWrap::Adapters::ActiveRecord::Base)
|
@@ -1,6 +1,13 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
|
1
3
|
module RansackWrap
|
2
4
|
module Helpers
|
3
5
|
module FormHelper
|
6
|
+
# :startdoc:
|
7
|
+
|
8
|
+
##
|
9
|
+
# Extends original +search_form_for+ method from Ransack gem
|
10
|
+
# to also support RansackWrap::Search instances.
|
4
11
|
def search_form_for(record, options = {}, &proc)
|
5
12
|
if record.is_a?(Ransack::Search) || record.is_a?(RansackWrap::Search)
|
6
13
|
search = record
|
data/lib/ransack_wrap/railtie.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'rails/railtie'
|
2
2
|
|
3
|
-
|
3
|
+
# :nodoc: all
|
4
|
+
module RansackWrap
|
4
5
|
class Railtie < Rails::Railtie
|
5
|
-
|
6
|
-
app
|
7
|
-
|
8
|
-
Rails::Generators.configure! app.config.generators
|
6
|
+
config.after_initialize do |app|
|
7
|
+
app.config.paths.add 'app/searchers', eager_load: true
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
module
|
12
|
+
module ActiveModel
|
14
13
|
class Railtie < Rails::Railtie
|
15
|
-
|
16
|
-
app.
|
14
|
+
generators do |app|
|
15
|
+
app ||= Rails.application # Rails 3.0.x does not yield `app`
|
16
|
+
|
17
|
+
Rails::Generators.configure! app.config.generators
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/ransack_wrap/search.rb
CHANGED
@@ -2,16 +2,22 @@ module RansackWrap
|
|
2
2
|
class Search
|
3
3
|
include Ransack::Naming
|
4
4
|
|
5
|
+
class_attribute :ransack_aliases, instance_writer: false
|
6
|
+
self.ransack_aliases = {}.with_indifferent_access
|
7
|
+
|
5
8
|
attr_reader :base
|
6
9
|
|
7
10
|
def initialize(object, params = {})
|
8
11
|
@base = scope_class.new(object)
|
9
12
|
|
10
|
-
params
|
11
|
-
ransack_params = params.slice! *
|
12
|
-
|
13
|
+
params = {} unless params.is_a? Hash
|
14
|
+
ransack_params = params.slice! *scope_keys+ransack_aliases.keys.map(&:to_sym)
|
15
|
+
|
16
|
+
params.slice!(*scope_keys).each do |key, val|
|
17
|
+
ransack_params[ransack_aliases[key].to_sym] = val
|
18
|
+
end
|
13
19
|
|
14
|
-
build params.with_indifferent_access
|
20
|
+
build params.with_indifferent_access
|
15
21
|
ransack.build ransack_params.with_indifferent_access
|
16
22
|
end
|
17
23
|
|
@@ -41,6 +47,8 @@ module RansackWrap
|
|
41
47
|
base.send method, *args
|
42
48
|
elsif ransack.respond_to? name
|
43
49
|
ransack.send method, *args
|
50
|
+
elsif ransack_alias_method?(name)
|
51
|
+
ransack.send ransack_aliases[name], *args
|
44
52
|
else
|
45
53
|
super
|
46
54
|
end
|
@@ -50,11 +58,26 @@ module RansackWrap
|
|
50
58
|
super or begin
|
51
59
|
name = method.to_s
|
52
60
|
writer = name.sub!(/\=$/, '')
|
53
|
-
base.attribute_method?(name) || ransack.respond_to?(name) || false
|
61
|
+
base.attribute_method?(name) || ransack.respond_to?(name) || ransack_alias_method?(name) || false
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
65
|
+
def self.alias_to_ransack(new_name, old_name, writer: true)
|
66
|
+
new_hash = {}
|
67
|
+
new_hash[new_name.to_s] = old_name.to_s
|
68
|
+
new_hash["#{new_name}=".to_s] = "#{old_name}=" if writer
|
69
|
+
ransack_aliases.merge! new_hash
|
70
|
+
end
|
71
|
+
|
57
72
|
private
|
73
|
+
def ransack_alias_method?(name)
|
74
|
+
ransack_aliases.key?(name) && ransack.respond_to?(ransack_aliases[name])
|
75
|
+
end
|
76
|
+
|
77
|
+
def scope_keys
|
78
|
+
@scope_keys ||= base.attributes.keys.map(&:to_sym)
|
79
|
+
end
|
80
|
+
|
58
81
|
def scope_class
|
59
82
|
raise NameError unless self.class.const_defined?(:Scopes)
|
60
83
|
self.class.const_get(:Scopes)
|
data/lib/ransack_wrap/version.rb
CHANGED
data/ransack_wrap.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# :enddoc:
|
2
3
|
|
3
4
|
lib = File.expand_path('../lib', __FILE__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -19,13 +20,20 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
21
|
spec.require_paths = ["lib"]
|
21
22
|
|
22
|
-
spec.add_dependency 'ransack', '>=
|
23
|
+
spec.add_dependency 'ransack', '>= 0.7.3', '< 1.2'
|
23
24
|
spec.add_dependency 'active_attr', '>= 0.8.2'
|
24
25
|
spec.add_dependency 'activerecord', '>= 3.0.2', "< 4.0"
|
25
26
|
spec.add_dependency 'actionpack', '>= 3.0.2', "< 4.0"
|
26
|
-
spec.
|
27
|
-
spec.add_runtime_dependency "activesupport", ">= 3.0.2", "< 4.0"
|
27
|
+
spec.add_dependency 'activesupport', '>= 3.0.2', "< 4.0"
|
28
28
|
spec.add_dependency 'polyamorous', '>= 0.5.0'
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "activemodel", ">= 3.0.2", "< 4.0"
|
31
|
+
|
29
32
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
33
|
spec.add_development_dependency "rake"
|
34
|
+
spec.add_development_dependency 'rspec', '~> 2.8.0'
|
35
|
+
spec.add_development_dependency 'machinist', '~> 1.0.6'
|
36
|
+
spec.add_development_dependency 'faker', '~> 0.9.5'
|
37
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.3'
|
38
|
+
spec.add_development_dependency 'pry'
|
31
39
|
end
|
data/spec/console.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# :enddoc:
|
2
|
+
|
3
|
+
Bundler.setup
|
4
|
+
require 'machinist/active_record'
|
5
|
+
require 'sham'
|
6
|
+
require 'faker'
|
7
|
+
require 'ransack_wrap'
|
8
|
+
|
9
|
+
Dir[File.expand_path('../../spec/{helpers,support,blueprints}/*.rb', __FILE__)]
|
10
|
+
.each do |f|
|
11
|
+
require f
|
12
|
+
end
|
13
|
+
|
14
|
+
Sham.define do
|
15
|
+
name { Faker::Name.name }
|
16
|
+
title { Faker::Lorem.sentence }
|
17
|
+
body { Faker::Lorem.paragraph }
|
18
|
+
salary { |index| 30000 + (index * 1000) }
|
19
|
+
tag_name { Faker::Lorem.words(3).join(' ') }
|
20
|
+
note { Faker::Lorem.words(7).join(' ') }
|
21
|
+
end
|
22
|
+
|
23
|
+
Schema.create
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# :nodoc: all
|
2
|
+
|
3
|
+
class PersonSearcher < RansackWrap::Search
|
4
|
+
class Scopes < RansackWrap::Scopes
|
5
|
+
attribute :only_with_large_salary, type: ActiveAttr::Typecasting::Boolean
|
6
|
+
|
7
|
+
def scope_only_with_large_salary(value)
|
8
|
+
scoped.with_large_salary
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_to_ransack :in_family_with, :children_name_or_parent_name_cont
|
13
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RansackWrap
|
4
|
+
describe Search do
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'does not raise exception for string :params argument' do
|
8
|
+
-> {
|
9
|
+
Person.wrap_searcher('')
|
10
|
+
}.should_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#build' do
|
15
|
+
it 'accept ransack attributes' do
|
16
|
+
search = Person.wrap_searcher(name_eq: 'Ernie')
|
17
|
+
condition = search.ransack.base[:name_eq]
|
18
|
+
condition.should be_a Ransack::Nodes::Condition
|
19
|
+
condition.predicate.name.should eq 'eq'
|
20
|
+
condition.attributes.first.name.should eq 'name'
|
21
|
+
condition.value.should eq 'Ernie'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#result' do
|
26
|
+
let(:people_table) { "#{quote_table_name("people")}" }
|
27
|
+
let(:people_name_field) { "#{quote_table_name("people")}.#{quote_column_name("name")}" }
|
28
|
+
let(:people_salary_field) { "#{quote_table_name("people")}.#{quote_column_name("salary")}" }
|
29
|
+
let(:parents_people_name_field) { "#{quote_table_name("parents_people")}.#{quote_column_name("name")}" }
|
30
|
+
let(:children_people_name_field) { "#{quote_table_name("children_people")}.#{quote_column_name("name")}" }
|
31
|
+
|
32
|
+
it 'evalutes Ransack attributes' do
|
33
|
+
search = Person.wrap_searcher(children_name_eq: 'Ernie')
|
34
|
+
search.result.should be_an ActiveRecord::Relation
|
35
|
+
search.result.to_sql.should match /#{children_people_name_field} = 'Ernie'/
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'evalutes Ransack aliased attributes' do
|
39
|
+
search = Person.wrap_searcher(in_family_with: 'Ernie')
|
40
|
+
search.result.should be_an ActiveRecord::Relation
|
41
|
+
search.should respond_to :in_family_with
|
42
|
+
search.ransack.should respond_to search.ransack_aliases[:in_family_with]
|
43
|
+
search.result.to_sql.should match /#{children_people_name_field} LIKE '%Ernie%'/
|
44
|
+
search.result.to_sql.should match /#{parents_people_name_field} LIKE '%Ernie%'/
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'evalutes Scopes attributes' do
|
48
|
+
search = Person.wrap_searcher(only_with_large_salary: true)
|
49
|
+
search.result.should be_an ActiveRecord::Relation
|
50
|
+
search.result.to_sql.should match /#{people_salary_field} > 40000/
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'evalutes Ransack alias and Scopes attributes' do
|
54
|
+
search = Person.wrap_searcher(in_family_with: 'Ernie', only_with_large_salary: true)
|
55
|
+
search.result.should be_an ActiveRecord::Relation
|
56
|
+
search.result.to_sql.should match /#{people_salary_field} > 40000/
|
57
|
+
search.result.to_sql.should match /#{children_people_name_field} LIKE '%Ernie%'/
|
58
|
+
search.result.to_sql.should match /#{parents_people_name_field} LIKE '%Ernie%'/
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'evalutes Ransack and skips Scopes boolean false attributes' do
|
62
|
+
search = Person.wrap_searcher(children_name_eq: 'Ernie', only_with_large_salary: false)
|
63
|
+
search.result.should be_an ActiveRecord::Relation
|
64
|
+
search.result.to_sql.should match /#{children_people_name_field} = 'Ernie'/
|
65
|
+
search.result.to_sql.should_not match /#{people_salary_field} > 40000/
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# :enddoc:
|
2
|
+
|
3
|
+
require 'machinist/active_record'
|
4
|
+
require 'sham'
|
5
|
+
require 'faker'
|
6
|
+
require 'ransack_wrap'
|
7
|
+
|
8
|
+
Time.zone = 'Eastern Time (US & Canada)'
|
9
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'support', '*.yml')]
|
10
|
+
|
11
|
+
Dir[File.expand_path('../{helpers,support,blueprints}/*.rb', __FILE__)].each do |f|
|
12
|
+
require f
|
13
|
+
end
|
14
|
+
|
15
|
+
Sham.define do
|
16
|
+
name { Faker::Name.name }
|
17
|
+
title { Faker::Lorem.sentence }
|
18
|
+
body { Faker::Lorem.paragraph }
|
19
|
+
salary { |index| 30000 + (index * 1000) }
|
20
|
+
tag_name { Faker::Lorem.words(3).join(' ') }
|
21
|
+
note { Faker::Lorem.words(7).join(' ') }
|
22
|
+
only_admin { Faker::Lorem.words(3).join(' ') }
|
23
|
+
only_search { Faker::Lorem.words(3).join(' ') }
|
24
|
+
only_sort { Faker::Lorem.words(3).join(' ') }
|
25
|
+
notable_id { |id| id }
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior'
|
30
|
+
|
31
|
+
config.before(:suite) do
|
32
|
+
puts '=' * 80
|
33
|
+
connection_name = ActiveRecord::Base.connection.adapter_name
|
34
|
+
puts "Running specs against #{connection_name}, ActiveRecord #{ActiveRecord::VERSION::STRING} and ARel #{Arel::VERSION}..."
|
35
|
+
puts '=' * 80
|
36
|
+
Schema.create
|
37
|
+
end
|
38
|
+
|
39
|
+
config.before(:all) { Sham.reset(:before_all) }
|
40
|
+
config.before(:each) { Sham.reset(:before_each) }
|
41
|
+
|
42
|
+
config.include RansackWrapHelper
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec::Matchers.define :be_like do |expected|
|
46
|
+
match do |actual|
|
47
|
+
actual.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip == expected.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
RSpec::Matchers.define :have_attribute_method do |expected|
|
52
|
+
match do |actual|
|
53
|
+
actual.attribute_method?(expected)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# :enddoc:
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
6
|
+
|
7
|
+
class Person < ActiveRecord::Base
|
8
|
+
if ActiveRecord::VERSION::MAJOR == 3
|
9
|
+
default_scope order('id DESC')
|
10
|
+
else
|
11
|
+
default_scope { order(id: :desc) }
|
12
|
+
end
|
13
|
+
belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
|
14
|
+
has_many :children, class_name: 'Person', foreign_key: :parent_id
|
15
|
+
has_many :articles
|
16
|
+
has_many :comments
|
17
|
+
has_many :authored_article_comments, through: :articles,
|
18
|
+
source: :comments, foreign_key: :person_id
|
19
|
+
has_many :notes, as: :notable
|
20
|
+
|
21
|
+
scope :with_large_salary, -> {
|
22
|
+
where("\"people\".\"salary\" > ?", 40000)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
class Article < ActiveRecord::Base
|
27
|
+
belongs_to :person
|
28
|
+
has_many :comments
|
29
|
+
has_and_belongs_to_many :tags
|
30
|
+
has_many :notes, as: :notable
|
31
|
+
end
|
32
|
+
|
33
|
+
class Comment < ActiveRecord::Base
|
34
|
+
belongs_to :article
|
35
|
+
belongs_to :person
|
36
|
+
end
|
37
|
+
|
38
|
+
class Tag < ActiveRecord::Base
|
39
|
+
has_and_belongs_to_many :articles
|
40
|
+
end
|
41
|
+
|
42
|
+
class Note < ActiveRecord::Base
|
43
|
+
belongs_to :notable, polymorphic: true
|
44
|
+
end
|
45
|
+
|
46
|
+
module Schema
|
47
|
+
def self.create
|
48
|
+
ActiveRecord::Migration.verbose = false
|
49
|
+
|
50
|
+
ActiveRecord::Schema.define do
|
51
|
+
create_table :people, force: true do |t|
|
52
|
+
t.integer :parent_id
|
53
|
+
t.string :name
|
54
|
+
t.string :email
|
55
|
+
t.string :only_search
|
56
|
+
t.string :only_sort
|
57
|
+
t.string :only_admin
|
58
|
+
t.integer :salary
|
59
|
+
t.boolean :awesome, default: false
|
60
|
+
t.timestamps
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table :articles, force: true do |t|
|
64
|
+
t.integer :person_id
|
65
|
+
t.string :title
|
66
|
+
t.text :body
|
67
|
+
end
|
68
|
+
|
69
|
+
create_table :comments, force: true do |t|
|
70
|
+
t.integer :article_id
|
71
|
+
t.integer :person_id
|
72
|
+
t.text :body
|
73
|
+
end
|
74
|
+
|
75
|
+
create_table :tags, force: true do |t|
|
76
|
+
t.string :name
|
77
|
+
end
|
78
|
+
|
79
|
+
create_table :articles_tags, force: true, id: false do |t|
|
80
|
+
t.integer :article_id
|
81
|
+
t.integer :tag_id
|
82
|
+
end
|
83
|
+
|
84
|
+
create_table :notes, force: true do |t|
|
85
|
+
t.integer :notable_id
|
86
|
+
t.string :notable_type
|
87
|
+
t.string :note
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
10.times do
|
92
|
+
person = Person.make
|
93
|
+
Note.make(notable: person)
|
94
|
+
3.times do
|
95
|
+
article = Article.make(person: person)
|
96
|
+
3.times do
|
97
|
+
article.tags = [Tag.make, Tag.make, Tag.make]
|
98
|
+
end
|
99
|
+
Note.make(notable: article)
|
100
|
+
10.times do
|
101
|
+
Comment.make(article: article, person: person)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
Comment.make(body: 'First post!', article: Article.make(title: 'Hello, world!'))
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack_wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tõnis Simo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ransack
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.7.3
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 0.7.3
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: active_attr
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,7 +85,7 @@ dependencies:
|
|
79
85
|
- !ruby/object:Gem::Version
|
80
86
|
version: '4.0'
|
81
87
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
88
|
+
name: activesupport
|
83
89
|
requirement: !ruby/object:Gem::Requirement
|
84
90
|
requirements:
|
85
91
|
- - '>='
|
@@ -99,7 +105,21 @@ dependencies:
|
|
99
105
|
- !ruby/object:Gem::Version
|
100
106
|
version: '4.0'
|
101
107
|
- !ruby/object:Gem::Dependency
|
102
|
-
name:
|
108
|
+
name: polyamorous
|
109
|
+
requirement: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 0.5.0
|
114
|
+
type: :runtime
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.5.0
|
121
|
+
- !ruby/object:Gem::Dependency
|
122
|
+
name: activemodel
|
103
123
|
requirement: !ruby/object:Gem::Requirement
|
104
124
|
requirements:
|
105
125
|
- - '>='
|
@@ -119,35 +139,91 @@ dependencies:
|
|
119
139
|
- !ruby/object:Gem::Version
|
120
140
|
version: '4.0'
|
121
141
|
- !ruby/object:Gem::Dependency
|
122
|
-
name:
|
142
|
+
name: bundler
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ~>
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '1.3'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ~>
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '1.3'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: rake
|
123
157
|
requirement: !ruby/object:Gem::Requirement
|
124
158
|
requirements:
|
125
159
|
- - '>='
|
126
160
|
- !ruby/object:Gem::Version
|
127
|
-
version: 0
|
128
|
-
type: :
|
161
|
+
version: '0'
|
162
|
+
type: :development
|
129
163
|
prerelease: false
|
130
164
|
version_requirements: !ruby/object:Gem::Requirement
|
131
165
|
requirements:
|
132
166
|
- - '>='
|
133
167
|
- !ruby/object:Gem::Version
|
134
|
-
version: 0
|
168
|
+
version: '0'
|
135
169
|
- !ruby/object:Gem::Dependency
|
136
|
-
name:
|
170
|
+
name: rspec
|
137
171
|
requirement: !ruby/object:Gem::Requirement
|
138
172
|
requirements:
|
139
173
|
- - ~>
|
140
174
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
175
|
+
version: 2.8.0
|
142
176
|
type: :development
|
143
177
|
prerelease: false
|
144
178
|
version_requirements: !ruby/object:Gem::Requirement
|
145
179
|
requirements:
|
146
180
|
- - ~>
|
147
181
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
182
|
+
version: 2.8.0
|
149
183
|
- !ruby/object:Gem::Dependency
|
150
|
-
name:
|
184
|
+
name: machinist
|
185
|
+
requirement: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 1.0.6
|
190
|
+
type: :development
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ~>
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 1.0.6
|
197
|
+
- !ruby/object:Gem::Dependency
|
198
|
+
name: faker
|
199
|
+
requirement: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ~>
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: 0.9.5
|
204
|
+
type: :development
|
205
|
+
prerelease: false
|
206
|
+
version_requirements: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ~>
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: 0.9.5
|
211
|
+
- !ruby/object:Gem::Dependency
|
212
|
+
name: sqlite3
|
213
|
+
requirement: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ~>
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: 1.3.3
|
218
|
+
type: :development
|
219
|
+
prerelease: false
|
220
|
+
version_requirements: !ruby/object:Gem::Requirement
|
221
|
+
requirements:
|
222
|
+
- - ~>
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: 1.3.3
|
225
|
+
- !ruby/object:Gem::Dependency
|
226
|
+
name: pry
|
151
227
|
requirement: !ruby/object:Gem::Requirement
|
152
228
|
requirements:
|
153
229
|
- - '>='
|
@@ -183,6 +259,18 @@ files:
|
|
183
259
|
- lib/ransack_wrap/search.rb
|
184
260
|
- lib/ransack_wrap/version.rb
|
185
261
|
- ransack_wrap.gemspec
|
262
|
+
- spec/blueprints/articles.rb
|
263
|
+
- spec/blueprints/comments.rb
|
264
|
+
- spec/blueprints/notes.rb
|
265
|
+
- spec/blueprints/people.rb
|
266
|
+
- spec/blueprints/tags.rb
|
267
|
+
- spec/console.rb
|
268
|
+
- spec/helpers/person_searcher.rb
|
269
|
+
- spec/helpers/ransack_wrap_helper.rb
|
270
|
+
- spec/ransack_wrap/dependencies_spec.rb
|
271
|
+
- spec/ransack_wrap/search_spec.rb
|
272
|
+
- spec/spec_helper.rb
|
273
|
+
- spec/support/schema.rb
|
186
274
|
homepage: http://github.com/estum/ransack_wrap
|
187
275
|
licenses:
|
188
276
|
- MIT
|
@@ -208,5 +296,17 @@ signing_key:
|
|
208
296
|
specification_version: 4
|
209
297
|
summary: Ransack Wrap helps to customize Ransack searching for each models, it allows
|
210
298
|
to easy overwrite and add search keys, scopes and queries
|
211
|
-
test_files:
|
299
|
+
test_files:
|
300
|
+
- spec/blueprints/articles.rb
|
301
|
+
- spec/blueprints/comments.rb
|
302
|
+
- spec/blueprints/notes.rb
|
303
|
+
- spec/blueprints/people.rb
|
304
|
+
- spec/blueprints/tags.rb
|
305
|
+
- spec/console.rb
|
306
|
+
- spec/helpers/person_searcher.rb
|
307
|
+
- spec/helpers/ransack_wrap_helper.rb
|
308
|
+
- spec/ransack_wrap/dependencies_spec.rb
|
309
|
+
- spec/ransack_wrap/search_spec.rb
|
310
|
+
- spec/spec_helper.rb
|
311
|
+
- spec/support/schema.rb
|
212
312
|
has_rdoc:
|