rename organizations in test/

This commit is contained in:
zmagod 2017-01-25 13:56:43 +01:00
parent f04a2f663a
commit 883a6ea544
26 changed files with 355 additions and 356 deletions

View file

@ -1,25 +1,25 @@
org_1:
name: Org1
team_1:
name: Team1
org_2:
name: Org2
team_2:
name: Team2
user_1:
full_name: Usr1
email: usr1@gmail.com
organizations: org_1, org_2
teams: team_1, team_2
password: secretPassword
user_2:
full_name: Usr2
email: usr2@gmail.com
organizations: org_1
teams: team_1
user_3:
full_name: Usr3
email: usr3@gmail.com
organizations: org_2
teams: team_2
user_4:
full_name: Usr4
email: usr4@gmail.com
email: usr4@gmail.com

View file

@ -1,6 +1,6 @@
require 'test_helper'
class OrganizationsControllerTest < ActionController::TestCase
class TeamsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end

View file

@ -1,16 +1,14 @@
volume:
name: "Volume"
user: steve
organization: biosistemika
team: biosistemika
location:
name: "Location"
user: jlaw
organization: biosistemika
team: biosistemika
description:
name: "Description"
user: nora
organization: nib
team: nib

View file

@ -1,8 +1,7 @@
one:
organization: biosistemika
team: biosistemika
message: This is a test log numero uno
two:
organization: biosistemika
team: biosistemika
message: This is a test log numero due

View file

@ -2,7 +2,7 @@ interfaces:
name: INTERFACES
visibility: 1
due_date: 2015-11-02 15:30:22
organization: biosistemika
team: biosistemika
archived: false
archived_on:
created_at: 2015-11-01 11:37:26
@ -16,7 +16,7 @@ eurostars:
name: EUROSTARS
visibility: 1
due_date: 2015-11-02 15:30:22
organization: biosistemika
team: biosistemika
archived: false
archived_on:
created_at: 2015-11-01 12:53:07
@ -30,7 +30,7 @@ krop:
name: KROP 2012
visibility: 1
due_date: 2012-05-07 13:30:25
organization: biosistemika
team: biosistemika
archived: true
archived_on: 2012-05-09 16:23:33
created_by: mark
@ -43,7 +43,7 @@ phd:
name: PhD Thesis
visibility: 0
due_date:
organization: nib
team: nib
archived: false
archived_on:
created_by: mark
@ -56,7 +56,7 @@ decathlon:
name: DECATHLON
visibility: 1
due_date:
organization: phylos
team: phylos
archived: false
archived_on:
created_by: jlaw
@ -69,7 +69,7 @@ valor:
name: VALOR 2010
visibility: 1
due_date: 2010-11-13 14:11:23
organization: nib
team: nib
archived: false
archived_on: 2012-05-09 16:33:33
created_by: nora
@ -82,9 +82,9 @@ secret:
name: My Secret Life
visibility: 0
due_date: 2030-06-04 13:00:00
organization: nib
team: nib
archived: false
archived_on:
archived_on:
created_by: mark
last_modified_by: steve
archived_by:
@ -95,7 +95,7 @@ a_project:
name: A Project
visibility: 1
due_date: 2018-12-02 15:30:22
organization: biosistemika
team: biosistemika
archived: false
archived_on:
created_at: 2015-11-01 14:28:15
@ -109,7 +109,7 @@ z_project:
name: Z Project
visibility: 1
due_date: 2018-12-02 15:30:22
organization: biosistemika
team: biosistemika
archived: false
archived_on:
created_at: 2015-11-01 16:15:37
@ -123,7 +123,7 @@ a_archived_project:
name: A Archived Project
visibility: 1
due_date: 2018-12-02 15:30:22
organization: biosistemika
team: biosistemika
archived: true
archived_on: 2015-11-05 08:14:56
created_at: 2015-11-01 14:28:15
@ -137,7 +137,7 @@ z_archived_project:
name: Z Archived Project
visibility: 1
due_date: 2018-12-02 15:30:22
organization: biosistemika
team: biosistemika
archived: true
archived_on: 2015-11-05 08:12:56
created_at: 2015-11-01 16:15:37
@ -151,25 +151,25 @@ test1:
name: Project 1
visibility: 1
due_date: <%= DateTime.now %>
organization: biosistemika
team: biosistemika
archived: false
created_by: steve
test2:
name: Project 2
visibility: 0
organization: biosistemika
team: biosistemika
archived: true
archived_on: <%= DateTime.now %>
test3:
name: Project 3
visibility: 1
organization: nib
team: nib
archived: false
dummy:
name: Dummy project
visibility: 1
organization: nib
team: nib
archived: false

