Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
jnraine committed Jun 25, 2013
1 parent fb9fdd0 commit 24413d3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
27 changes: 13 additions & 14 deletions app/models/version_tracker.rb
Expand Up @@ -82,7 +82,7 @@ def scrape_download_links(page)
download_links = []
page.css("#downloadlink").each do |link_element|
download_url = MAC_UPDATE_SITE_URL + link_element[:href]
caption = link_element.parent().css(".info").text.lstrip.rstrip
caption = link_element.parent().css(".info").text.lstrip.rstrip
text = link_element.text
download_links << self.download_links.build({:text => text, :url => download_url, :caption => caption})
end
Expand All @@ -100,23 +100,22 @@ def scrape_data(page, options = {})
def scrape_icon(page)
if image_element = page.at_css("#appiconinfo")
url_string = image_element[:src]
uri = URI.parse(URI.escape(url_string))
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response_body = http.request(request).body
image_file = Tempfile.new("icon", :encoding => response_body.encoding.name)
image_file.write(response_body)
image_file = open(url_string)
icon = Icon.new({:photo => image_file})
if icon.save
icon
else
nil
end
icon if icon.save
end
end

def url_to_file(url_string)
puts url_string
uri = URI.parse(URI.escape(url_string))
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response_body = http.request(request).body
end

# Retrieves and returns web ID of first search result
def retrieve_web_id
if macupdate_is_up?
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin_mailer/computer_report.html.erb
@@ -1,5 +1,5 @@
<% report = @computer.managed_install_reports.last %>
<h2><%= @computer %> (<%= @computer.name%>) - <%= @computer.status%></h2>
<h2><%= @computer %> (<%= @computer.name %>) - <%= @computer.status %></h2>
<% ManagedInstallReport::LOG_ATTRIBUTES.each do |attribute_name| %>
<%= render :partial => 'managed_install_reports/report_log', :locals => {:attribute_name => attribute_name,:report => report} if report.send(attribute_name).present? %>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions spec/nokogiri_helper_spec.rb
Expand Up @@ -16,7 +16,7 @@

context "given an unescaped URL" do
it "returns a nokogiri document" do
NokogiriHelper.page("https://www.macupdate.com/find/mac/Foo App").title.should match("foo")
NokogiriHelper.page("https://www.macupdate.com/find/mac/A term that has no results").title.should match("Search for")
end
end

Expand All @@ -29,13 +29,13 @@

describe "redirect_url" do
context "given a URL with a redirect" do
it "returns a redirect URL from a URL" do
NokogiriHelper.redirect_url("https://www.macupdate.com/app/mac/10700").should == "https://www.macupdate.com/app/mac/10700/firefox"
it "returns a URL" do
NokogiriHelper.redirect_url("https://www.macupdate.com/app/mac/10700").should == "https://macupdate.com/app/mac/10700/firefox"
end
end

context "given a URL with no redirect" do
it "returns a redirect URL from a URL" do
it "returns nil" do
NokogiriHelper.redirect_url("https://www.macupdate.com/app/mac/10700/firefox").should be_nil
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/version_tracker_spec.rb
Expand Up @@ -8,13 +8,13 @@
context "given a package branch with a perfect macupdate.com page" do
it "fetches and assigns all kinds of stuff" do
branch = FactoryGirl.create(:package_branch, :display_name => "Firefox")
tracker = VersionTracker.new do |t|
t.package_branch = branch
tracker = VersionTracker.new do |vt|
vt.package_branch = branch
end

tracker.fetch_data
[tracker.icon, tracker.description, tracker.version, tracker.download_links].each do |attr|
attr.should be_present
[:icon, :description, :version, :download_links].each do |method_name|
tracker.send(method_name).should be_present, "expected #{method_name} to be present"
end
end
end
Expand Down

0 comments on commit 24413d3

Please sign in to comment.