Created
April 16, 2009 12:55
-
-
Save matthewrudy/96398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- HTMLTrace:Start sites/vacancies/_dam_link_rdfa.rhtml --> | |
<% | |
return unless file = dam_link_rdfa.downloadable_application_form | |
return unless file_name = file.file_name | |
if file_found?(file) | |
file_name_for_link = case file_name | |
when /\.pdf$/i then "Downloadable Form (PDF)" | |
when /\.doc$/i then "E-mailable Form (Word)" | |
else dam_link_rdfa.name | |
end | |
-%> | |
<p property="dc:references"><%= link_to file_name_for_link, :controller => "/sites/uploaded_files", :action => "download", :file => url_for_file_column(file, "file_name"), :vacancy_permalink => @vacancy.permalink, :vacancy => @vacancy, :source => file_name.match(/[doc|pdf]*$/)[0] %></p> | |
<% else -%> | |
<p>File not found (<%= file_name %>)</p> | |
<% end -%> | |
<!-- HTMLTrace:End sites/vacancies/_dam_link_rdfa.rhtml --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../../../spec_helper' | |
describe "sites/vacancies/_dam_link_rdfa" do | |
before(:each) do | |
@vacancy = stub_model(Vacancy, :permalink => "/somewhere/nice") | |
application_form = mock_model(DownloadableApplicationForm, :file_name => "my_file") | |
assigns[:dam_link_rdfa] = mock_model(VacancyDownloadableApplicationForm, :downloadable_application_form => application_form, :name => "My File Name") | |
end | |
def set_file_name!(new_file_name) | |
assigns[:dam_link_rdfa].downloadable_application_form.stub!(:file_name).and_return(new_file_name) | |
end | |
it "should not contain the element to downloadable file if file does not exists" do | |
template.stub!(:file_found?).and_return(false) | |
render :partial => 'sites/vacancies/dam_link_rdfa' | |
response.should_not have_tag("p[property=dc:references]") | |
end | |
it "should contain link to downloadable file if file exists" do | |
template.stub!(:file_found?).and_return(true) | |
render :partial => 'sites/vacancies/dam_link_rdfa' | |
response.should have_tag("p[property=dc:references]") | |
end | |
it "should set the link text as 'Downloadable Form (PDF)' for .PDFs" do | |
set_file_name!("something.pdf") | |
template.stub!(:file_found?).and_return(true) | |
render :partial => 'sites/vacancies/dam_link_rdfa' | |
response.body.should include("Downloadable Form (PDF)") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment