spec/mongoid/adapters/mongoid/base_spec.rb in ransack-1.7.0 vs spec/mongoid/adapters/mongoid/base_spec.rb in ransack-1.8.0

- old
+ new

@@ -18,11 +18,13 @@ expect(subject.object).to be_an ::Mongoid::Criteria end context 'with scopes' do before do - Person.stub :ransackable_scopes => [:active, :over_age] + allow(Person) + .to receive(:ransackable_scopes) + .and_return([:active, :over_age]) end it "applies true scopes" do search = Person.search('active' => true) expect(search.result.selector).to eq({ 'active' => 1 }) @@ -48,10 +50,25 @@ expect(search.result.selector).to eq({ 'age' => { '$gt' => 18 }, 'active' => 1 }) end end end + describe '#ransack_alias' do + it 'translates an alias to the correct attributes' do + p = Person.create!(name: 'Meatloaf', email: 'babies@example.com') + + 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? case ::Mongoid::Document.connection.adapter_name when "SQLite3", "PostgreSQL" @@ -211,10 +228,11 @@ subject { Person.ransackable_attributes } 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' } end @@ -222,9 +240,10 @@ subject { Person.ransackable_attributes(:admin) } 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' } end end