Sha256: 67eda9a25c8e607efefadade3f8b003d6a70efed33c4cdae381c96be3eaa3544

Contents?: true

Size: 782 Bytes

Versions: 8

Compression:

Stored size: 782 Bytes

Contents

require 'spec_helper'

describe 'Api::Filtered', type: :controller do
  let(:filters) do
    nil
  end

  controller do
    include ::Api::Filtered

    def action
      render json: filtered_collection(Blog.all)
    end
  end

  before do
    routes.draw { get :action, to: "anonymous#action" }

    create(:blog, title: "Lean's blog")
    create(:blog, title: "Santiago's blog")

    get :action, params: { q: filters }
  end

  def resources_count
    JSON.parse(response.body).count
  end

  it { expect(resources_count).to eq(2) }
  it { expect(response.status).to eq(200) }

  context "with filters" do
    let(:filters) do
      {
        title_cont: "Lean"
      }
    end

    it { expect(resources_count).to eq(1) }
    it { expect(response.status).to eq(200) }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
power_api-2.1.1 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-2.1.0 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-2.0.2 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-2.0.1 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-2.0.0 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-1.0.0 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-0.2.0 spec/dummy/app/controllers/concerns/api/filtered_spec.rb
power_api-0.1.0 spec/dummy/app/controllers/concerns/api/filtered_spec.rb