开发者

Rails 3.1 respond_to & render_403 problem

开发者 https://www.devze.com 2023-03-20 06:48 出处:网络
I\'m not sure what it is. I\'ve just upgraded to Rails 3.1 from 3.0.9 and here\'s what I get in my specs:

I'm not sure what it is. I've just upgraded to Rails 3.1 from 3.0.9 and here's what I get in my specs:

PeopleController edit action should require owner
Failure/Error: response.should render_template("/public/403.html")
expecting <"/public/403.html"> but rendering with <"search/_searc开发者_StackOverflow社区h_menu_item">

This is all over my specs in various controllers. I also have this code in my AppController:

def render_403
  respond_to do |format|
    format.html { render :file => "#{Rails.root}/public/403.html", :status => 403, :layout => false }
    format.json { render :json => { :error => true, :message => "Error 403, you don't have permissions for this operation." } }
  end
end

And this in PeopleController:

def edit
  render_403 unless @person.account.id == current_account.id
end

I'm certain that format.html block gets executed (checked it). However the spec expectation fails. Wonder what is going on here.

(search/_search_menu_item is a partial that gets included onto every page, which basically means that the app layout gets rendered here instead.)

Update: I've replaced render_403 in #edit with render(:file => "#{Rails.root}/public/403.html", :status => 403, :layout => false) to see what happens - got the same result.


Ok, figured it out. Possibly not a Rails problem. At least the problem appears only when running the specs.

I've been checking if 403 pages are rendered with this:

response.should render_template("public/403.html")

Doesn't work no more. Replacing it with

response.status.should == 403

fixed the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消