scinote-web/test/models/project_test.rb

75 lines
2.2 KiB
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
require 'test_helper'
require 'helpers/archivable_model_test_helper'
require 'helpers/searchable_model_test_helper'
class ProjectTest < ActiveSupport::TestCase
include ArchivableModelTestHelper
include SearchableModelTestHelper
def setup
@project = projects(:test1)
@project2 = projects(:test2)
@project3 = projects(:test3)
end
2016-10-11 14:25:32 +08:00
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
2016-10-11 14:25:32 +08:00
2017-01-25 20:56:43 +08:00
test 'should have non-blank name' do
@project.name = ''
assert @project.invalid?, 'Project with blank name returns valid? = true'
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should have team-wide unique name' do
2016-02-12 23:52:43 +08:00
@project.name = @project2.name
2017-01-25 20:56:43 +08:00
assert @project.invalid?,
'Project with non-unique team-wide name returns valid? = true'
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should not have non-team-wide unique name' do
2016-02-12 23:52:43 +08:00
@project.name = @project3.name
2017-01-25 20:56:43 +08:00
assert @project.valid?,
'Project with non-unique name in different teams ' \
'returns valid? = false'
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should have default visibility & archived' do
project = Project.new(name: 'sample project',
team_id: teams(:biosistemika).id)
assert project.hidden?,
'Project by default doesn\'t have visibility = hidden set'
assert_not project.archived?, 'Project has default archived = true'
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should belong to team' do
@project.team = nil
assert_not @project.valid?, 'Project without team returns valid? = true'
@project.team_id = 12321321
assert_not @project.valid?, 'Project with team returls valid? = false'
2016-02-12 23:52:43 +08:00
end
2017-01-25 20:56:43 +08:00
test 'should have archived set' do
2016-02-12 23:52:43 +08:00
project = Project.new(
2017-01-25 20:56:43 +08:00
name: 'test project',
2016-02-12 23:52:43 +08:00
visibility: 1,
2017-01-25 20:56:43 +08:00
team_id: teams(:biosistemika).id
2016-02-12 23:52:43 +08:00
)
assert_archived_present(project)
assert_active_is_inverse_of_archived(project)
end
2017-01-25 20:56:43 +08:00
test 'archiving should work' do
2016-02-12 23:52:43 +08:00
user = users(:steve)
2017-01-25 20:56:43 +08:00
project = Project.new(name: 'test project',
visibility: 1,
team_id: teams(:biosistemika).id)
2016-02-12 23:52:43 +08:00
project.save
archive_and_restore_action_test(project, user)
end
2017-01-25 20:56:43 +08:00
test 'where_attributes_like should work' do
attributes_like_test(Project, :name, 'star')
2016-02-12 23:52:43 +08:00
end
end