spec/querying_spec.rb in sequel_mapper-0.0.1 vs spec/querying_spec.rb in sequel_mapper-0.0.3

- old
+ new

@@ -1,51 +1,48 @@ require "spec_helper" +require "support/mapper_setup" +require "support/sequel_persistence_setup" +require "support/seed_data_setup" require "sequel_mapper" -require "support/graph_fixture" RSpec.describe "Querying" do - include SequelMapper::GraphFixture + include_context "mapper setup" + include_context "sequel persistence setup" + include_context "seed data setup" - subject(:graph) { - SequelMapper::Graph.new( - top_level_namespace: :users, - datastore: datastore, - relation_mappings: relation_mappings, - ) - } + subject(:mapper) { user_mapper } let(:user) { - graph.where(id: "user/1").first + mapper.where(id: "users/1").first } let(:query_criteria) { { - body: "Lazy load all the things!", + 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( - user.posts - .where(query_criteria) - .map(&:id) - ).to eq(["post/2"]) + expect(filtered_posts.map(&:id)).to eq(["posts/2"]) end - it "sends the query directly to the datastore" do + it "delegates the query to the datastore, performs two additiona reads" do expect { - user.posts - .where(query_criteria) - .map(&:id) + filtered_posts.map(&:id) }.to change { query_counter.read_count }.by(2) + end - # 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", - ]) + 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