Skip to content

Commit

Permalink
✨🥔 Agreement: They can be shown! (#1365)
Browse files Browse the repository at this point in the history
🥔 `Agreement`: They can be shown!

 - #1364

This isn't the prettiest, but it'll do.
  • Loading branch information
zspencer authored Apr 15, 2023
1 parent f38f1e2 commit 6ec234c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/controllers/space/agreements_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Space
class AgreementsController < ApplicationController
def show
authorize(agreement)
end

helper_method def agreement
@agreement ||= policy_scope(space.agreements).friendly.find(params[:id])
end

def space
current_space
end
end
end
2 changes: 1 addition & 1 deletion app/lib/space_routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SpaceRoutes
def self.append_routes(router)
router.resource :agreements, only: %i[show]
router.resources :agreements, only: %i[show], controller: "space/agreements"
router.resource :authenticated_session, only: %i[new create update destroy show]
router.resources :invitations, only: %i[create destroy index] do
router.resource :rsvp, only: %i[show update]
Expand Down
6 changes: 6 additions & 0 deletions app/models/space/agreement.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
class Space
class Agreement < ApplicationRecord
extend StripsNamespaceFromModelName
include RendersMarkdown

self.table_name = "space_agreements"

extend FriendlyId
friendly_id :name, use: :slugged

validates :name, presence: true, uniqueness: {scope: :space_id}
validates :slug, uniqueness: {scope: :space_id}

belongs_to :space, inverse_of: :agreements
location(parent: :space)

attribute :body, :string
validates :body, presence: true
Expand Down
13 changes: 13 additions & 0 deletions app/policies/space/agreement_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Space
class AgreementPolicy < ApplicationPolicy
def show?
true
end

class Scope < ::ApplicationScope
def resolve
scope.all
end
end
end
end
7 changes: 7 additions & 0 deletions app/views/space/agreements/_agreement.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render CardComponent.new(dom_id: dom_id(agreement), classes: "mx-auto mt-2 max-w-prose w-full") do %>
<h2><%= agreement.name %></h2>

<div>
<%== agreement.to_html %>
</div>
<%- end %>
3 changes: 3 additions & 0 deletions app/views/space/agreements/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- breadcrumb :show_space_agreement, agreement %>
<%= render agreement %>
5 changes: 5 additions & 0 deletions config/breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
link "Configure Space", [:edit, space]
end

crumb :show_space_agreement do |agreement|
parent :root, agreement.space
link t("show.link_to", name: agreement.name)
end

crumb :memberships do |space|
link "Members", [space, :memberships]
if policy(space).edit?
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ en:
formats:
day_month_date_year_hour_minute: "%A %B %d, %Y %l:%M%p"
day_month_date_hour_minute: "%A %B %d %l:%M%p"
show:
link_to: "%{name}"
edit:
link_to: "Edit"
destroy:
Expand Down
15 changes: 15 additions & 0 deletions spec/requests/space/agreements_controller_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "rails_helper"

RSpec.describe Space::AgreementsController do
describe "#show" do
subject(:perform_request) do
get polymorphic_path([space, agreement])
response
end

let(:space) { agreement.space }
let(:agreement) { create(:space_agreement) }

it { is_expected.to render_template(:show) }
end
end

0 comments on commit 6ec234c

Please sign in to comment.