spec/post_comments_spec.rb in cachai-0.2.7 vs spec/post_comments_spec.rb in cachai-0.2.8
- old
+ new
@@ -1,6 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require 'rest-client'
describe 'post comment' do
include Rack::Test::Methods
def app
@@ -88,10 +89,14 @@
end
describe 'valid data' do
+ before do
+ allow(RestClient).to receive(:post).and_return(true)
+ end
+
describe 'unexisting post' do
before do
Cachai::Post.delete_all
end
@@ -118,10 +123,20 @@
it 'post is approved' do
post_comment
expect(Cachai::Response.last.approved).to eql(1)
end
+ it 'sends emails' do
+ expect(RestClient).to receive(:post).with("https://api:key-aoidjoaijdoaijdoaijsd@api.mailgun.net/v3/foobartest1234.mailgun.org/messages", {
+ :from =>"comments@domain.com",
+ :to =>"test@example.com",
+ :subject =>"Nuevo comentario de Some author at /another/blog/post.html",
+ :text =>"New comment\n\n--\nhttp://domain.com/another/blog/post.html"
+ }).and_return(true)
+ post_comment
+ end
+
end
describe 'if blocked' do
it 'creates a new response for that post' do
@@ -133,10 +148,15 @@
it 'post is not approved' do
post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
expect(Cachai::Response.last.approved).to eql(0)
end
+ it 'does not send emails' do
+ expect(RestClient).not_to receive(:post)
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
+ end
+
end
end
describe 'existing post' do
@@ -164,10 +184,54 @@
it 'post is approved' do
post_comment
expect(Cachai::Response.last.approved).to eql(1)
end
+ it 'sends admin emails' do
+ expect(RestClient).to receive(:post).with("https://api:key-aoidjoaijdoaijdoaijsd@api.mailgun.net/v3/foobartest1234.mailgun.org/messages", {
+ :from =>"comments@domain.com",
+ :to =>"test@example.com",
+ :subject =>"Nuevo comentario de Some author at /another/blog/post.html",
+ :text =>"New comment\n\n--\nhttp://domain.com/another/blog/post.html"
+ }).and_return(true)
+
+ post_comment
+ end
+
+ describe 'if comment is response to parent' do
+
+ before do
+ post = Cachai::Post.find_by_path('/another/blog/post.html')
+ @parent = post.responses.create!({
+ :content => 'Content',
+ :author_name => 'Some guy',
+ :author_email => 'some@email.com',
+ :author_ip => '22.33.44.55'
+ })
+ end
+
+ it 'sends email both to admin and to parent comment guy' do
+
+ expect(RestClient).to receive(:post).with("https://api:key-aoidjoaijdoaijdoaijsd@api.mailgun.net/v3/foobartest1234.mailgun.org/messages", {
+ :from => "comments@domain.com",
+ :to => "test@example.com",
+ :subject => "Nuevo comentario de Some author at /another/blog/post.html",
+ :text => "New comment\n\n--\nhttp://domain.com/another/blog/post.html"
+ }).and_return(true)
+
+ expect(RestClient).to receive(:post).with("https://api:key-aoidjoaijdoaijdoaijsd@api.mailgun.net/v3/foobartest1234.mailgun.org/messages", {
+ :from => "comments@domain.com",
+ :to => "some@email.com",
+ :subject => "Respuesta de Some author a tu comentario en /another/blog/post.html",
+ :text => "New comment\n\n--\nhttp://domain.com/another/blog/post.html"
+ }).and_return(true)
+
+ post_comment(parent_id: @parent.id)
+ end
+
+ end
+
end
describe 'if blocked' do
it 'creates a new response for that post' do
@@ -177,9 +241,14 @@
end
it 'post is not approved' do
post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
expect(Cachai::Response.last.approved).to eql(0)
+ end
+
+ it 'does not send emails' do
+ expect(RestClient).not_to receive(:post)
+ post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'})
end
end
end