Sha256: ebbd0b195cb3586ea2747c042bee500f67e88fef9465a8a4b41425fae4b2282a

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

context 'get sorting key' do
  subject { SampleFilter::ParamsSet.new(options) }

  context 'when options has one sorting field' do
    let(:options) do
      {
        title: {type: :string},
        amount: {type: :number},
        "sort" => {
          type: :sorting,
          values: [:id, :title, :amount],
          default_value: :id_desc
        }
      }
    end

    it { expect(subject.sorting_key).to eq(:sort) }
  end

  context 'when options has two sorting field' do
    let(:options) do
      {
        title: {type: :string},
        amount: {type: :number},
        sort: {
          type: :sorting,
          values: [:id, :title, :amount],
          default_value: 'id_desc'
        },
        another_sort: {
          type: :sorting,
          values: [:field, :one_field],
          default_value: 'field_desc'
        }
      }
    end

    it { expect(subject.sorting_key).to eq(:sort) }
  end

  context 'when options does not have sorting field' do
    let(:options) { {title: {type: :string}, amount: {type: :number}} }

    it { expect(subject.sorting_key).to be_nil }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sample_filter-0.1.7 spec/lib/params_set/sorting_key_spec.rb
sample_filter-0.1.6 spec/lib/params_set/sorting_key_spec.rb
sample_filter-0.1.5 spec/lib/params_set/sorting_key_spec.rb