2019-01-31 22:27:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'PATCH/PUT /settings/profile' do
|
|
|
|
let(:current_account) { create :personal_account }
|
|
|
|
|
|
|
|
let :account_attributes do
|
|
|
|
{
|
2019-04-28 09:34:46 -04:00
|
|
|
nickname: Faker::Internet.username(3..36, %w[_]),
|
2019-02-01 16:52:45 -05:00
|
|
|
public_name: Faker::Name.name,
|
2019-04-28 09:34:46 -04:00
|
|
|
biography: Faker::Lorem.paragraph,
|
2019-01-31 22:27:35 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in current_account.user if current_account&.user
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_request
|
|
|
|
patch '/settings/profile', params: { account: account_attributes }
|
|
|
|
end
|
|
|
|
|
2019-09-01 07:27:18 -04:00
|
|
|
for_account_types nil do
|
2019-01-31 22:27:35 -05:00
|
|
|
before { make_request }
|
|
|
|
|
|
|
|
specify do
|
2019-02-01 21:00:49 -05:00
|
|
|
expect(response).to have_http_status :forbidden
|
2019-01-31 22:27:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for_account_types :usual, :superuser do
|
|
|
|
specify do
|
|
|
|
expect { make_request }.to \
|
2019-03-24 15:27:06 -04:00
|
|
|
change { current_account.reload.nickname }
|
|
|
|
.from(current_account.nickname)
|
|
|
|
.to(account_attributes[:nickname])
|
2019-01-31 22:27:35 -05:00
|
|
|
end
|
|
|
|
|
2019-02-01 16:52:45 -05:00
|
|
|
specify do
|
|
|
|
expect { make_request }.to \
|
|
|
|
change { current_account.reload.public_name }
|
|
|
|
.from(current_account.public_name)
|
|
|
|
.to(account_attributes[:public_name])
|
|
|
|
end
|
|
|
|
|
2019-01-31 23:23:01 -05:00
|
|
|
specify do
|
|
|
|
expect { make_request }.to \
|
|
|
|
change { current_account.reload.biography }
|
|
|
|
.from(current_account.biography)
|
|
|
|
.to(account_attributes[:biography])
|
|
|
|
end
|
|
|
|
|
2019-01-31 22:27:35 -05:00
|
|
|
context 'after request' do
|
|
|
|
before { make_request }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(response).to redirect_to edit_settings_profile_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|