Merge pull request #208 from ZmagoD/aditional-notification-tests

Fix failing tests + add test to notification model
This commit is contained in:
Zmago Devetak 2016-10-17 08:17:29 +02:00 committed by GitHub
commit f10b25dd31
19 changed files with 95 additions and 216 deletions

View file

@ -1,11 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
message: MyString
title: 'Notification one'
message: 'Message for notification one'
type_of: 1
two:
title: MyString
message: MyString
title: 'Notification two'
message: 'Message for notification two'
type_of: 1

View file

@ -1,6 +1,9 @@
require 'test_helper'
class ChecklistItemTest < ActiveSupport::TestCase
should validate_presence_of(:text)
should validate_length_of(:text)
.is_at_most(TEXT_MAX_LENGTH)
test "should validate with correct data" do
chkItem = ChecklistItem.new(
@ -11,22 +14,6 @@ class ChecklistItemTest < ActiveSupport::TestCase
assert chkItem.valid?
end
test "should not validate without text" do
chkItem = ChecklistItem.new(
text: " ", checked: false,
checklist: checklists(:one))
assert_not chkItem.valid?, "Checklist item was created without text."
end
test "should not validate with text too long" do
chkItem = ChecklistItem.new(
text: "#" * 1001,
checked: false,
checklist: checklists(:one)
)
assert_not chkItem.valid?, "Checklist item was created with text being too long."
end
test "should not validate without checked value" do
chkItem = ChecklistItem.new(
text: "text", checked: nil,

View file

@ -1,6 +1,10 @@
require 'test_helper'
class ChecklistTest < ActiveSupport::TestCase
should validate_presence_of(:step)
should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(TEXT_MAX_LENGTH)
test "should validate with correct data" do
checklist = Checklist.new(
name: "test",
@ -9,26 +13,6 @@ class ChecklistTest < ActiveSupport::TestCase
assert checklist
end
test "should not validate without name" do
checklist = Checklist.new(step: steps(:step1))
assert_not checklist.valid?
end
test "should not validate with name too long" do
checklist = Checklist.new(
name: "#" * 51,
step: steps(:step1)
)
assert_not checklist.valid?
end
test "should not validate with non existent step" do
checklist = Checklist.new(
name: "test",
step_id: 123123)
assert_not checklist.valid?
end
test "should have association step -> checklist" do
checklist = Checklist.new(
name: "test",

View file

@ -13,26 +13,13 @@ class CommentTest < ActiveSupport::TestCase
)
end
should validate_presence_of(:message)
should validate_length_of(:message).is_at_most(TEXT_MAX_LENGTH)
test "should validate" do
assert @valid.valid?
end
test "should not validate with empty or nil message" do
comment_empty = Comment.new(message: " ", user: users(:steve))
comment_nil = Comment.new(message: nil, user: users(:steve))
assert_not comment_empty.valid?, "Comment was created with empty message."
assert_not comment_nil.valid?, "Comment was created with nil message."
end
test "should not validate with message too long" do
comment = Comment.new(
message: "#" * 1001,
user: users(:steve)
)
assert_not comment.valid?, "Comment was created with message being too long."
end
test "should not validate with empty user_id" do
comment = Comment.new(message: "Message")
assert_not comment.valid?, "Comment was created with empty user_id."

View file

@ -5,22 +5,20 @@ class CustomFieldTest < ActiveSupport::TestCase
@custom_field = custom_fields(:volume)
end
should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(NAME_MAX_LENGTH)
should validate_exclusion_of(:name)
.in_array(['Assigned',
'Sample name',
'Sample type',
'Sample group',
'Added on',
'Added by'])
test "should validate with correct data" do
assert @custom_field.valid?
end
test "should not validate without name" do
@custom_field.name = ""
assert_not @custom_field.valid?
@custom_field.name = nil
assert_not @custom_field.valid?
end
test "should not validate with too long name" do
@custom_field.name = "n" * 51
assert_not @custom_field.valid?
end
test "should not validate with non existent user" do
@custom_field.user_id = 11231231
assert_not @custom_field.valid?

View file

@ -3,12 +3,14 @@ require 'helpers/archivable_model_test_helper'
require 'helpers/searchable_model_test_helper'
class ExperimentTest < ActiveSupport::TestCase
should validate_presence_of(:name)
should validate_length_of(:name).is_at_least(4).is_at_most(50)
should validate_length_of(:name)
.is_at_least(NAME_MIN_LENGTH)
.is_at_most(NAME_MAX_LENGTH)
should validate_presence_of(:project)
should validate_presence_of(:created_by)
should validate_presence_of(:last_modified_by)
should validate_length_of(:description).is_at_most(255)
should validate_length_of(:description)
.is_at_most(TEXT_MAX_LENGTH)
should have_db_column(:name).of_type(:string)
should have_db_column(:description).of_type(:text)

View file

@ -8,22 +8,14 @@ class MyModuleGroupTest < ActiveSupport::TestCase
@module_group = my_module_groups(:wf1)
end
should validate_presence_of(:name)
should validate_length_of(:name)
.is_at_most(NAME_MAX_LENGTH)
test "should validate with valid data" do
assert @module_group.valid?
end
test "should not validate with name" do
@module_group.name = ""
assert_not @module_group.valid?
@module_group.name = nil
assert_not @module_group.valid?
end
test "should not validate too long name" do
@module_group.name = "n" * 51
assert_not @module_group.valid?
end
test "where_attributes_like should work" do
attributes_like_test(MyModuleGroup, :name, "expression")
end

View file

@ -10,6 +10,10 @@ class MyModuleTest < ActiveSupport::TestCase
@my_module = my_modules(:list_of_samples)
end
should validate_length_of(:name)
.is_at_least(NAME_MIN_LENGTH)
.is_at_most(NAME_MAX_LENGTH)
test "should validate valid module object" do
assert @my_module.valid?
end
@ -21,16 +25,6 @@ class MyModuleTest < ActiveSupport::TestCase
assert_not @my_module.valid?
end
test "should not validate too short name" do
@my_module.name = "n"
assert_not @my_module.valid?
end
test "should not validate too long name" do
@my_module.name = "n" * 51
assert_not @my_module.valid?
end
test "should not validate with non existing experiment" do
@my_module.experiment_id = 123123
assert_not @my_module.valid?

View file

@ -2,11 +2,13 @@ require 'test_helper'
class NotificationTest < ActiveSupport::TestCase
should have_db_column(:title).of_type(:string)
should have_db_column(:message).of_type(:text)
should have_db_column(:message).of_type(:string)
should have_db_column(:type_of).of_type(:integer)
should have_db_column(:created_at).of_type(:datetime)
should have_db_column(:updated_at).of_type(:datetime)
should have_db_column(:generator_user_id)
should have_many(:user_notifications)
should have_many(:users)
should belong_to(:generator_user).class_name('User')
end

View file

@ -5,6 +5,13 @@ class OrganizationTest < ActiveSupport::TestCase
@org = organizations(:test)
end
should validate_length_of(:name)
.is_at_least(NAME_MIN_LENGTH)
.is_at_most(NAME_MAX_LENGTH)
should validate_length_of(:description)
.is_at_most(TEXT_MAX_LENGTH)
test "should validate organization default values" do
assert @org.valid?
end
@ -14,11 +21,6 @@ class OrganizationTest < ActiveSupport::TestCase
assert @org.invalid?, "Organization with blank name returns valid? = true"
end
test "should have short name" do
@org.name = "k" * 101
assert @org.invalid?, "Organization with name too long 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"

View file

@ -12,21 +12,15 @@ class ProjectTest < ActiveSupport::TestCase
@project3 = projects(:test3)
end
should validate_length_of(:name)
.is_at_least(NAME_MIN_LENGTH)
.is_at_most(NAME_MAX_LENGTH)
test "should have non-blank name" do
@project.name = ""
assert @project.invalid?, "Project with blank name returns valid? = true"
end
test "should have short name" do
@project.name = "k" * 31
assert @project.invalid?, "Project with name too long returns valid? = true"
end
test "should have long enough name" do
@project.name = "k" * 3
assert @project.invalid?, "Project with name too short returns valid? = true"
end
test "should have organization-wide unique name" do
@project.name = @project2.name
assert @project.invalid?, "Project with non-unique organization-wide name returns valid? = true"

View file

@ -6,17 +6,6 @@ class ProtocolKeywordTest < ActiveSupport::TestCase
@kw = protocol_keywords(:kw1)
end
test "should not validate without name" do
assert @kw.valid?
@kw.name = nil
assert_not @kw.valid?
end
test "should not validate with name too long" do
@kw.name = "A" * 50
assert @kw.valid?
@kw.name = "A" * 51
assert_not @kw.valid?
end
end
should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(NAME_MAX_LENGTH)
end

View file

@ -13,6 +13,9 @@ class ProtocolTest < ActiveSupport::TestCase
)
end
should validate_length_of(:name).is_at_most(NAME_MAX_LENGTH)
should validate_length_of(:description).is_at_most(TEXT_MAX_LENGTH)
test "protocol_type enum works" do
@p.protocol_type = :unlinked
assert @p.in_module?
@ -26,13 +29,6 @@ class ProtocolTest < ActiveSupport::TestCase
assert @p.in_repository?
end
test "should not validate with name too long" do
@p.name = "Q" * 100
assert @p.valid?
@p.name = "Q" * 101
assert_not @p.valid?
end
test "should not validate without organization" do
@p.organization = @org
assert @p.valid?
@ -164,4 +160,4 @@ class ProtocolTest < ActiveSupport::TestCase
)
end
end
end

View file

@ -11,30 +11,27 @@ class ReportTest < ActiveSupport::TestCase
}
end
should validate_length_of(:name)
.is_at_least(NAME_MIN_LENGTH)
.is_at_most(NAME_MAX_LENGTH)
should validate_length_of(:description)
.is_at_most(TEXT_MAX_LENGTH)
test "should validate with valid data" do
assert @report.valid?, "Report with valid data was invalid"
end
test "should not validate with invalid name" do
@report.name = nil
assert_not @report.valid?, "Report with nil name was valid"
@report.name = "a"
assert_not @report.valid?, "Report with name too short was valid"
@report.name = "a" * 31
assert_not @report.valid?, "Report with name too long was valid"
test 'should not validate with invalid name' do
# Check if uniqueness constraint works
@report2 = Report.new(
name: @report.name_was,
name: @report.name,
project: projects(:interfaces),
user: users(:steve)
)
assert_not @report.valid?, "Report with same name for specific user was valid"
end
test "should not validate with invalid description" do
@report.description = "a" * 1001
assert_not @report.valid?, "Report with description too long was valid"
assert_not @report2.valid?,
'Report with same name for specific user was valid'
end
test "should not validate without project" do

