Skip to content

Commit

Permalink
Pages: Create controller, model, migration, basic RSpecs (refs #286)
Browse files Browse the repository at this point in the history
  • Loading branch information
ut committed Sep 16, 2023
1 parent 76d3a15 commit e6df693
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ group :development, :test do
gem 'rspec'
gem 'rspec_junit_formatter'
gem 'rspec-rails'
gem 'selenium-webdriver', '4.9.0' # 4.9.1 crashed feature tests
gem 'selenium-webdriver'
gem 'shoulda-matchers'
gem 'simplecov'
gem 'simplecov-small-badge', require: false
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ GEM
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.6.3)
json-schema (4.0.0)
json-schema (4.1.1)
addressable (>= 2.8)
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -343,7 +343,7 @@ GEM
rspec-support (3.12.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.56.2)
rubocop (1.56.3)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand All @@ -361,7 +361,7 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-rspec (2.23.2)
rubocop-rspec (2.24.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
Expand All @@ -388,7 +388,7 @@ GEM
tilt
secure_headers (6.5.0)
select2-rails (4.0.13)
selenium-webdriver (4.9.0)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -531,7 +531,7 @@ DEPENDENCIES
sassc-rails
secure_headers
select2-rails
selenium-webdriver (= 4.9.0)
selenium-webdriver
shoulda-matchers
simple_form
simplecov
Expand Down
69 changes: 69 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

class PagesController < ApplicationController
before_action :set_page, only: %i[show edit update destroy]

def index
@pages = if admin?
Page.all
else
Page.published
end
end

def new
@page = Page.new
end

def edit; end

def create
@page = Page.new(page_params)

respond_to do |format|
if @page.save
format.html { redirect_to page_url(@page), notice: 'Page was successfully created.' }
format.json { render :index, status: :created, location: @page }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /people/1 or /people/1.json
def update
respond_to do |format|
if @page.update(page_params)
format.html { redirect_to page_url(@page), notice: 'Page was successfully updated.' }
format.json { render :index, status: :ok, location: @page }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end

def destroy
if @page.destroy
respond_to do |format|
format.html { redirect_to page_url(@page), notice: 'Page was successfully destroyed.' }
format.json { head :no_content }
end
else
respond_to do |format|
format.html { redirect_to page_url(@page), notice: 'Page could not be destroyed, since its connected to 1 or more annotations.' }
end
end
end

private

def set_page
@page = Page.find(params[:id])
end

def page_params
params.require(:page).permit(:title, :is_published, :is_in_menu, :ptype, :teasertext, :fulltext, :footertext)
end
end
8 changes: 8 additions & 0 deletions app/helpers/pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module PagesHelper
def ptype_for_select
ptypes = %w[help faq imprint privacy]
ptypes.each_with_object({}) { |e, m| m[e.capitalize] = e }
end
end
9 changes: 9 additions & 0 deletions app/models/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Page < ApplicationRecord
validates :title, presence: true

scope :sorted, -> { order(title: :asc) }
scope :published, -> { where(is_published: true) }
scope :in_menu, -> { where(is_in_menu: true) }
end
15 changes: 15 additions & 0 deletions db/migrate/20230916110019_create_pages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreatePages < ActiveRecord::Migration[6.1]
def change
create_table :pages do |t|
t.boolean :is_published, default: false
t.boolean :in_menu, default: false
t.string :ptype
t.string :title
t.text :teasertext
t.text :fulltext
t.text :footertext

t.timestamps
end
end
end
62 changes: 37 additions & 25 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_02_27_174811) do
ActiveRecord::Schema.define(version: 2023_09_16_110019) do

create_table "active_storage_attachments", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "active_storage_attachments", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
Expand All @@ -22,7 +22,7 @@
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "active_storage_blobs", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
Expand All @@ -34,13 +34,13 @@
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "active_storage_variant_records", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "active_storage_variant_records", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end

create_table "annotations", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "annotations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.text "text"
t.bigint "place_id"
Expand All @@ -54,7 +54,7 @@
t.index ["place_id"], name: "fk_rails_51dbcfe977"
end

