Created
August 16, 2013 01:54
-
-
Save daphsta/6246589 to your computer and use it in GitHub Desktop.
inbound_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe InboundController do | |
describe "reply from support team" do | |
context "upon creating successful reply " do | |
before do | |
@ticket = Ticket.create(sender: "[email protected]", subject: "my phone freezes all the time", body: "my phone freezes after hanging up", status: "new") | |
post :create, { | |
headers: { | |
'To'=> "ticket+#{@ticket.id}@laantern.com", | |
'Subject'=> "my phone freezes all the time", | |
'From'=> "[email protected]" | |
}, | |
plain: "please try to look into the logs" | |
} | |
end | |
it "returns 200" do | |
expect(response.status).to eq(200) | |
end | |
it "creates a reply ticket" do | |
reply = @ticket.replies.first | |
expect(reply.body).to eq("please try to look into the logs") | |
expect(reply.sender).to eq("[email protected]") | |
end | |
it "delivers email to customer and internal support team" do | |
support_email,customer_email = ActionMailer::Base.deliveries.last(2) | |
expect(support_email.to).to eq(["[email protected]", "[email protected]", "[email protected]"]) | |
expect(customer_email.to).to eq(["[email protected]"]) | |
end | |
end | |
context "failing to create a reply" do | |
before do | |
@ticket = Ticket.create(sender: "[email protected]", subject: "my phone freezes all the time", body: "my phone freezes after hanging up", status: "new") | |
post :create, { | |
headers: { | |
'To'=> "ticket+#{@ticket.id}@laantern.com", | |
'Subject'=> "my phone freezes all the time", | |
'From'=> "" | |
}, | |
plain: "please try to look into the logs" | |
} | |
end | |
it "returns 422" do | |
expect(response.status).to eq(422) | |
end | |
end | |
end | |
describe "reply from customer" do | |
context "upon creating successful reply" do | |
before do | |
@ticket = Ticket.create(sender: "[email protected]", subject: "my phone freezes all the time", body: "my phone freezes after hanging up", status: "new") | |
post :create, { | |
headers: { | |
'To'=> "[email protected]", | |
'Subject'=> "[#{@ticket.id}]my phone freezes all the time", | |
'From'=> "[email protected]" | |
}, | |
plain: "Nothing in the logs. Need more details." | |
} | |
end | |
it "returns 200" do | |
expect(response.status).to eq(200) | |
end | |
it "creates a reply ticket" do | |
end | |
it "delivers email to customer and internal support team" do | |
end | |
end | |
context "failing to create a reply" do | |
before do | |
@ticket = Ticket.create(sender: "[email protected]", subject: "my phone freezes all the time", body: "my phone freezes after hanging up", status: "new") | |
end | |
let(:params) do | |
{ | |
headers: { | |
'To'=> "[email protected]", | |
'Subject'=> "[#{@ticket.id}]my phone freezes all the time", | |
'From'=> "" | |
}, | |
plain: "please try to look into the logs" | |
} | |
end | |
it "returns 422" do | |
post :create, params | |
expect(response.status).to eq(422) | |
end | |
it "should not send an email to the internal support team" do | |
UserMailer.should_not_receive :new_reply_created | |
post :create, params | |
end | |
end | |
end | |
describe "new ticket" do | |
context "upon creating a successful new ticket" do | |
it "returns 200" do | |
end | |
it "creates a new ticket" do | |
end | |
it "delivers email to internal support team" do | |
end | |
end | |
context "failing to create a new ticket" do | |
end | |
end | |
describe "reply to [email protected] is not from support team" do | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment