Sha256: bbebd8d9d4e14f005591425dd2338831c0ea68c0ec0b1b30cede58103224e0a1

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe CountriesController, '-> Ransack query search', type: :controller do

  it 'Filter by q[name_eq]' do
    3.times { create :country }

    country = Country.first

    get :index, q: {name_eq: country.name}

    response.should be_success
    assigns(:countries).should eq [country]
  end

  it 'Filter by attribute, predicate and value' do
    3.times { create :country }

    country = Country.first

    get :index, q: {c: [{a: {'0' => {name: 'name'}}, p: 'eq', v: {'0' => {value: country.name}}}]}

    response.should be_success
    assigns(:countries).should eq [country]
  end

  it 'Filter by NQL' do
    3.times { create :country }

    country = Country.first

    get :index, q: "name = #{country.name}"

    response.should be_success
    assigns(:countries).should eq [country]
  end

  it 'Filter by NQL with invalid field' do
    3.times { create :country }

    country = Country.first

    get :index, q: "abcd = #{country.name}"

    response.should be_success
    assigns(:countries).should eq []
  end

  it 'Filter by NQL with invalid expression' do
    3.times { create :country }

    get :index, q: 'abcd = '

    response.should be_success
    assigns(:countries).should eq []
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynamic_controller-0.0.12 spec/controllers/ransack_spec.rb
dynamic_controller-0.0.11 spec/controllers/ransack_spec.rb
dynamic_controller-0.0.10 spec/controllers/ransack_spec.rb
dynamic_controller-0.0.9 spec/controllers/ransack_spec.rb