View file

@ -1,19 +1,19 @@
kw1:
name: "qPCR"
organization: biosistemika
team: biosistemika
kw2:
name: "Lab"
organization: biosistemika
team: biosistemika
kw3:
name: "ELISA"
organization: biosistemika
team: biosistemika
kw4:
name: "Sample Prep"
organization: biosistemika
team: biosistemika
kw5:
name: "Vortexing"
organization: biosistemika
team: biosistemika

View file

@ -4,21 +4,21 @@ rna_test_protocol:
description: "This is a test protocol."
added_by: steve
my_module: rna_test
organization: biosistemika
team: biosistemika
protocol_type: 1
parent: rna_test_protocol_global
parent_updated_at: "2015-11-06 11:12:00"
sample_prep_protocol:
my_module: sample_prep
organization: biosistemika
team: biosistemika
protocol_type: 0
list_of_samples_protocol:
name: "List samples"
description: "This is WIP, don't touch"
my_module: list_of_samples
organization: biosistemika
team: biosistemika
protocol_type: 0
rna_test_protocol_global:
@ -26,7 +26,7 @@ rna_test_protocol_global:
authors: "Schmidt, Jurgen"
description: "This is a test protocol."
added_by: steve
organization: biosistemika
team: biosistemika
protocol_type: 3
updated_at: "2015-11-06 11:12:00"
published_on: "2015-11-06 11:12:00"
published_on: "2015-11-06 11:12:00"

View file

@ -1,7 +1,7 @@
blood:
name: Blood
color: "#ff0000"
organization: biosistemika
team: biosistemika
created_by: steve
last_modified_by: mark
@ -9,6 +9,6 @@ blood:
noble:
name: Blue blood
color: "#0000ff"
organization: biosistemika
team: biosistemika
created_by: steve
last_modified_by: steve

View file

@ -1,9 +1,9 @@
skin:
name: Skin
organization: biosistemika
team: biosistemika
created_by: steve
urine:
name: Urine
organization: biosistemika
team: biosistemika
created_by: steve

View file

@ -1,7 +1,7 @@
sample1:
name: Cow DNA
user: steve
organization: biosistemika
team: biosistemika
sample_type: urine
sample_group: blood
last_modified_by: steve
@ -9,7 +9,7 @@ sample1:
sample2:
name: Bat DNA
user: steve
organization: biosistemika
team: biosistemika
sample_type: skin
sample_group: noble
last_modified_by: steve
@ -17,15 +17,15 @@ sample2:
sample3:
name: Cat DNA
user: steve
organization: biosistemika
team: biosistemika
last_modified_by: jlaw
test:
name: Test Sample
user: jlaw
organization: biosistemika
team: biosistemika
test2:
name: Another test sample
user: jlaw
organization: biosistemika
team: biosistemika

View file

@ -12,10 +12,10 @@ phylos:
created_by: steve
test:
name: Test Organization
description: "Testing organization, you know"
name: Test Team
description: "Testing team, you know"
steve_org:
name: Steve's Organization
description: "Private organization"
created_by: steve
steve_team:
name: Steve's Team
description: "Private team"
created_by: steve

View file

