Sha256: b7bddba8061265bd84490c2d23afdf2075f50f640630d2cf1fe2c119295de611

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "spec_helper"

require "sequel_mapper"
require "support/graph_fixture"

RSpec.describe "Querying" do
  include SequelMapper::GraphFixture

  subject(:graph) {
    SequelMapper::Graph.new(
      top_level_namespace: :users,
      datastore: datastore,
      relation_mappings: relation_mappings,
    )
  }

  let(:user) {
    graph.where(id: "user/1").first
  }

  let(:query_criteria) {
    {
      body: "Lazy load all the things!",
    }
  }

  describe "arbitrary where query" do
    it "returns a filtered version of the association" do
      expect(
        user.posts
          .where(query_criteria)
          .map(&:id)
      ).to eq(["post/2"])
    end

    it "sends the query directly to the datastore" do
      expect {
        user.posts
          .where(query_criteria)
          .map(&:id)
      }.to change { query_counter.read_count }.by(2)

      # TODO: this is a quick hack to assert that no superfluous records where
      #       loaded. Figure out a better way to check efficiency
      expect(graph.send(:identity_map).values.map(&:id)).to match_array([
        "user/1",
        "post/2",
      ])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_mapper-0.0.1 spec/querying_spec.rb