Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:22:00+00:00 2026-05-23T19:22:00+00:00

In my test, I do this: delete :destroy, :id => p.id assert_equal You do

  • 0

In my test, I do this:

     delete :destroy, :id => p.id
     assert_equal "You do not have permission to delete this Object.", flash[:error]
     Object.find_by_id(p.id).should_not be_nil #line 48 (reffed by console output below)

and my before filter, has a puts, so I know the result is false, and doesn’t return

  before_filter lambda { |controller| 
      result = controller.is_object_on_same_account_as_current_account_for_id?(
                  controller_name.classify.constantize, 
                  controller.params[:id])
      puts result
      return if result
  }, :only => [:destroy]

according to this page: http://citizen428.net/archives/846, actions bound by a filter are only executed if the filter returns.

And here is the console output:

Started
false
F
Finished in 0.865708 seconds.

  1) Failure:
test: .... ...
blah blah, issue is on line 48

     shoulda (2.11.3) lib/shoulda/context.rb:382:in `...']:
expected: not nil
     got: nil

So… what is going on here? I’m completely clueless.

related code:

destroy method:

 def destroy
    @content.destroy 

Not, that I’m only running the one test.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:22:01+00:00Added an answer on May 23, 2026 at 7:22 pm

    Per the official Rails Docs, the proper way to stop an action from being executed with a before_filter is to actually redirect or render within the filter.

    So you’d probably want:

    before_filter lambda { |controller| 
          result = controller.is_object_on_same_account_as_current_account_for_id?(
                      controller_name.classify.constantize, 
                      controller.params[:id])
          puts result
          if !result
            flash[:error] = "You do not have permission to delete this Object."
            redirect_to "/" # or wherever you want to redirect to
          end
      }, :only => [:destroy]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my controller and want to test this code line
I have these pieces of HTML: <li class=icon iconDelete><a href=/projects/delete/{id}/ title=Delete this test case.></a></li>
Although I don't have an iPhone to test this out, my colleague told me
Say I have a vector: (def data [Hello World Test This]) And I want
This example is simplified. I have the following design: http://img835.imageshack.us/i/designyi.jpg/ I have inserted test
I have a sql file test.sql used to run some SQL (create object /
How would you test this scenario? I've just started looking into NHibernate and having
I'm trying to test this out on my site but it doesn't quite work
Hello I'm writting junit test how can I test this method .. this is
is it possible to do something like the following: struct test { this {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.