Skip to content

Commit

Permalink
Use generate_file_path method that does not require analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
dessy committed Nov 2, 2014
1 parent 953d05f commit 49fe09f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
17 changes: 4 additions & 13 deletions pedometer/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,17 @@ def initialize(file_path)

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

def self.generate_file_path_temp(user_params, trial_params)
def self.generate_file_path(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}-" +
"#{analyzer.user.stride}_" +
"#{analyzer.trial.name.to_s.gsub(/\s+/, '')}-" +
"#{analyzer.trial.rate}-" +
"#{analyzer.trial.steps}-" +
"#{analyzer.trial.method}.txt"
end

def self.create(temp_file, analyzer)
cp(temp_file, self.generate_file_path(analyzer))
user_params = [analyzer.user.gender, analyzer.user.height, analyzer.user.stride]
trial_params = [analyzer.trial.name, analyzer.trial.rate, analyzer.trial.steps, analyzer.trial.method]
cp(temp_file, self.generate_file_path(user_params, trial_params))
end

def self.find(file_path)
Expand Down
18 changes: 3 additions & 15 deletions pedometer/test/unit/upload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@

class UploadTest < Test::Unit::TestCase

def test_generate_file_path_temp
def test_generate_file_path
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)
assert_equal expected, Upload.generate_file_path(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 2', 5, '10', 'walk')

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

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

def test_create
Expand Down
6 changes: 5 additions & 1 deletion pedometer/views/summary.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
<td><%= analyzer.trial.steps ? (analyzer.steps - analyzer.trial.steps) : '' %></td>
<td><%= analyzer.user.gender %></td>
<% if detail_hidden %>
<td><a href=<%= "upload/" + Upload.generate_file_path(analyzer) %>>Detail</a></td>
<td>
<% user_params = [analyzer.user.gender, analyzer.user.height, analyzer.user.stride] %>
<% trial_params = [analyzer.trial.name, analyzer.trial.rate, analyzer.trial.steps, analyzer.trial.method] %>
<a href=<%= "upload/" + Upload.generate_file_path(user_params, trial_params) %>>Detail</a>
</td>
<% else %>
<td><%= format_distance(analyzer.distance) %></td>
<td><%= format_time(analyzer.time) %></td>
Expand Down

0 comments on commit 49fe09f

Please sign in to comment.