Skip to content

Commit ff150e2

Browse files
committed
exclude fallback slide from location slides
The fallback slide should only be retrieved when there is no slides to be shown.
1 parent e48ffef commit ff150e2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

app/models/spree/slide_location.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Spree::SlideLocation < ActiveRecord::Base
2-
32
has_and_belongs_to_many :slides,
3+
->(model) { where('spree_slides.id != ?', model.fallback_slide_id || 0) },
44
class_name: 'Spree::Slide',
55
join_table: 'spree_slide_slide_locations'
6+
67
belongs_to :fallback_slide, class_name: 'Spree::Slide', foreign_key: 'fallback_slide_id'
78

89
validates :name, presence: true
9-
1010
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Spree::SlideLocation do
4+
let(:slide1) { Spree::Slide.create }
5+
let(:slide2) { Spree::Slide.create }
6+
7+
describe '#slides' do
8+
before do
9+
Spree::SlideLocation.create name: 'Test location',
10+
slides: [slide1, slide2],
11+
fallback_slide: slide1
12+
end
13+
14+
it 'doesnt include its fallback slide' do
15+
location = Spree::SlideLocation.find_by! name: 'Test location'
16+
expect(location.slides.map(&:id)).to contain_exactly slide2.id
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)