spec/post_comments_spec.rb in cachai-0.2.6 vs spec/post_comments_spec.rb in cachai-0.2.7

- old
+ new

@@ -5,22 +5,22 @@ def app TestApp end - def post_comment(opts = {}) + def post_comment(opts = {}, env_opts = {}) data = { :domain => 'domain.com', :protocol => 'http', :path => '/another/blog/post.html', :content => 'New comment', :author_name => 'Some author', :author_email => 'test@email.com', :author_url => 'http://url.com' }.merge(opts) - post '/comments.json', data.to_json, { 'CONTENT_TYPE' => 'application/json' } + post '/comments.json', data.to_json, { 'CONTENT_TYPE' => 'application/json' }.merge(env_opts) end describe 'no domain' do it 'returns 400' do @@ -105,16 +105,40 @@ it 'sets a created_at timestamp on new post' do post_comment Cachai::Post.last.created_at.should_not be_nil end - it 'creates a new response for that post' do - expect do + describe 'if not blocked' do + + it 'creates a new response for that post' do + expect do + post_comment + end.to change(Cachai::Response, :count).by(1) + end + + it 'post is approved' do post_comment - end.to change(Cachai::Response, :count).by(1) + expect(Cachai::Response.last.approved).to eql(1) + end + end + describe 'if blocked' do + + it 'creates a new response for that post' do + expect do + post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'}) + end.to change(Cachai::Response, :count).by(1) + end + + it 'post is not approved' do + post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'}) + expect(Cachai::Response.last.approved).to eql(0) + end + + end + end describe 'existing post' do before do @@ -127,13 +151,37 @@ end.not_to change(Cachai::Post, :count).by(1) end describe 'if within comments duration' do - it 'creates a new response for that post' do - expect do + describe 'if not blocked' do + + it 'creates a new response for that post' do + expect do + post_comment + end.to change(Cachai::Response, :count).by(1) + end + + it 'post is approved' do post_comment - end.to change(Cachai::Response, :count).by(1) + expect(Cachai::Response.last.approved).to eql(1) + end + + end + + describe 'if blocked' do + + it 'creates a new response for that post' do + expect do + post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'}) + end.to change(Cachai::Response, :count).by(1) + end + + it 'post is not approved' do + post_comment({}, {'REMOTE_ADDR' => '12.12.12.12'}) + expect(Cachai::Response.last.approved).to eql(0) + end + end end describe 'if after comments duration' do