Skip to content

Commit

Permalink
Fixed bug + tests ZIP output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilawal Hameed committed Oct 17, 2015
1 parent 7cc3668 commit 36be77c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def to_min_secs
# The filename we'll call it in the ZIP file.
def filename
formatted_name = "#{name}".tr(' ', '_')
random_string = SecureRandom.urlsafe_base64[0..4]
formatted_time = "#{created_at.hour}:#{created_at.min}:#{created_at.sec}"

"#{hackathon}/#{formatted_name}_#{random_string}.html"
"#{hackathon}/#{formatted_name}_#{formatted_time}.html"
end

key :name, String
Expand Down
6 changes: 4 additions & 2 deletions no_light_sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def show_editor(custom_branding = 'dell')
end

def create_tempfile
@create_tempfile = Tempfile.new(get_hackathon)
@create_tempfile ||= Tempfile.new(get_hackathon)
end

def get_submit_params
Expand All @@ -78,7 +78,9 @@ def create_zip_folder(array = [])
if block_given?
yield(zip)
else
array.to_a.each { |entry| zip[entry.filename] = entry.html }
array.to_a.each do |entry|
zip[entry.filename] = entry.html
end
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions spec/admin_can_download_submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def visit_download_and_validate_zip(hackathon)
page.response_headers['Content-Disposition'].must_equal 'attachment; filename="' + hackathon + '.zip"'
page.response_headers['Content-Transfer-Encoding'].must_equal 'binary'

# Need to add tests to check the contents of the ZIP.
# Currently `page.body` isn't returning anything. Need to investigate.
tempfile = Tempfile.new(hackathon)
tempfile.write(page.source)
tempfile.close

Submission.by_hackathon(hackathon).map(&:filename).must_equal Zippy.list(tempfile.path)
end
end

0 comments on commit 36be77c

Please sign in to comment.