1
0
Fork 0

Add action AccountsController#show

This commit is contained in:
Alex Kotov 2019-02-02 02:36:10 +05:00
parent 9c34b77f2a
commit d9a978504f
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
8 changed files with 80 additions and 0 deletions

View 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

View File

@ -34,6 +34,10 @@ class Account < ApplicationRecord
validates :biography, length: { maximum: 10_000 }
def to_param
username
end
def guest?
user.nil?
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AccountPolicy < ApplicationPolicy
def show?
true
end
end

View 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>

View File

@ -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]
###############

View File

@ -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

View 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

View 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