I have an application that runs ok, however running the rspec I receieve
a multitude of similar errors like this:
ArgumentError in ‘AccessControlTestController requesting html; I am
logged in and Login not required succeeds’
wrong number of arguments (2 for 1)
/mnt/hgfs/chameleon/spec/controllers/access_control_spec.rb:23:in
`login_not_required’
/mnt/hgfs/chameleon/spec/controllers/access_control_spec.rb:66:
Within access_control_spec.rb the lines in question are:
respond_to do |format|
@foo = { 'success' => params[:format]||'no fmt given'}
format.html #do render :text => "success" end
format.xml do render :xml => @foo, :status => :ok end
format.json do render :json => @foo, :status => :ok end
end
and when i run the code with a debugger statement just before and step
into the code the exception raised is:
“respond_to takes either types or a block, never both”
I see this respond_to format stuff all over the place, so i can’t
believe there’s actually anything wrong with that part of the code,
which leaves me a little lost where to look for the problem.
I’m no expert in ruby, so if anyone has a suggestion where to continue
my investigation it would be very much appreciated.
respond_to do |format|
@foo = { 'success' => params[:format]||'no fmt given'}
format.html #do render :text => "success" end
format.xml do render :xml => @foo, :status => :ok end
format.json do render :json => @foo, :status => :ok end
end
I just tried this block of code in a quick test application using the
latest version of Rails 2.3.5. While I did not see any errors I don’t
believe it’s going to produce the result you want.
I created a very simple Person model and replaced the code generated by
the scaffolding with your respond_to block.
Here are the results:
The action:
def index @people = Person.all
respond_to do |format|
@foo = { 'success' => params[:format]||'no fmt given'}
format.html #do render :text => "success" end
format.xml do render :xml => @foo, :status => :ok end
format.json do render :json => @foo, :status => :ok end
end
Are you sure you wanted to simply return a hash with a key of ‘success’
and value of the format requested to the client? I imagine not.
In any case, the code that you posted here does not appear to throw any
errors or exceptions. The errors you’re seeing must be a side-effect of
something else. You really need to take a second look at this code. I
can’t see any way that it would ever be useful.
Thanks for your reply - unfortunately I did not write the code, its from
restful_authentication plugin, which i have since discovered is
“notorious” for having bad/non-passing tests. I have since found another
fork on github which has been updated to ensure its passing its tests.
Thanks for your reply - unfortunately I did not write the code, its from
restful_authentication plugin, which i have since discovered is
“notorious” for having bad/non-passing tests. I have since found another
fork on github which has been updated to ensure its passing its tests.
Just get rid of restful_authentication and use Authlogic instead.