Skip to content

Commit

Permalink
Merge pull request #270 from jywarren/2.0.3
Browse files Browse the repository at this point in the history
2.0.3
  • Loading branch information
jywarren committed Jan 22, 2016
2 parents 528075e + e26e9d6 commit c87d5ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index
if logged_in?
if params[:calibration_id]
@calibration = Spectrum.find(params[:calibration_id])
else
elsif current_user.calibrations.count > 0
@calibration = current_user.last_calibration
end
@calibrations = Spectrum.where(calibrated: true, user_id: current_user.id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/spectrum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def generate_processed_spectrum
end

def latest_json_data
if self.snapshots.length > 0
if self.snapshots.count > 0
return ActiveSupport::JSON.decode(self.snapshots.last.data)
else
return ActiveSupport::JSON.decode(self.clean_json)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def email=(value)
end

def last_calibration
self.calibrations.first
Spectrum.find self.calibrations.first.id
end

def calibrations
Expand Down
25 changes: 25 additions & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,29 @@
class UserTest < ActiveSupport::TestCase
fixtures :users

test "user calibrations" do
u = User.first
assert_not_nil u.calibrations
end

test "user last calibration" do
u = User.first

s = Spectrum.new({
title: "A new spectrum",
author: User.first.login,
video_row: 1, # the vertical cross section of the video feed
notes: "This was nice, wasn't it.",
user_id: User.first.id,
})
s.image_from_dataurl("data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7")
s.data = '{"lines":[{"r":10,"g":10,"b":10,"average":10,"wavelength":400},{"r":10,"g":10,"b":10,"average":10,"wavelength":700}]}'
assert s.save!
assert s.tag('linearCalibration:0-1', User.first.id)

assert u.calibrations.count > 0
assert_not_nil u.last_calibration
assert_not_nil u.last_calibration
end

end

0 comments on commit c87d5ae

Please sign in to comment.