scinote-web/test/models/sample_test.rb

56 lines
1.3 KiB
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
require 'test_helper'
require 'helpers/searchable_model_test_helper'
class SampleTest < ActiveSupport::TestCase
include SearchableModelTestHelper
def setup
@sample = samples(:sample1)
@user = users(:jlaw)
end
2017-01-25 20:56:43 +08:00
test 'should validate with correct data' do
2016-02-12 23:52:43 +08:00
assert @sample.valid?
end
2017-01-25 20:56:43 +08:00
test 'should not validate without name' do
2016-02-12 23:52:43 +08:00
@sample.name = nil
assert_not @sample.valid?
2017-01-25 20:56:43 +08:00
@sample.name = ''
2016-02-12 23:52:43 +08:00
assert_not @sample.valid?
end
2017-01-25 20:56:43 +08:00
test 'should not validate with to long name' do
2016-02-12 23:52:43 +08:00
@sample.name *= 50
assert_not @sample.valid?
end
2017-01-25 20:56:43 +08:00
test 'should not validate with non existent user' do
2016-02-12 23:52:43 +08:00
@sample.user_id = 1232132
assert_not @sample.valid?
@sample.user = nil
assert_not @sample.valid?
end
2017-01-25 20:56:43 +08:00
test 'should not validate with non existent team' do
@sample.team_id = 1231232
2016-02-12 23:52:43 +08:00
assert_not @sample.valid?
2017-01-25 20:56:43 +08:00
@sample.team = nil
2016-02-12 23:52:43 +08:00
assert_not @sample.valid?
end
2017-01-25 20:56:43 +08:00
test 'where_attributes_like should work' do
attributes_like_test(Sample, :name, 'dna')
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should get user\'s samples' do
2016-02-12 23:52:43 +08:00
samples = Sample.search(@user, false)
assert_equal 5, samples.size
end
2017-01-25 20:56:43 +08:00
test 'should search user\'s samples by name' do
samples = Sample.search(@user, false, 'test')
2016-02-12 23:52:43 +08:00
assert_equal 2, samples.size
end
end