Sha256: 8a19c7e701e2705eb72cbaf6da637bd5e6eb7c14c44429084e8cade332cd2761
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
require "spec_helper" require "support/mapper_setup" require "support/sequel_persistence_setup" require "support/seed_data_setup" require "terrestrial" require "terrestrial/configurations/conventional_configuration" RSpec.describe "Ordered associations" do include_context "mapper setup" include_context "sequel persistence setup" include_context "seed data setup" context "one to many association ordered by `created_at DESC`" do let(:posts) { user_mapper.first.posts } before do configs.fetch(:users).fetch(:associations).fetch(:posts).merge!( order: Terrestrial::QueryOrder.new( fields: [:created_at], direction: "DESC", ) ) end it "enumerates the objects in order specified in the config" do expect(posts.map(&:id)).to eq( posts.to_a.sort_by(&:created_at).reverse.map(&:id) ) end end context "many to many associatin ordered by reverse alphabetical name" do before do configs.fetch(:posts).fetch(:associations).fetch(:categories).merge!( order: Terrestrial::QueryOrder.new( fields: [:name], direction: "DESC", ) ) end let(:categories) { user_mapper.first.posts.first.categories } it "enumerates the objects in order specified in the config" do expect(categories.map(&:id)).to eq( categories.to_a.sort_by(&:name).reverse.map(&:id) ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
terrestrial-0.1.1 | spec/ordered_association_spec.rb |