create_table "build_logs", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "build_logs", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.bigint "map_id"
t.bigint "layer_id"
t.string "output"
Expand All @@ -66,7 +66,7 @@
t.index ["map_id"], name: "index_build_logs_on_map_id"
end

create_table "friendly_id_slugs", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "friendly_id_slugs", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "slug", null: false
t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 50
Expand All @@ -77,23 +77,23 @@
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
end

create_table "groups", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "groups", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active", default: true
t.text "message"
end

create_table "icons", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "icons", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.bigint "iconset_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["iconset_id"], name: "index_icons_on_iconset_id"
end

create_table "iconsets", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "iconsets", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.text "text"
t.datetime "created_at", null: false
Expand All @@ -104,7 +104,7 @@
t.string "class_name"
end

create_table "images", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "images", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.string "licence"
t.text "source"
Expand All @@ -120,7 +120,7 @@
t.index ["place_id"], name: "index_images_on_place_id"
end

create_table "layers", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "layers", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.string "subtitle"
t.boolean "published", default: false
Expand Down Expand Up @@ -157,7 +157,7 @@
t.index ["slug"], name: "index_layers_on_slug", unique: true
end

create_table "maps", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "maps", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.string "subtitle"
t.boolean "published", default: false
Expand Down Expand Up @@ -192,7 +192,7 @@
t.index ["slug"], name: "index_maps_on_slug", unique: true
end

create_table "mobility_string_translations", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "mobility_string_translations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "locale", null: false
t.string "key", null: false
t.string "value"
Expand All @@ -205,7 +205,7 @@
t.index ["translatable_type", "key", "value", "locale"], name: "index_mobility_string_translations_on_query_keys"
end

create_table "mobility_text_translations", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "mobility_text_translations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "locale", null: false
t.string "key", null: false
t.text "value"
Expand All @@ -217,7 +217,19 @@
t.index ["translatable_id", "translatable_type", "locale", "key"], name: "index_mobility_text_translations_on_keys", unique: true
end

create_table "people", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "pages", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.boolean "is_published", default: false
t.boolean "in_menu", default: false
t.string "ptype"
t.string "title"
t.text "teasertext"
t.text "fulltext"
t.text "footertext"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "people", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "name"
t.text "info"
t.datetime "created_at", null: false
Expand All @@ -226,7 +238,7 @@
t.index ["map_id"], name: "index_people_on_map_id"
end

create_table "places", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "places", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.text "teaser"
t.text "text"
Expand Down Expand Up @@ -255,15 +267,15 @@
t.index ["layer_id"], name: "index_places_on_layer_id"
end

create_table "relations", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "relations", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.integer "relation_from_id"
t.integer "relation_to_id"
t.string "rtype"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "submission_configs", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "submission_configs", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title_intro"
t.string "subtitle_intro"
t.text "intro"
Expand All @@ -279,7 +291,7 @@
t.index ["layer_id"], name: "index_submission_configs_on_layer_id"
end

create_table "submissions", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "submissions", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "name"
t.string "email"
t.boolean "rights"
Expand All @@ -292,7 +304,7 @@
t.index ["place_id"], name: "index_submissions_on_place_id"
end

create_table "taggings", id: :integer, charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "taggings", id: :integer, charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.integer "tag_id"
t.string "taggable_type"
t.integer "taggable_id"
Expand All @@ -311,15 +323,15 @@
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
end

create_table "tags", id: :integer, charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
t.string "name", collation: "utf8_bin"
create_table "tags", id: :integer, charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "name", collation: "utf8mb3_bin"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "taggings_count", default: 0
t.index ["name"], name: "index_tags_on_name", unique: true
end

create_table "users", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "users", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
Expand All @@ -339,7 +351,7 @@
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

create_table "videos", charset: "utf8", collation: "utf8_general_ci", force: :cascade do |t|
create_table "videos", charset: "utf8mb3", collation: "utf8mb3_general_ci", force: :cascade do |t|
t.string "title"
t.string "licence"
t.text "source"
Expand Down
Loading

0 comments on commit e6df693

Please sign in to comment.