@ -1,98 +1,98 @@
one:
user: steve
organization: biosistemika
team: biosistemika
role: 1
assigned_by: steve
two:
user: steve
organization: nib
team: nib
role: 1
assigned_by: steve
seven:
user: steve
organization: phylos
team: phylos
role: 1
assigned_by: steve
three:
user: mark
organization: biosistemika
team: biosistemika
role: 1
assigned_by: mark
four:
user: mark
organization: nib
team: nib
role: 2
assigned_by: mark
five:
user: jlaw
organization: biosistemika
team: biosistemika
role: 0
assigned_by: steve
six:
user: nora
organization: nib
team: nib
role: 1
assigned_by: nora
eight:
user: nora
organization: phylos
team: phylos
role: 2
assigned_by: nora
nine:
user: default
organization: biosistemika
team: biosistemika
role: 2
assigned_by: default
ten:
user: default
organization: nib
team: nib
role: 2
assigned_by: default
without_role:
user: nora
organization: nib
team: nib
role: -1
assigned_by: steve
without_user:
user: 0
organization: nib
team: nib
role: 1
assigned_by: steve
without_organization:
without_team:
user: nora
organization: 0
team: 0
role: 1
assigned_by: steve
with_invalid_user:
user_id: <%= Constants::INFINITY %>
organization: nib
team: nib
role: 1
assigned_by: steve
with_invalid_organization:
with_invalid_team:
user: nora
organization_id: <%= Constants::INFINITY %>
team_id: <%= Constants::INFINITY %>
role: 1
assigned_by: steve

View file

@ -21,14 +21,14 @@ class AppMailerPreview < ActionMailer::Preview
Notification.new(
type_of: :assignment,
title: I18n.t(
'notifications.assign_user_to_organization',
'notifications.assign_user_to_team',
assigned_user: fake_user_2.full_name,
role: 'Administrator',
organization: fake_org.name,
team: fake_team.name,
assigned_by_user: fake_user.full_name
),
message: ActionController::Base.helpers.sanitize(
"<a href='#' target='_blank'>#{fake_org.name}</a>"
"<a href='#' target='_blank'>#{fake_team.name}</a>"
),
generator_user: fake_user,
created_at: Time.now
@ -93,8 +93,8 @@ class AppMailerPreview < ActionMailer::Preview
)
end
def fake_org
Organization.new(
def fake_team
Team.new(
name: 'Greatest musicians of all time'
)
end

View file

@ -15,21 +15,21 @@ class CustomFieldTest < ActiveSupport::TestCase
'Added on',
'Added by'])
test "should validate with correct data" do
test 'should validate with correct data' do
assert @custom_field.valid?
end
test "should not validate with non existent user" do
test 'should not validate with non existent user' do
@custom_field.user_id = 11231231
assert_not @custom_field.valid?
@custom_field.user = nil
assert_not @custom_field.valid?
end
test "should not validate with non existent organization" do
@custom_field.organization_id = 1231231
test 'should not validate with non existent team' do
@custom_field.team_id = 1231231
assert_not @custom_field.valid?
@custom_field.organization = nil
@custom_field.team = nil
assert_not @custom_field.valid?
end
end

View file

@ -1,28 +1,27 @@
require 'test_helper'
class LogTest < ActiveSupport::TestCase
def setup
@log = logs(:one)
end
test "should validate log with valid data" do
test 'should validate log with valid data' do
assert @log.valid?
end
test "should have non-blank message" do
@log.message = ""
assert @log.invalid?, "Log with blank message returns valid? = true"
test 'should have non-blank message' do
@log.message = ''
assert @log.invalid?, 'Log with blank message returns valid? = true'
@log.message = nil
assert @log.invalid?, "Log with nil message returns valid? = true"
assert @log.invalid?, 'Log with nil message returns valid? = true'
end
test "should have organization" do
@log.organization_id = 12321321
assert @log.invalid?, "Log without organization returns valid? = true"
@log.organization = nil
assert @log.invalid?, "Log without organization returns valid? = true"
@log.organization = Organization.new
assert @log.valid?, "Log with organization returns valid? = false"
test 'should have team' do
@log.team_id = 12321321
assert @log.invalid?, 'Log without team returns valid? = true'
@log.team = nil
assert @log.invalid?, 'Log without team returns valid? = true'
@log.team = Team.new
assert @log.valid?, 'Log with team returns valid? = false'
end
end

View file

@ -1,44 +0,0 @@
require 'test_helper'
class OrganizationTest < ActiveSupport::TestCase
def setup
@org = organizations(:test)
end
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
should validate_length_of(:description)
.is_at_most(Constants::TEXT_MAX_LENGTH)
test "should validate organization default values" do
assert @org.valid?
end
test "should have non-blank name" do
@org.name = ""
assert @org.invalid?, "Organization with blank name returns valid? = true"
end
test "should have space_taken present" do
@org.space_taken = nil
assert @org.invalid?, "Organization without space_taken returns valid? = true"
end
test "space_taken_defaults_to_value" do
org = Organization.new
assert_equal Constants::MINIMAL_ORGANIZATION_SPACE_TAKEN, org.space_taken
end
test "should save log message" do
message = "This is test message"
@org.log(message)
log_message = Log.last.message[26..-1]
assert_equal log_message, message
end
test "should open spreadsheet file" do
skip
end
end

View file

@ -16,58 +16,59 @@ class ProjectTest < ActiveSupport::TestCase
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
test "should have non-blank name" do
@project.name = ""
assert @project.invalid?, "Project with blank name returns valid? = true"
test 'should have non-blank name' do
@project.name = ''
assert @project.invalid?, 'Project with blank name returns valid? = true'
end
test "should have organization-wide unique name" do
test 'should have team-wide unique name' do
@project.name = @project2.name
assert @project.invalid?, "Project with non-unique organization-wide name returns valid? = true"
assert @project.invalid?,
'Project with non-unique team-wide name returns valid? = true'
end
test "should not have non-organization-wide unique name" do
test 'should not have non-team-wide unique name' do
@project.name = @project3.name
assert @project.valid?, "Project with non-unique name in different organizations returns valid? = false"
assert @project.valid?,
'Project with non-unique name in different teams ' \
'returns valid? = false'
end
test "should have default visibility & archived" do
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'
end
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'
end
test 'should have archived set' do
project = Project.new(
name: "sample project",
organization_id: organizations(:biosistemika).id)
assert project.hidden?, "Project by default doesn't have visibility = hidden set"
assert_not project.archived?, "Project has default archived = true"
end
test "should belong to organization" do
@project.organization = nil
assert_not @project.valid?, "Project without organization returns valid? = true"
@project.organization_id = 12321321
assert_not @project.valid?, "Project with organization returls valid? = false"
end
test "should have archived set" do
project = Project.new(
name: "test project",
name: 'test project',
visibility: 1,
organization_id: organizations(:biosistemika).id
team_id: teams(:biosistemika).id
)
assert_archived_present(project)
assert_active_is_inverse_of_archived(project)
end
test "archiving should work" do
test 'archiving should work' do
user = users(:steve)
project = Project.new(
name: "test project",
visibility: 1,
organization_id: organizations(:biosistemika).id,
)
project = Project.new(name: 'test project',
visibility: 1,
team_id: teams(:biosistemika).id)
project.save
archive_and_restore_action_test(project, user)
end
test "where_attributes_like should work" do
attributes_like_test(Project, :name, "star")
test 'where_attributes_like should work' do
attributes_like_test(Project, :name, 'star')
end
end

View file

@ -3,20 +3,20 @@ require 'test_helper'
class ProtocolTest < ActiveSupport::TestCase
def setup
@user = users(:steve)
@org = organizations(:biosistemika)
@team = teams(:biosistemika)
@my_module = my_modules(:sample_prep)
@global = protocols(:rna_test_protocol_global)
@p = Protocol.new(
my_module: @my_module,
organization: @org
team: @team
)
end
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
should validate_length_of(:description).is_at_most(Constants::TEXT_MAX_LENGTH)
test "protocol_type enum works" do
test 'protocol_type enum works' do
@p.protocol_type = :unlinked
assert @p.in_module?
@p.protocol_type = :linked
@ -29,31 +29,31 @@ class ProtocolTest < ActiveSupport::TestCase
assert @p.in_repository?
end
test "should not validate without organization" do
@p.organization = @org
test 'should not validate without team' do
@p.team = @team
assert @p.valid?
@p.organization = nil
@p.team = nil
assert_not @p.valid?
end
test "should not validate without protocol type" do
test 'should not validate without protocol type' do
assert @p.valid?
@p.protocol_type = nil
assert_not @p.valid?
end
test "should count steps of protocol" do
test 'should count steps of protocol' do
assert_equal 0, @p.number_of_steps
end
test "specific validations for :unlinked" do
test 'specific validations for :unlinked' do
p = new_unlinked_protocol
assert p.valid?
p.my_module = nil
assert_not p.valid?
end
test "specific validations for :linked" do
test 'specific validations for :linked' do
p = new_linked_protocol
assert p.valid?
@ -73,17 +73,17 @@ class ProtocolTest < ActiveSupport::TestCase
assert_not p.valid?
end
test "specific validations for :in_repository" do
test 'specific validations for :in_repository' do
[
:in_repository_private,
:in_repository_public,
:in_repository_archived
].each do |protocol_type|
p = new_repository_protocol(protocol_type)
if protocol_type == :in_repository_archived then
if protocol_type == :in_repository_archived
p.archived_by = @user
p.archived_on = Time.now
elsif protocol_type == :in_repository_public then
elsif protocol_type == :in_repository_public
p.published_on = Time.now
end
assert p.valid?
@ -109,7 +109,7 @@ class ProtocolTest < ActiveSupport::TestCase
end
end
test "specific validations for :in_repository_public" do
test 'specific validations for :in_repository_public' do
p = new_repository_protocol(:in_repository_public)
p.published_on = nil
assert_not p.valid?
@ -118,7 +118,7 @@ class ProtocolTest < ActiveSupport::TestCase
assert p.valid?
end
test "specific validations for :in_repository_archived" do
test 'specific validations for :in_repository_archived' do
p = new_repository_protocol(:in_repository_archived)
p.archived_by = nil
p.archived_on = nil
@ -136,7 +136,7 @@ class ProtocolTest < ActiveSupport::TestCase
def new_unlinked_protocol
Protocol.new(
my_module: @my_module,
organization: @org
team: @team
)
end
@ -144,7 +144,7 @@ class ProtocolTest < ActiveSupport::TestCase
Protocol.new(
protocol_type: :linked,
my_module: @my_module,
organization: @org,
team: @team,
added_by: @user,
parent: @global,
parent_updated_at: @global.updated_at
@ -153,11 +153,10 @@ class ProtocolTest < ActiveSupport::TestCase
def new_repository_protocol(type)
Protocol.new(
name: "Test protocol",
name: 'Test protocol',
protocol_type: type,
organization: @org,
team: @team,
added_by: @user
)
end
end

View file

@ -9,14 +9,14 @@ class SampleGroupTest < ActiveSupport::TestCase
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
should validate_presence_of(:color)
should validate_length_of(:color).is_at_most(Constants::COLOR_MAX_LENGTH)
should validate_presence_of(:organization)
should validate_presence_of(:team)
test "should validate with correct data" do
test 'should validate with correct data' do
assert @sample_group.valid?
end
test "should not validate without organization" do
@sample_group.organization = nil
test 'should not validate without team' do
@sample_group.team = nil
assert_not @sample_group.valid?
end
end

View file

@ -5,31 +5,30 @@ class SampleMyModuleTest < ActiveSupport::TestCase
@sample_module = sample_my_modules(:one)
end
test "should validate with correct data" do
test 'should validate with correct data' do
assert @sample_module.valid?
end
test "should not validate with non existent sample" do
test 'should not validate with non existent sample' do
@sample_module.sample_id = 123123213
assert_not @sample_module.valid?
@sample_module.sample = nil
assert_not @sample_module.valid?
end
test "should not validate with non existent my_module" do
test 'should not validate with non existent my_module' do
@sample_module.my_module_id = 12312312
assert_not @sample_module.valid?
@sample_module.my_module = nil
assert_not @sample_module.valid?
end
test "should have association my_module <-> sample" do
sample = Sample.create(
name: "test sample",
user: users(:jlaw),
organization: organizations(:biosistemika))
test 'should have association my_module <-> sample' do
sample = Sample.create(name: 'test sample',
user: users(:jlaw),
team: teams(:biosistemika))
my_module = MyModule.create(
name: "test module",
name: 'test module',
experiment: experiments(:philadelphia),
my_module_group: my_module_groups(:wf1)
)

View file

@ -9,47 +9,47 @@ class SampleTest < ActiveSupport::TestCase
@user = users(:jlaw)
end
test "should validate with correct data" do
test 'should validate with correct data' do
assert @sample.valid?
end
test "should not validate without name" do
test 'should not validate without name' do
@sample.name = nil
assert_not @sample.valid?
@sample.name = ""
@sample.name = ''
assert_not @sample.valid?
end
test "should not validate with to long name" do
test 'should not validate with to long name' do
@sample.name *= 50
assert_not @sample.valid?
end
test "should not validate with non existent user" do
test 'should not validate with non existent user' do
@sample.user_id = 1232132
assert_not @sample.valid?
@sample.user = nil
assert_not @sample.valid?
end
test "should not validate with non existent organization" do
@sample.organization_id = 1231232
test 'should not validate with non existent team' do
@sample.team_id = 1231232
assert_not @sample.valid?
@sample.organization = nil
@sample.team = nil
assert_not @sample.valid?
end
test "where_attributes_like should work" do
attributes_like_test(Sample, :name, "dna")
test 'where_attributes_like should work' do
attributes_like_test(Sample, :name, 'dna')
end
test "should get user's samples" do
test 'should get user\'s samples' do
samples = Sample.search(@user, false)
assert_equal 5, samples.size
end
test "should search user's samples by name" do
samples = Sample.search(@user, false, "test")
test 'should search user\'s samples by name' do
samples = Sample.search(@user, false, 'test')
assert_equal 2, samples.size
end
end

View file

@ -7,16 +7,16 @@ class SampleTypeTest < ActiveSupport::TestCase
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
should validate_presence_of(:name)
should validate_presence_of(:organization)
should validate_presence_of(:team)
test 'should validate with correct data' do
assert @sample_type.valid?
end
test 'should not validate without organization' do
@sample_type.organization_id = 12321321
test 'should not validate without team' do
@sample_type.team_id = 12321321
assert_not @sample_type.valid?
@sample_type.organization = nil
@sample_type.team = nil
assert_not @sample_type.valid?
end
end

45
test/models/team_test.rb Normal file
View file

@ -0,0 +1,45 @@
require 'test_helper'
class TeamTest < ActiveSupport::TestCase
def setup
@team = teams(:test)
end
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
should validate_length_of(:description)
.is_at_most(Constants::TEXT_MAX_LENGTH)
test 'should validate team default values' do
assert @team.valid?
end
test 'should have non-blank name' do
@team.name = ''
assert @team.invalid?, 'Team with blank name returns valid? = true'
end
test 'should have space_taken present' do
@team.space_taken = nil
assert @team.invalid?,
'Team without space_taken returns valid? = true'
end
test 'space_taken_defaults_to_value' do
team = Team.new
assert_equal Constants::MINIMAL_TEAM_SPACE_TAKEN, team.space_taken
end
test 'should save log message' do
message = 'This is test message'
@team.log(message)
log_message = Log.last.message[26..-1]
assert_equal log_message, message
end
test 'should open spreadsheet file' do
skip
end
end

View file

@ -1,67 +0,0 @@
require 'test_helper'
class UserOrganizationTest < ActiveSupport::TestCase
def setup
@user_org = user_organizations(:one)
end
# Test role attribute
test "should not save user organization without role" do
assert_not user_organizations(:without_role).save,
"Saved user organization without role"
end
test "should have default role" do
assert @user_org.normal_user?,
"User organization does not have default normal_user role"
end
test "should set valid role values" do
assert_nothing_raised(ArgumentError,
"User organization role was set with invalid role value") {
@user_org.role = 0
@user_org.role = 1
@user_org.role = 2
@user_org.role = "guest"
@user_org.role = "normal_user"
@user_org.role = "admin"
}
end
test "should not have undefined role" do
assert_raises(ArgumentError,
"User organization role can not be set to undefined numeric role value") {
@user_org.role = 5
}
assert_raises(ArgumentError,
"User organization role can not be set to undefined role value") {
@user_org.role = "gatekeeper"
}
end
# Test user attribute
test "should not save user organization without user" do
assert_not user_organizations(:without_user).save,
"Saved user organization without user"
end
test "should not associate unexisting user" do
assert_raises(ActiveRecord::RecordInvalid,
"User organization saved unexisting user association") {
user_organizations(:with_invalid_user).save!
}
end
# Test organization attribute
test "should not save user organization without organization" do
assert_not user_organizations(:without_organization).save,
"Saved user organization without organization"
end
test "should not associate unexisting organization" do
assert_raises(ActiveRecord::RecordInvalid,
"User organization saved unexisting organization association") {
user_organizations(:with_invalid_organization).save!
}
end
end

View file

@ -0,0 +1,69 @@
require 'test_helper'
class UserTeamTest < ActiveSupport::TestCase
def setup
@user_team = user_teams(:one)
end
# Test role attribute
test 'should not save user team without role' do
assert_not user_teams(:without_role).save,
'Saved user team without role'
end
test 'should have default role' do
assert @user_team.normal_user?,
'User team does not have default normal_user role'
end
test 'should set valid role values' do
assert_nothing_raised(
ArgumentError,
'User team role was set with invalid role value'
) do
@user_team.role = 0
@user_team.role = 1
@user_team.role = 2
@user_team.role = 'guest'
@user_team.role = 'normal_user'
@user_team.role = 'admin'
end
end
test 'should not have undefined role' do
assert_raises(
ArgumentError,
'User team role can not be set to undefined numeric role value'
) { @user_team.role = 5 }
assert_raises(
ArgumentError,
'User team role can not be set to undefined role value'
) { @user_team.role = 'gatekeeper' }
end
# Test user attribute
test 'should not save user team without user' do
assert_not user_teams(:without_user).save,
'Saved user team without user'
end
test 'should not associate unexisting user' do
assert_raises(
ActiveRecord::RecordInvalid,
'User team saved unexisting user association'
) { user_teams(:with_invalid_user).save! }
end
# Test team attribute
test 'should not save user team without team' do
assert_not user_teams(:without_team).save,
'Saved user team without team'
end
test 'should not associate unexisting team' do
assert_raises(
ActiveRecord::RecordInvalid,
'User team saved unexisting team association'
) { user_teams(:with_invalid_team).save! }
end
end

View file

@ -4,7 +4,7 @@ class UserTest < ActiveSupport::TestCase
def setup
@user = users(:john)
@user2 = users(:steve)
@org = organizations(:biosistemika)
@team = teams(:biosistemika)
end
should validate_presence_of(:full_name)
@ -13,108 +13,109 @@ class UserTest < ActiveSupport::TestCase
should validate_length_of(:initials)
.is_at_most(Constants::USER_INITIALS_MAX_LENGTH)
# Test password attribute
test "should have non-blank password" do
@user.password = ""
assert @user.invalid?, "User with blank email is not valid"
# Test password attribute
test 'should have non-blank password' do
@user.password = ''
assert @user.invalid?, 'User with blank email is not valid'
end
test "should have password with at least 8 characters" do
@user.password = "1234567"
assert @user.invalid?, "User with too short password is not valid"
@user.password = "12345678"
assert_not @user.invalid?, "User with password longer than 7 characters is valid"
test 'should have password with at least 8 characters' do
@user.password = '1234567'
assert @user.invalid?, 'User with too short password is not valid'
@user.password = '12345678'
assert_not @user.invalid?,
'User with password longer than 7 characters is valid'
end
# Test email attribute
test "should have non-blank email" do
@user.email = ""
assert @user.invalid?, "User with blank email is not valid"
# Test email attribute
test 'should have non-blank email' do
@user.email = ''
assert @user.invalid?, 'User with blank email is not valid'
end
test "should have unique email" do
test 'should have unique email' do
@user.email = @user2.email
assert @user.invalid?, "User with non-unique email in not valid"
assert @user.invalid?, 'User with non-unique email in not valid'
end
# Test methods
test "should get projects for organization" do
org_projects = @user2.projects_by_orgs(@org.id)
assert_equal 1, org_projects.size, "Projects are grouped into one organization"
assert_equal 4, org_projects[@org].size, "Organization group has many projects"
# Test methods
test 'should get projects for team' do
team_projects = @user2.projects_by_teams(@team.id)
assert_equal 1, team_projects.size, 'Projects are grouped into one team'
assert_equal 4, team_projects[@team].size, 'Team group has many projects'
end
test "should get archived projects for organization" do
org_projects = @user2.projects_by_orgs(@org.id, nil, true)
assert_equal 1, org_projects.size, "Projects are grouped into one organization"
assert_equal 2, org_projects[@org].size, "Organization group has many projects"
test 'should get archived projects for team' do
team_projects = @user2.projects_by_teams(@team.id, nil, true)
assert_equal 1, team_projects.size, 'Projects are grouped into one team'
assert_equal 2, team_projects[@team].size, 'Team group has many projects'
end
test "should sort projects by create timestamp ascending" do
org_projects = @user2.projects_by_orgs(@org.id, "old")
test 'should sort projects by create timestamp ascending' do
team_projects = @user2.projects_by_teams(@team.id, 'old')
first_project = projects(:interfaces)
last_project = projects(:z_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort projects by create timestamp descending" do
org_projects = @user2.projects_by_orgs(@org.id)
test 'should sort projects by create timestamp descending' do
team_projects = @user2.projects_by_teams(@team.id)
first_project = projects(:z_project)
last_project = projects(:interfaces)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort projects by project name ascending" do
org_projects = @user2.projects_by_orgs(@org.id, "atoz")
test 'should sort projects by project name ascending' do
team_projects = @user2.projects_by_teams(@team.id, 'atoz')
first_project = projects(:a_project)
last_project = projects(:z_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort projects by project name descending" do
org_projects = @user2.projects_by_orgs(@org.id, "ztoa")
test 'should sort projects by project name descending' do
team_projects = @user2.projects_by_teams(@team.id, 'ztoa')
first_project = projects(:z_project)
last_project = projects(:a_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort archived projects by create timestamp ascending" do
org_projects = @user2.projects_by_orgs(@org.id, "old", true)
test 'should sort archived projects by create timestamp ascending' do
team_projects = @user2.projects_by_teams(@team.id, 'old', true)
first_project = projects(:a_archived_project)
last_project = projects(:z_archived_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort archived projects by create timestamp descending" do
org_projects = @user2.projects_by_orgs(@org.id, nil, true)
test 'should sort archived projects by create timestamp descending' do
team_projects = @user2.projects_by_teams(@team.id, nil, true)
first_project = projects(:z_archived_project)
last_project = projects(:a_archived_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort archived projects by project name ascending" do
org_projects = @user2.projects_by_orgs(@org.id, "atoz", true)
test 'should sort archived projects by project name ascending' do
team_projects = @user2.projects_by_teams(@team.id, 'atoz', true)
first_project = projects(:a_archived_project)
last_project = projects(:z_archived_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should sort archived projects by project name descending" do
org_projects = @user2.projects_by_orgs(@org.id, "ztoa", true)
test 'should sort archived projects by project name descending' do
team_projects = @user2.projects_by_teams(@team.id, 'ztoa', true)
first_project = projects(:z_archived_project)
last_project = projects(:a_archived_project)
assert_equal first_project, org_projects[@org].first
assert_equal last_project, org_projects[@org].last
assert_equal first_project, team_projects[@team].first
assert_equal last_project, team_projects[@team].last
end
test "should get last activities" do
test 'should get last activities' do
last_activities = @user2.last_activities(0)
first_activity = activities(:twelve)
last_activity = activities(:three)
@ -123,7 +124,7 @@ class UserTest < ActiveSupport::TestCase
assert_equal last_activity, last_activities.last
end
test "should get specified number of last activities" do
test 'should get specified number of last activities' do
last_activities = @user2.last_activities(0, 4)
first_activity = activities(:twelve)
last_activity = activities(:nine)
@ -132,19 +133,19 @@ class UserTest < ActiveSupport::TestCase
assert_equal last_activity, last_activities.last
end
test "should allow to change time zone" do
test 'should allow to change time zone' do
assert @user.valid?
@user.time_zone = "Ljubljana"
@user.time_zone = 'Ljubljana'
assert @user.valid?
end
test "should validate time zone value" do
test 'should validate time zone value' do
assert @user.valid?
@user.time_zone = "Very Strange Place on Earth"
@user.time_zone = 'Very Strange Place on Earth'
assert_not @user.valid?
end
test "should check if time zone value is set" do
test 'should check if time zone value is set' do
assert @user.valid?
@user.time_zone = nil
assert_not @user.valid?