-
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.
Merge pull request #223 from cassiosantana/refactor/222-authors-resou…
…rce-should-be-moved-to-the-admin-namespace refactor/222-authors-resource-should-be-moved-to-the-admin-namespace
- Loading branch information
Showing
20 changed files
with
144 additions
and
142 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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AuthorsController < ApplicationController | ||
before_action :set_author, only: %i[show edit update destroy] | ||
|
||
def index | ||
@authors = Author.all | ||
end | ||
|
||
def show; end | ||
|
||
def new | ||
@author = Author.new | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@author = Author.new(author_params) | ||
|
||
if @author.save | ||
redirect_to admin_author_url(@author), notice: "Author was successfully created." | ||
else | ||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @author.update(author_params) | ||
redirect_to admin_author_url(@author), notice: "Author was successfully updated." | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@author.destroy | ||
|
||
redirect_to admin_authors_url, notice: "Author was successfully destroyed." | ||
end | ||
|
||
def report | ||
@author = Author.includes(:books).find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def set_author | ||
@author = Author.find(params[:id]) | ||
end | ||
|
||
def author_params | ||
params.require(:author).permit(:name, :cpf) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
app/views/authors/_form.html.erb → app/views/admin/authors/_form.html.erb
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,10 @@ | ||
<h1>Editing author</h1> | ||
|
||
<%= render "form", author: @author %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this author", admin_author_path(@author) %> | | ||
<%= link_to "Back to authors", admin_authors_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
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,11 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render "admin/authors/author", author: @author %> | ||
|
||
<div> | ||
<%= link_to "Edit this author", edit_admin_author_path(@author) %> | | ||
<%= link_to "Back to authors", admin_authors_path %> | | ||
<%= link_to "Show report", report_admin_author_path(@author) %> | ||
<%= button_to "Destroy this author", admin_author_path(@author), method: :delete %> | ||
</div> |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Admin::AuthorsController, type: :routing do | ||
describe "routing" do | ||
it "routes to #index" do | ||
expect(get: "admin/authors").to route_to("admin/authors#index") | ||
end | ||
|
||
it "routes to #new" do | ||
expect(get: "admin/authors/new").to route_to("admin/authors#new") | ||
end | ||
|
||
it "routes to #show" do | ||
expect(get: "admin/authors/1").to route_to("admin/authors#show", id: "1") | ||
end | ||
|
||
it "routes to #edit" do | ||
expect(get: "admin/authors/1/edit").to route_to("admin/authors#edit", id: "1") | ||
end | ||
|
||
it "routes to #create" do | ||
expect(post: "admin/authors").to route_to("admin/authors#create") | ||
end | ||
|
||
it "routes to #update via PUT" do | ||
expect(put: "admin/authors/1").to route_to("admin/authors#update", id: "1") | ||
end | ||
|
||
it "routes to #update via PATCH" do | ||
expect(patch: "admin/authors/1").to route_to("admin/authors#update", id: "1") | ||
end | ||
|
||
it "routes to #destroy" do | ||
expect(delete: "admin/authors/1").to route_to("admin/authors#destroy", id: "1") | ||
end | ||
end | ||
end |
File renamed without changes.
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
Oops, something went wrong.