Merge pull request #1124 from jpiasetz/master

Change cucumber tests to not write posts with timezones
This commit is contained in:
Matt Rogers 2013-05-23 14:28:01 -07:00
commit 1cf9efcfa1
2 changed files with 41 additions and 27 deletions

View File

@ -47,44 +47,38 @@ Given /^I have an? (.*) directory$/ do |dir|
FileUtils.mkdir_p(dir)
end
Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, direction, folder, table|
Given /^I have the following (draft|post)s?(?: (in|under) "([^"]+)")?:$/ do |status, direction, folder, table|
table.hashes.each do |post|
title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
if direction && direction == "in"
before = folder || '.'
elsif direction && direction == "under"
after = folder || '.'
end
title = slug(post['title'])
ext = post['type'] || 'textile'
before, after = location(folder, direction)
if post['date']
in_format, out_format = time_format(post['date'])
parsed_date = DateTime.strptime(post['date'], in_format)
post['date'] = parsed_date.strftime(out_format)
end
if "draft" == status
path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}")
else
format = if has_time_component?(post['date'])
'%Y-%m-%d %H:%M %z'
else
'%m/%d/%Y' # why even
end
parsed_date = DateTime.strptime(post['date'], format)
post['date'] = parsed_date.to_s
date = parsed_date.strftime('%Y-%m-%d')
path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}")
folder_post = '_drafts'
filename = "#{title}.#{ext}"
elsif "post" == status
folder_post = '_posts'
filename = "#{parsed_date.strftime('%Y-%m-%d')}-#{title}.#{ext}"
end
path = File.join(before, folder_post, after, filename)
matter_hash = {}
%w(title layout tag tags category categories published author path).each do |key|
%w(title layout tag tags category categories published author path date).each do |key|
matter_hash[key] = post[key] if post[key]
end
if "post" == status
matter_hash["date"] = post["date"] if post["date"]
end
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp
content = post['content']
if post['input'] && post['filter']
content = "{{ #{post['input']} | #{post['filter']} }}"
content = if post['input'] && post['filter']
"{{ #{post['input']} | #{post['filter']} }}"
else
post['content']
end
File.open(path, 'w') do |f|

View File

@ -17,9 +17,29 @@ def run_jekyll(opts = {})
system command
end
def time_format(date)
if has_time_component?(date)
['%Y-%m-%d %H:%M %z'] * 2
else
['%m/%d/%Y', '%Y-%m-%d %H:%M']
end
end
def has_time_component?(date_string)
date_string.split(" ").size > 1
end
def slug(title)
title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
end
def location(folder, direction)
if folder
before = folder if direction == "in"
after = folder if direction == "under"
end
[before || '.', after || '.']
end
# work around "invalid option: --format" cucumber bug (see #296)
Test::Unit.run = true if RUBY_VERSION < '1.9'