Answer the question
In order to leave comments, you need to log in
Rspec.How to pass admin to edit action?
Hello!
There are two controllers posts and admin_posts (accordingly, create, update, destroy actions are prohibited in the posts controller - only the admin from the admin_posts controller can create).
That is, if I do this
describe 'GET /edit_post' do
it 'works for edit post' do
get edit_post_path(post)
expect(response).to have_http_status(200)
end
end
describe 'GET /edit_post' do
it 'works for edit post' do
user = FactoryGirl.create(:user, role: 'admin')
post = FactoryGirl.create(:post)
get edit_post_path(post)
expect(response).to have_http_status(200)
end
end
Failures:
1) Posts GET /edit_post works for edit post
Failure/Error: get edit_post_path(post)
ActionView::Template::Error:
First argument in form cannot contain nil or be empty
class PostsController < ApplicationController
before_action :set_post, only: [:show]
respond_to :html
def index
@posts = Post.page(params[:page]).per(3)
respond_with(@posts)
end
def show
@comments = @post.comments.page(params[:comments_page]).per(3)
respond_with(@post)
end
def new
@post = Post.new
respond_with(@post)
end
def edit
end
def create
@post = Post.new(post_params)
@post.save
respond_with(@post)
end
def update
@post.update(post_params)
respond_with(@post)
end
def destroy
@post.destroy
respond_with(@post)
end
private
def set_post
@post = Post.find(params[:id])
end
def post_params
params.require(:post).permit(:title, :body, :photo)
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question