-
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
1 parent
12b6eea
commit 80ecfcc
Showing
19 changed files
with
306 additions
and
1 deletion.
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 SpotsController < ApplicationController | ||
before_action :set_spot, only: %i[ show edit update destroy ] | ||
|
||
# GET /spots or /spots.json | ||
def index | ||
@spots = Spot.all | ||
end | ||
|
||
# GET /spots/1 or /spots/1.json | ||
def show | ||
end | ||
|
||
# GET /spots/new | ||
def new | ||
@spot = Spot.new | ||
end | ||
|
||
# GET /spots/1/edit | ||
def edit | ||
end | ||
|
||
# POST /spots or /spots.json | ||
def create | ||
@spot = Spot.new(spot_params) | ||
|
||
respond_to do |format| | ||
if @spot.save | ||
format.html { redirect_to spot_url(@spot), notice: "Spot was successfully created." } | ||
format.json { render :show, status: :created, location: @spot } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @spot.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /spots/1 or /spots/1.json | ||
def update | ||
respond_to do |format| | ||
if @spot.update(spot_params) | ||
format.html { redirect_to spot_url(@spot), notice: "Spot was successfully updated." } | ||
format.json { render :show, status: :ok, location: @spot } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @spot.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /spots/1 or /spots/1.json | ||
def destroy | ||
@spot.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to spots_url, notice: "Spot was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_spot | ||
@spot = Spot.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def spot_params | ||
params.require(:spot).permit(:name, :latitude, :longitude) | ||
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 SpotsHelper | ||
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 Spot < 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,32 @@ | ||
<%= form_with(model: spot) do |form| %> | ||
<% if spot.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(spot.errors.count, "error") %> prohibited this spot from being saved:</h2> | ||
|
||
<ul> | ||
<% spot.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.label :latitude, style: "display: block" %> | ||
<%= form.text_field :latitude %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :longitude, style: "display: block" %> | ||
<%= form.text_field :longitude %> | ||
</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,17 @@ | ||
<div id="<%= dom_id spot %>"> | ||
<p> | ||
<strong>Name:</strong> | ||
<%= spot.name %> | ||
</p> | ||
|
||
<p> | ||
<strong>Latitude:</strong> | ||
<%= spot.latitude %> | ||
</p> | ||
|
||
<p> | ||
<strong>Longitude:</strong> | ||
<%= spot.longitude %> | ||
</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! spot, :id, :name, :latitude, :longitude, :created_at, :updated_at | ||
json.url spot_url(spot, 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,10 @@ | ||
<h1>Editing spot</h1> | ||
|
||
<%= render "form", spot: @spot %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this spot", @spot %> | | ||
<%= link_to "Back to spots", spots_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>Spots</h1> | ||
|
||
<div id="spots"> | ||
<% @spots.each do |spot| %> | ||
<%= render spot %> | ||
<p> | ||
<%= link_to "Show this spot", spot %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New spot", new_spot_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! @spots, partial: "spots/spot", as: :spot |
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 spot</h1> | ||
|
||
<%= render "form", spot: @spot %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to spots", spots_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 @spot %> | ||
|
||
<div> | ||
<%= link_to "Edit this spot", edit_spot_path(@spot) %> | | ||
<%= link_to "Back to spots", spots_path %> | ||
<%= button_to "Destroy this spot", @spot, 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! "spots/spot", spot: @spot |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Rails.application.routes.draw do | ||
resources :spots | ||
get 'errors/not_found' | ||
get 'errors/internal_server_error' | ||
|
||
|
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,11 @@ | ||
class CreateSpots < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :spots do |t| | ||
t.string :name | ||
t.float :latitude | ||
t.float :longitude | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "test_helper" | ||
|
||
class SpotsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@spot = spots(:one) | ||
end | ||
|
||
test "should get index" do | ||
get spots_url | ||
assert_response :success | ||
end | ||
|
||
test "should get new" do | ||
get new_spot_url | ||
assert_response :success | ||
end | ||
|
||
test "should create spot" do | ||
assert_difference("Spot.count") do | ||
post spots_url, params: { spot: { latitude: @spot.latitude, longitude: @spot.longitude, name: @spot.name } } | ||
end | ||
|
||
assert_redirected_to spot_url(Spot.last) | ||
end | ||
|
||
test "should show spot" do | ||
get spot_url(@spot) | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get edit_spot_url(@spot) | ||
assert_response :success | ||
end | ||
|
||
test "should update spot" do | ||
patch spot_url(@spot), params: { spot: { latitude: @spot.latitude, longitude: @spot.longitude, name: @spot.name } } | ||
assert_redirected_to spot_url(@spot) | ||
end | ||
|
||
test "should destroy spot" do | ||
assert_difference("Spot.count", -1) do | ||
delete spot_url(@spot) | ||
end | ||
|
||
assert_redirected_to spots_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 @@ | ||
require "test_helper" | ||
|
||
class SpotTest < 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,45 @@ | ||
require "application_system_test_case" | ||
|
||
class SpotsTest < ApplicationSystemTestCase | ||
setup do | ||
@spot = spots(:one) | ||
end | ||
|
||
test "visiting the index" do | ||
visit spots_url | ||
assert_selector "h1", text: "Spots" | ||
end | ||
|
||
test "should create spot" do | ||
visit spots_url | ||
click_on "New spot" | ||
|
||
fill_in "Latitude", with: @spot.latitude | ||
fill_in "Longitude", with: @spot.longitude | ||
fill_in "Name", with: @spot.name | ||
click_on "Create Spot" | ||
|
||
assert_text "Spot was successfully created" | ||
click_on "Back" | ||
end | ||
|
||
test "should update Spot" do | ||
visit spot_url(@spot) | ||
click_on "Edit this spot", match: :first | ||
|
||
fill_in "Latitude", with: @spot.latitude | ||
fill_in "Longitude", with: @spot.longitude | ||
fill_in "Name", with: @spot.name | ||
click_on "Update Spot" | ||
|
||
assert_text "Spot was successfully updated" | ||
click_on "Back" | ||
end | ||
|
||
test "should destroy Spot" do | ||
visit spot_url(@spot) | ||
click_on "Destroy this spot", match: :first | ||
|
||
assert_text "Spot was successfully destroyed" | ||
end | ||
end |