Skip to content

Commit

Permalink
Use Signbank::AssetURL for examples and sign video
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmcarthur committed Jan 11, 2024
1 parent bae5dac commit 2bc14f8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/signbank/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Asset < Signbank::Record
def url
return unless super

AssetURL.new(super).url
AssetURL.new(super).url.to_s
end
end
end
6 changes: 6 additions & 0 deletions app/models/signbank/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ class Example < Signbank::Record
foreign_key: :word_id,
inverse_of: :examples
default_scope -> { order(display_order: :asc).where.not(video: nil) }

def video
return unless super

AssetURL.new(super).url.to_s
end
end
end
6 changes: 6 additions & 0 deletions app/models/signbank/sign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def picture_url
picture&.url
end

def video
return unless super

AssetURL.new(super).url.to_s
end

##
# These are all aliases for the object shape that
# existing code is expecting
Expand Down
10 changes: 6 additions & 4 deletions spec/models/signbank/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
end

describe '#url' do
it 'is a Signbank::AssetURL' do
asset = Signbank::Asset.new(filename: 'test.png', url: '/test.png')
expect(asset.url).to be_a(URI)
it 'uses Signbank::AssetURL' do
double = instance_double(Signbank::AssetURL, url: URI.parse('/test.png'))
allow(Signbank::AssetURL).to receive(:new).and_return(double)
asset = Signbank::Asset.new(url: 'test.png')
expect(asset.url).to eq '/test.png'
end

it 'is nil when the URL is nil' do
asset = Signbank::Asset.new(filename: 'test.png', url: nil)
asset = Signbank::Asset.new(url: nil)
expect(asset.url).to be_nil
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/models/signbank/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@
expect(sign.examples).to be_empty
end
end

describe '#video' do
it 'uses Signbank::AssetURL' do
double = instance_double(Signbank::AssetURL, url: URI.parse('/test.png'))
allow(Signbank::AssetURL).to receive(:new).and_return(double)
example = Signbank::Example.new(video: 'test.png')
expect(example.video).to eq '/test.png'
end

it 'is nil when the URL is nil' do
example = Signbank::Example.new(video: nil)
expect(example.video).to be_nil
end
end
end
14 changes: 14 additions & 0 deletions spec/models/signbank/sign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,18 @@ module Signbank
end
end
end

describe '#url' do
it 'uses Signbank::AssetURL' do
double = instance_double(Signbank::AssetURL, url: URI.parse('/test.png'))
allow(Signbank::AssetURL).to receive(:new).and_return(double)
sign = Signbank::Sign.new(video: 'test.png')
expect(sign.video).to eq '/test.png'
end

it 'is nil when the URL is nil' do
sign = Signbank::Sign.new(video: nil)
expect(sign.video).to be_nil
end
end
end

0 comments on commit 2bc14f8

Please sign in to comment.