Scaffold todo model
This commit is contained in:
48
test/controllers/todos_controller_test.rb
Normal file
48
test/controllers/todos_controller_test.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
require "test_helper"
|
||||
|
||||
class TodosControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@todo = todos(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get todos_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_todo_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create todo" do
|
||||
assert_difference("Todo.count") do
|
||||
post todos_url, params: { todo: { status: @todo.status, title: @todo.title } }
|
||||
end
|
||||
|
||||
assert_redirected_to todo_url(Todo.last)
|
||||
end
|
||||
|
||||
test "should show todo" do
|
||||
get todo_url(@todo)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_todo_url(@todo)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update todo" do
|
||||
patch todo_url(@todo), params: { todo: { status: @todo.status, title: @todo.title } }
|
||||
assert_redirected_to todo_url(@todo)
|
||||
end
|
||||
|
||||
test "should destroy todo" do
|
||||
assert_difference("Todo.count", -1) do
|
||||
delete todo_url(@todo)
|
||||
end
|
||||
|
||||
assert_redirected_to todos_url
|
||||
end
|
||||
end
|
||||
9
test/fixtures/todos.yml
vendored
Normal file
9
test/fixtures/todos.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
title: MyString
|
||||
status: 1
|
||||
|
||||
two:
|
||||
title: MyString
|
||||
status: 1
|
||||
7
test/models/todo_test.rb
Normal file
7
test/models/todo_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class TodoTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
43
test/system/todos_test.rb
Normal file
43
test/system/todos_test.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require "application_system_test_case"
|
||||
|
||||
class TodosTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@todo = todos(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit todos_url
|
||||
assert_selector "h1", text: "Todos"
|
||||
end
|
||||
|
||||
test "should create todo" do
|
||||
visit todos_url
|
||||
click_on "New todo"
|
||||
|
||||
fill_in "Status", with: @todo.status
|
||||
fill_in "Title", with: @todo.title
|
||||
click_on "Create Todo"
|
||||
|
||||
assert_text "Todo was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should update Todo" do
|
||||
visit todo_url(@todo)
|
||||
click_on "Edit this todo", match: :first
|
||||
|
||||
fill_in "Status", with: @todo.status
|
||||
fill_in "Title", with: @todo.title
|
||||
click_on "Update Todo"
|
||||
|
||||
assert_text "Todo was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "should destroy Todo" do
|
||||
visit todo_url(@todo)
|
||||
click_on "Destroy this todo", match: :first
|
||||
|
||||
assert_text "Todo was successfully destroyed"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user