spec/post_comments_spec.rb in cachai-0.2.3 vs spec/post_comments_spec.rb in cachai-0.2.4
- old
+ new
@@ -23,30 +23,29 @@
describe 'no domain' do
it 'returns 400' do
post_comment :domain => nil
- puts last_response.body
last_response.status.should == 400
end
end
describe 'no protocol' do
it 'returns 400' do
post_comment :protocol => nil
- last_response.status.should == 400
+ last_response.status.should == 422
end
end
describe 'no path' do
it 'returns 400' do
post_comment :path => nil
- last_response.status.should == 400
+ last_response.status.should == 422
end
end
describe 'existing domain and path' do
@@ -111,19 +110,48 @@
end
describe 'existing post' do
+ before do
+ Cachai::Post.find_by_path('/another/blog/post.html').should be_a(Cachai::Post)
+ end
+
it 'does not create a new post entry' do
expect do
post_comment
end.not_to change(Cachai::Post, :count).by(1)
end
- it 'creates a new response for that post' do
- expect do
+ describe 'if within comments duration' do
+
+ it 'creates a new response for that post' do
+ expect do
+ post_comment
+ end.to change(Cachai::Response, :count).by(1)
+ end
+
+ end
+
+ describe 'if after comments duration' do
+
+ before do
+ post = Cachai::Post.find_by_path('/another/blog/post.html')
+ post.update_attribute(:created_at, 100.days.ago)
+ end
+
+ it 'returns 400' do
post_comment
- end.to change(Cachai::Response, :count).by(1)
+ last_response.status.should == 400
+ end
+
+ it 'does not create a new response for that post' do
+ expect do
+ post_comment
+ end.not_to change(Cachai::Response, :count)
+ end
+
+
end
end
end