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 'ApplicationModel'
|
||||||
it_behaves_like 'CanBeImported'
|
it_behaves_like 'CanBeImported'
|
||||||
|
|
||||||
describe '.create' do
|
describe 'Callbacks, Observers, & Async Transactions' do
|
||||||
it 'handles NULL byte in subject or body' do
|
describe 'NULL byte handling (via ChecksAttributeValuesAndLength concern):' do
|
||||||
expect(create(:ticket_article, subject: "com test 1\u0000", body: "some\u0000message 123"))
|
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
|
.to be_persisted
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'hooks on creation' do
|
describe 'Auto-setting of outgoing Twitter article attributes (via bj jobs):' do
|
||||||
context 'of outgoing article' do
|
|
||||||
context 'over Twitter' do
|
|
||||||
subject!(:twitter_article) { create(:twitter_article, sender_name: 'Agent') }
|
subject!(:twitter_article) { create(:twitter_article, sender_name: 'Agent') }
|
||||||
let(:channel) { Channel.find(twitter_article.ticket.preferences[:channel_id]) }
|
let(:channel) { Channel.find(twitter_article.ticket.preferences[:channel_id]) }
|
||||||
|
|
||||||
describe 'background job actions' do
|
|
||||||
let(:run_bg_jobs) do
|
let(:run_bg_jobs) do
|
||||||
lambda do
|
lambda do
|
||||||
VCR.use_cassette(cassette, match_requests_on: %i[method uri oauth_headers]) 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' }
|
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)
|
expect(&run_bg_jobs)
|
||||||
.to change { twitter_article.reload.from }
|
.to change { twitter_article.reload.from }
|
||||||
.to('@example')
|
.to('@example')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets #to attribute to recipient’s Twitter handle' do
|
it 'sets #to to recipient’s Twitter handle' do
|
||||||
expect(&run_bg_jobs)
|
expect(&run_bg_jobs)
|
||||||
.to change { twitter_article.reload.to }
|
.to change { twitter_article.reload.to }
|
||||||
.to('') # Tweet in VCR cassette is addressed to no one
|
.to('') # Tweet in VCR cassette is addressed to no one
|
||||||
end
|
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)
|
expect(&run_bg_jobs)
|
||||||
.to change { twitter_article.reload.message_id }
|
.to change { twitter_article.reload.message_id }
|
||||||
.to('1069382411899817990')
|
.to('1069382411899817990')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets #preferences hash with tweet metadata' do
|
it 'sets #preferences with tweet metadata' do
|
||||||
expect(&run_bg_jobs)
|
expect(&run_bg_jobs)
|
||||||
.to change { twitter_article.reload.preferences }
|
.to change { twitter_article.reload.preferences }
|
||||||
.to(hash_including('twitter', 'links'))
|
.to(hash_including('twitter', 'links'))
|
||||||
|
@ -61,27 +64,27 @@ RSpec.describe Ticket::Article, type: :model do
|
||||||
)
|
)
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.cc }
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.subject }
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.content_type }
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.body }
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.sender }
|
||||||
end
|
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 }
|
expect(&run_bg_jobs).not_to change { twitter_article.reload.type }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,8 +125,6 @@ RSpec.describe Ticket::Article, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'clone attachments' do
|
describe 'clone attachments' do
|
||||||
context 'of forwarded article' do
|
context 'of forwarded article' do
|
||||||
|
|
Loading…
Reference in a new issue