help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
ruby-todo-list
/
test
/
models
RSK World
ruby-todo-list
Ruby Todo List - Task Management with User Authentication + Categories + Search + File Attachments + Email Notifications + Rails MVC + Modern Web Interface + API Integration + Educational Design
models
  • category_test.rb1.4 KB
  • task_test.rb2.2 KB
task_test.rb
test/models/task_test.rb
Raw Download
Find: Go to:
# Ruby To-Do List Application - Task Model Test
# Created by: Molla Samser (help@rskworld.in, +91 93305 39277)
# Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
# Year: 2026

require "test_helper"

class TaskTest < ActiveSupport::TestCase
  setup do
    @user = users(:one)
    @task = @user.tasks.build(title: "Test Task", description: "Test description", priority: 2)
  end

  test "should be valid" do
    assert @task.valid?
  end

  test "title should be present" do
    @task.title = ""
    assert_not @task.valid?
  end

  test "priority should be valid" do
    @task.priority = 1
    assert @task.valid?

    @task.priority = 2
    assert @task.valid?

    @task.priority = 3
    assert @task.valid?

    @task.priority = 4
    assert_not @task.valid?
  end

  test "should belong to user" do
    assert_respond_to @task, :user
  end

  test "should have priority scopes" do
    assert_respond_to Task, :high_priority
    assert_respond_to Task, :medium_priority
    assert_respond_to Task, :low_priority
  end

  test "should have completion scopes" do
    assert_respond_to Task, :completed
    assert_respond_to Task, :pending
  end

  test "should set completed_at when toggled to complete" do
    @task.completed = false
    @task.save

    @task.completed = true
    @task.save

    assert_not_nil @task.completed_at
  end

  test "should clear completed_at when marked as pending" do
    @task.completed = true
    @task.save

    @task.completed = false
    @task.save

    assert_nil @task.completed_at
  end

  test "priority_name should return correct values" do
    @task.priority = 1
    assert_equal "Low", @task.priority_name

    @task.priority = 2
    assert_equal "Medium", @task.priority_name

    @task.priority = 3
    assert_equal "High", @task.priority_name
  end

  test "overdue? should work correctly" do
    @task.due_date = 1.day.ago
    @task.completed = false
    assert @task.overdue?

    @task.completed = true
    assert_not @task.overdue?

    @task.due_date = 1.day.from_now
    @task.completed = false
    assert_not @task.overdue?
  end
end
95 lines•2.2 KB
ruby

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer