From 5f6a10eb984c0398cccaef728e56b300cbe4acfd Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:27:18 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Rename=20to=20`Content=20Block`?= =?UTF-8?q?=20because=20that=20sounds=20better=20to=20me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/furniture/{text_block.rb => content_block.rb} | 2 +- app/furniture/content_block/content_block_policy.rb | 11 +++++++++++ .../content_block/content_blocks_controller.rb | 9 +++++++++ app/furniture/text_block/text_block_policy.rb | 11 ----------- app/furniture/text_block/text_blocks_controller.rb | 10 ---------- app/lib/space_routes.rb | 2 +- app/views/rooms/edit.html.erb | 4 ++-- db/migrate/20240328004901_create_content_blocks.rb | 7 +++++++ db/migrate/20240328004901_create_text_blocks.rb | 7 ------- db/seeds.rb | 2 ++ spec/system/slots_system_spec.rb | 6 +++--- 11 files changed, 36 insertions(+), 35 deletions(-) rename app/furniture/{text_block.rb => content_block.rb} (70%) create mode 100644 app/furniture/content_block/content_block_policy.rb create mode 100644 app/furniture/content_block/content_blocks_controller.rb delete mode 100644 app/furniture/text_block/text_block_policy.rb delete mode 100644 app/furniture/text_block/text_blocks_controller.rb create mode 100644 db/migrate/20240328004901_create_content_blocks.rb delete mode 100644 db/migrate/20240328004901_create_text_blocks.rb diff --git a/app/furniture/text_block.rb b/app/furniture/content_block.rb similarity index 70% rename from app/furniture/text_block.rb rename to app/furniture/content_block.rb index a9e401089..91e6c7bfb 100644 --- a/app/furniture/text_block.rb +++ b/app/furniture/content_block.rb @@ -1,4 +1,4 @@ -class TextBlock < ApplicationRecord +class ContentBlock < ApplicationRecord belongs_to :slot has_one :section, through: :slot has_one :space, through: :section diff --git a/app/furniture/content_block/content_block_policy.rb b/app/furniture/content_block/content_block_policy.rb new file mode 100644 index 000000000..0f6adfe77 --- /dev/null +++ b/app/furniture/content_block/content_block_policy.rb @@ -0,0 +1,11 @@ +class ContentBlock + class ContentBlockPolicy < ApplicationPolicy + alias_method :content_block, :object + def create? + current_person.member_of?(content_block.space) + end + + class Scope < ApplicationScope + end + end +end diff --git a/app/furniture/content_block/content_blocks_controller.rb b/app/furniture/content_block/content_blocks_controller.rb new file mode 100644 index 000000000..b6ff520a7 --- /dev/null +++ b/app/furniture/content_block/content_blocks_controller.rb @@ -0,0 +1,9 @@ +class ContentBlock + class ContentBlocksController < ApplicationController + expose :content_block, scope: -> { policy_scope(ContentBlock, policy_scope_class: ContentBlockPolicy::Scope) }, model: ContentBlock + + def new + authorize(content_block, policy_class: ContentBlockPolicy) + end + end +end diff --git a/app/furniture/text_block/text_block_policy.rb b/app/furniture/text_block/text_block_policy.rb deleted file mode 100644 index a64cb484e..000000000 --- a/app/furniture/text_block/text_block_policy.rb +++ /dev/null @@ -1,11 +0,0 @@ -class TextBlock - class TextBlockPolicy < ApplicationPolicy - alias_method :text_block, :object - def create? - current_person.member_of?(text_block.space) - end - - class Scope < ApplicationScope - end - end -end diff --git a/app/furniture/text_block/text_blocks_controller.rb b/app/furniture/text_block/text_blocks_controller.rb deleted file mode 100644 index 787439338..000000000 --- a/app/furniture/text_block/text_blocks_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class TextBlock - class TextBlocksController < ApplicationController - expose :text_block, scope: -> { policy_scope(TextBlock, policy_scope_class: TextBlockPolicy::Scope) }, model: TextBlock, - build: ->(params, scope) { scope.new(params.merge(slottable: slottable)) } - - def new - authorize(text_block, policy_class: TextBlockPolicy) - end - end -end diff --git a/app/lib/space_routes.rb b/app/lib/space_routes.rb index fe5e2a88d..3b68fe6ff 100644 --- a/app/lib/space_routes.rb +++ b/app/lib/space_routes.rb @@ -9,7 +9,7 @@ def self.append_routes(router) Furniture.append_routes(router) router.resources :furnitures, only: %i[create edit update destroy] router.resource :hero_image, controller: "room/hero_images" - router.resources :text_block, controller: "text_block/text_blocks" + router.resources :content_block, controller: "content_block/content_blocks" end router.resources :utilities diff --git a/app/views/rooms/edit.html.erb b/app/views/rooms/edit.html.erb index 226eda64a..63f9f6ef8 100644 --- a/app/views/rooms/edit.html.erb +++ b/app/views/rooms/edit.html.erb @@ -18,10 +18,10 @@

Gizmos (but lighter)

<%- end %> - - <%= link_to "Add Text Block", room.location(:new, child: :text_block), class: "button"%> + <%= link_to "Add Content Block", room.location(:new, child: :content_block), class: "button"%> <%- end %> <%- end %> +
<%= render CardComponent.new do %>

Gizmos

diff --git a/db/migrate/20240328004901_create_content_blocks.rb b/db/migrate/20240328004901_create_content_blocks.rb new file mode 100644 index 000000000..695003982 --- /dev/null +++ b/db/migrate/20240328004901_create_content_blocks.rb @@ -0,0 +1,7 @@ +class CreateContentBlocks < ActiveRecord::Migration[7.1] + def change + create_table :content_blocks, id: :uuid do |t| + t.timestamps + end + end +end diff --git a/db/migrate/20240328004901_create_text_blocks.rb b/db/migrate/20240328004901_create_text_blocks.rb deleted file mode 100644 index 4518fcfca..000000000 --- a/db/migrate/20240328004901_create_text_blocks.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CreateTextBlocks < ActiveRecord::Migration[7.1] - def change - create_table :text_blocks, id: :uuid do |t| - t.timestamps - end - end -end diff --git a/db/seeds.rb b/db/seeds.rb index aa08ecf98..bd4917fa6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -43,3 +43,5 @@ _content_block_section = FactoryBot.create(:room, space:, name: "Content Block-o-Clock", description: "Content Blocks show static Words, Photos, or Videos!") + +# FactoryBot.create(:content_block, in_section: content_block_section) diff --git a/spec/system/slots_system_spec.rb b/spec/system/slots_system_spec.rb index 20bfea41a..6fad5a881 100644 --- a/spec/system/slots_system_spec.rb +++ b/spec/system/slots_system_spec.rb @@ -6,18 +6,18 @@ let(:space) { create(:space, :with_members) } let(:section) { create(:room, space:) } - scenario "Adding a Text Block to a Slot" do + scenario "Adding a Content Block to a Slot" do sign_in(space.members.first, space) visit(polymorphic_path(section.location(:edit))) - click_link("Add Text Block") + click_link("Add Content Block") expect(page).to have_current_path(polymorphic_path(section.location(:new, child: :text_block))) fill_in_rich_text_area("Body", with: "Prepare yourself for AMAZING") click_button("Create") expect(section.slots.count).to eq(1) - expect(section.slots.first.slottable).to be_a(TextBlock) + expect(section.slots.first.slottable).to be_a(ContentBlock) expect(sections.slots.first.slottable.body).to eq("Prepare yourself for AMAZING") end end