spec/lib/embeddable_spec.rb in embeddable-0.0.7 vs spec/lib/embeddable_spec.rb in embeddable-0.0.8

- old
+ new

@@ -5,66 +5,83 @@ class Dummy include Embeddable embeddable :video, from: :video_url + embeddable :super_video, from: :another_url - attr_accessor :video_url + attr_accessor :video_url, :another_url end describe '.embeddable' do it 'requires a source property' do expect do Dummy.embeddable :video end.to raise_error KeyError end end + describe 'predicate' do + context ':video_url is a supported url' do + it 'should be true' do + subject.video_url = 'http://youtube.com/watch?v=1&feature=foo' + expect(subject.video?).to be_truthy + end + end + + context ':video_url is an unsupported url' do + it 'should be false' do + subject.video_url = 'http://foo.bar' + expect(subject.video?).to be_falsey + end + end + end + describe 'Liveleak' do context 'with http://liveleak.com/...' do - before { - subject.video_url = 'http://www.liveleak.com/view?i=290_1392029603' + before { + subject.video_url = 'http://www.liveleak.com/view?i=290_1392029603' } its(:video_type) { should eq :liveleak } its(:video_id) { should eq '290_1392029603' } end end describe 'Dailymotion' do context 'with http://dailymotion.com/video/<id>...' do - before { - subject.video_url = 'http://www.dailymotion.com/video/xu4q8m' + before { + subject.video_url = 'http://www.dailymotion.com/video/xu4q8m' } its(:video_type) { should eq :dailymotion } its(:video_id) { should eq 'xu4q8m' } end context 'with http://dailymotion.com/video/<id>_<blargablarga>...' do - before { - subject.video_url = 'http://www.dailymotion.com/video/xu4q8m_apprendre-le-deltaplane-a-millau-hang-gliding-in-france-creative-motion_sport' + before { + subject.video_url = 'http://www.dailymotion.com/video/xu4q8m_apprendre-le-deltaplane-a-millau-hang-gliding-in-france-creative-motion_sport' } its(:video_type) { should eq :dailymotion } its(:video_id) { should eq 'xu4q8m_apprendre-le-deltaplane-a-millau-hang-gliding-in-france-creative-motion_sport' } end end describe 'Veoh' do context 'with http://veoh.com/watch/<id>...' do - before { - subject.video_url = 'http://www.veoh.com/watch/v36298453QmtnSAza' + before { + subject.video_url = 'http://www.veoh.com/watch/v36298453QmtnSAza' } its(:video_type) { should eq :veoh } its(:video_id) { should eq 'v36298453QmtnSAza' } end context 'with http://veoh.com/watch/<id>/<blargablarga>...' do - before { - subject.video_url = 'http://www.veoh.com/watch/v36298453QmtnSAza/CBS-SciTech-News' + before { + subject.video_url = 'http://www.veoh.com/watch/v36298453QmtnSAza/CBS-SciTech-News' } its(:video_type) { should eq :veoh } its(:video_id) { should eq 'v36298453QmtnSAza/CBS-SciTech-News' } end @@ -79,11 +96,11 @@ end end describe 'Vippy' do context 'with http://liveleak.com/...' do - before { + before { subject.video_url = <<SUCH_EMBED_CODE <!-- Start Vippy video --> <div itemscope itemtype="http://schema.org/VideoObject" class="vippy-video" style="width: 640px; height: 360px; position: relative;"> <meta itemprop="name" content="bademiljo_hurum_v1.mp4" /> <meta itemprop="duration" content="PT9M38S" /> @@ -177,9 +194,27 @@ its(:video_type) { should eq :youtube } its(:video_id) { should eq '1' } it { should be_video_on_youtube } end + end + + describe '.video_source' do + it 'should return the source of video' do + expect(subject.video_source).to eql(:video_url) + end + end + + describe '.super_video_source' do + it 'should return the source of super_video' do + expect(subject.super_video_source).to eql(:another_url) + end + end + + context 'multiple embeddable columns' do + it 'should store an array of names on the class' do + expect(Dummy.embeddables).to eql([:video, :super_video]) + end end describe 'unsupported scenarios' do context 'unknown service' do