Skip to content

Commit

Permalink
fill in some app code and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Mar 21, 2024
1 parent 233e94c commit e587bb6
Show file tree
Hide file tree
Showing 35 changed files with 729 additions and 62 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git libvips pkg-config
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config

# Install application gems
COPY Gemfile Gemfile.lock ./
Expand All @@ -42,7 +42,7 @@ FROM base as web

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 libvips && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand Down
12 changes: 4 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ gem "rails", "~> 7.1.3", ">= 7.1.3.2"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
Expand Down Expand Up @@ -45,6 +45,8 @@ gem "bootsnap", require: false
# gem "image_processing", "~> 1.2"

group :development, :test do
gem 'rspec-rails', '~> 6.1.0'
gem 'rspec_junit_formatter'
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ]
end
Expand All @@ -59,9 +61,3 @@ group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
end
57 changes: 24 additions & 33 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,20 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
base64 (0.2.0)
bigdecimal (3.1.7)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
builder (3.2.4)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.12.0)
globalid (1.2.1)
Expand All @@ -125,7 +115,6 @@ GEM
net-pop
net-smtp
marcel (1.0.4)
matrix (0.4.2)
mini_mime (1.1.5)
minitest (5.22.3)
msgpack (1.7.2)
Expand All @@ -152,9 +141,9 @@ GEM
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4)
pg (1.5.6)
psych (5.1.2)
stringio
public_suffix (5.0.4)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
Expand Down Expand Up @@ -202,29 +191,34 @@ GEM
redis-client (>= 0.17.0)
redis-client (0.21.0)
connection_pool
regexp_parser (2.9.0)
reline (0.4.3)
io-console (~> 0.5)
rexml (3.2.6)
rubyzip (2.3.2)
selenium-webdriver (4.18.1)
base64 (~> 0.2)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.7.3-aarch64-linux)
sqlite3 (1.7.3-arm-linux)
sqlite3 (1.7.3-arm64-darwin)
sqlite3 (1.7.3-x86-linux)
sqlite3 (1.7.3-x86_64-darwin)
sqlite3 (1.7.3-x86_64-linux)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
Expand All @@ -242,12 +236,9 @@ GEM
bindex (>= 0.4.0)
railties (>= 6.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.13)

PLATFORMS
Expand All @@ -260,16 +251,16 @@ PLATFORMS

DEPENDENCIES
bootsnap
capybara
debug
importmap-rails
jbuilder
pg (~> 1.1)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.2)
redis (>= 4.0.1)
selenium-webdriver
rspec-rails (~> 6.1.0)
rspec_junit_formatter
sprockets-rails
sqlite3 (~> 1.4)
stimulus-rails
turbo-rails
tzinfo-data
Expand Down
70 changes: 70 additions & 0 deletions app/controllers/blogs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class BlogsController < ApplicationController
before_action :set_blog, only: %i[ show edit update destroy ]

# GET /blogs or /blogs.json
def index
@blogs = Blog.all
end

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

# GET /blogs/new
def new
@blog = Blog.new
end

# GET /blogs/1/edit
def edit
end

# POST /blogs or /blogs.json
def create
@blog = Blog.new(blog_params)

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

# PATCH/PUT /blogs/1 or /blogs/1.json
def update
respond_to do |format|
if @blog.update(blog_params)
format.html { redirect_to blog_url(@blog), notice: "Blog was successfully updated." }
format.json { render :show, status: :ok, location: @blog }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @blog.errors, status: :unprocessable_entity }
end
end
end

# DELETE /blogs/1 or /blogs/1.json
def destroy
@blog.destroy!

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

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

# Only allow a list of trusted parameters through.
def blog_params
params.require(:blog).permit(:title, :body, :user_id)
end
end
2 changes: 2 additions & 0 deletions app/helpers/blogs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BlogsHelper
end
3 changes: 3 additions & 0 deletions app/models/blog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Blog < ApplicationRecord
belongs_to :user
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class User < ApplicationRecord
end
17 changes: 17 additions & 0 deletions app/views/blogs/_blog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div id="<%= dom_id blog %>">
<p>
<strong>Title:</strong>
<%= blog.title %>
</p>

<p>
<strong>Body:</strong>
<%= blog.body %>
</p>

<p>
<strong>User:</strong>
<%= blog.user_id %>
</p>

</div>
2 changes: 2 additions & 0 deletions app/views/blogs/_blog.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! blog, :id, :title, :body, :user_id, :created_at, :updated_at
json.url blog_url(blog, format: :json)
32 changes: 32 additions & 0 deletions app/views/blogs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= form_with(model: blog) do |form| %>
<% if blog.errors.any? %>
<div style="color: red">
<h2><%= pluralize(blog.errors.count, "error") %> prohibited this blog from being saved:</h2>

<ul>
<% blog.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
</div>

<div>
<%= form.label :body, style: "display: block" %>
<%= form.text_area :body %>
</div>

<div>
<%= form.label :user_id, style: "display: block" %>
<%= form.text_field :user_id %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/blogs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing blog</h1>

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

<br>

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

<h1>Blogs</h1>

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

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

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

<br>

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

<%= render @blog %>

<div>
<%= link_to "Edit this blog", edit_blog_path(@blog) %> |
<%= link_to "Back to blogs", blogs_path %>
<%= button_to "Destroy this blog", @blog, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/blogs/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "blogs/blog", blog: @blog
17 changes: 16 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
require_relative "boot"

require "rails/all"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand All @@ -23,5 +35,8 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Don't generate system test files.
config.generators.system_tests = nil
end
end
Loading

0 comments on commit e587bb6

Please sign in to comment.