I have an ArticleController with the following code :
def edit
@article = current_user.articles.find(params[:id])
end
And the following test:
describe "GET 'edit'" do
it "should fail when signed in and editing another user article" do
sign_in @user
get :edit, :id => @another_user_article.id
response.should_not be_success
end
end
However, when I start the test, I get the following error (which is normal), but I wonder how to handle that so my test can pass?
Failure/Error: get :edit, :id => @another_user_article.id
Mongoid::Errors::DocumentNotFound:
Document not found for class Article with id(s) 4f9e71be4adfdcc02300001d.
I thought about changing my controller method by this one, but that does not seems right to me :
def edit
@article = Article.first(conditions: { _id: params[:id], user_id: current_user.id })
end