Convert to system spec

pull/32730/head
Christian Schmidt 2025-01-08 18:07:01 +01:00
parent ef5f1c2e92
commit e7f45ee35a
2 changed files with 17 additions and 70 deletions

View File

@ -1,68 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings / Verification' do
let(:user) { Fabricate :user, account_attributes: { attribution_domains: ['example.com', 'example.net'] } }
let(:params) do
{
account: {
attribution_domains: attribution_domains,
},
}
end
let(:attribution_domains) { " example.com\n\n https://example.org" }
describe 'GET /settings/verification' do
it 'shows attribution domains in textarea' do
sign_in user if user
get settings_verification_path
expect(response.body)
.to include(">\nexample.com\nexample.net</textarea>")
end
context 'when not signed in' do
it 'redirects to sign in page' do
get settings_verification_path
expect(response)
.to redirect_to new_user_session_path
end
end
end
describe 'PUT /settings/verification' do
before do
sign_in user if user
put settings_verification_path, params: params
end
it 'updates account and redirects' do
expect(user.account.reload.attribution_domains)
.to eq ['example.com', 'example.org']
expect(response)
.to redirect_to settings_verification_path
end
context 'when attribution_domains contains invalid domain' do
let(:attribution_domains) { "example.com\ninvalid_com" }
it 'mentions invalid domain' do
expect(response).to have_http_status(200)
expect(response.body)
.to include I18n.t('activerecord.errors.messages.invalid_domain_on_line', value: 'invalid_com')
end
end
context 'when not signed in' do
let(:user) { nil }
it 'redirects to sign in page' do
expect(response)
.to redirect_to new_user_session_path
end
end
end
end

View File

@ -15,12 +15,27 @@ RSpec.describe 'Settings verification page' do
.to have_content(verification_summary)
.and have_private_cache_control
fill_in attribution_field, with: 'host.example'
fill_in attribution_field, with: " example.com\n\n https://example.net"
expect { click_on submit_button }
.to(change { user.account.reload.attribution_domains })
.to(change { user.account.reload.attribution_domains }.to(['example.com', 'example.net']))
expect(page)
.to have_content(success_message)
expect(find_field(attribution_field).value)
.to have_content("example.com\nexample.net")
end
it 'rejects invalid attribution domains' do
visit settings_verification_path
fill_in attribution_field, with: "example.com \n invalid_com"
expect { click_on submit_button }
.to_not(change { user.account.reload.attribution_domains })
expect(page)
.to have_content(I18n.t('activerecord.errors.messages.invalid_domain_on_line', value: 'invalid_com'))
expect(find_field(attribution_field).value)
.to have_content("example.com\ninvalid_com")
end
end