View file

@ -111,8 +111,8 @@ class ResultTest < ActiveSupport::TestCase
first_comment = comments(:test_result_comment_24)
last_comment = comments(:test_result_comment_5)
assert_equal 20, last_comments.size
assert_equal first_comment, last_comments.first
assert_equal last_comment, last_comments.last
assert_equal first_comment, last_comments.last
assert_equal last_comment, last_comments.first
end
# Not possible to test with fixtures and random id values
@ -125,8 +125,8 @@ class ResultTest < ActiveSupport::TestCase
first_comment = comments(:test_result_comment_24)
last_comment = comments(:test_result_comment_20)
assert_equal 5, last_comments.size
assert_equal first_comment, last_comments.first
assert_equal last_comment, last_comments.last
assert_equal first_comment, last_comments.last
assert_equal last_comment, last_comments.first
end
test "should search for results of user" do

View file

@ -5,34 +5,16 @@ class SampleGroupTest < ActiveSupport::TestCase
@sample_group = sample_groups(:blood)
end
should validate_presence_of(:name)
should validate_length_of(:name).is_at_most(NAME_MAX_LENGTH)
should validate_presence_of(:color)
should validate_length_of(:color).is_at_most(COLOR_MAX_LENGTH)
should validate_presence_of(:organization)
test "should validate with correct data" do
assert @sample_group.valid?
end
test "should not validate without name" do
@sample_group.name = ""
assert_not @sample_group.valid?
@sample_group.name = nil
assert_not @sample_group.valid?
end
test "should validate too long name value" do
@sample_group.name *= 50
assert_not @sample_group.valid?
end
test "should validate without color because of default value" do
@sample_group.color = ""
assert_not @sample_group.valid?
@sample_group.color = nil
assert_not @sample_group.valid?
end
test "should validate too long color value" do
@sample_group.color *= 7
assert_not @sample_group.valid?
end
test "should not validate without organization" do
@sample_group.organization = nil
assert_not @sample_group.valid?

