spec/rest/templates/versions_spec.rb in sendgrid4r-0.5.0 vs spec/rest/templates/versions_spec.rb in sendgrid4r-1.0.0
- old
+ new
@@ -4,70 +4,76 @@
describe SendGrid4r::REST::Templates::Versions do
describe 'integration test', :it do
before do
begin
Dotenv.load
- @client = SendGrid4r::Client.new(
- username: ENV['SENDGRID_USERNAME'],
- password: ENV['SENDGRID_PASSWORD'])
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
@template_name = 'version_test'
@version1_name = 'version_name1'
@version2_name = 'version_name2'
@factory = SendGrid4r::Factory::VersionFactory.new
# celan up test env
tmps = @client.get_templates
tmps.templates.each do |tmp|
next if tmp.name != @template_name
tmp.versions.each do |ver|
- @client.delete_version(tmp.id, ver.id)
+ @client.delete_version(template_id: tmp.id, version_id: ver.id)
end
- @client.delete_template(tmp.id)
+ @client.delete_template(template_id: tmp.id)
end
# post a template
- @template = @client.post_template(@template_name)
+ @template = @client.post_template(name: @template_name)
# post a version
ver1 = @factory.create(name: @version1_name)
- @version1 = @client.post_version(@template.id, ver1)
- rescue => e
+ @version1 = @client.post_version(
+ template_id: @template.id, version: ver1
+ )
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
context 'without block call' do
it '#post_version' do
begin
ver2 = @factory.create(name: @version2_name)
- version2 = @client.post_version(@template.id, ver2)
+ version2 = @client.post_version(
+ template_id: @template.id, version: ver2
+ )
expect(version2.name).to eq(@version2_name)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#activate_version' do
begin
- actual = @client.activate_version(@template.id, @version1.id)
+ actual = @client.activate_version(
+ template_id: @template.id, version_id: @version1.id
+ )
expect(actual.active).to eq(1)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#get_version' do
begin
- actual = @client.get_version(@template.id, @version1.id)
+ actual = @client.get_version(
+ template_id: @template.id, version_id: @version1.id
+ )
expect(actual.template_id).to eq(@version1.template_id)
expect(actual.active).to be_a(Fixnum)
expect(actual.name).to eq(@version1.name)
expect(actual.html_content).to eq(@version1.html_content)
expect(actual.plain_content).to eq(@version1.plain_content)
expect(actual.subject).to eq(@version1.subject)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
@@ -77,31 +83,38 @@
edit_ver1.name = 'edit_version'
edit_ver1.subject = 'edit<%subject%>edit'
edit_ver1.html_content = 'edit<%body%>edit'
edit_ver1.plain_content = 'edit<%body%>edit'
edit_ver1.active = 0
- @client.patch_version(@template.id, @version1.id, edit_ver1)
- rescue => e
+ @client.patch_version(
+ template_id: @template.id, version_id: @version1.id,
+ version: edit_ver1
+ )
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#delete_version' do
begin
- @client.delete_version(@template.id, @version1.id)
- rescue => e
+ @client.delete_version(
+ template_id: @template.id, version_id: @version1.id
+ )
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
end
context 'with block call' do
it '#post_version' do
ver2 = @factory.create(name: @version2_name)
- @client.post_version(@template.id, ver2) do |resp, req, res|
+ @client.post_version(
+ template_id: @template.id, version: ver2
+ ) do |resp, req, res|
resp =
SendGrid4r::REST::Templates::Versions.create_version(
JSON.parse(resp)
)
expect(resp).to be_a(SendGrid4r::REST::Templates::Versions::Version)
@@ -109,11 +122,13 @@
expect(res).to be_a(Net::HTTPCreated)
end
end
it '#activate_version' do
- @client.activate_version(@template.id, @version1.id) do |resp, req, res|
+ @client.activate_version(
+ template_id: @template.id, version_id: @version1.id
+ ) do |resp, req, res|
resp =
SendGrid4r::REST::Templates::Versions.create_version(
JSON.parse(resp)
)
expect(resp).to be_a(SendGrid4r::REST::Templates::Versions::Version)
@@ -121,11 +136,13 @@
expect(res).to be_a(Net::HTTPOK)
end
end
it '#get_version' do
- @client.get_version(@template.id, @version1.id) do |resp, req, res|
+ @client.get_version(
+ template_id: @template.id, version_id: @version1.id
+ ) do |resp, req, res|
resp =
SendGrid4r::REST::Templates::Versions.create_version(
JSON.parse(resp)
)
expect(resp).to be_a(SendGrid4r::REST::Templates::Versions::Version)
@@ -140,11 +157,12 @@
edit_ver1.subject = 'edit<%subject%>edit'
edit_ver1.html_content = 'edit<%body%>edit'
edit_ver1.plain_content = 'edit<%body%>edit'
edit_ver1.active = 0
@client.patch_version(
- @template.id, @version1.id, edit_ver1
+ template_id: @template.id, version_id: @version1.id,
+ version: edit_ver1
) do |resp, req, res|
resp =
SendGrid4r::REST::Templates::Versions.create_version(
JSON.parse(resp)
)
@@ -153,11 +171,13 @@
expect(res).to be_a(Net::HTTPOK)
end
end
it '#delete_version' do
- @client.delete_version(@template.id, @version1.id) do |resp, req, res|
+ @client.delete_version(
+ template_id: @template.id, version_id: @version1.id
+ ) do |resp, req, res|
expect(resp).to eq('')
expect(req).to be_a(RestClient::Request)
expect(res).to be_a(Net::HTTPNoContent)
end
end
@@ -184,34 +204,36 @@
)
end
it '#post_version' do
allow(client).to receive(:execute).and_return(version)
- actual = client.post_version('', nil)
+ actual = client.post_version(template_id: '', version: nil)
expect(actual).to be_a(SendGrid4r::REST::Templates::Versions::Version)
end
it '#activate_version' do
allow(client).to receive(:execute).and_return(version)
- actual = client.activate_version('', '')
+ actual = client.activate_version(template_id: '', version_id: '')
expect(actual).to be_a(SendGrid4r::REST::Templates::Versions::Version)
end
it '#get_version' do
allow(client).to receive(:execute).and_return(version)
- actual = client.get_version('', '')
+ actual = client.get_version(template_id: '', version_id: '')
expect(actual).to be_a(SendGrid4r::REST::Templates::Versions::Version)
end
it '#patch_version' do
allow(client).to receive(:execute).and_return(version)
- actual = client.patch_version('', '', nil)
+ actual = client.patch_version(
+ template_id: '', version_id: '', version: nil
+ )
expect(actual).to be_a(SendGrid4r::REST::Templates::Versions::Version)
end
it '#delete_version' do
allow(client).to receive(:execute).and_return('')
- actual = client.delete_version('', '')
+ actual = client.delete_version(template_id: '', version_id: '')
expect(actual).to eq('')
end
it 'creates version instance' do
actual = SendGrid4r::REST::Templates::Versions.create_version(version)