-
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
19 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,69 @@ | ||
class AllergensController < ApplicationController | ||
before_action :set_allergen, only: %i[show edit update destroy] | ||
|
||
# GET /allergens or /allergens.json | ||
def index | ||
@allergens = Allergen.all | ||
end | ||
|
||
# GET /allergens/1 or /allergens/1.json | ||
def show; end | ||
|
||
# GET /allergens/new | ||
def new | ||
@allergen = Allergen.new | ||
end | ||
|
||
# GET /allergens/1/edit | ||
def edit; end | ||
|
||
# POST /allergens or /allergens.json | ||
def create | ||
@allergen = Allergen.new(allergen_params) | ||
|
||
respond_to do |format| | ||
if @allergen.save | ||
format.html { redirect_to allergen_url(@allergen), notice: t(:allergen_created) } | ||
format.json { render :show, status: :created, location: @allergen } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @allergen.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /allergens/1 or /allergens/1.json | ||
def update | ||
respond_to do |format| | ||
if @allergen.update(allergen_params) | ||
format.html { redirect_to allergen_url(@allergen), notice: t(:allergen_updated) } | ||
format.json { render :show, status: :ok, location: @allergen } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @allergen.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /allergens/1 or /allergens/1.json | ||
def destroy | ||
@allergen.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to allergens_url, notice: t(:allergen_destroyed) } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_allergen | ||
@allergen = Allergen.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def allergen_params | ||
params.require(:allergen).permit(:name) | ||
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 AllergensHelper | ||
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 Allergen < 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,7 @@ | ||
<div id="<%= dom_id allergen %>"> | ||
<p> | ||
<strong>Name:</strong> | ||
<%= allergen.name %> | ||
</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! allergen, :id, :name, :created_at, :updated_at | ||
json.url allergen_url(allergen, 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,22 @@ | ||
<%= form_with(model: allergen) do |form| %> | ||
<% if allergen.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(allergen.errors.count, "error") %> prohibited this allergen from being saved:</h2> | ||
|
||
<ul> | ||
<% allergen.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.label :name, style: "display: block" %> | ||
<%= form.text_field :name %> | ||
</div> | ||
|
||
<div> | ||
<%= form.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 allergen</h1> | ||
|
||
<%= render "form", allergen: @allergen %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this allergen", @allergen %> | | ||
<%= link_to "Back to allergens", allergens_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>Allergens</h1> | ||
|
||
<div id="allergens"> | ||
<% @allergens.each do |allergen| %> | ||
<%= render allergen %> | ||
<p> | ||
<%= link_to "Show this allergen", allergen %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New allergen", new_allergen_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! @allergens, partial: 'allergens/allergen', as: :allergen |
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 allergen</h1> | ||
|
||
<%= render "form", allergen: @allergen %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to allergens", allergens_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 @allergen %> | ||
|
||
<div> | ||
<%= link_to "Edit this allergen", edit_allergen_path(@allergen) %> | | ||
<%= link_to "Back to allergens", allergens_path %> | ||
|
||
<%= button_to "Destroy this allergen", @allergen, 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! 'allergens/allergen', allergen: @allergen |
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
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 @@ | ||
class CreateAllergens < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :allergens do |t| | ||
t.string :name | ||
|
||
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 AllergensControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@allergen = allergens(:one) | ||
end | ||
|
||
test 'should get index' do | ||
get allergens_url | ||
assert_response :success | ||
end | ||
|
||
test 'should get new' do | ||
get new_allergen_url | ||
assert_response :success | ||
end | ||
|
||
test 'should create allergen' do | ||
assert_difference('Allergen.count') do | ||
post allergens_url, params: { allergen: { name: @allergen.name } } | ||
end | ||
|
||
assert_redirected_to allergen_url(Allergen.last) | ||
end | ||
|
||
test 'should show allergen' do | ||
get allergen_url(@allergen) | ||
assert_response :success | ||
end | ||
|
||
test 'should get edit' do | ||
get edit_allergen_url(@allergen) | ||
assert_response :success | ||
end | ||
|
||
test 'should update allergen' do | ||
patch allergen_url(@allergen), params: { allergen: { name: @allergen.name } } | ||
assert_redirected_to allergen_url(@allergen) | ||
end | ||
|
||
test 'should destroy allergen' do | ||
assert_difference('Allergen.count', -1) do | ||
delete allergen_url(@allergen) | ||
end | ||
|
||
assert_redirected_to allergens_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,7 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
name: MyString | ||
|
||
two: | ||
name: 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 AllergenTest < 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,41 @@ | ||
require 'application_system_test_case' | ||
|
||
class AllergensTest < ApplicationSystemTestCase | ||
setup do | ||
@allergen = allergens(:one) | ||
end | ||
|
||
test 'visiting the index' do | ||
visit allergens_url | ||
assert_selector 'h1', text: 'Allergens' | ||
end | ||
|
||
test 'should create allergen' do | ||
visit allergens_url | ||
click_on 'New allergen' | ||
|
||
fill_in 'Name', with: @allergen.name | ||
click_on 'Create Allergen' | ||
|
||
assert_text 'Allergen was successfully created' | ||
click_on 'Back' | ||
end | ||
|
||
test 'should update Allergen' do | ||
visit allergen_url(@allergen) | ||
click_on 'Edit this allergen', match: :first | ||
|
||
fill_in 'Name', with: @allergen.name | ||
click_on 'Update Allergen' | ||
|
||
assert_text 'Allergen was successfully updated' | ||
click_on 'Back' | ||
end | ||
|
||
test 'should destroy Allergen' do | ||
visit allergen_url(@allergen) | ||
click_on 'Destroy this allergen', match: :first | ||
|
||
assert_text 'Allergen was successfully destroyed' | ||
end | ||
end |