Project initialize

This commit is contained in:
Zin Bo Thit
2026-01-28 09:53:14 +06:30
commit e8380c6e23
139 changed files with 4599 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end

0
test/controllers/.keep Normal file
View File

View File

@@ -0,0 +1,50 @@
require 'test_helper'
class DepartmentsControllerTest < ActionDispatch::IntegrationTest
setup do
@admin = users(:admin)
sign_in @admin
@department = departments(:one)
end
test "should get index" do
get departments_url
assert_response :success
end
test "should get new" do
get new_department_url
assert_response :success
end
test "should create department" do
assert_difference('Department.count') do
post departments_url, params: { department: { name: 'New Dept', description: 'New Desc' } }
end
assert_redirected_to department_url(Department.last)
end
test "should show department" do
get department_url(@department)
assert_response :success
end
test "should get edit" do
get edit_department_url(@department)
assert_response :success
end
test "should update department" do
patch department_url(@department), params: { department: { name: 'Updated Dept' } }
assert_redirected_to department_url(@department)
@department.reload
assert_equal 'Updated Dept', @department.name
end
test "should destroy department" do
assert_difference('Department.count', -1) do
delete department_url(@department)
end
assert_redirected_to departments_url
end
end

View File

@@ -0,0 +1,74 @@
require 'test_helper'
class TasksControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:admin)
sign_in @user
@task = tasks(:one)
end
test "should get index" do
get tasks_url
assert_response :success
end
test "should show task" do
get task_url(@task)
assert_response :success
end
test "should create task" do
assert_difference('Task.count') do
post tasks_url, params: { task: { title: 'New Task', description: 'Test description', priority: 'urgent', status: 'open' } }
end
assert_redirected_to task_url(Task.last)
end
test "should update task" do
patch task_url(@task), params: { task: { title: 'Updated Title', status: 'completed' } }
assert_redirected_to task_url(@task)
@task.reload
assert_equal 'Updated Title', @task.title
assert_equal 'completed', @task.status
end
test "should destroy task" do
assert_difference('Task.count', -1) do
delete task_url(@task)
end
assert_redirected_to tasks_url
end
test "should update task via ajax" do
patch task_url(@task), params: { task: { status: 'completed' } }, xhr: true
assert_response :success
@task.reload
assert_equal 'completed', @task.status
end
test "should get dashboard" do
get dashboard_url
assert_response :success
end
test "should get my_tasks" do
get my_tasks_url
assert_response :success
end
test "should assign task" do
patch assign_task_url(@task), params: { assignee_id: users(:employee).id }
assert_redirected_to task_url(@task)
@task.reload
assert_equal users(:employee).id, @task.assignee_id
assert_equal 'in_progress', @task.status
end
test "should keep planning tasks at top based on priority asc" do
# priority enums: planning (0), urgent (4)
# ordered scope: order(priority: :asc, created_at: :desc)
# planning should come before urgent
get tasks_url
assert_select '.tasks-list .task:first-child .task-priority', text: /Planning/
end
end

0
test/fixtures/.keep vendored Normal file
View File

7
test/fixtures/departments.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
one:
name: IT
description: Information Technology
two:
name: HR
description: Human Resources

0
test/fixtures/files/.keep vendored Normal file
View File

13
test/fixtures/task_activities.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
task: one
user: one
action: MyString
details: MyText
two:
task: two
user: two
action: MyString
details: MyText

24
test/fixtures/tasks.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
one:
title: Setup Server
description: Initial server setup for the IT department
priority: urgent
status: open
creator: admin
department: one
two:
title: Recruitment Plan
description: Plan for new hires
priority: planning
status: open
creator: manager
department: two
assignee: employee
completed_task:
title: Policy Update
description: Update the company policy
priority: review
status: completed
creator: manager
department: two

22
test/fixtures/users.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
admin:
name: Admin User
email: admin@example.com
role: admin
encrypted_password: <%= Devise::Encryptor.digest(User, 'password123') %>
confirmed_at: <%= Time.current %>
manager:
name: Manager User
email: manager@example.com
role: manager
department: one
encrypted_password: <%= Devise::Encryptor.digest(User, 'password123') %>
confirmed_at: <%= Time.current %>
employee:
name: Employee User
email: employee@example.com
role: employee
department: one
encrypted_password: <%= Devise::Encryptor.digest(User, 'password123') %>
confirmed_at: <%= Time.current %>

0
test/helpers/.keep Normal file
View File

0
test/integration/.keep Normal file
View File

0
test/mailers/.keep Normal file
View File

0
test/models/.keep Normal file
View File

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class DepartmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class TaskActivityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

41
test/models/task_test.rb Normal file
View File

@@ -0,0 +1,41 @@
require 'test_helper'
class TaskTest < ActiveSupport::TestCase
setup do
@user = users(:admin)
end
test "should be valid with a title and creator" do
task = Task.new(title: "Do something", creator: @user)
assert task.valid?
end
test "should be invalid without a title" do
task = Task.new(title: "", creator: @user)
assert_not task.valid?
assert_includes task.errors[:title], "can't be blank"
end
test "should be invalid without a creator" do
task = Task.new(title: "Do something")
assert_not task.valid?
assert_includes task.errors[:creator], "can't be blank"
end
test "incomplete scope returns only incomplete tasks" do
Task.create!(title: "Incomplete", status: :open, creator: @user)
Task.create!(title: "Complete", status: :completed, creator: @user)
# fixture 'one' has status: open
assert_includes Task.incomplete, tasks(:one)
assert_not_includes Task.incomplete, Task.find_by(status: :completed, title: "Complete")
end
test "complete scope returns only completed tasks" do
Task.create!(title: "Incomplete", status: :open, creator: @user)
Task.create!(title: "Complete", status: :completed, creator: @user)
assert_includes Task.complete, Task.find_by(status: :completed, title: "Complete")
assert_not_includes Task.complete, tasks(:one)
end
end

7
test/models/user_test.rb Normal file
View File

@@ -0,0 +1,7 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0
test/system/.keep Normal file
View File

13
test/test_helper.rb Normal file
View File

@@ -0,0 +1,13 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
end