Displaying 20 results from an estimated 4000 matches similar to: "Stubbing authentication across multiple controllers"
2008 Jan 30
2
Stubbing controller methods vs model methods
I had an error that I couldn''t figure out, then when writing up a
question for the forum I figured it out. The thing is I don''t
understand why the change that was made works and why what existed
before didn''t.
Here is the initial post when I had the error:
----------------------------------
In the controllers/application.rb file
I have a method that finds the account
2007 Jul 06
3
stubbing helper methods for View specs
Hi there
I have several view specs, that include the following snippet in
their "before" block to stub the methods by acts_as_authenticated
before :each do
@u = mock_model(User)
@u.should_receive(:name).and_return("Hans Muster")
template.should_receive(:logged_in?).and_return(true)
template.should_receive(:current_user).and_return(@u)
end
this
2007 May 20
9
How to test for exceptions
Hi folks,
I''m in the process of converting a Test::Unit functional test to RSpec, but I''ve run into a slight problem. I tried looking through the documentation but I still don''t know what I missed.
Thanks in advance,
Blake
describe VenuesController, "on update" do
before(:each) do
@venue = mock("venue")
2007 May 29
5
Trouble defining a stub method for a controller
Hello,
Not sure if I am doing something really wrong (let''s not say
stupid for now), but I haven''t been able to stub a controller method
like:
controller.stub!(:logged_in?).and_return(true)
Please help, this is driving me nuts ;-)
--
An?bal Rojas
http://www.rubycorner.com
http://www.hasmanydevelopers.com
2007 May 30
6
authentication mocks
hi
I''m using restful_authentication
and have controller specs working using users fixtures (and login_as)
however i''ve been trying for hours without success to do it without
fixtures, using mocks and stubs instead.
anyone here done this? got code?
:)
thanks
2007 Oct 25
1
Mocking/Stubbing help with subdomain as account key
My app uses account_location to set up subdomains as account keys. In
my controllers, all my model operations are scoped through the
@current_person object.
The question is: How do I test this with RSpec''s mocking and
stubbing? Basically, I need to test that @current_person.things is
getting the find message and returning @thing. I''ve tried stubbing
and mocking
2008 Aug 08
2
template.expect_render fails when partial is rendered from a helper
My spec;
describe ''subnav rendering while logged in'' do
before do
template.stub!(:logged_in?).and_return(true)
template.stub!
(:current_profile).at_least(:once).and_return(mock_profile)
end
def do_render
render "/homepages/show.html.erb"
end
it "should render the logged in partial for homepages" do
2006 Nov 10
3
Stubbing Time.now in trunk
I''m a big fan of stubbing Time.now so it returns a known value. I used
to be able to use stubba and say:
@time_now = Time.parse("Jan 1 2001")
Time.stubs(:now).returns(lambda{@time_now})
However, something in trunk broke that. Fine, rspec''s got its own
stubbing lib now, so I tried switching to that:
@time_now = Time.parse("Jan 1 2001")
2007 Jun 15
6
problem getting started with stubbing in rails controller specs
Hello, Ingo!
I''m copying your question to a new e-mail instead of replying to try
to keep message threads separate.
Have you tried setting up your expectation before issuing the get
statement? For example, take this out of the setup block:
get ''index'', :locale => ''en''
and move it after:
2007 Oct 05
7
Easy AR association stubbing
I''ve added a method to the mock class that makes it pretty easy to
stub associations in rails. I''ve been using it for awhile and it seems
to cut down on a lot of setup code for the controller and model specs
that use associations.
#before
@person = mock_model(Person)
posts = mock(''post_proxy'')
posts.stub!(:build).and_return(mock_model(Post, :save => true))
2007 Oct 01
15
how to spec views
I''m trying to spec a view but haven''t done much view specing.
This view render different partials depending on authentication of the user:
annon, admin, player
So I I''ll write if conditionals in the view with the partials
it "should render signup propaganda for annon users trying to view games"
do
render "/games/index.rhtml"
2006 Dec 21
3
Stubbing an instance method on a class
Hi all,
I''m not sure if I''ve missed it, but I couldn''t find any docs for
stubbing an instance method on a class. For example:
class Foo; end
Foo.stub!(:my_instance_method).and_return(nil)
The reason (I think) I need this is because a certain class
(Test::Unit::TestCase) expects an argument (name of method) to new and
throws an exception if that instance method
2007 Feb 11
1
Specing Rails Views
Hello -
I''m currently trying to write some specs for my rails views. My
views depend upon
the restful authentication plugin method logged_in? Like so,
<% if logged_in? %>
<ul id="product-admin-nav">
<dd><%= link_to "create a new product", new_product_url %></dd>
</ul>
<% end %>
However, when I have the following
2007 Aug 11
2
Rspec and acl_system2 plugin
Hello,
I''m trying to spec a Rails application using the couple
restful_authentication/acl_system2 plugins.
In my admin layout, I put the following code :
<% restrict_to "admin" do -%>
<ul id="admin-tabs">
<li> /users Users management </li>
</ul>
<% end -%>
Then in my spec file
2007 Oct 19
3
Stubbing a Kernel method?
Is it possible to stub a Kernel method? I''m specifically interested in
the ''open'' method to test some code using open-uri. I''ve tried:
Kernel.should_receive(:open).with(''filename'').and_return(''data'')
However, this doesn''t seem to work. Any suggestions would be appreciated.
--Paul
2007 Jun 02
7
I''m really bad at controllers, help please.
Hey,
Sorry for so many questions - I''m really bad at this right now.
I''m trying to cover the following code w/ rspec
def index
if params[:user_id]
@user = User.find(params[:user_id])
@messages = @user.messages
end
end
So basically what I''m doing is listing all the messages for a user,
provided there is an id parameter.
describe
2008 Jan 10
4
Mocking and stubbing Rails'' association extensions
I''m having a lot of trouble stubbing out an association extension for
some view tests. Example rails code modeling a music album:
class Album < ActiveRecord::Base
has_many :songs do
def streamable
find(:all, :conditions => ''streamable = 1'')
end
end
end
So for a given Album instance (say @album), I need to be able to stub
both
2010 Jun 23
1
RSpec, plugins and stubbing controller methods
Hello,
I have some code that is going to be used in other applications, so I
decided to bundle the code (mostly controllers and views) into a plugin to
make sharing easier. I copied the RSpec tests for the controllers into the
plugin as well.
The plugin RSpec tests run, however when it gets to stubbing controller
methods it does not work. For example:
2008 Sep 17
1
Stubbing Paperclip calls to Amazon S3 (for Rspec)
Would anyone happen to know how to stub a call to S3 from Paperclip?
I''ve searched every where and no one seems to have posted anything about
this. I''ve done very little in the way of spec''ing dependencies on
external services, so any ideas on how to do this with Paperclip & S3
would be most appreciated. I''m happy with stubbing out Thinking Sphinx -
would
2007 Oct 26
2
Examples of writing controller specs that use authentication
Hello,
I''m working on specs for a controller that handles authentication
using the restful_authentication plugin. I''m trying to find a
resource (tutorial or examples, if possible) about the best way to go
about writing mocks and specs to make sure that things like my
before_filters are working correctly. Does anyone know of any good
resources for this?
Thanks,
Les