Skip to content

Commit

Permalink
Generate the agenda
Browse files Browse the repository at this point in the history
  • Loading branch information
vic778 committed Sep 1, 2023
1 parent be80ad9 commit 5c661b4
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 0 deletions.
70 changes: 70 additions & 0 deletions app/controllers/agendas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class AgendasController < ApplicationController
before_action :set_agenda, only: %i[ show edit update destroy ]

# GET /agendas or /agendas.json
def index
@agendas = Agenda.all
end

# GET /agendas/1 or /agendas/1.json
def show
end

# GET /agendas/new
def new
@agenda = Agenda.new
end

# GET /agendas/1/edit
def edit
end

# POST /agendas or /agendas.json
def create
@agenda = Agenda.new(agenda_params)

respond_to do |format|
if @agenda.save
format.html { redirect_to agenda_url(@agenda), notice: "Agenda was successfully created." }
format.json { render :show, status: :created, location: @agenda }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @agenda.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /agendas/1 or /agendas/1.json
def update
respond_to do |format|
if @agenda.update(agenda_params)
format.html { redirect_to agenda_url(@agenda), notice: "Agenda was successfully updated." }
format.json { render :show, status: :ok, location: @agenda }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @agenda.errors, status: :unprocessable_entity }
end
end
end

# DELETE /agendas/1 or /agendas/1.json
def destroy
@agenda.destroy

respond_to do |format|
format.html { redirect_to agendas_url, notice: "Agenda was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_agenda
@agenda = Agenda.find(params[:id])
end

# Only allow a list of trusted parameters through.
def agenda_params
params.require(:agenda).permit(:name, :description)
end
end
2 changes: 2 additions & 0 deletions app/helpers/agendas_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AgendasHelper
end
2 changes: 2 additions & 0 deletions app/models/agenda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Agenda < ApplicationRecord
end
12 changes: 12 additions & 0 deletions app/views/agendas/_agenda.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="<%= dom_id agenda %>">
<p>
<strong>Name:</strong>
<%= agenda.name %>
</p>

<p>
<strong>Description:</strong>
<%= agenda.description %>
</p>

</div>
2 changes: 2 additions & 0 deletions app/views/agendas/_agenda.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! agenda, :id, :name, :description, :created_at, :updated_at
json.url agenda_url(agenda, format: :json)
14 changes: 14 additions & 0 deletions app/views/agendas/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= simple_form_for(@agenda) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>

<div class="form-inputs">
<%= f.input :name %>
<%= f.input :description %>
</div>

<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/agendas/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing agenda</h1>

<%= render "form", agenda: @agenda %>

<br>

<div>
<%= link_to "Show this agenda", @agenda %> |
<%= link_to "Back to agendas", agendas_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/agendas/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Agendas</h1>

<div id="agendas">
<% @agendas.each do |agenda| %>
<%= render agenda %>
<p>
<%= link_to "Show this agenda", agenda %>
</p>
<% end %>
</div>

<%= link_to "New agenda", new_agenda_path %>
1 change: 1 addition & 0 deletions app/views/agendas/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @agendas, partial: "agendas/agenda", as: :agenda
9 changes: 9 additions & 0 deletions app/views/agendas/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New agenda</h1>

<%= render "form", agenda: @agenda %>

<br>

<div>
<%= link_to "Back to agendas", agendas_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/agendas/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @agenda %>

<div>
<%= link_to "Edit this agenda", edit_agenda_path(@agenda) %> |
<%= link_to "Back to agendas", agendas_path %>
<%= button_to "Destroy this agenda", @agenda, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/agendas/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "agendas/agenda", agenda: @agenda
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :agendas
devise_for :users, controllers: {
registrations: 'registrations'
}
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20230901122621_create_agendas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateAgendas < ActiveRecord::Migration[7.0]
def change
create_table :agendas do |t|
t.string :name
t.string :description

t.timestamps
end
end
end
48 changes: 48 additions & 0 deletions test/controllers/agendas_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class AgendasControllerTest < ActionDispatch::IntegrationTest
setup do
@agenda = agendas(:one)
end

test "should get index" do
get agendas_url
assert_response :success
end

test "should get new" do
get new_agenda_url
assert_response :success
end

test "should create agenda" do
assert_difference("Agenda.count") do
post agendas_url, params: { agenda: { description: @agenda.description, name: @agenda.name } }
end

assert_redirected_to agenda_url(Agenda.last)
end

test "should show agenda" do
get agenda_url(@agenda)
assert_response :success
end

test "should get edit" do
get edit_agenda_url(@agenda)
assert_response :success
end

test "should update agenda" do
patch agenda_url(@agenda), params: { agenda: { description: @agenda.description, name: @agenda.name } }
assert_redirected_to agenda_url(@agenda)
end

test "should destroy agenda" do
assert_difference("Agenda.count", -1) do
delete agenda_url(@agenda)
end

assert_redirected_to agendas_url
end
end
9 changes: 9 additions & 0 deletions test/fixtures/agendas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
description: MyString

two:
name: MyString
description: MyString
7 changes: 7 additions & 0 deletions test/models/agenda_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class AgendaTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
43 changes: 43 additions & 0 deletions test/system/agendas_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "application_system_test_case"

class AgendasTest < ApplicationSystemTestCase
setup do
@agenda = agendas(:one)
end

test "visiting the index" do
visit agendas_url
assert_selector "h1", text: "Agendas"
end

test "should create agenda" do
visit agendas_url
click_on "New agenda"

fill_in "Description", with: @agenda.description
fill_in "Name", with: @agenda.name
click_on "Create Agenda"

assert_text "Agenda was successfully created"
click_on "Back"
end

test "should update Agenda" do
visit agenda_url(@agenda)
click_on "Edit this agenda", match: :first

fill_in "Description", with: @agenda.description
fill_in "Name", with: @agenda.name
click_on "Update Agenda"

assert_text "Agenda was successfully updated"
click_on "Back"
end

test "should destroy Agenda" do
visit agenda_url(@agenda)
click_on "Destroy this agenda", match: :first

assert_text "Agenda was successfully destroyed"
end
end

0 comments on commit 5c661b4

Please sign in to comment.