Sha256: 176c7fa1a504398489be6ddf211619d5d1b2824115464d18ebfd2a20bfb926ce
Contents?: true
Size: 1.74 KB
Versions: 4
Compression:
Stored size: 1.74 KB
Contents
require 'spec_helper' module Admino module Query describe Field do subject(:field) { Field.new(config, params) } let(:config) { Configuration::Field.new(:foo) } let(:params) { {} } describe '#value' do context 'with a value' do let(:params) { { 'query' => { 'foo' => 'bar' } } } it 'returns the param value for the field' do expect(field.value).to eq 'bar' end end context 'else' do it 'returns nil' do expect(field.value).to be_nil end end context 'with coertion' do let(:config) { Configuration::Field.new(:foo, coerce: :to_date) } context 'with a possible coertion' do let(:params) { { 'query' => { 'foo' => '2014-10-05' } } } it 'returns the coerced param value for the field' do expect(field.value).to be_a Date end end context 'with a possible coertion' do let(:params) { { 'query' => { 'foo' => '' } } } it 'returns nil' do expect(field.value).to be_nil end end end end describe '#augment_scope' do let(:result) { field.augment_scope(scope) } let(:scope) { ScopeMock.new('original') } context 'if the field has a value' do let(:params) { { 'query' => { 'foo' => 'bar' } } } it 'returns the original scope chained with the field scope' do expect(result.chain).to eq [:foo, ['bar']] end end context 'else' do it 'returns the original scope' do expect(result).to eq scope end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
admino-0.0.4 | spec/admino/query/field_spec.rb |
admino-0.0.3 | spec/admino/query/field_spec.rb |
admino-0.0.2 | spec/admino/query/field_spec.rb |
admino-0.0.1 | spec/admino/query/field_spec.rb |