Skip to content

Instantly share code, notes, and snippets.

@mattb20
Created May 15, 2018 13:41
Show Gist options
  • Save mattb20/e1554a4935d25b6fd5e4baa64bba82c0 to your computer and use it in GitHub Desktop.
Save mattb20/e1554a4935d25b6fd5e4baa64bba82c0 to your computer and use it in GitHub Desktop.
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = current_user.posts.build(post_params)
redirect_to posts_url
end
def index
@posts = Post.all
end
private
def post_params
params.require(:post).permit(:message)
end
end
require 'rails_helper'
def user_makes_a_post
user_signs_up
visit "/posts"
click_link "New post"
fill_in "Message", with: "Hello, world!"
click_button "Submit"
end
def user_signs_up
visit "/users/sign_up"
fill_in "user_email", with: "jordan@matt.com"
fill_in "user_password", with: "123456abc"
fill_in "user_password_confirmation", with: "123456abc"
click_button "Sign up"
end
RSpec.feature "Timeline", type: :feature do
scenario "User email displayed with a post" do
user_signs_up
user_makes_a_post
expect(page).to have_content("Hello, world! jordan@matt.com")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment