spec/integration/mailgun_spec.rb in mailgun-ruby-1.0.1 vs spec/integration/mailgun_spec.rb in mailgun-ruby-1.0.2
- old
+ new
@@ -19,11 +19,11 @@
result = @mg_obj.send_message(@domain, {:from => 'bob@domain.com',
:to => 'sally@example.com',
:subject => 'Hash Integration Test',
:text => 'INTEGRATION TESTING',
'o:testmode' => true})
- result.to_hash!
+ result.to_h!
result.body.should include("message")
result.body.should include("id")
end
it 'sends a message builder message in test mode.' do
@@ -34,11 +34,11 @@
mb_obj.set_text_body("This is the text body.")
mb_obj.set_test_mode(true)
result = @mg_obj.send_message(@domain, mb_obj)
- result.to_hash!
+ result.to_h!
result.body.should include("message")
result.body.should include("id")
end
it 'sends a custom MIME message in test mode.' do
@@ -61,11 +61,11 @@
message_params = {:to => 'sally@example.com',
:message => mime_string}
result = @mg_obj.send_message(@domain, message_params)
- result.to_hash!
+ result.to_h!
result.body.should include("message")
result.body.should include("id")
end
after(:all) do
@@ -80,36 +80,36 @@
@domain = "integration-test-#{random_number}.example.com"
@result = @mg_obj.post("domains", {:name => @domain,
:smtp_password => 'super_secret',
:spam_action => 'tag'})
- @result.to_hash!
+ @result.to_h!
@result.body.should include("domain")
expect(@result.body["domain"]["name"]).to eq(@domain)
expect(@result.body["domain"]["spam_action"]).to eq("tag")
expect(@result.body["domain"]["smtp_password"]).to eq("super_secret")
end
it 'get the domain.' do
result = @mg_obj.get("domains/#{@domain}")
- result.to_hash!
+ result.to_h!
result.body.should include("domain")
result.body["domain"]["name"].should eq(@domain)
end
it 'gets a list of domains.' do
result = @mg_obj.get("domains")
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
it 'deletes a domain.' do
result = @mg_obj.delete("domains/#{@domain}")
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Domain has been deleted")
end
after(:all) do
@mg_obj.delete("domains/#{@domain}")
@@ -129,27 +129,27 @@
@email = "integration-test-#{random_number}@example.com"
@result = @mg_obj.post("#{@domain}/unsubscribes",
{:address => @email,
:tag => '*'})
- @result.to_hash!
+ @result.to_h!
expect(@result.body["message"]).to eq("Address has been added to the unsubscribes table")
expect(@result.body["address"]).to eq(@email)
end
it 'get an unsubscribee.' do
result = @mg_obj.get("#{@domain}/unsubscribes/#{@email}")
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to eq 1
expect(result.body["items"][0]["address"]).to eq(@email)
end
it 'gets a list of unsubscribes.' do
result = @mg_obj.get("#{@domain}/unsubscribes")
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
after(:each) do
@mg_obj.delete("#{@domain}/unsubscribes/#{@email}")
@@ -171,27 +171,27 @@
before(:each) do
random_number = rand(1 .. 5000000)
@email = "integration-test-#{random_number}@example.com"
@result = @mg_obj.post("#{@domain}/complaints", {:address => @email})
- @result.to_hash!
+ @result.to_h!
expect(@result.body["message"]).to eq("Address has been added to the complaints table")
expect(@result.body["address"]).to eq(@email)
end
it 'get a complaint.' do
result = @mg_obj.get("#{@domain}/complaints/#{@email}")
- result.to_hash!
+ result.to_h!
expect(result.body["complaint"]["count"]).to eq 1
expect(result.body["complaint"]["address"]).to eq(@email)
end
it 'gets a list of complaints.' do
result = @mg_obj.get("#{@domain}/complaints")
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
after(:each) do
@mg_obj.delete("#{@domain}/complaints/#{@email}")
@@ -216,28 +216,28 @@
@result = @mg_obj.post("#{@domain}/bounces",
{:address => @email,
:code => 550,
:error => "Integration Test"})
- @result.to_hash!
+ @result.to_h!
expect(@result.body["message"]).to eq("Address has been added to the bounces table")
expect(@result.body["address"]).to eq(@email)
end
it 'get a bounce.' do
result = @mg_obj.get("#{@domain}/bounces/#{@email}")
- result.to_hash!
+ result.to_h!
expect(result.body["bounce"]["code"]).to eq("550")
expect(result.body["bounce"]["address"]).to eq(@email)
expect(result.body["bounce"]["error"]).to eq("Integration Test")
end
it 'gets a list of bounces.' do
result = @mg_obj.get("#{@domain}/bounces")
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
after(:each) do
@mg_obj.delete("#{@domain}/bounces/#{@email}")
@@ -274,11 +274,11 @@
end
it 'get an event.' do
result = @mg_obj.get("#{@domain}/events", {:limit => 1})
- result.to_hash!
+ result.to_h!
expect(result.body["items"].length).to be_within(1).of(1)
expect(result.body["paging"]).to include("next")
expect(result.body["paging"]).to include("previous")
end
@@ -296,11 +296,11 @@
result = @mg_obj.post("routes", {:priority => 10,
:description => 'Integration Test Route',
:expression => 'match_recipient(".*@example.com")',
:action => 'forward("alice@example.com")'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Route has been created")
expect(result.body["route"]["description"]).to eq("Integration Test Route")
expect(result.body["route"]["actions"]).to include('forward("alice@example.com")')
expect(result.body["route"]["expression"]).to include('match_recipient(".*@example.com")')
expect(result.body["route"]["priority"]).to eq(10)
@@ -309,31 +309,31 @@
end
it 'get the route.' do
result = @mg_obj.get("routes/#{@route_id}")
- result.to_hash!
+ result.to_h!
expect(result.body["route"]["description"]).to eq("Integration Test Route")
expect(result.body["route"]["actions"]).to include('forward("alice@example.com")')
expect(result.body["route"]["expression"]).to include('match_recipient(".*@example.com")')
expect(result.body["route"]["priority"]).to eq(10)
end
it 'gets a list of all routes.' do
result = @mg_obj.get("routes", {:limit => 50})
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
it 'updates the route.' do
result = @mg_obj.put("routes/#{@route_id}", {:priority => 10,
:description => 'Integration Test Route Update',
:expression => 'match_recipient(".*@example.com")',
:action => 'forward("update@example.com")'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Route has been updated")
expect(result.body["description"]).to eq("Integration Test Route Update")
expect(result.body["actions"]).to include('forward("update@example.com")')
expect(result.body["expression"]).to include('match_recipient(".*@example.com")')
expect(result.body["priority"]).to eq(10)
@@ -356,36 +356,36 @@
random_number = rand(1 .. 5000000)
@campaign_id = "integration_test_#{random_number}"
result = @mg_obj.post("#{@domain}/campaigns", {:name => 'My Campaign',
:id => @campaign_id})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Campaign created")
expect(result.body["campaign"]["id"]).to eq(@campaign_id)
expect(result.body["campaign"]["name"]).to eq('My Campaign')
end
it 'get a campaign.' do
result = @mg_obj.get("#{@domain}/campaigns/#{@campaign_id}")
- result.to_hash!
+ result.to_h!
expect(result.body["id"]).to eq(@campaign_id)
expect(result.body["name"]).to eq('My Campaign')
end
it 'gets a list of all campaigns.' do
result = @mg_obj.get("#{@domain}/campaigns", {:limit => 50})
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
it 'update a campaign.' do
result = @mg_obj.put("#{@domain}/campaigns/#{@campaign_id}", {:name => 'My Updated Campaign',
:id => @campaign_id})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Campaign updated")
expect(result.body["campaign"]["id"]).to eq(@campaign_id)
expect(result.body["campaign"]["name"]).to eq('My Updated Campaign')
end
@@ -417,34 +417,34 @@
random_number = rand(1 .. 5000000)
@campaign_id = "integration_test_#{random_number}"
result = @mg_obj.post("domains/#{@domain}/webhooks", {:id => 'bounce',
:url => 'http://example.com/mailgun/events/bounce'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Webhook has been created")
expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/bounce')
end
it 'get a webhook.' do
result = @mg_obj.get("domains/#{@domain}/webhooks/bounce")
- result.to_hash!
+ result.to_h!
expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/bounce')
end
it 'gets a list of all webhooks.' do
result = @mg_obj.get("domains/#{@domain}/webhooks")
- result.to_hash!
+ result.to_h!
expect(result.body["webhooks"]["bounce"]["url"]).to eq('http://example.com/mailgun/events/bounce')
end
it 'update a webhook.' do
result = @mg_obj.put("domains/#{@domain}/webhooks/bounce", {:id => 'bounce',
:url => 'http://example.com/mailgun/events/new_bounce'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Webhook has been updated")
expect(result.body["webhook"]["url"]).to eq('http://example.com/mailgun/events/new_bounce')
end
after(:each) do
@@ -470,39 +470,39 @@
result = @mg_obj.post("lists", {:address => @ml_address,
:name => 'Integration Test List',
:description => 'This list should be deleted automatically.',
:access_level => 'members'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Mailing list has been created")
expect(result.body["list"]["address"]).to eq(@ml_address)
expect(result.body["list"]["name"]).to eq('Integration Test List')
end
it 'get a list.' do
result = @mg_obj.get("lists/#{@ml_address}")
- result.to_hash!
+ result.to_h!
expect(result.body["list"]["address"]).to eq(@ml_address)
expect(result.body["list"]["name"]).to eq('Integration Test List')
end
it 'gets a list of all lists.' do
result = @mg_obj.get("lists", {:limit => 50})
- result.to_hash!
+ result.to_h!
expect(result.body["total_count"]).to be > 0
end
it 'update a list.' do
result = @mg_obj.put("lists/#{@ml_address}",
{:address => @ml_address,
:name => 'Integration Test List Update',
:description => 'This list should be deleted automatically.',
:access_level => 'readonly'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Mailing list has been updated")
expect(result.body["list"]["address"]).to eq(@ml_address)
expect(result.body["list"]["name"]).to eq('Integration Test List Update')
expect(result.body["list"]["access_level"]).to eq('readonly')
end
@@ -535,30 +535,30 @@
{:address => @ml_member,
:name => 'Jane Doe',
:subscribed => true,
:upsert => 'no'})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Mailing list member has been created")
expect(result.body["member"]["address"]).to eq(@ml_member)
expect(result.body["member"]["name"]).to eq('Jane Doe')
end
it 'get a list member.' do
result = @mg_obj.get("lists/#{@ml_address}/members/#{@ml_member}")
- result.to_hash!
+ result.to_h!
expect(result.body["member"]["address"]).to eq(@ml_member)
expect(result.body["member"]["name"]).to eq('Jane Doe')
end
it 'updates a list member.' do
result = @mg_obj.put("lists/#{@ml_address}/members/#{@ml_member}",
{:name => 'Jane Doe Update',
:subscribed => false})
- result.to_hash!
+ result.to_h!
expect(result.body["message"]).to eq("Mailing list member has been updated")
expect(result.body["member"]["address"]).to eq(@ml_member)
expect(result.body["member"]["name"]).to eq('Jane Doe Update')
expect(result.body["member"]["subscribed"]).to eq(false)
end
@@ -579,19 +579,19 @@
it 'validates an address.' do
result = @mg_obj.get("address/validate",
{:address => "test@example.com"})
- result.to_hash!
+ result.to_h!
expect(result.body["is_valid"]).to eq(false)
expect(result.body["address"]).to eq("test@example.com")
end
it 'parses an address.' do
result = @mg_obj.get("address/parse",
{:addresses => "Alice <alice@example.com>,bob@example.com,example.com"})
- result.to_hash!
+ result.to_h!
expect(result.body["parsed"]).to include("Alice <alice@example.com>")
expect(result.body["parsed"]).to include("bob@example.com")
expect(result.body["unparseable"]).to include("example.com")
end
end