Skip to content

Commit

Permalink
Merge 69f12ce into f3d680e
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeese committed Aug 30, 2017
2 parents f3d680e + 69f12ce commit ec2f725
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -24,7 +24,7 @@ GIT

GIT
remote: https://github.com/avalonmediasystem/media-element-add-to-playlist.git
revision: 90c07c0c8403d88c4c5c091af4468a9656ea4e2b
revision: 129f6bb1d05bd9cea5b359d25ccd2288f2336632
specs:
media_element_add_to_playlist (0.0.1)
rails (~> 4.0)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/media_objects_controller.rb
Expand Up @@ -87,8 +87,8 @@ def add_to_playlist
if playlistitem_scope=='structure' && mf.has_structuralMetadata? && mf.structuralMetadata.xpath('//Span').present?
#create individual items for spans within structure
mf.structuralMetadata.xpath('//Span').each do |s|
labels = [@media_object.title, mf.title]
labels += s.xpath('ancestor::*[\'label\']').collect{|a|a.attribute('label').value.strip}
labels = [mf.embed_title]
labels += s.xpath('ancestor::Div[\'label\']').collect{|a|a.attribute('label').value.strip}
labels << s.attribute('label')
label = labels.reject(&:blank?).join(' - ')
start_time = s.attribute('begin')
Expand Down
5 changes: 4 additions & 1 deletion app/models/concerns/master_file_behavior.rb
Expand Up @@ -68,7 +68,10 @@ def stream_details(token,host=nil)
end

def embed_title
"#{ self.media_object.title } - #{ self.title.present? ? self.title : self.file_location.split( "/" ).last }"
mf_title = self.structuralMetadata.section_title unless self.structuralMetadata.blank?
mf_title ||= self.title if self.title.present?
mf_title ||= self.file_location.split( "/" ).last if self.file_location.present?
[ self.media_object.title, mf_title ].compact.join(" - ")
end

def embed_code(width, permalink_opts = {})
Expand Down
4 changes: 4 additions & 0 deletions app/models/structural_metadata.rb
Expand Up @@ -33,4 +33,8 @@ def self.content_valid? content
def valid?
self.class.schema.validate(self.ng_xml).empty?
end

def section_title
xpath('/Item/@label').text()
end
end
6 changes: 4 additions & 2 deletions spec/controllers/media_objects_controller_spec.rb
Expand Up @@ -1057,12 +1057,14 @@
end

describe "#add_to_playlist" do
let(:media_object) { FactoryGirl.create(:media_object, ordered_master_files: [FactoryGirl.create(:master_file), master_file_with_structure], title: 'Test Item') }
let(:master_file_with_structure) { FactoryGirl.create(:master_file, :with_structure) }
let(:media_object) { FactoryGirl.create(:media_object, title: 'Test Item') }
let(:master_file) { FactoryGirl.create(:master_file, media_object: media_object, title: 'Test Section') }
let(:master_file_with_structure) { FactoryGirl.create(:master_file, :with_structure, media_object: media_object) }
let(:playlist) { FactoryGirl.create(:playlist) }

before do
login_as 'administrator'
media_object.ordered_master_files = [master_file, master_file_with_structure]
end

it "should create a single playlist_item for a single master_file" do
Expand Down
26 changes: 20 additions & 6 deletions spec/models/master_file_spec.rb
Expand Up @@ -380,16 +380,30 @@ class MyEncoder < ActiveEncode::Base
end

describe "#embed_title" do
subject { FactoryGirl.create( :master_file, { media_object: FactoryGirl.create( :media_object, { title: "test" })})}
context "with structure" do
subject { FactoryGirl.create( :master_file, :with_structure, { media_object: FactoryGirl.create( :media_object, { title: "test" })})}

it "should have an appropriate title for the embed code with no label" do
expect( subject.embed_title ).to eq( "test - video.mp4" )
it "should favor the structure item label" do
expect( subject.embed_title ).to eq( "test - CD 1" )
end
end

it "should have an appropriate title for the embed code with a label" do
subject.title = "test"
context "without structure" do
subject { FactoryGirl.create( :master_file, { media_object: FactoryGirl.create( :media_object, { title: "test" })})}

it "should have an appropriate title for the embed code with a label" do
subject.title = "test"
expect( subject.embed_title ).to eq( "test - test" )
end

it "should have an appropriate title for the embed code with no label" do
expect( subject.embed_title ).to eq( "test - video.mp4" )
end

expect( subject.embed_title ).to eq( "test - test" )
it "should have an appropriate title for the embed code with no label or file_location" do
subject.file_location = nil
expect( subject.embed_title ).to eq( "test" )
end
end
end

Expand Down

0 comments on commit ec2f725

Please sign in to comment.