Sha256: df17d0e564a4cbcee0fafec2395fa1632e4d8fa11c62ab1fc540a78ea911248f

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require "spec_helper"

require "support/mapper_setup"
require "support/sequel_persistence_setup"
require "support/seed_data_setup"
require "sequel_mapper"

RSpec.describe "Querying" do
  include_context "mapper setup"
  include_context "sequel persistence setup"
  include_context "seed data setup"

  subject(:mapper) { user_mapper }

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

  let(:query_criteria) {
    {
      body: "I do it three times purrr day",
    }
  }

  let(:filtered_posts) {
    user.posts.where(query_criteria)
  }

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

    it "delegates the query to the datastore, performs two additiona reads" do
      expect {
        filtered_posts.map(&:id)
      }.to change { query_counter.read_count }.by(2)
    end

    it "returns another collection" do
      expect(filtered_posts).not_to be(user.posts)
    end

    it "returns an immutable collection" do
      expect(filtered_posts.public_methods).not_to include(:push, :<<, :delete)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_mapper-0.0.3 spec/querying_spec.rb