Sha256: d3dc4c193c5d38e9ce6c7ef5298b7fa6de1e0f1ceefee5efb442293fc82f3a19
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
require 'rails_helper' describe Blogit::CommentsController do before do @routes = Blogit::Engine.routes end let(:blog_post) { Blogit::Post.active.first || create(:post, :active) } let(:comment_attributes) { attributes_for(:comment) } describe "POST create" do def do_post(format = :html) post :create, post_id: blog_post.id, comment: comment_attributes, format: format end subject { do_post(:js) } context "when POST is AJAX" do it "persists comment" do expect { subject }.to change { blog_post.comments.count }.by(1) end it "returns a status :created" do subject expect(response.status).to eql(201) end end describe "with HTML" do it "persists the comment" do expect { do_post(:html) }.to change { blog_post.comments.count }.by(1) end it "should redirect to the blog post" do do_post expect(response).to redirect_to(controller.post_url(blog_post)) end it "should display a flash notice" do do_post expect(flash[:notice]).to be_present end end end end
Version data entries
3 entries across 3 versions & 1 rubygems