test(nonprofit): fix xhr deprecation warnings

`xhr` and `xml_http_request` are deprecated, changed to new syntax
This commit is contained in:
Luis Castro 2019-07-14 10:07:15 +02:00
parent d4f6e2d91d
commit e08d7836c6
No known key found for this signature in database
GPG key ID: 0A8F33D4C4E27639

View file

@ -52,15 +52,16 @@ describe Houdini::V1::Nonprofit, :type => :request do
e.run e.run
Rails.configuration.action_controller.allow_forgery_protection = false Rails.configuration.action_controller.allow_forgery_protection = false
} }
it 'rejects csrf' do
xhr :post, '/api/v1/nonprofit' it 'rejects csrf' do
post '/api/v1/nonprofit', params: {}, xhr: true
expect(response.code).to eq "401" expect(response.code).to eq "401"
end end
end end
it 'validates nothing' do it 'validates nothing' do
input = {} input = {}
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "400" expect(response.code).to eq "400"
expect_validation_errors(JSON.parse(response.body), create_errors("nonprofit", "user")) expect_validation_errors(JSON.parse(response.body), create_errors("nonprofit", "user"))
end end
@ -72,7 +73,7 @@ describe Houdini::V1::Nonprofit, :type => :request do
phone: "notphone", phone: "notphone",
url: "" url: ""
}} }}
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "400" expect(response.code).to eq "400"
expected = create_errors("user") expected = create_errors("user")
expected[:errors].push(h(params:["nonprofit[email]"], messages: gr_e("regexp"))) expected[:errors].push(h(params:["nonprofit[email]"], messages: gr_e("regexp")))
@ -92,7 +93,7 @@ describe Houdini::V1::Nonprofit, :type => :request do
password_confirmation: 'doesn\'t match' password_confirmation: 'doesn\'t match'
} }
} }
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "400" expect(response.code).to eq "400"
expect(JSON.parse(response.body)['errors']).to include(h(params:["user[password]", "user[password_confirmation]"], messages: gr_e("is_equal_to"))) expect(JSON.parse(response.body)['errors']).to include(h(params:["user[password]", "user[password_confirmation]"], messages: gr_e("is_equal_to")))
@ -107,7 +108,7 @@ describe Houdini::V1::Nonprofit, :type => :request do
expect_any_instance_of(SlugNonprofitNamingAlgorithm).to receive(:create_copy_name).and_raise(UnableToCreateNameCopyError.new) expect_any_instance_of(SlugNonprofitNamingAlgorithm).to receive(:create_copy_name).and_raise(UnableToCreateNameCopyError.new)
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "400" expect(response.code).to eq "400"
expect_validation_errors(JSON.parse(response.body), { expect_validation_errors(JSON.parse(response.body), {
@ -128,7 +129,7 @@ describe Houdini::V1::Nonprofit, :type => :request do
user: {name: "Name", email: "em@em.com", password: "12345678", password_confirmation: "12345678"} user: {name: "Name", email: "em@em.com", password: "12345678", password_confirmation: "12345678"}
} }
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "400" expect(response.code).to eq "400"
expect_validation_errors(JSON.parse(response.body), { expect_validation_errors(JSON.parse(response.body), {
@ -155,7 +156,7 @@ describe Houdini::V1::Nonprofit, :type => :request do
#expect(Houdini::V1::Nonprofit).to receive(:sign_in) #expect(Houdini::V1::Nonprofit).to receive(:sign_in)
xhr :post, '/api/v1/nonprofit', input post '/api/v1/nonprofit', params: input, xhr: true
expect(response.code).to eq "201" expect(response.code).to eq "201"
our_np = Nonprofit.all[1] our_np = Nonprofit.all[1]
@ -211,4 +212,4 @@ end
def gr_e(*keys) def gr_e(*keys)
keys.map {|i| I18n.translate("grape.errors.messages." + i, locale: 'en')} keys.map {|i| I18n.translate("grape.errors.messages." + i, locale: 'en')}
end end