Sha256: f4e12ee5055f227b8efa63ff6506785b33310ce7d2f08c77807027f7b77ccb99

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

module Admino
  module Query
    describe Dsl do
      let(:config) { TestQuery.config }
      let(:instance) { TestQuery.new }

      it 'allows #field declaration' do
        field = config.fields.last
        expect(field.name).to eq :starting_from
        expect(field.coerce_to).to eq :to_date
      end

      it 'allows #group declaration' do
        group = config.groups.first
        expect(group.name).to eq :bar
        expect(group.scopes).to eq [:one, :two]
      end

      it 'allows #sortings declaration' do
        sorting = config.sorting
        expect(sorting.scopes).to eq [:by_title, :by_date]
        expect(sorting.default_scope).to eq :by_title
        expect(sorting.default_direction).to eq :desc
      end

      it 'allows #starting_scope block declaration' do
        expect(config.starting_scope_callable.call).to eq 'start'
      end

      it 'allows #ending_scope block declaration' do
        expect(config.ending_scope_callable.call).to eq 'end'
      end

      context 'with a field' do
        let(:field) { double('Field', value: 'value') }

        before do
          instance.stub(:field_by_name).
            with(:foo).
            and_return(field)
        end

        it 'it generates a getter' do
          expect(instance.foo).to eq 'value'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
admino-0.0.3 spec/admino/query/dsl_spec.rb
admino-0.0.2 spec/admino/query/dsl_spec.rb