Remove unnecessary routes and actions for Contents

We won't use index, edit, update, patch or delete. This removes route
definitions, controller actions and views.
Signed-off-by: marcheing's avatarHeitor Reis <marcheing@gmail.com>
parent 185f94a5
Pipeline #3598304 passed with stage
in 8 minutes and 31 seconds
class ContentsController < ApplicationController
before_action :set_content, only: [:show, :edit, :update, :destroy]
# GET /contents
# GET /contents.json
def index
@contents = Content.all
end
before_action :set_content, only: [:show]
# GET /contents/1
# GET /contents/1.json
......@@ -17,10 +11,6 @@ class ContentsController < ApplicationController
@content = Content.new
end
# GET /contents/1/edit
def edit
end
# POST /contents
# POST /contents.json
def create
......@@ -38,30 +28,6 @@ class ContentsController < ApplicationController
end
end
# PATCH/PUT /contents/1
# PATCH/PUT /contents/1.json
def update
respond_to do |format|
if @content.update(content_params)
format.html { redirect_to @content, notice: 'Content was successfully updated.' }
format.json { render :show, status: :ok, location: @content }
else
format.html { render :edit }
format.json { render json: @content.errors, status: :unprocessable_entity }
end
end
end
# DELETE /contents/1
# DELETE /contents/1.json
def destroy
@content.destroy
respond_to do |format|
format.html { redirect_to contents_url, notice: 'Content was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_content
......
<h1>Editing Content</h1>
<%= render 'form', content: @content %>
<%= link_to 'Show', @content %> |
<%= link_to 'Back', contents_path %>
<p id="notice"><%= notice %></p>
<h1>Contents</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>User</th>
<th>Adult</th>
<th>Rating</th>
<th>Soundtrack</th>
<th>View count</th>
<th>Deleted</th>
<th>Zip code</th>
<th>Director</th>
<th>Co director</th>
<th>Team</th>
<th>Allow comments</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @contents.each do |content| %>
<tr>
<td><%= content.title %></td>
<td><%= content.description %></td>
<td><%= content.user_id %></td>
<td><%= content.adult %></td>
<td><%= content.rating %></td>
<td><%= content.soundtrack %></td>
<td><%= content.view_count %></td>
<td><%= content.deleted %></td>
<td><%= content.zip_code %></td>
<td><%= content.director %></td>
<td><%= content.co_director %></td>
<td><%= content.team %></td>
<td><%= content.allow_comments %></td>
<td><%= link_to 'Show', content %></td>
<td><%= link_to 'Edit', edit_content_path(content) %></td>
<td><%= link_to 'Destroy', content, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Content', new_content_path %>
......@@ -65,5 +65,4 @@
<%= @content.allow_comments %>
</p>
<%= link_to 'Edit', edit_content_path(@content) %> |
<%= link_to 'Back', contents_path %>
......@@ -3,7 +3,7 @@ Rails.application.routes.draw do
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :profiles, except: [:index]
resources :contents
resources :contents, only: [:new, :create, :show]
get 'states' => 'profiles#states', as: 'states'
......
......@@ -36,14 +36,6 @@ RSpec.describe ContentsController, type: :controller do
# ContentsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "assigns all contents as @contents" do
content = Content.create! valid_attributes
get :index, params: {}, session: valid_session
expect(assigns(:contents)).to eq([content])
end
end
describe "GET #show" do
it "assigns the requested content as @content" do
content = Content.create! valid_attributes
......@@ -59,14 +51,6 @@ RSpec.describe ContentsController, type: :controller do
end
end
describe "GET #edit" do
it "assigns the requested content as @content" do
content = Content.create! valid_attributes
get :edit, params: {id: content.to_param}, session: valid_session
expect(assigns(:content)).to eq(content)
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new Content" do
......@@ -99,61 +83,4 @@ RSpec.describe ContentsController, type: :controller do
end
end
end
describe "PUT #update" do
context "with valid params" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
}
it "updates the requested content" do
content = Content.create! valid_attributes
put :update, params: {id: content.to_param, content: new_attributes}, session: valid_session
content.reload
skip("Add assertions for updated state")
end
it "assigns the requested content as @content" do
content = Content.create! valid_attributes
put :update, params: {id: content.to_param, content: valid_attributes}, session: valid_session
expect(assigns(:content)).to eq(content)
end
it "redirects to the content" do
content = Content.create! valid_attributes
put :update, params: {id: content.to_param, content: valid_attributes}, session: valid_session
expect(response).to redirect_to(content)
end
end
context "with invalid params" do
it "assigns the content as @content" do
content = Content.create! valid_attributes
put :update, params: {id: content.to_param, content: invalid_attributes}, session: valid_session
expect(assigns(:content)).to eq(content)
end
it "re-renders the 'edit' template" do
content = Content.create! valid_attributes
put :update, params: {id: content.to_param, content: invalid_attributes}, session: valid_session
expect(response).to render_template("edit")
end
end
end
describe "DELETE #destroy" do
it "destroys the requested content" do
content = Content.create! valid_attributes
expect {
delete :destroy, params: {id: content.to_param}, session: valid_session
}.to change(Content, :count).by(-1)
end
it "redirects to the contents list" do
content = Content.create! valid_attributes
delete :destroy, params: {id: content.to_param}, session: valid_session
expect(response).to redirect_to(contents_url)
end
end
end
......@@ -4,7 +4,7 @@ RSpec.describe ContentsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/contents").to route_to("contents#index")
expect(:get => "/contents").to_not route_to("contents#index")
end
it "routes to #new" do
......@@ -16,7 +16,7 @@ RSpec.describe ContentsController, type: :routing do
end
it "routes to #edit" do
expect(:get => "/contents/1/edit").to route_to("contents#edit", :id => "1")
expect(:get => "/contents/1/edit").to_not route_to("contents#edit", :id => "1")
end
it "routes to #create" do
......@@ -24,15 +24,15 @@ RSpec.describe ContentsController, type: :routing do
end
it "routes to #update via PUT" do
expect(:put => "/contents/1").to route_to("contents#update", :id => "1")
expect(:put => "/contents/1").to_not route_to("contents#update", :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "/contents/1").to route_to("contents#update", :id => "1")
expect(:patch => "/contents/1").to_not route_to("contents#update", :id => "1")
end
it "routes to #destroy" do
expect(:delete => "/contents/1").to route_to("contents#destroy", :id => "1")
expect(:delete => "/contents/1").to_not route_to("contents#destroy", :id => "1")
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment