Sha256: f0c9ad58f22ca1c958edce1d3cdfe994aa75423ffc8dcdfa58a99bdbbf5cf0a8

Contents?: true

Size: 1.83 KB

Versions: 22

Compression:

Stored size: 1.83 KB

Contents

require 'mongoid_spec_helper'

module Ransack
  module Adapters
    module Mongoid
      describe Context do
        subject { Context.new(Person) }

        describe '#relation_for' do
          before { pending "not implemented for mongoid" }
          it 'returns relation for given object' do
            expect(subject.object).to be_an ::ActiveRecord::Relation
          end
        end

        describe '#evaluate' do
          it 'evaluates search objects' do
            search = Search.new(Person, :name_eq => 'Joe Blow')
            result = subject.evaluate(search)

            expect(result).to be_an ::Mongoid::Criteria
            expect(result.selector).to eq({ 'name' => 'Joe Blow' })
          end

          it 'SELECTs DISTINCT when distinct: true' do
            pending "distinct doesn't work"

            search = Search.new(Person, :name_eq => 'Joe Blow')
            result = subject.evaluate(search, :distinct => true)

            expect(result).to be_an ::ActiveRecord::Relation
            expect(result.to_sql).to match /SELECT DISTINCT/
          end
        end

        it 'contextualizes strings to attributes' do
          attribute = subject.contextualize 'name'
          expect(attribute).to be_a ::Ransack::Adapters::Mongoid::Attributes::Attribute
          expect(attribute.name.to_s).to eq 'name'
          # expect(attribute.relation.table_alias).to eq 'parents_people'
        end

        it 'builds new associations if not yet built' do
          pending "not implemented for mongoid"

          attribute = subject.contextualize 'children_articles_title'
          expect(attribute).to be_a Arel::Attributes::Attribute
          expect(attribute.name.to_s).to eq 'title'
          expect(attribute.relation.name).to eq 'articles'
          expect(attribute.relation.table_alias).to be_nil
        end

      end
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
ransack-1.8.10 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.9 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.8 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.7 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.6 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.4 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.3 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.2 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.1 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.8.0 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.7.0 spec/mongoid/adapters/mongoid/context_spec.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/ransack-1.6.6/spec/mongoid/adapters/mongoid/context_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/ransack-1.6.6/spec/mongoid/adapters/mongoid/context_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/ransack-1.6.6/spec/mongoid/adapters/mongoid/context_spec.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/ransack-1.6.2/spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.6.6 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.6.5 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.6.4 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.6.3 spec/mongoid/adapters/mongoid/context_spec.rb
ransack-1.6.2 spec/mongoid/adapters/mongoid/context_spec.rb