Skip to content

Commit c87d5ae

Browse files
committed
Merge pull request #270 from jywarren/2.0.3
2.0.3
2 parents 528075e + e26e9d6 commit c87d5ae

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

app/controllers/capture_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def index
1111
if logged_in?
1212
if params[:calibration_id]
1313
@calibration = Spectrum.find(params[:calibration_id])
14-
else
14+
elsif current_user.calibrations.count > 0
1515
@calibration = current_user.last_calibration
1616
end
1717
@calibrations = Spectrum.where(calibrated: true, user_id: current_user.id)

app/models/spectrum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def generate_processed_spectrum
510510
end
511511

512512
def latest_json_data
513-
if self.snapshots.length > 0
513+
if self.snapshots.count > 0
514514
return ActiveSupport::JSON.decode(self.snapshots.last.data)
515515
else
516516
return ActiveSupport::JSON.decode(self.clean_json)

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def email=(value)
7777
end
7878

7979
def last_calibration
80-
self.calibrations.first
80+
Spectrum.find self.calibrations.first.id
8181
end
8282

8383
def calibrations

test/unit/user_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,29 @@
33
class UserTest < ActiveSupport::TestCase
44
fixtures :users
55

6+
test "user calibrations" do
7+
u = User.first
8+
assert_not_nil u.calibrations
9+
end
10+
11+
test "user last calibration" do
12+
u = User.first
13+
14+
s = Spectrum.new({
15+
title: "A new spectrum",
16+
author: User.first.login,
17+
video_row: 1, # the vertical cross section of the video feed
18+
notes: "This was nice, wasn't it.",
19+
user_id: User.first.id,
20+
})
21+
s.image_from_dataurl("data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7")
22+
s.data = '{"lines":[{"r":10,"g":10,"b":10,"average":10,"wavelength":400},{"r":10,"g":10,"b":10,"average":10,"wavelength":700}]}'
23+
assert s.save!
24+
assert s.tag('linearCalibration:0-1', User.first.id)
25+
26+
assert u.calibrations.count > 0
27+
assert_not_nil u.last_calibration
28+
assert_not_nil u.last_calibration
29+
end
30+
631
end

0 commit comments

Comments
 (0)