Namespace languages controller to admin
This commit is contained in:
parent
206c4da31f
commit
c2891a66f8
@ -1,4 +1,4 @@
|
||||
class LanguagesController < ApplicationController
|
||||
class Admin::LanguagesController < ApplicationController
|
||||
|
||||
def index
|
||||
@languages = Language.all
|
||||
@ -12,7 +12,7 @@ class LanguagesController < ApplicationController
|
||||
@language = Language.new(language_params)
|
||||
if @language.save
|
||||
flash[:notice] = "Language successfully created."
|
||||
redirect_to languages_path
|
||||
redirect_to admin_languages_path
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
@ -26,7 +26,7 @@ class LanguagesController < ApplicationController
|
||||
@language = Language.find_by_id(params[:id])
|
||||
if @language.update(language_params)
|
||||
flash[:notice] = "Language successfully updated."
|
||||
redirect_to languages_path
|
||||
redirect_to admin_languages_path
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
@ -36,7 +36,7 @@ class LanguagesController < ApplicationController
|
||||
@language = Language.find_by_id(params[:id])
|
||||
if @language.destroy
|
||||
flash[:notice] = "Language successfully deleted."
|
||||
redirect_to languages_path
|
||||
redirect_to admin_languages_path
|
||||
else
|
||||
render :index, status: :not_modified
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
<%= form_for language do |f| %>
|
||||
<%= form_for [:admin, language] do |f| %>
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %><br/>
|
||||
<br/>
|
5
app/views/admin/languages/edit.html.erb
Normal file
5
app/views/admin/languages/edit.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<%= render "admin/languages/errors", language: @language %>
|
||||
|
||||
<h1>Edit Language</h1>
|
||||
|
||||
<%= render "admin/languages/form", language: @language %>
|
@ -7,9 +7,9 @@
|
||||
<% @languages.each do |language| %>
|
||||
<tr>
|
||||
<td><%= language.name %></td>
|
||||
<td><%= link_to "Edit", edit_language_path(language) %></td>
|
||||
<td><%= link_to "Edit", edit_admin_language_path(language) %></td>
|
||||
<td> | </td>
|
||||
<td><%= link_to "Delete", language_path(language), data: { turbo_method: :delete,
|
||||
<td><%= link_to "Delete", admin_language_path(language), data: { turbo_method: :delete,
|
||||
turbo_confirm: "Are you sure?" } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@ -17,4 +17,4 @@
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<%= link_to "New Language", new_language_path %>
|
||||
<%= link_to "New Language", new_admin_language_path %>
|
5
app/views/admin/languages/new.html.erb
Normal file
5
app/views/admin/languages/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<%= render "admin/languages/errors", language: @language %>
|
||||
|
||||
<h1>New Language</h1>
|
||||
|
||||
<%= render "admin/languages/form", language: @language %>
|
@ -1,4 +1,5 @@
|
||||
<h1>Parts of Speech</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>Part of Speech</b></td>
|
||||
@ -11,4 +12,3 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
<%= render "languages/errors", language: @language %>
|
||||
|
||||
<h1>Edit Language</h1>
|
||||
|
||||
<%= render "languages/form", language: @language %>
|
@ -1,5 +0,0 @@
|
||||
<%= render "languages/errors", language: @language %>
|
||||
|
||||
<h1>New Language</h1>
|
||||
|
||||
<%= render "languages/form", language: @language %>
|
@ -17,7 +17,7 @@
|
||||
<%= link_to "Dictionary", dictionary_index_path %>
|
||||
<% if user_signed_in? %>
|
||||
<pre style="display: inline;">|</pre>
|
||||
<%= link_to "Languages", languages_path %>
|
||||
<%= link_to "Languages", admin_languages_path %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="ms-auto p-2">
|
||||
|
@ -1,9 +1,11 @@
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
#get 'dictionary/index'
|
||||
resources :dictionary, only: [:index, :show]
|
||||
resources :dictionary, only: [:index, :show, :create]
|
||||
resources :words, only: [:index, :show]
|
||||
namespace :admin do
|
||||
resources :languages
|
||||
end
|
||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||
|
||||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
||||
|
@ -4,59 +4,59 @@ RSpec.describe "Languages", type: :request do
|
||||
|
||||
describe "GET :index" do
|
||||
it "returns http success" do
|
||||
get "/languages/"
|
||||
get "/admin/languages/"
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "lists all languages" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/languages/"
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to include(language.name)
|
||||
end
|
||||
|
||||
it "has a new-language link" do
|
||||
get "/languages/"
|
||||
expect(response.body).to have_selector(%(a[href="#{new_language_path}"]))
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_selector(%(a[href="#{new_admin_language_path}"]))
|
||||
end
|
||||
|
||||
it "has an edit button" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/languages/"
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_link("Edit")
|
||||
end
|
||||
|
||||
it "has a delete button" do
|
||||
language = FactoryBot.create(:language)
|
||||
get "/languages/"
|
||||
get "/admin/languages/"
|
||||
expect(response.body).to have_link("Delete")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET :new" do
|
||||
it "returns http success" do
|
||||
get "/languages/new"
|
||||
get "/admin/languages/new"
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it "has a form for a new language" do
|
||||
get "/languages/new"
|
||||
get "/admin/languages/new"
|
||||
expect(response.body).to have_selector(%(input[name="language[name]"]))
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST :create" do
|
||||
it "redirect to languages_path on success" do
|
||||
post "/languages", params: { language: { name: "Test Name" } }
|
||||
expect(response).to redirect_to(languages_path)
|
||||
it "redirect to admin_languages_path on success" do
|
||||
post "/admin/languages", params: { language: { name: "Test Name" } }
|
||||
expect(response).to redirect_to(admin_languages_path)
|
||||
end
|
||||
|
||||
it "creates a new language" do
|
||||
post "/languages", params: { language: { name: "Test Name" } }
|
||||
post "/admin/languages", params: { language: { name: "Test Name" } }
|
||||
expect(Language.count).to eq(1)
|
||||
end
|
||||
|
||||
it "requires a name for a new language" do
|
||||
post "/languages", params: { language: { name: nil } }
|
||||
post "/admin/languages", params: { language: { name: nil } }
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
@ -64,7 +64,7 @@ RSpec.describe "Languages", type: :request do
|
||||
describe "GET :edit" do
|
||||
before :each do
|
||||
@language = FactoryBot.create(:language)
|
||||
get "/languages/#{@language.id}/edit"
|
||||
get "/admin/languages/#{@language.id}/edit"
|
||||
end
|
||||
|
||||
it "returns http success" do
|
||||
@ -83,13 +83,13 @@ RSpec.describe "Languages", type: :request do
|
||||
end
|
||||
|
||||
it "updates a language" do
|
||||
patch "/languages/#{@language.id}", params: @params
|
||||
expect(response).to redirect_to(languages_path)
|
||||
patch "/admin/languages/#{@language.id}", params: @params
|
||||
expect(response).to redirect_to(admin_languages_path)
|
||||
end
|
||||
|
||||
it "requires params to update a language" do
|
||||
@params = { language: { name: nil, invalid: "oh no" } }
|
||||
patch "/languages/#{@language.id}", params: @params
|
||||
patch "/admin/languages/#{@language.id}", params: @params
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
@ -99,7 +99,7 @@ RSpec.describe "Languages", type: :request do
|
||||
it "deletes a language" do
|
||||
language = FactoryBot.create(:language)
|
||||
language2 = FactoryBot.create(:language)
|
||||
delete "/languages/#{language.id}"
|
||||
delete "/admin/languages/#{language.id}"
|
||||
expect(Language.all).to eq([language2])
|
||||
end
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe "Root path", type: :request do
|
||||
it "should have the 'Languages' link" do
|
||||
sign_in FactoryBot.create(:user)
|
||||
get root_path
|
||||
expect(response.body).to have_selector(%(a[href="#{languages_path}"]))
|
||||
expect(response.body).to have_selector(%(a[href="#{admin_languages_path}"]))
|
||||
end
|
||||
|
||||
it "should welcome user by username" do
|
||||
|
Loading…
Reference in New Issue
Block a user