-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AgendasHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Agenda < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @agendas, partial: "agendas/agenda", as: :agenda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "agendas/agenda", agenda: @agenda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |