Files
nairobi/spec/controllers/remote_translation_controller_spec.rb
voodoorai2000 2acba1c5db Use Rails 5 syntax to set referer in specs
The previous way was working fine with Rails 4, but now the referer was
returning nil and therefore raising an error in this spec.
2019-06-27 09:21:19 +02:00

50 lines
1.5 KiB
Ruby

require "rails_helper"
describe RemoteTranslationsController do
describe "POST create" do
let(:debate) { create(:debate) }
before do
@remote_translations_params = [{ remote_translatable_id: debate.id.to_s,
remote_translatable_type: debate.class.to_s,
locale: :es }].to_json
request.env["HTTP_REFERER"] = "any_path"
Delayed::Worker.delay_jobs = true
end
after do
Delayed::Worker.delay_jobs = false
end
it "create correctly remote translation" do
post :create, remote_translations: @remote_translations_params
expect(RemoteTranslation.count).to eq(1)
end
it "create remote translation when same remote translation with error_message is enqueued" do
create(:remote_translation, remote_translatable: debate, locale: :es, error_message: "Has errors")
post :create, remote_translations: @remote_translations_params
expect(RemoteTranslation.count).to eq(2)
end
it "not create remote translation when same remote translation is enqueued" do
create(:remote_translation, remote_translatable: debate, locale: :es)
post :create, remote_translations: @remote_translations_params
expect(RemoteTranslation.count).to eq(1)
end
it "redirect_to request referer after create" do
post :create, remote_translations: @remote_translations_params
expect(subject).to redirect_to("any_path")
end
end
end