diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb new file mode 100644 index 0000000..e1e641d --- /dev/null +++ b/app/controllers/stories_controller.rb @@ -0,0 +1,58 @@ +class StoriesController < ApplicationController + before_action :set_story, only: %i[ show edit update destroy ] + + # GET /stories + def index + @stories = Story.all + end + + # GET /stories/1 + def show + end + + # GET /stories/new + def new + @story = Story.new + end + + # GET /stories/1/edit + def edit + end + + # POST /stories + def create + @story = Story.new(story_params) + + if @story.save + redirect_to @story, notice: "Story was successfully created." + else + render :new, status: :unprocessable_entity + end + end + + # PATCH/PUT /stories/1 + def update + if @story.update(story_params) + redirect_to @story, notice: "Story was successfully updated." + else + render :edit, status: :unprocessable_entity + end + end + + # DELETE /stories/1 + def destroy + @story.destroy + redirect_to stories_url, notice: "Story was successfully destroyed." + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_story + @story = Story.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def story_params + params.require(:story).permit(:picture, :header, :text, :happened) + end +end diff --git a/app/helpers/stories_helper.rb b/app/helpers/stories_helper.rb new file mode 100644 index 0000000..43e5cd8 --- /dev/null +++ b/app/helpers/stories_helper.rb @@ -0,0 +1,2 @@ +module StoriesHelper +end diff --git a/app/models/story.rb b/app/models/story.rb new file mode 100644 index 0000000..9bb96ba --- /dev/null +++ b/app/models/story.rb @@ -0,0 +1,2 @@ +class Story < ApplicationRecord +end diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb deleted file mode 100644 index 49ba357..0000000 --- a/app/views/active_storage/blobs/_blob.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
attachment--<%= blob.filename.extension %>"> - <% if blob.representable? %> - <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> - <% end %> - -
- <% if caption = blob.try(:caption) %> - <%= caption %> - <% else %> - <%= blob.filename %> - <%= number_to_human_size blob.byte_size %> - <% end %> -
-
diff --git a/app/views/app/views/active_storage/blobs/_blob.html.erb b/app/views/app/views/active_storage/blobs/_blob.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/members/index.html.haml b/app/views/members/index.html.haml index 2e88109..1f8baf6 100644 --- a/app/views/members/index.html.haml +++ b/app/views/members/index.html.haml @@ -1,14 +1,12 @@ += paginate @members .flex.justify-center - %h1 Listing members - = paginate @members - -.grid.grid-cols-4 - - @members.each do |member| - .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10 - = image_for( member , class: "h-60 w-full object-cover") - %h3.p-5.text-2xl.bg-gray-100.text-black.font-bold.text-center= member.name - %div.h-full - .p-5.text-center - .m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes } - = markdown(member.bio) + .grid.grid-cols-4 + - @members.each do |member| + .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10 + = image_for( member , class: "h-60 w-full object-cover") + %h3.p-5.text-2xl.bg-gray-100.text-black.font-bold.text-center= member.name + %div.h-full + .p-5.text-center + .m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes } + = markdown(member.bio) diff --git a/app/views/stories/_form.html.haml b/app/views/stories/_form.html.haml new file mode 100644 index 0000000..2c3b9ad --- /dev/null +++ b/app/views/stories/_form.html.haml @@ -0,0 +1,22 @@ += form_for @story do |f| + - if @story.errors.any? + #error_explanation + %h2= "#{pluralize(@story.errors.count, "error")} prohibited this story from being saved:" + %ul + - @story.errors.full_messages.each do |message| + %li= message + + .field + = f.label :picture + = f.text_field :picture + .field + = f.label :header + = f.text_field :header + .field + = f.label :text + = f.text_area :text + .field + = f.label :happened + = f.date_field :happened + .actions + = f.submit 'Save' diff --git a/app/views/stories/edit.html.haml b/app/views/stories/edit.html.haml new file mode 100644 index 0000000..0a666bb --- /dev/null +++ b/app/views/stories/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing story + += render 'form' + += link_to 'Show', @story +\| += link_to 'Back', stories_path diff --git a/app/views/stories/index.html.haml b/app/views/stories/index.html.haml new file mode 100644 index 0000000..1dd6ddf --- /dev/null +++ b/app/views/stories/index.html.haml @@ -0,0 +1,27 @@ +%h1 Listing stories + +%table + %thead + %tr + %th Picture + %th Header + %th Text + %th Happened + %th + %th + %th + + %tbody + - @stories.each do |story| + %tr + %td= story.picture + %td= story.header + %td= story.text + %td= story.happened + %td= link_to 'Show', story + %td= link_to 'Edit', edit_story_path(story) + %td= link_to 'Destroy', story, method: :delete, data: { confirm: 'Are you sure?' } + +%br + += link_to 'New Story', new_story_path diff --git a/app/views/stories/new.html.haml b/app/views/stories/new.html.haml new file mode 100644 index 0000000..15878b7 --- /dev/null +++ b/app/views/stories/new.html.haml @@ -0,0 +1,5 @@ +%h1 New story + += render 'form' + += link_to 'Back', stories_path diff --git a/app/views/stories/show.html.haml b/app/views/stories/show.html.haml new file mode 100644 index 0000000..73ba65f --- /dev/null +++ b/app/views/stories/show.html.haml @@ -0,0 +1,18 @@ +%p#notice= notice + +%p + %b Picture: + = @story.picture +%p + %b Header: + = @story.header +%p + %b Text: + = @story.text +%p + %b Happened: + = @story.happened + += link_to 'Edit', edit_story_path(@story) +\| += link_to 'Back', stories_path diff --git a/config/routes.rb b/config/routes.rb index 04f0470..815e14c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :stories devise_for :members diff --git a/db/migrate/20230111164425_create_stories.rb b/db/migrate/20230111164425_create_stories.rb new file mode 100644 index 0000000..6152cbd --- /dev/null +++ b/db/migrate/20230111164425_create_stories.rb @@ -0,0 +1,12 @@ +class CreateStories < ActiveRecord::Migration[7.0] + def change + create_table :stories do |t| + t.string :picture + t.string :header + t.text :text + t.date :happened + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ab12193..8e0ed44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_12_31_154221) do +ActiveRecord::Schema[7.0].define(version: 2023_01_11_164425) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -46,6 +46,15 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_31_154221) do t.index ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true end + create_table "stories", force: :cascade do |t| + t.string "picture" + t.string "header" + t.text "text" + t.date "happened" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "thredded_categories", force: :cascade do |t| t.bigint "messageboard_id", null: false t.text "name", null: false diff --git a/test/controllers/stories_controller_test.rb b/test/controllers/stories_controller_test.rb new file mode 100644 index 0000000..321c995 --- /dev/null +++ b/test/controllers/stories_controller_test.rb @@ -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 diff --git a/test/fixtures/stories.yml b/test/fixtures/stories.yml new file mode 100644 index 0000000..12c03b3 --- /dev/null +++ b/test/fixtures/stories.yml @@ -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 diff --git a/test/models/story_test.rb b/test/models/story_test.rb new file mode 100644 index 0000000..275e648 --- /dev/null +++ b/test/models/story_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class StoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/stories_test.rb b/test/system/stories_test.rb new file mode 100644 index 0000000..b9e5c06 --- /dev/null +++ b/test/system/stories_test.rb @@ -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