Convert invites controller spec to system/request specs (#31755)
This commit is contained in:
parent
5b1ae15a36
commit
e820cc30b8
6 changed files with 135 additions and 85 deletions
86
spec/system/invites_spec.rb
Normal file
86
spec/system/invites_spec.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Invites' do
|
||||
include ActionView::RecordIdentifier
|
||||
|
||||
let(:user) { Fabricate :user }
|
||||
|
||||
before do
|
||||
host! 'localhost:3000' # TODO: Move into before for all system specs?
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe 'Viewing invites' do
|
||||
it 'Lists existing user invites' do
|
||||
invite = Fabricate :invite, user: user
|
||||
|
||||
visit invites_path
|
||||
|
||||
within css_id(invite) do
|
||||
expect(page)
|
||||
.to have_content(invite.uses)
|
||||
.and have_private_cache_control
|
||||
expect(copyable_field.value)
|
||||
.to eq(public_invite_url(invite_code: invite.code))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Creating a new invite' do
|
||||
it 'Saves the invite for the user' do
|
||||
visit invites_path
|
||||
|
||||
fill_invite_form
|
||||
|
||||
expect { submit_form }
|
||||
.to change(user.invites, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Deleting an existing invite' do
|
||||
it 'Expires the invite' do
|
||||
invite = Fabricate :invite, user: user
|
||||
|
||||
visit invites_path
|
||||
|
||||
expect { delete_invite(invite) }
|
||||
.to change { invite.reload.expired? }.to(true)
|
||||
|
||||
within css_id(invite) do
|
||||
expect(page).to have_content I18n.t('invites.expired')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def css_id(record)
|
||||
"##{dom_id(record)}" # TODO: Extract to system spec helper?
|
||||
end
|
||||
|
||||
def copyable_field
|
||||
within '.input-copy' do
|
||||
find(:field, type: :text, readonly: true)
|
||||
end
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('invites.generate')
|
||||
end
|
||||
|
||||
def delete_invite(invite)
|
||||
within css_id(invite) do
|
||||
click_on I18n.t('invites.delete')
|
||||
end
|
||||
end
|
||||
|
||||
def fill_invite_form
|
||||
select I18n.t('invites.max_uses', count: 100),
|
||||
from: I18n.t('simple_form.labels.defaults.max_uses')
|
||||
select I18n.t("invites.expires_in.#{30.minutes.to_i}"),
|
||||
from: I18n.t('simple_form.labels.defaults.expires_in')
|
||||
check I18n.t('simple_form.labels.defaults.autofollow')
|
||||
end
|
||||
end
|
|
@ -6,11 +6,14 @@ RSpec.describe 'Tags' do
|
|||
describe 'Viewing a tag' do
|
||||
let(:tag) { Fabricate(:tag, name: 'test') }
|
||||
|
||||
before { sign_in Fabricate(:user) }
|
||||
|
||||
it 'visits the tag page and renders the web app' do
|
||||
visit tag_path(tag)
|
||||
|
||||
expect(page)
|
||||
.to have_css('noscript', text: /Mastodon/)
|
||||
.and have_private_cache_control
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue