Skip to content

2.0.3 #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2016
Merged

2.0.3 #270

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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