View file

@ -5,23 +5,15 @@ class SampleTypeTest < ActiveSupport::TestCase
@sample_type = sample_types(:skin)
end
test "should validate with correct data" do
should validate_length_of(:name).is_at_most(NAME_MAX_LENGTH)
should validate_presence_of(:name)
should validate_presence_of(:organization)
test 'should validate with correct data' do
assert @sample_type.valid?
end
test "should not validate without name" do
@sample_type.name = ""
assert_not @sample_type.valid?
@sample_type.name = nil
assert_not @sample_type.valid?
end
test "should validate too long name value" do
@sample_type.name *= 50
assert_not @sample_type.valid?
end
test "should not validate without organization" do
test 'should not validate without organization' do
@sample_type.organization_id = 12321321
assert_not @sample_type.valid?
@sample_type.organization = nil

View file

@ -85,8 +85,8 @@ class StepTest < ActiveSupport::TestCase
first_comment = comments(:test_step_comment_24)
last_comment = comments(:test_step_comment_5)
assert_equal 20, last_comments.size
assert_equal first_comment, last_comments.first
assert_equal last_comment, last_comments.last
assert_equal first_comment, last_comments.last
assert_equal last_comment, last_comments.first
end
# Not possible to test with fixtures and random id values
@ -98,8 +98,8 @@ class StepTest < ActiveSupport::TestCase
first_comment = comments(:test_step_comment_24)
last_comment = comments(:test_step_comment_20)
assert_equal 5, last_comments.size
assert_equal first_comment, last_comments.first
assert_equal last_comment, last_comments.last
assert_equal first_comment, last_comments.last
assert_equal last_comment, last_comments.first
end

View file

@ -7,27 +7,10 @@ class UserTest < ActiveSupport::TestCase
@org = organizations(:biosistemika)
end
# Test full_name attribute
test "should have non-blank full_name" do
@user.full_name = ""
assert @user.invalid?, "User with blank full_name is not valid"
end
test "should have short full_name" do
@user.full_name = "k" * 51
assert @user.invalid?, "User with name too long is not valid"
end
# Test initials attribute
test "should have non-blank initials" do
@user.initials = ""
assert @user.invalid?, "User with blank initials is not valid"
end
test "should have short initials" do
@user.initials = "k" * 5
assert @user.invalid?, "User with initials too long is not valid"
end
should validate_presence_of(:full_name)
should validate_length_of(:full_name).is_at_most(NAME_MAX_LENGTH)
should validate_presence_of(:initials)
should validate_length_of(:initials).is_at_most(USER_INITIALS_MAX_LENGTH)
# Test password attribute
test "should have non-blank password" do
@ -137,7 +120,7 @@ class UserTest < ActiveSupport::TestCase
assert_equal 10, last_activities.size
assert_equal first_activity, last_activities.first
assert_equal last_activity, last_activities.last
end
end
test "should get specified number of last activities" do
last_activities = @user2.last_activities(0, 4)
@ -146,7 +129,7 @@ class UserTest < ActiveSupport::TestCase
assert_equal 4, last_activities.size
assert_equal first_activity, last_activities.first
assert_equal last_activity, last_activities.last
end
end
test "should allow to change time zone" do
assert @user.valid?