2011-03-07 17:39:47 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'avm/image'
|
|
|
|
|
|
|
|
describe AVM::Image do
|
2011-03-11 18:59:34 +00:00
|
|
|
let(:image) { self.class.describes.new(options) }
|
|
|
|
let(:options) { {} }
|
2011-03-07 17:39:47 +00:00
|
|
|
|
|
|
|
subject { image }
|
|
|
|
|
2011-03-14 16:35:29 +00:00
|
|
|
let(:title) { 'My title' }
|
|
|
|
let(:headline) { 'Headline' }
|
|
|
|
let(:description) { 'Description' }
|
|
|
|
let(:distance_notes) { 'Distance Notes' }
|
2011-03-16 14:41:01 +00:00
|
|
|
let(:spectral_notes) { 'Spectral Notes' }
|
2011-03-14 16:35:29 +00:00
|
|
|
let(:reference_url) { 'Reference URL' }
|
|
|
|
let(:credit) { 'Credit' }
|
|
|
|
let(:date) { '2010-01-01' }
|
|
|
|
let(:id) { 'ID' }
|
2011-03-15 14:55:09 +00:00
|
|
|
let(:type) { 'Observation' }
|
2011-03-14 16:35:29 +00:00
|
|
|
let(:image_quality) { 'Good' }
|
|
|
|
let(:redshift) { 'Redshift' }
|
|
|
|
let(:light_years) { 'Light years' }
|
2011-03-07 17:39:47 +00:00
|
|
|
|
2011-03-14 16:35:29 +00:00
|
|
|
def self.with_all_options
|
2011-03-11 18:59:34 +00:00
|
|
|
let(:options) { {
|
|
|
|
:title => title,
|
|
|
|
:headline => headline,
|
|
|
|
:description => description,
|
|
|
|
:distance_notes => distance_notes,
|
2011-03-16 14:41:01 +00:00
|
|
|
:spectral_notes => spectral_notes,
|
2011-03-11 18:59:34 +00:00
|
|
|
:reference_url => reference_url,
|
|
|
|
:credit => credit,
|
|
|
|
:date => date,
|
|
|
|
:id => id,
|
|
|
|
:type => type,
|
2011-03-15 14:55:09 +00:00
|
|
|
:quality => image_quality,
|
2011-03-11 19:04:50 +00:00
|
|
|
:redshift => redshift,
|
|
|
|
:light_years => light_years
|
2011-03-11 18:59:34 +00:00
|
|
|
} }
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
2011-03-11 18:59:34 +00:00
|
|
|
|
2011-03-15 14:55:09 +00:00
|
|
|
def self.has_most_options
|
2011-03-07 17:39:47 +00:00
|
|
|
its(:creator) { should be_a_kind_of(AVM::Creator) }
|
2011-03-11 18:59:34 +00:00
|
|
|
its(:title) { should == title }
|
|
|
|
its(:headline) { should == headline }
|
|
|
|
its(:description) { should == description }
|
|
|
|
its(:distance_notes) { should == distance_notes }
|
2011-03-16 14:41:01 +00:00
|
|
|
its(:spectral_notes) { should == spectral_notes }
|
2011-03-11 18:59:34 +00:00
|
|
|
its(:reference_url) { should == reference_url }
|
|
|
|
its(:credit) { should == credit }
|
|
|
|
its(:date) { should == Time.parse(date) }
|
|
|
|
its(:id) { should == id }
|
2011-03-15 14:55:09 +00:00
|
|
|
its(:image_type) { should be_a_kind_of eval("AVM::ImageType::#{type}") }
|
|
|
|
its(:image_quality) { should be_a_kind_of eval("AVM::ImageQuality::#{image_quality}") }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
with_all_options
|
|
|
|
|
|
|
|
it { should be_a_kind_of(AVM::Image) }
|
|
|
|
|
|
|
|
has_most_options
|
2011-03-11 19:04:50 +00:00
|
|
|
|
|
|
|
its(:distance) { should == [ light_years, redshift ] }
|
2011-03-07 17:39:47 +00:00
|
|
|
end
|
2011-03-09 15:14:31 +00:00
|
|
|
|
2011-03-15 14:55:09 +00:00
|
|
|
describe '.from_xml' do
|
|
|
|
let(:image) { AVM::Image.from_xml(File.read(file_path)) }
|
|
|
|
|
|
|
|
subject { image }
|
|
|
|
|
|
|
|
context "nothing in it" do
|
|
|
|
let(:file_path) { 'spec/sample_files/image/nothing.xmp' }
|
|
|
|
|
|
|
|
its(:title) { should be_nil }
|
|
|
|
its(:headline) { should be_nil }
|
|
|
|
its(:description) { should be_nil }
|
|
|
|
its(:distance_notes) { should be_nil }
|
2011-03-16 14:41:01 +00:00
|
|
|
its(:spectral_notes) { should be_nil }
|
2011-03-15 14:55:09 +00:00
|
|
|
its(:reference_url) { should be_nil }
|
|
|
|
its(:credit) { should be_nil }
|
|
|
|
its(:date) { should be_nil }
|
|
|
|
its(:id) { should be_nil }
|
|
|
|
its(:image_type) { should be_nil }
|
|
|
|
its(:image_quality) { should be_nil }
|
|
|
|
its(:redshift) { should be_nil }
|
|
|
|
its(:light_years) { should be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "image in it" do
|
|
|
|
context "distance in light years" do
|
|
|
|
let(:file_path) { 'spec/sample_files/image/light_years.xmp' }
|
|
|
|
|
|
|
|
has_most_options
|
|
|
|
|
|
|
|
its(:redshift) { should be_nil }
|
2011-03-15 15:16:10 +00:00
|
|
|
its(:light_years) { should == light_years }
|
2011-03-15 14:55:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "distaince in redshift" do
|
2011-03-15 15:16:10 +00:00
|
|
|
let(:file_path) { 'spec/sample_files/image/redshift.xmp' }
|
|
|
|
|
|
|
|
has_most_options
|
|
|
|
|
|
|
|
its(:light_years) { should be_nil }
|
|
|
|
its(:redshift) { should == redshift }
|
2011-03-15 14:55:09 +00:00
|
|
|
end
|
2011-03-15 15:16:10 +00:00
|
|
|
|
2011-03-15 14:55:09 +00:00
|
|
|
context "distance in both" do
|
2011-03-15 15:16:10 +00:00
|
|
|
let(:file_path) { 'spec/sample_files/image/both.xmp' }
|
2011-03-15 14:55:09 +00:00
|
|
|
|
2011-03-15 15:16:10 +00:00
|
|
|
has_most_options
|
|
|
|
|
|
|
|
its(:light_years) { should == light_years }
|
|
|
|
its(:redshift) { should == redshift }
|
2011-03-15 14:55:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-09 15:14:31 +00:00
|
|
|
describe '#to_xml' do
|
|
|
|
let(:xml) { image.to_xml }
|
|
|
|
|
2011-03-15 14:55:09 +00:00
|
|
|
let(:dublin_core) { xml.at_xpath('//rdf:Description[@rdf:about="Dublin Core"]') }
|
|
|
|
let(:photoshop) { xml.at_xpath('//rdf:Description[@rdf:about="Photoshop"]') }
|
|
|
|
let(:avm) { xml.at_xpath('//rdf:Description[@rdf:about="AVM"]') }
|
2011-03-14 16:35:29 +00:00
|
|
|
|
2011-03-09 15:14:31 +00:00
|
|
|
context 'nothing in it' do
|
2011-03-14 16:35:29 +00:00
|
|
|
it "should have basic tags" do
|
|
|
|
xml.at_xpath('//rdf:RDF').should_not be_nil
|
|
|
|
xml.search('//rdf:RDF/rdf:Description').should_not be_empty
|
|
|
|
avm.at_xpath('./avm:Date').should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with basics' do
|
|
|
|
with_all_options
|
|
|
|
|
|
|
|
it "should have the image info tags" do
|
|
|
|
dublin_core.at_xpath('./dc:title/rdf:Alt/rdf:li').text.should == title
|
|
|
|
photoshop.at_xpath('./photoshop:Headline').text.should == headline
|
|
|
|
dublin_core.at_xpath('./dc:description/rdf:Alt/rdf:li').text.should == description
|
|
|
|
|
|
|
|
avm.at_xpath('./avm:Distance.Notes').text.should == distance_notes
|
2011-03-16 14:41:01 +00:00
|
|
|
avm.at_xpath('./avm:Spectral.Notes').text.should == spectral_notes
|
2011-03-14 16:35:29 +00:00
|
|
|
avm.at_xpath('./avm:ReferenceURL').text.should == reference_url
|
|
|
|
avm.at_xpath('./avm:Credit').text.should == credit
|
|
|
|
avm.at_xpath('./avm:Date').text.should == date
|
|
|
|
avm.at_xpath('./avm:ID').text.should == id
|
2011-03-15 14:55:09 +00:00
|
|
|
avm.at_xpath('./avm:Type').text.should == type
|
|
|
|
avm.at_xpath('./avm:Image.ProductQuality').text.should == image_quality
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "distance" do
|
|
|
|
context "no distances" do
|
2011-03-15 14:55:09 +00:00
|
|
|
let(:redshift) { nil }
|
|
|
|
let(:light_years) { nil }
|
2011-03-14 16:35:29 +00:00
|
|
|
|
2011-03-15 14:55:09 +00:00
|
|
|
specify { avm.at_xpath('./avm:Distance').should be_nil }
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "redshift only" do
|
2011-03-15 14:55:09 +00:00
|
|
|
let(:light_years) { nil }
|
|
|
|
|
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[1]').text.should == '-' }
|
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[2]').text.should == redshift }
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "light years only" do
|
2011-03-15 14:55:09 +00:00
|
|
|
let(:redshift) { nil }
|
|
|
|
|
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[1]').text.should == light_years }
|
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[2]').should be_nil }
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "redshift and light years" do
|
2011-03-15 14:55:09 +00:00
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[1]').text.should == light_years }
|
|
|
|
specify { avm.at_xpath('./avm:Distance/rdf:Seq/rdf:li[2]').text.should == redshift }
|
2011-03-14 16:35:29 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-09 15:14:31 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-07 17:39:47 +00:00
|
|
|
end
|
|
|
|
|