Splits long lines in more readable ones
Those tests have too long lines. We have to split the to have more readable ones. This is based on a real project with Ruby and RSpec.
require 'spec_helper'
describe ContentsController, type: :controller do
before :each do
set_request_on_domain :domain_test
sign_in users(:admin)
end
describe '#update_categories' do
let(:content) { contents(:adsl_cancel_question).set(intervention: nil) }
it 'is success' do
put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id
expect(response).to be_success
expect(response.body).to be_blank
end
it 'is success if mandatory categories are not specified' do
expect {
put :update_categories, id: content.id, category_ids: [], thread_id: content_threads(:adsl_cancel).id
}.to_not change { content }
expect(response).to be_success
end
it 'updates categories' do
expect {
put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id
}.to change { content.reload.categories.to_a.sort }.from(array_including([categories(:internet), categories(:sales)])).to(array_including([categories(:technical), categories(:mobile)]))
end
it 'sets categories' do
expect {
put :update_categories, id: contents(:new_smartphone).id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:new_smartphone).id
}.to change { contents(:new_smartphone).reload.categories.to_a.sort }.from([]).to([categories(:technical), categories(:mobile)])
end
end
end
require 'spec_helper'
describe ContentsController, type: :controller do
before :each do
set_request_on_domain :domain_test
sign_in users(:admin)
end
describe '#update_categories' do
let(:content) { contents(:adsl_cancel_question).set(intervention: nil) }
it 'is success' do
put :update_categories,
id: content.id,
category_ids: [categories(:mobile).id, categories(:technical).id],
thread_id: content_threads(:adsl_cancel).id
expect(response).to be_success
expect(response.body).to be_blank
end
it 'is success if mandatory categories are not specified' do
expect {
put :update_categories,
id: content.id,
category_ids: [],
thread_id: content_threads(:adsl_cancel).id
}.to_not change { content }
expect(response).to be_success
end
it 'updates categories' do
expect {
put :update_categories,
id: content.id,
category_ids: [categories(:mobile).id, categories(:technical).id],
thread_id: content_threads(:adsl_cancel).id
}.to change { content.reload.categories.to_a.sort }
.from(array_including([categories(:internet), categories(:sales)]))
.to(array_including([categories(:technical), categories(:mobile)]))
end
it 'sets categories' do
expect {
put :update_categories,
id: contents(:new_smartphone).id,
category_ids: [categories(:mobile).id, categories(:technical).id],
thread_id: content_threads(:new_smartphone).id
}.to change { contents(:new_smartphone).reload.categories.to_a.sort }
.from([])
.to([categories(:technical), categories(:mobile)])
end
end
end