Skip to content

Commit eb41e9f

Browse files
committed
[Test] Add test for supporting several passed aspect_ratios for allowing / rejecting methods
1 parent 9084286 commit eb41e9f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/dummy/app/models/aspect_ratio/matcher.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class AspectRatio::Matcher < ApplicationRecord
2020
has_one_attached :"allowing_one_#{aspect_ratio}"
2121
validates :"allowing_one_#{aspect_ratio}", aspect_ratio: aspect_ratio
2222
end
23+
24+
has_one_attached :allowing_several
25+
validates :allowing_several, aspect_ratio: [ :square, :portrait ]
26+
2327
has_one_attached :allowing_one_is_x_y
2428
validates :allowing_one_is_x_y, aspect_ratio: :is_16_9
2529

test/matchers/aspect_ratio_validator_matcher_test.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,29 @@
109109
end
110110
end
111111
end
112+
113+
describe "several" do
114+
describe "when all specified aspect ratios exactly match the allowed list" do
115+
let(:model_attribute) { :allowing_several }
116+
subject { matcher.allowing(:portrait, :square) }
117+
118+
it { is_expected_to_match_for(klass) }
119+
end
120+
121+
describe "when some specified aspect ratios match but not all" do
122+
let(:model_attribute) { :allowing_several }
123+
subject { matcher.allowing(:landscape, :square) }
124+
125+
it { is_expected_not_to_match_for(klass) }
126+
end
127+
128+
describe "when none of the specified aspect ratios match" do
129+
let(:model_attribute) { :allowing_several }
130+
subject { matcher.allowing(:landscape, :is_4_3) }
131+
132+
it { is_expected_not_to_match_for(klass) }
133+
end
134+
end
112135
end
113136

114137
describe "#rejecting" do
@@ -172,6 +195,29 @@
172195
end
173196
end
174197
end
198+
199+
describe "several" do
200+
describe "when rejecting aspect ratios that are not in the allowed list" do
201+
let(:model_attribute) { :allowing_several }
202+
subject { matcher.rejecting(:landscape, :square) }
203+
204+
it { is_expected_to_match_for(klass) }
205+
end
206+
207+
describe "when rejecting some aspect ratios that overlap with the allowed list" do
208+
let(:model_attribute) { :allowing_several }
209+
subject { matcher.rejecting(:landscape, :square) }
210+
211+
it { is_expected_not_to_match_for(klass) }
212+
end
213+
214+
describe "when rejecting aspect ratios that are in the allowed list" do
215+
let(:model_attribute) { :allowing_several }
216+
subject { matcher.rejecting(:square, :portrait) }
217+
218+
it { is_expected_not_to_match_for(klass) }
219+
end
220+
end
175221
end
176222

177223
describe "Combinations" do

0 commit comments

Comments
 (0)