Skip to content

Commit

Permalink
Add easier generate_file_path method
Browse files Browse the repository at this point in the history
  • Loading branch information
dessy committed Oct 27, 2014
1 parent 3cafc96 commit 73ec129
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pedometer/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ def initialize(file_path)

# -- Class Methods --------------------------------------------------------

def self.generate_file_path_temp(user_params, trial_params)
user_file_path = user_params.join('-')
trial_file_path = trial_params.map { |x| x.to_s.gsub(/\s+/, '')}.join('-')

UPLOAD_DIRECTORY + "#{user_file_path}_#{trial_file_path}.txt"
end

# TODO: Get rid of this and use the one above
def self.generate_file_path(analyzer)
UPLOAD_DIRECTORY + "#{analyzer.user.gender}-" +
"#{analyzer.user.height}-" +
Expand Down
15 changes: 13 additions & 2 deletions pedometer/test/unit/upload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

class UploadTest < Test::Unit::TestCase

def test_generate_file_path_temp
user_params = ['male', 167.5, 80]
trial_params = ['test trial 1', 5, '10', 'walk']
expected = "public/uploads/male-167.5-80_testtrial1-5-10-walk.txt"
assert_equal expected, Upload.generate_file_path_temp(user_params, trial_params)

user_params = ['male', '167.5', '80']
trial_params = ['test trial 1', '5', '10', 'walk']
assert_equal expected, Upload.generate_file_path_temp(user_params, trial_params)
end

def test_generate_file_path
parser = Parser.run(File.read('test/data/upload-1.txt'))
processor = Processor.run(parser.parsed_data)
user = User.new('male', 167.5, 80)
trial = Trial.new('test trial 1', 5, '10', 'walk')
trial = Trial.new('test trial 2', 5, '10', 'walk')

analyzer = Analyzer.run(processor, user, trial)

expected = "public/uploads/male-167.5-80.0_testtrial1-5-10-walk.txt"
expected = "public/uploads/male-167.5-80.0_testtrial2-5-10-walk.txt"
assert_equal expected, Upload.generate_file_path(analyzer)
end

Expand Down

0 comments on commit 73ec129

Please sign in to comment.