Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.1-stable] fix Ingredient Audio and Video boolean type casting #2911

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/models/alchemy/ingredients/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ class Audio < Alchemy::Ingredient
def preview_text(max_length = 30)
name.to_s[0..max_length - 1]
end

%i[
autoplay
controls
loop
muted
].each do |method|
define_method(:"#{method}=") do |value|
super(ActiveModel::Type::Boolean.new.cast(value))
end
end
end
end
end
12 changes: 12 additions & 0 deletions app/models/alchemy/ingredients/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class Video < Alchemy::Ingredient
def preview_text(max_length = 30)
name.to_s[0..max_length - 1]
end

%i[
autoplay
controls
loop
muted
playsinline
].each do |method|
define_method(:"#{method}=") do |value|
super(ActiveModel::Type::Boolean.new.cast(value))
end
end
end
end
end
40 changes: 40 additions & 0 deletions spec/models/alchemy/ingredients/audio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,64 @@
subject { audio_ingredient.autoplay }
before { audio_ingredient.autoplay = false }
it { is_expected.to eq(false) }

context "when set to '0'" do
before { audio_ingredient.autoplay = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { audio_ingredient.autoplay = "t" }
it { is_expected.to eq(true) }
end
end

describe "#controls" do
subject { audio_ingredient.controls }
before { audio_ingredient.controls = true }
it { is_expected.to eq(true) }

context "when set to '0'" do
before { audio_ingredient.controls = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { audio_ingredient.controls = "t" }
it { is_expected.to eq(true) }
end
end

describe "#loop" do
subject { audio_ingredient.loop }
before { audio_ingredient.loop = false }
it { is_expected.to eq(false) }

context "when set to '0'" do
before { audio_ingredient.loop = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { audio_ingredient.loop = "t" }
it { is_expected.to eq(true) }
end
end

describe "#muted" do
subject { audio_ingredient.muted }
before { audio_ingredient.muted = true }
it { is_expected.to eq(true) }

context "when set to '0'" do
before { audio_ingredient.muted = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { audio_ingredient.muted = "t" }
it { is_expected.to eq(true) }
end
end

describe "#attachment" do
Expand Down
50 changes: 50 additions & 0 deletions spec/models/alchemy/ingredients/video_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,32 @@
subject { video_ingredient.autoplay }
before { video_ingredient.autoplay = false }
it { is_expected.to eq(false) }

context "when set to '0'" do
before { video_ingredient.autoplay = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { video_ingredient.autoplay = "t" }
it { is_expected.to eq(true) }
end
end

describe "#controls" do
subject { video_ingredient.controls }
before { video_ingredient.controls = true }
it { is_expected.to eq(true) }

context "when set to '0'" do
before { video_ingredient.controls = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { video_ingredient.controls = "t" }
it { is_expected.to eq(true) }
end
end

describe "#height" do
Expand All @@ -45,18 +65,48 @@
subject { video_ingredient.loop }
before { video_ingredient.loop = false }
it { is_expected.to eq(false) }

context "when set to '0'" do
before { video_ingredient.loop = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { video_ingredient.loop = "t" }
it { is_expected.to eq(true) }
end
end

describe "#muted" do
subject { video_ingredient.muted }
before { video_ingredient.muted = true }
it { is_expected.to eq(true) }

context "when set to '0'" do
before { video_ingredient.muted = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { video_ingredient.muted = "t" }
it { is_expected.to eq(true) }
end
end

describe "#playsinline" do
subject { video_ingredient.playsinline }
before { video_ingredient.playsinline = true }
it { is_expected.to eq(true) }

context "when set to '0'" do
before { video_ingredient.playsinline = "0" }
it { is_expected.to eq(false) }
end

context "when set to 't'" do
before { video_ingredient.playsinline = "t" }
it { is_expected.to eq(true) }
end
end

describe "#preload" do
Expand Down
Loading