-
-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #623 from rzane/ransack-alias
Allow creating aliases for ransack attributes.
- Loading branch information
Showing
10 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,21 @@ module Mongoid | |
end | ||
end | ||
|
||
describe '#ransack_alias' do | ||
it 'translates an alias to the correct attributes' do | ||
p = Person.create!(name: 'Meatloaf', email: '[email protected]') | ||
|
||
s = Person.ransack(term_cont: 'atlo') | ||
expect(s.result.to_a).to eq [p] | ||
|
||
s = Person.ransack(term_cont: 'babi') | ||
expect(s.result.to_a).to eq [p] | ||
|
||
s = Person.ransack(term_cont: 'nomatch') | ||
expect(s.result.to_a).to eq [] | ||
end | ||
end | ||
|
||
describe '#ransacker' do | ||
# For infix tests | ||
def self.sane_adapter? | ||
|
@@ -213,6 +228,7 @@ def self.sane_adapter? | |
it { should include 'name' } | ||
it { should include 'reversed_name' } | ||
it { should include 'doubled_name' } | ||
it { should include 'term' } | ||
it { should include 'only_search' } | ||
it { should_not include 'only_sort' } | ||
it { should_not include 'only_admin' } | ||
|
@@ -224,6 +240,7 @@ def self.sane_adapter? | |
it { should include 'name' } | ||
it { should include 'reversed_name' } | ||
it { should include 'doubled_name' } | ||
it { should include 'term' } | ||
it { should include 'only_search' } | ||
it { should_not include 'only_sort' } | ||
it { should include 'only_admin' } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,32 @@ module ActiveRecord | |
end | ||
end | ||
|
||
describe '#ransack_alias' do | ||
it 'translates an alias to the correct attributes' do | ||
p = Person.create!(name: 'Meatloaf', email: '[email protected]') | ||
|
||
s = Person.ransack(term_cont: 'atlo') | ||
expect(s.result.to_a).to eq [p] | ||
|
||
s = Person.ransack(term_cont: 'babi') | ||
expect(s.result.to_a).to eq [p] | ||
|
||
s = Person.ransack(term_cont: 'nomatch') | ||
expect(s.result.to_a).to eq [] | ||
end | ||
|
||
it 'also works with associations' do | ||
dad = Person.create!(name: 'Birdman') | ||
son = Person.create!(name: 'Weezy', parent: dad) | ||
|
||
s = Person.ransack(daddy_eq: 'Birdman') | ||
expect(s.result.to_a).to eq [son] | ||
|
||
s = Person.ransack(daddy_eq: 'Drake') | ||
expect(s.result.to_a).to eq [] | ||
end | ||
end | ||
|
||
describe '#ransacker' do | ||
# For infix tests | ||
def self.sane_adapter? | ||
|
@@ -416,6 +442,7 @@ def self.simple_escaping? | |
it { should include 'name' } | ||
it { should include 'reversed_name' } | ||
it { should include 'doubled_name' } | ||
it { should include 'term' } | ||
it { should include 'only_search' } | ||
it { should_not include 'only_sort' } | ||
it { should_not include 'only_admin' } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters