adding stories, scaffold

This commit is contained in:
2023-01-11 18:48:06 +02:00
parent 10686d1f5e
commit 23a2254d2e
18 changed files with 289 additions and 27 deletions

View File

@ -0,0 +1,48 @@
require "test_helper"
class StoriesControllerTest < ActionDispatch::IntegrationTest
setup do
@story = stories(:one)
end
test "should get index" do
get stories_url
assert_response :success
end
test "should get new" do
get new_story_url
assert_response :success
end
test "should create story" do
assert_difference("Story.count") do
post stories_url, params: { story: { happened: @story.happened, header: @story.header, picture: @story.picture, text: @story.text } }
end
assert_redirected_to story_url(Story.last)
end
test "should show story" do
get story_url(@story)
assert_response :success
end
test "should get edit" do
get edit_story_url(@story)
assert_response :success
end
test "should update story" do
patch story_url(@story), params: { story: { happened: @story.happened, header: @story.header, picture: @story.picture, text: @story.text } }
assert_redirected_to story_url(@story)
end
test "should destroy story" do
assert_difference("Story.count", -1) do
delete story_url(@story)
end
assert_redirected_to stories_url
end
end

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

@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
picture: MyString
header: MyString
text: MyText
happened: 2023-01-11
two:
picture: MyString
header: MyString
text: MyText
happened: 2023-01-11

View File

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

View File

@ -0,0 +1,47 @@
require "application_system_test_case"
class StoriesTest < ApplicationSystemTestCase
setup do
@story = stories(:one)
end
test "visiting the index" do
visit stories_url
assert_selector "h1", text: "Stories"
end
test "should create story" do
visit stories_url
click_on "New story"
fill_in "Happened", with: @story.happened
fill_in "Header", with: @story.header
fill_in "Picture", with: @story.picture
fill_in "Text", with: @story.text
click_on "Create Story"
assert_text "Story was successfully created"
click_on "Back"
end
test "should update Story" do
visit story_url(@story)
click_on "Edit this story", match: :first
fill_in "Happened", with: @story.happened
fill_in "Header", with: @story.header
fill_in "Picture", with: @story.picture
fill_in "Text", with: @story.text
click_on "Update Story"
assert_text "Story was successfully updated"
click_on "Back"
end
test "should destroy Story" do
visit story_url(@story)
click_on "Destroy this story", match: :first
assert_text "Story was successfully destroyed"
end
end