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
/
integration
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
integration
  • api_test.rb2.5 KB
api_test.rb
test/integration/api_test.rb
Raw Download
Find: Go to:
# Ruby To-Do List Application - API Integration 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 ApiTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  setup do
    @user = users(:one)
    @task = tasks(:one)
    sign_in @user
  end

  test "should get tasks via API" do
    get "/api/v1/tasks"
    assert_response :success

    json_response = JSON.parse(response.body)
    assert json_response["success"]
    assert json_response["data"].is_a?(Array)
  end

  test "should get specific task via API" do
    get "/api/v1/tasks/#{@task.id}"
    assert_response :success

    json_response = JSON.parse(response.body)
    assert json_response["success"]
    assert_equal @task.title, json_response["data"]["title"]
  end

  test "should create task via API" do
    assert_difference("Task.count") do
      post "/api/v1/tasks",
           params: { task: { title: "API Task", description: "Created via API" } },
           headers: { "Accept" => "application/json" }
    end

    assert_response :created
    json_response = JSON.parse(response.body)
    assert json_response["success"]
  end

  test "should update task via API" do
    patch "/api/v1/tasks/#{@task.id}",
          params: { task: { title: "Updated via API" } },
          headers: { "Accept" => "application/json" }

    assert_response :success
    json_response = JSON.parse(response.body)
    assert json_response["success"]
    assert_equal "Updated via API", json_response["data"]["title"]
  end

  test "should delete task via API" do
    assert_difference("Task.count", -1) do
      delete "/api/v1/tasks/#{@task.id}",
             headers: { "Accept" => "application/json" }
    end

    assert_response :success
  end

  test "should get categories via API" do
    get "/api/v1/categories"
    assert_response :success

    json_response = JSON.parse(response.body)
    assert json_response["success"]
    assert json_response["data"].is_a?(Array)
  end

  test "should toggle task completion via API" do
    original_status = @task.completed

    patch "/api/v1/tasks/#{@task.id}/toggle_complete",
          headers: { "Accept" => "application/json" }

    assert_response :success
    json_response = JSON.parse(response.body)
    assert json_response["success"]
    assert_not_equal original_status, json_response["data"]["completed"]
  end
end
87 lines•2.5 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