From ac8dff2a28e2fb15c153f09874529bdc85365e9e Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 16 Oct 2018 14:29:44 +1300 Subject: [PATCH] Update new post spec --- spec/views/posts/new.html.haml_spec.rb | 44 ++++++++++++-------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/spec/views/posts/new.html.haml_spec.rb b/spec/views/posts/new.html.haml_spec.rb index fa344e55b..9bf53e563 100644 --- a/spec/views/posts/new.html.haml_spec.rb +++ b/spec/views/posts/new.html.haml_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' describe "posts/new" do + let(:author) { FactoryBot.create(:member) } before(:each) do - @author = FactoryBot.create(:member) - assign(:post, FactoryBot.create(:post, author: @author)) + assign(:post, FactoryBot.create(:post, author: author)) # assign(:forum, Forum.new) - sign_in @author - controller.stub(:current_user) { @author } + sign_in author + controller.stub(:current_user) { author } + render end it "renders new post form" do - render assert_select "form", action: posts_path, method: "post" do assert_select "input#post_subject", name: "post[subject]" assert_select "textarea#post_body", name: "post[body]" @@ -18,44 +18,42 @@ describe "posts/new" do end it 'no hidden forum field' do - render assert_select "input#post_forum_id[type=hidden]", false end it 'no forum mentioned' do - render - rendered.should_not have_content "This post will be posted in the forum" + expect(rendered).not_to have_content "This post will be posted in the forum" end it "asks what's going on in your garden" do - render - rendered.should have_content "What's going on in your food garden?" + expect(rendered).to have_content "What's going on in your food garden?" + end + + it 'shows markdown help' do + expect(rendered).to have_content 'Markdown' end context "forum specified" do + let(:forum) { FactoryBot.create(:forum) } + before(:each) do - @forum = assign(:forum, FactoryBot.create(:forum)) - assign(:post, FactoryBot.create(:post, forum: @forum)) + assign(:forum, forum) + assign(:post, FactoryBot.create(:post, forum: forum)) render end it 'creates a hidden field' do - assert_select "input#post_forum_id[type='hidden'][value='#{@forum.id}']" + assert_select "input#post_forum_id[type='hidden'][value='#{forum.id}']" end it 'tells the user what forum it will be posted in' do - rendered.should have_content "This post will be posted in the forum #{@forum.name}" + expect(rendered).to have_content "This post will be posted in the forum\n#{forum.name}" end + it { expect(rendered).to have_link forum.name } - it "asks what's going on generally" do - render - rendered.should_not have_content "What's going on in your food garden?" - rendered.should have_content "What's up?" + describe "asks what's going on generally" do + it { expect(rendered).to have_content "What's going on in your food garden?" } + it { expect(rendered).to have_content "What's up?" } end end - - it 'shows markdown help' do - render - rendered.should have_content 'Markdown' - end end