Refactoring: Clean up ticket/article_spec.rb
This commit is contained in:
parent
c02d7f2159
commit
768a350160
1 changed files with 102 additions and 101 deletions
|
@ -6,20 +6,23 @@ RSpec.describe Ticket::Article, type: :model do
|
|||
it_behaves_like 'ApplicationModel'
|
||||
it_behaves_like 'CanBeImported'
|
||||
|
||||
describe '.create' do
|
||||
it 'handles NULL byte in subject or body' do
|
||||
expect(create(:ticket_article, subject: "com test 1\u0000", body: "some\u0000message 123"))
|
||||
describe 'Callbacks, Observers, & Async Transactions' do
|
||||
describe 'NULL byte handling (via ChecksAttributeValuesAndLength concern):' do
|
||||
it 'removes them from subject on creation, if necessary (postgres doesn’t like them)' do
|
||||
expect(create(:ticket_article, subject: "com test 1\u0000"))
|
||||
.to be_persisted
|
||||
end
|
||||
|
||||
it 'removes them from body on creation, if necessary (postgres doesn’t like them)' do
|
||||
expect(create(:ticket_article, body: "some\u0000message 123"))
|
||||
.to be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
describe 'hooks on creation' do
|
||||
context 'of outgoing article' do
|
||||
context 'over Twitter' do
|
||||
describe 'Auto-setting of outgoing Twitter article attributes (via bj jobs):' do
|
||||
subject!(:twitter_article) { create(:twitter_article, sender_name: 'Agent') }
|
||||
let(:channel) { Channel.find(twitter_article.ticket.preferences[:channel_id]) }
|
||||
|
||||
describe 'background job actions' do
|
||||
let(:run_bg_jobs) do
|
||||
lambda do
|
||||
VCR.use_cassette(cassette, match_requests_on: %i[method uri oauth_headers]) do
|
||||
|
@ -30,25 +33,25 @@ RSpec.describe Ticket::Article, type: :model do
|
|||
|
||||
let(:cassette) { 'models/channel/driver/twitter/article_to_tweet' }
|
||||
|
||||
it 'sets #from attribute to sender’s Twitter handle' do
|
||||
it 'sets #from to sender’s Twitter handle' do
|
||||
expect(&run_bg_jobs)
|
||||
.to change { twitter_article.reload.from }
|
||||
.to('@example')
|
||||
end
|
||||
|
||||
it 'sets #to attribute to recipient’s Twitter handle' do
|
||||
it 'sets #to to recipient’s Twitter handle' do
|
||||
expect(&run_bg_jobs)
|
||||
.to change { twitter_article.reload.to }
|
||||
.to('') # Tweet in VCR cassette is addressed to no one
|
||||
end
|
||||
|
||||
it 'sets #message_id attribute to tweet ID (https://twitter.com/statuses/<id>)' do
|
||||
it 'sets #message_id to tweet ID (https://twitter.com/statuses/<id>)' do
|
||||
expect(&run_bg_jobs)
|
||||
.to change { twitter_article.reload.message_id }
|
||||
.to('1069382411899817990')
|
||||
end
|
||||
|
||||
it 'sets #preferences hash with tweet metadata' do
|
||||
it 'sets #preferences with tweet metadata' do
|
||||
expect(&run_bg_jobs)
|
||||
.to change { twitter_article.reload.preferences }
|
||||
.to(hash_including('twitter', 'links'))
|
||||
|
@ -61,27 +64,27 @@ RSpec.describe Ticket::Article, type: :model do
|
|||
)
|
||||
end
|
||||
|
||||
it 'does not change #cc attribute' do
|
||||
it 'does not change #cc' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.cc }
|
||||
end
|
||||
|
||||
it 'does not change #subject attribute' do
|
||||
it 'does not change #subject' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.subject }
|
||||
end
|
||||
|
||||
it 'does not change #content_type attribute' do
|
||||
it 'does not change #content_type' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.content_type }
|
||||
end
|
||||
|
||||
it 'does not change #body attribute' do
|
||||
it 'does not change #body' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.body }
|
||||
end
|
||||
|
||||
it 'does not change #sender association' do
|
||||
it 'does not change #sender' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.sender }
|
||||
end
|
||||
|
||||
it 'does not change #type association' do
|
||||
it 'does not change #type' do
|
||||
expect(&run_bg_jobs).not_to change { twitter_article.reload.type }
|
||||
end
|
||||
|
||||
|
@ -122,8 +125,6 @@ RSpec.describe Ticket::Article, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'clone attachments' do
|
||||
context 'of forwarded article' do
|
||||
|
|
Loading…
Reference in a new issue