Skip to content

Commit

Permalink
Test for merged preload values
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hollinger <[email protected]>
  • Loading branch information
jhollinger committed May 21, 2024
1 parent 8d17a10 commit d0d9118
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/preloader_extension_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ def test_blueprinter_preload_now
assert_equal [{:battery1=>{:fake_assoc=>{}, :refurb_plan=>{}}, :battery2=>{:fake_assoc=>{}, :refurb_plan=>{}}, :category=>{}, :project=>{:customer=>{}}}], q.values[:preload]
end

def test_blueprinter_preload_now_with_existing_preloads
q = Widget.
where("widgets.name <> ?", "Widget C").
order(:name).
preload({battery1: :refurb_plan}).
preload_blueprint(WidgetBlueprint, :no_power).
strict_loading

assert_equal({:battery1=>{:refurb_plan=>{}}, :category=>{}, :project=>{:customer=>{}}}, BlueprinterActiveRecord::Helpers.merge_values(q.values[:preload]))
end

def test_auto_preload
ext = BlueprinterActiveRecord::Preloader.new(auto: true)
q = Widget.
Expand All @@ -121,6 +132,20 @@ def test_auto_preload
assert_equal [{:battery1=>{:fake_assoc=>{}, :refurb_plan=>{}}, :battery2=>{:fake_assoc=>{}, :refurb_plan=>{}}, :category=>{}, :project=>{:customer=>{}}}], q.values[:preload]
end

def test_auto_preload_with_existing_preloads
ext = BlueprinterActiveRecord::Preloader.new(auto: true)
q = Widget.
where("name <> ?", "Widget C").
order(:name).
preload({battery1: :refurb_plan}).
strict_loading
q = ext.pre_render(q, WidgetBlueprint, :no_power, {})

assert ext.auto
assert_equal :preload, ext.use
assert_equal({:battery1=>{:refurb_plan=>{}}, :category=>{}, :project=>{:customer=>{}}}, BlueprinterActiveRecord::Helpers.merge_values(q.values[:preload]))
end

def test_auto_preload_with_block_true
ext = BlueprinterActiveRecord::Preloader.new { |object| true }
q = Widget.
Expand Down

0 comments on commit d0d9118

Please sign in to comment.