Add action AccountsController#show
This commit is contained in:
parent
9c34b77f2a
commit
d9a978504f
8 changed files with 80 additions and 0 deletions
16
app/controllers/accounts_controller.rb
Normal file
16
app/controllers/accounts_controller.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountsController < ApplicationController
|
||||
before_action :set_account
|
||||
|
||||
# GET /accounts/:username
|
||||
def show
|
||||
authorize @account
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = Account.find_by! username: params[:username]
|
||||
end
|
||||
end
|
|
@ -34,6 +34,10 @@ class Account < ApplicationRecord
|
|||
|
||||
validates :biography, length: { maximum: 10_000 }
|
||||
|
||||
def to_param
|
||||
username
|
||||
end
|
||||
|
||||
def guest?
|
||||
user.nil?
|
||||
end
|
||||
|
|
7
app/policies/account_policy.rb
Normal file
7
app/policies/account_policy.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountPolicy < ApplicationPolicy
|
||||
def show?
|
||||
true
|
||||
end
|
||||
end
|
9
app/views/accounts/show.html.erb
Normal file
9
app/views/accounts/show.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<p class="h4 text-muted"><%= @account.username %></p>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -13,6 +13,8 @@ Rails.application.routes.draw do
|
|||
get :join, to: 'membership_apps#new'
|
||||
post :join, to: 'membership_apps#create'
|
||||
|
||||
resources :accounts, param: :username, only: :show
|
||||
|
||||
resources :country_states, only: %i[index show]
|
||||
|
||||
###############
|
||||
|
|
|
@ -39,6 +39,12 @@ RSpec.describe Account do
|
|||
pending '#guest?'
|
||||
pending '#can_access_sidekiq_web_interface?'
|
||||
|
||||
describe '#to_param' do
|
||||
specify do
|
||||
expect(subject.to_param).to eq subject.username
|
||||
end
|
||||
end
|
||||
|
||||
describe '#username' do
|
||||
def allow_value(*)
|
||||
super.for :username
|
||||
|
|
18
spec/policies/account_policy_spec.rb
Normal file
18
spec/policies/account_policy_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountPolicy do
|
||||
subject { described_class.new account, record }
|
||||
|
||||
let!(:record) { create :personal_account }
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
it { is_expected.to permit_action :show }
|
||||
|
||||
it { is_expected.to forbid_action :index }
|
||||
it { is_expected.to forbid_new_and_create_actions }
|
||||
it { is_expected.to forbid_edit_and_update_actions }
|
||||
it { is_expected.to forbid_action :destroy }
|
||||
end
|
||||
end
|
18
spec/requests/accounts/show_spec.rb
Normal file
18
spec/requests/accounts/show_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /accounts/:username' do
|
||||
let!(:account_record) { create :personal_account }
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
get "/accounts/#{account_record.username}"
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue