generate page

This commit is contained in:
Torsten 2022-11-25 13:21:52 +02:00
parent 45541938b9
commit 58259c4b15
13 changed files with 309 additions and 0 deletions

View File

@ -0,0 +1,58 @@
class Cms::PagesController < ApplicationController
before_action :set_cms_page, only: %i[ show edit update destroy ]
# GET /cms/pages
def index
@cms_pages = Cms::Page.all
end
# GET /cms/pages/1
def show
end
# GET /cms/pages/new
def new
@cms_page = Cms::Page.new
end
# GET /cms/pages/1/edit
def edit
end
# POST /cms/pages
def create
@cms_page = Cms::Page.new(cms_page_params)
if @cms_page.save
redirect_to @cms_page, notice: "Page was successfully created."
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT /cms/pages/1
def update
if @cms_page.update(cms_page_params)
redirect_to @cms_page, notice: "Page was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /cms/pages/1
def destroy
@cms_page.destroy
redirect_to cms_pages_url, notice: "Page was successfully destroyed."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_cms_page
@cms_page = Cms::Page.find(params[:id])
end
# Only allow a list of trusted parameters through.
def cms_page_params
params.fetch(:cms_page, {})
end
end

View File

@ -0,0 +1,2 @@
module Cms::PagesHelper
end

5
app/models/cms.rb Normal file
View File

@ -0,0 +1,5 @@
module Cms
def self.table_name_prefix
"cms_"
end
end

2
app/models/cms/page.rb Normal file
View File

@ -0,0 +1,2 @@
class Cms::Page < ActiveModel
end

View File

@ -1,6 +1,7 @@
Rails.application.routes.draw do
namespace :cms do
resources :pages
resources :image
resources :page
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Cms::PagesHelper. For example:
#
# describe Cms::PagesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Cms::PagesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Cms::Page, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,130 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to test the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
RSpec.describe "/cms/pages", type: :request do
# Cms::Page. As you add validations to Cms::Page, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
}
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
describe "GET /index" do
it "renders a successful response" do
Cms::Page.create! valid_attributes
get cms_pages_url
expect(response).to be_successful
end
end
describe "GET /show" do
it "renders a successful response" do
page = Cms::Page.create! valid_attributes
get cms_page_url(cms_page)
expect(response).to be_successful
end
end
describe "GET /new" do
it "renders a successful response" do
get new_cms_page_url
expect(response).to be_successful
end
end
describe "GET /edit" do
it "render a successful response" do
page = Cms::Page.create! valid_attributes
get edit_cms_page_url(cms_page)
expect(response).to be_successful
end
end
describe "POST /create" do
context "with valid parameters" do
it "creates a new Cms::Page" do
expect {
post cms_pages_url, params: { cms_page: valid_attributes }
}.to change(Cms::Page, :count).by(1)
end
it "redirects to the created cms_page" do
post cms_pages_url, params: { cms_page: valid_attributes }
expect(response).to redirect_to(cms_page_url(@cms_page))
end
end
context "with invalid parameters" do
it "does not create a new Cms::Page" do
expect {
post cms_pages_url, params: { cms_page: invalid_attributes }
}.to change(Cms::Page, :count).by(0)
end
it "renders a successful response (i.e. to display the 'new' template)" do
post cms_pages_url, params: { cms_page: invalid_attributes }
expect(response).to be_successful
end
end
end
describe "PATCH /update" do
context "with valid parameters" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
}
it "updates the requested cms_page" do
page = Cms::Page.create! valid_attributes
patch cms_page_url(cms_page), params: { cms_page: new_attributes }
page.reload
skip("Add assertions for updated state")
end
it "redirects to the cms_page" do
page = Cms::Page.create! valid_attributes
patch cms_page_url(cms_page), params: { cms_page: new_attributes }
page.reload
expect(response).to redirect_to(cms_page_url(page))
end
end
context "with invalid parameters" do
it "renders a successful response (i.e. to display the 'edit' template)" do
page = Cms::Page.create! valid_attributes
patch cms_page_url(cms_page), params: { cms_page: invalid_attributes }
expect(response).to be_successful
end
end
end
describe "DELETE /destroy" do
it "destroys the requested cms_page" do
page = Cms::Page.create! valid_attributes
expect {
delete cms_page_url(cms_page)
}.to change(Cms::Page, :count).by(-1)
end
it "redirects to the cms_pages list" do
page = Cms::Page.create! valid_attributes
delete cms_page_url(cms_page)
expect(response).to redirect_to(cms_pages_url)
end
end
end

View File

@ -0,0 +1,38 @@
require "rails_helper"
RSpec.describe Cms::PagesController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(get: "/cms/pages").to route_to("cms/pages#index")
end
it "routes to #new" do
expect(get: "/cms/pages/new").to route_to("cms/pages#new")
end
it "routes to #show" do
expect(get: "/cms/pages/1").to route_to("cms/pages#show", id: "1")
end
it "routes to #edit" do
expect(get: "/cms/pages/1/edit").to route_to("cms/pages#edit", id: "1")
end
it "routes to #create" do
expect(post: "/cms/pages").to route_to("cms/pages#create")
end
it "routes to #update via PUT" do
expect(put: "/cms/pages/1").to route_to("cms/pages#update", id: "1")
end
it "routes to #update via PATCH" do
expect(patch: "/cms/pages/1").to route_to("cms/pages#update", id: "1")
end
it "routes to #destroy" do
expect(delete: "/cms/pages/1").to route_to("cms/pages#destroy", id: "1")
end
end
end

View File

@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "cms/pages/edit", type: :view do
before(:each) do
@cms_page = assign(:cms_page, Cms::Page.create!())
end
it "renders the edit cms_page form" do
render
assert_select "form[action=?][method=?]", cms_page_path(@cms_page), "post" do
end
end
end

View File

@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "cms/pages/index", type: :view do
before(:each) do
assign(:cms_pages, [
Cms::Page.create!(),
Cms::Page.create!()
])
end
it "renders a list of cms/pages" do
render
end
end

View File

@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "cms/pages/new", type: :view do
before(:each) do
assign(:cms_page, Cms::Page.new())
end
it "renders new cms_page form" do
render
assert_select "form[action=?][method=?]", cms_pages_path, "post" do
end
end
end

View File

@ -0,0 +1,11 @@
require 'rails_helper'
RSpec.describe "cms/pages/show", type: :view do
before(:each) do
@cms_page = assign(:cms_page, Cms::Page.create!())
end
it "renders attributes in <p>" do
render
end
end