-
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
337 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 WishlistsController < ApplicationController | ||
before_action :set_wishlist, only: %i[ show edit update destroy ] | ||
|
||
# GET /wishlists or /wishlists.json | ||
def index | ||
@wishlists = Wishlist.all | ||
end | ||
|
||
# GET /wishlists/1 or /wishlists/1.json | ||
def show | ||
end | ||
|
||
# GET /wishlists/new | ||
def new | ||
@wishlist = Wishlist.new | ||
end | ||
|
||
# GET /wishlists/1/edit | ||
def edit | ||
end | ||
|
||
# POST /wishlists or /wishlists.json | ||
def create | ||
@wishlist = Wishlist.new(wishlist_params) | ||
|
||
respond_to do |format| | ||
if @wishlist.save | ||
format.html { redirect_to wishlist_url(@wishlist), notice: "Wishlist was successfully created." } | ||
format.json { render :show, status: :created, location: @wishlist } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @wishlist.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /wishlists/1 or /wishlists/1.json | ||
def update | ||
respond_to do |format| | ||
if @wishlist.update(wishlist_params) | ||
format.html { redirect_to wishlist_url(@wishlist), notice: "Wishlist was successfully updated." } | ||
format.json { render :show, status: :ok, location: @wishlist } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @wishlist.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /wishlists/1 or /wishlists/1.json | ||
def destroy | ||
@wishlist.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to wishlists_url, notice: "Wishlist was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_wishlist | ||
@wishlist = Wishlist.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def wishlist_params | ||
params.require(:wishlist).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 WishlistsHelper | ||
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,19 @@ | ||
<%= form_with(model: wishlist, class: "contents") do |form| %> | ||
<% if wishlist.errors.any? %> | ||
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3"> | ||
<h2><%= pluralize(wishlist.errors.count, "error") %> prohibited this wishlist from being saved:</h2> | ||
|
||
<ul> | ||
<% wishlist.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<%= form.text_field :name %> | ||
|
||
<div class="inline"> | ||
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> | ||
</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,28 @@ | ||
<div id="<%= dom_id wishlist %>"> | ||
<% if action_name != "show" %> | ||
<%= link_to "Show this wishlist", wishlist, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to 'Edit this wishlist', edit_wishlist_path(wishlist), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> | ||
<hr class="mt-6"> | ||
<% end %> | ||
|
||
<table class="table-auto border-spacing-4 border-separate border border-slate-900"> | ||
<thead> | ||
<tr> | ||
<th>Attribute</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
|
||
<tr> | ||
<td class="border border-slate-900">ID</td> | ||
<td class="border border-slate-900"><%= @wishlist.id %></td> | ||
</tr> | ||
|
||
<tr> | ||
<td class="border border-slate-900">Name</td> | ||
<td class="border border-slate-900"><%= @wishlist.name %></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</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! wishlist, :id, :name, :created_at, :updated_at | ||
json.url wishlist_url(wishlist, 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,8 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">Editing wishlist</h1> | ||
|
||
<%= render "form", wishlist: @wishlist %> | ||
<%= link_to "Show this wishlist", @wishlist, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to "Back to wishlists", wishlists_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</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,37 @@ | ||
<div class="w-full"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<div class="flex justify-between items-center"> | ||
<h1 class="font-bold text-4xl">Wishlists</h1> | ||
<%= link_to 'New wishlist', new_wishlist_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> | ||
</div> | ||
|
||
<div id="wishlists" class="min-w-full"> | ||
<table class="table-auto border-spacing-4 border-separate border border-slate-900"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>URL</th> | ||
<th>Search</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @wishlists.each do |wishlist| %> | ||
<tr> | ||
<td class="border border-slate-900"><%= wishlist.name %></td> | ||
<td class="border border-slate-900"> | ||
<a href="<%= wishlist_url(wishlist) %>">Show</a> | ||
</td> | ||
<td class="border border-slate-900"> | ||
<a href="<%= "https://www.google.com/search?q=#{wishlist.name}" %>" target="_blank"> | ||
</a> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</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.array! @wishlists, partial: "wishlists/wishlist", as: :wishlist |
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 class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">New wishlist</h1> | ||
|
||
<%= render "form", wishlist: @wishlist %> | ||
<%= link_to 'Back to wishlists', wishlists_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</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,15 @@ | ||
<div class="mx-auto md:w-2/3 w-full flex"> | ||
<div class="mx-auto"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
<%= render @wishlist %> | ||
<%= link_to 'Edit this wishlist', edit_wishlist_path(@wishlist), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<div class="inline-block ml-2"> | ||
<%= button_to 'Destroy this wishlist', wishlist_path(@wishlist), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> | ||
</div> | ||
<%= link_to 'Back to wishlists', wishlists_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
</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! "wishlists/wishlist", wishlist: @wishlist |
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,38 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe WishlistsController, type: :routing do | ||
describe "routing" do | ||
it "routes to #index" do | ||
expect(get: "/wishlists").to route_to("wishlists#index") | ||
end | ||
|
||
it "routes to #new" do | ||
expect(get: "/wishlists/new").to route_to("wishlists#new") | ||
end | ||
|
||
it "routes to #show" do | ||
expect(get: "/wishlists/1").to route_to("wishlists#show", id: "1") | ||
end | ||
|
||
it "routes to #edit" do | ||
expect(get: "/wishlists/1/edit").to route_to("wishlists#edit", id: "1") | ||
end | ||
|
||
|
||
it "routes to #create" do | ||
expect(post: "/wishlists").to route_to("wishlists#create") | ||
end | ||
|
||
it "routes to #update via PUT" do | ||
expect(put: "/wishlists/1").to route_to("wishlists#update", id: "1") | ||
end | ||
|
||
it "routes to #update via PATCH" do | ||
expect(patch: "/wishlists/1").to route_to("wishlists#update", id: "1") | ||
end | ||
|
||
it "routes to #destroy" do | ||
expect(delete: "/wishlists/1").to route_to("wishlists#destroy", id: "1") | ||
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,18 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "wishlists/edit", type: :view do | ||
let(:wishlist) { | ||
Wishlist.create!(name: 'Euphorbia Atrox') | ||
} | ||
|
||
before(:each) do | ||
assign(:wishlist, wishlist) | ||
end | ||
|
||
it "renders the edit wishlist form" do | ||
render | ||
|
||
assert_select "form[action=?][method=?]", wishlist_path(wishlist), "post" do | ||
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,15 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "wishlists/index", type: :view do | ||
before(:each) do | ||
assign(:wishlists, [ | ||
Wishlist.create!(name: 'giga'), | ||
Wishlist.create!(name: 'omega') | ||
]) | ||
end | ||
|
||
it "renders a list of wishlists" do | ||
render | ||
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td' | ||
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,14 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "wishlists/new", type: :view do | ||
before(:each) do | ||
assign(:wishlist, Wishlist.new(name: 'omega')) | ||
end | ||
|
||
it "renders new wishlist form" do | ||
render | ||
|
||
assert_select "form[action=?][method=?]", wishlists_path, "post" do | ||
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,11 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "wishlists/show", type: :view do | ||
before(:each) do | ||
assign(:wishlist, Wishlist.create!(name: 'giga')) | ||
end | ||
|
||
it "renders attributes in <p>" do | ||
render | ||
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 WishlistControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@wishlist = wishlists(:one) | ||
end | ||
|
||
test "should get index" do | ||
get wishlists_url | ||
assert_response :success | ||
end | ||
|
||
test "should get new" do | ||
get new_wishlist_url | ||
assert_response :success | ||
end | ||
|
||
test "should create wishlist" do | ||
assert_difference("Wishlist.count") do | ||
post wishlists_url, params: { wishlist: { name: 'PlantThree' } } | ||
end | ||
|
||
assert_redirected_to wishlist_url(Wishlist.last) | ||
end | ||
|
||
test "should show wishlist" do | ||
get wishlist_url(@wishlist) | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get edit_wishlist_url(@wishlist) | ||
assert_response :success | ||
end | ||
|
||
test "should update wishlist" do | ||
patch wishlist_url(@wishlist), params: { wishlist: { name: 'PlantFour' } } | ||
assert_redirected_to wishlist_url(@wishlist) | ||
end | ||
|
||
test "should destroy wishlist" do | ||
assert_difference("Wishlist.count", -1) do | ||
delete wishlist_url(@wishlist) | ||
end | ||
|
||
assert_redirected_to wishlists_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,3 @@ | ||
one: | ||
id: 1 | ||
name: 'Euphorbia Atrox' |