diff --git a/app/controllers/cms/pages_controller.rb b/app/controllers/cms/pages_controller.rb new file mode 100644 index 0000000..88614c4 --- /dev/null +++ b/app/controllers/cms/pages_controller.rb @@ -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 diff --git a/app/helpers/cms/pages_helper.rb b/app/helpers/cms/pages_helper.rb new file mode 100644 index 0000000..67ad0cd --- /dev/null +++ b/app/helpers/cms/pages_helper.rb @@ -0,0 +1,2 @@ +module Cms::PagesHelper +end diff --git a/app/models/cms.rb b/app/models/cms.rb new file mode 100644 index 0000000..a82043b --- /dev/null +++ b/app/models/cms.rb @@ -0,0 +1,5 @@ +module Cms + def self.table_name_prefix + "cms_" + end +end diff --git a/app/models/cms/page.rb b/app/models/cms/page.rb new file mode 100644 index 0000000..fe6d1eb --- /dev/null +++ b/app/models/cms/page.rb @@ -0,0 +1,2 @@ +class Cms::Page < ActiveModel +end diff --git a/config/routes.rb b/config/routes.rb index 62afd87..08ef3ff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do namespace :cms do + resources :pages resources :image resources :page end diff --git a/spec/helpers/cms/pages_helper_spec.rb b/spec/helpers/cms/pages_helper_spec.rb new file mode 100644 index 0000000..c866325 --- /dev/null +++ b/spec/helpers/cms/pages_helper_spec.rb @@ -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 diff --git a/spec/models/cms/page_spec.rb b/spec/models/cms/page_spec.rb new file mode 100644 index 0000000..7460466 --- /dev/null +++ b/spec/models/cms/page_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Cms::Page, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/cms/pages_spec.rb b/spec/requests/cms/pages_spec.rb new file mode 100644 index 0000000..31f5abf --- /dev/null +++ b/spec/requests/cms/pages_spec.rb @@ -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 diff --git a/spec/routing/cms/pages_routing_spec.rb b/spec/routing/cms/pages_routing_spec.rb new file mode 100644 index 0000000..0afeb0c --- /dev/null +++ b/spec/routing/cms/pages_routing_spec.rb @@ -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 diff --git a/spec/views/cms/pages/edit.html.tailwindcss_spec.rb b/spec/views/cms/pages/edit.html.tailwindcss_spec.rb new file mode 100644 index 0000000..a90d423 --- /dev/null +++ b/spec/views/cms/pages/edit.html.tailwindcss_spec.rb @@ -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 diff --git a/spec/views/cms/pages/index.html.tailwindcss_spec.rb b/spec/views/cms/pages/index.html.tailwindcss_spec.rb new file mode 100644 index 0000000..e7942fd --- /dev/null +++ b/spec/views/cms/pages/index.html.tailwindcss_spec.rb @@ -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 diff --git a/spec/views/cms/pages/new.html.tailwindcss_spec.rb b/spec/views/cms/pages/new.html.tailwindcss_spec.rb new file mode 100644 index 0000000..d06baf2 --- /dev/null +++ b/spec/views/cms/pages/new.html.tailwindcss_spec.rb @@ -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 diff --git a/spec/views/cms/pages/show.html.tailwindcss_spec.rb b/spec/views/cms/pages/show.html.tailwindcss_spec.rb new file mode 100644 index 0000000..4f1513f --- /dev/null +++ b/spec/views/cms/pages/show.html.tailwindcss_spec.rb @@ -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
" do + render + end +end