-
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.
* gem group reorg * add factory_bot gem * ignore byebug history * ignore i18n cop * add GH action for CI * set categories#index as default route * enable command line JS driver setting foo
- Loading branch information
Showing
35 changed files
with
625 additions
and
14 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,50 @@ | ||
name: "CI" | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:12-alpine | ||
ports: | ||
- "5432:5432" | ||
env: | ||
POSTGRES_DB: rails_test | ||
POSTGRES_USER: rails | ||
POSTGRES_PASSWORD: password | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
# Add or replace dependency steps here | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
# Add or replace database setup steps here | ||
- name: Set up database schema | ||
run: bin/rails db:schema:load | ||
# Add or replace test runners here | ||
- name: Run specs | ||
run: bin/rspec | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
# Add or replace any other lints here | ||
- name: Security audit application code | ||
run: bin/brakeman | ||
- name: Lint Ruby files | ||
run: bin/rubocop --parallel |
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 |
---|---|---|
|
@@ -22,3 +22,5 @@ | |
|
||
# Ignore master key for decrypting credentials and more. | ||
/config/master.key | ||
|
||
.byebug_history |
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 was deleted.
Oops, something went wrong.
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
Empty file.
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,71 @@ | ||
# frozen_string_literal: true | ||
|
||
class CategoriesController < ApplicationController | ||
before_action :set_category, only: %i[show edit update destroy] | ||
|
||
# GET /categories or /categories.json | ||
def index | ||
@categories = Category.all | ||
end | ||
|
||
# GET /categories/1 or /categories/1.json | ||
def show; end | ||
|
||
# GET /categories/new | ||
def new | ||
@category = Category.new | ||
end | ||
|
||
# GET /categories/1/edit | ||
def edit; end | ||
|
||
# POST /categories or /categories.json | ||
def create | ||
@category = Category.new(category_params) | ||
|
||
respond_to do |format| | ||
if @category.save | ||
format.html { redirect_to category_url(@category), notice: 'Category was successfully created.' } | ||
format.json { render :show, status: :created, location: @category } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @category.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /categories/1 or /categories/1.json | ||
def update | ||
respond_to do |format| | ||
if @category.update(category_params) | ||
format.html { redirect_to category_url(@category), notice: 'Category was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @category } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @category.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /categories/1 or /categories/1.json | ||
def destroy | ||
@category.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to categories_url, notice: 'Category was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_category | ||
@category = Category.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def category_params | ||
params.require(:category).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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module CategoriesHelper | ||
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Category < ApplicationRecord | ||
validates :name, uniqueness: true, presence: true | ||
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 category %>"> | ||
<p> | ||
<strong>Name:</strong> | ||
<%= category.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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
json.extract! category, :id, :name, :created_at, :updated_at | ||
json.url category_url(category, 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: category) do |form| %> | ||
<% if category.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:</h2> | ||
|
||
<ul> | ||
<% category.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 category</h1> | ||
|
||
<%= render "form", category: @category %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this category", @category %> | | ||
<%= link_to "Back to categories", categories_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>Categories</h1> | ||
|
||
<div id="categories"> | ||
<% @categories.each do |category| %> | ||
<%= render category %> | ||
<p> | ||
<%= link_to "Show this category", category %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New category", new_category_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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
json.array! @categories, partial: 'categories/category', as: :category |
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 category</h1> | ||
|
||
<%= render "form", category: @category %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to categories", categories_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 @category %> | ||
|
||
<div> | ||
<%= link_to "Edit this category", edit_category_path(@category) %> | | ||
<%= link_to "Back to categories", categories_path %> | ||
<%= button_to "Destroy this category", @category, 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,3 @@ | ||
# frozen_string_literal: true | ||
|
||
json.partial! 'categories/category', category: @category |
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,27 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'brakeman' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
|
||
bundle_binstub = File.expand_path("bundle", __dir__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("brakeman", "brakeman") |
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,8 @@ | ||
--- | ||
:rails3: false | ||
:rails4: false | ||
:rails5: false | ||
:rails6: false | ||
:rails7: true | ||
:quiet: true | ||
:summary_only: :no_summary |
Oops, something went wrong.