Displaying 20 results from an estimated 75 matches for "do_get".
2007 Jun 02
7
I''m really bad at controllers, help please.
...ndling GET /messages for a user" do
before do
@message = mock_model(Message)
@message.stub!(:user_id).and_return(1)
@user = mock_model(User)
@user.stub!(:id).and_return(1)
User.stub!(:messages).and_return([@message])
User.stub!(:find).and_return([@user])
end
def do_get
get :index, :user_id => 1
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
it "should find all messages&quo...
2007 Oct 08
6
spec''in controllers request for nested routes
describe PlayersController, "handling GET /saltmines/games/1/players" do
before do
@game = mock_model(Game, :to_param => "1")
@game.stub_association!(:players, :find => mock_model(Player))
end
def do_get
get :index, :game_id => @game
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
end
1)
ActiveRecord::RecordNotFoun...
2008 Jun 07
2
When to send "post" and "get" in blocks.
Hi,
I''m new to RSpec. I have a question about how to write controller specs.
Here''s a code generated by scaffolding (with Rspec).
def do_get
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
it "should find all books&qu...
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
...find_by_id(params[:company_id])
end
My controller spec code for handling GET /addresses:
before do
@company = mock_model(Company)
@addresses = mock("addresses")
@company.stub!(:addresses).and_return(@addresses)
Company.stub!(:find).and_return(@company)
end
def do_get
get :index, :company_id => 1
end
it "should be successful" do
do_get
response.should be_success
end
.............
All of my tests (4) fail:
4) NoMethodError in ''AddressesController handling GET /addresses should be
successful''
You have a nil obje...
2008 Jan 30
3
Order of the get call and xxx.should
Just out of curiosity, why is that the following .should calls have to
differ to work?
The first is a normal check on the if the user is redirected if not
logged in
=========
it "should redirect the user to the login screen" do
do_get
response.should redirect_to(new_session_url)
end
The second is checking to ensure that the proper user validation method
is called
=========
it "should validate the user" do
controller.should_receive(:authorized?).and_return(true)
do_get
end
**Note: These are specs from...
2007 Oct 26
3
Specing with Subdomains as Account Keys
...tem)
Item.stub!(:find).and_return([@item])
@current_company = mock(Company)
@current_company.stub!(:items).and_return([])
@current_company.stub!(:find_items).and_return([@item])
@current_company.stub!(:subdomain).and_return("subdomain")
end
# Passes
def do_get
get :index
end
# Passes
it "should be successful" do
do_get
response.should be_success
end
# Passes
it "should render index template" do
do_get
response.should render_template(''index'')
end
# FAILS with messa...
2007 Sep 30
9
Problems with testing nested routes using mocking
...@virtual_host = mock("virtual_host")
Domain.should_receive(:find).with("1").and_return(@domain)
@domain.should_receive(:virtual_hosts).and_return(@virtual_hosts)
@virtual_hosts.should_receive(:find).and_return(@virtual_host)
login_as :admin
end
def do_get
get :show, :id => "1", :domain_id => "1"
end
it "should render show template" do
do_get
response.should render_template(''show'')
end
it "should find the virtual_host requested" do
# @domain.should_receive(:v...
2007 Nov 13
2
More Rails Pattern Examples?
Hi,
I have been reading the documentation and examples on the rspec site.
There are two "patterns" from Rails that I am not clear how to
implement that are kind of related, and so I am not sure how to start.
Does anyone have any examples of how to write rspecs for these?
1/ Nested resources.
2/ Resources that are specific to the current_user. In other words, I
only want to
2007 Oct 16
3
Controller iterating through returned records and appending to each
...false))
@employees = [@mock_employee]
@employees.each { |f| f.stub!(:current_goal=) }
@employees.each { |f| f.stub!(:current_goal) }
Employee.stub!(:find_active_employees).and_return(@employees)
login # used to bypass the restful_authentication login_required filter
end
def do_get
get :employee_report
end
it "should add the current billable goal to each returned employee" do
do_get
@employees[0].should respond_to(:current_goal)
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/...
2007 Feb 15
4
defining context(s) dynamically
...; @model = Object.const_get(klass)<br>
@model.should_receive(:find).with(@mock.id).and_return(@mock)<br>
end<br>
<br>
def do_get() get :edit, :id => @mock.id end<br>
<br>
specify "should be successful" do<br>
do_get<br>
response.should_be_success<br>
&...
2007 Apr 20
1
getting controller specs to work on edge
...9;'s an example:
describe "Requesting /users using GET" do
controller_name :users
setup do
@user = mock_model(User)
User.stub!(:find).and_return(@user)
end
it "should render index.rhtml" do
response.should render_template(''index'')
do_get
end
end
When I run that via rake spec:controllers I get:
NoMethodError in ''Requesting /users using GET should render index.rhtml''
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.first_render
.../vendor/plugins/rspec_on_rails/li...
2007 Sep 14
2
Testing a nested controller
...veryone.
I really stuck on testing a nested controller. I''m trying to make a
request using get and afterwards checking the response by
response.should ...
My routes.rb looks like this:
map.resources :writers do |writers|
writers.resources :notes
end
In my notes_controller_spec.rb
def do_get
writer_id = 1
note_id = 1
get note_path(writer_id, note_id)
end
it "should show a note" do
do_get
response.should be_success
end
But this always ends in an error message:
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.rewrite
Can...
2007 Sep 14
2
Testing nested controller
...eryone.
I really stuck on testing a nested controller. I''m trying to make a
request using get and afterwards checking the response by
response.should ...
My routes.rb looks like this:
map.resources :writers do |writers|
writers.resources :notes
end
In my notes_controller_spec.rb
def do_get
writer_id = 1
note_id = 1
get note_path(writer_id, note_id)
end
it "should show a note" do
do_get
response.should be_success
end
But this always ends in an error message:
You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.rewrite...
2007 Oct 11
2
Login testing ideas
I''ve been going through Pat''s example story and noticed that there was
no checking for a bad login. I assume this is because that would have
made the article bigger and more complicated than it needed to be.
So the question that comes of of this is:
How do folks normally handle the negative case? My plan was to just
use another scenario, but as a new person to BDD/TDD,
2007 Jun 14
1
rspec will_paginate
...s == "solved"
return Ticket.paginate(:page => page, :per_page => per_page, :conditions
=> conditions)
end
describe TicketsController, "handling GET /tickets" do
before do
@tickets = mock_model(Ticket)
Ticket.stub!(:find).and_return([@ticket])
end
def do_get
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
it "should find all pagniated tickets" do...
2007 Mar 27
2
mocking/stubbing newbie questions
...w to mocking and stubbing. Can someone help me out with the
following? I don''t exactly know why this spec is failing:
describe "GET /users/1/terms" do
controller_name :terms
setup do
@user = mock_model(User)
User.stub!(:find).and_return(@user)
end
def do_get
get :index, :user_id => 1
end
it "should find all terms associated with the user" do
User.should_receive(:find).with("1")
end
end
the controller code:
class TermsController < ApplicationController
def index
User.find(1)
end
end
the spec...
2007 Oct 25
1
Mocking/Stubbing help with subdomain as account key
..._spec.rb
before do
@request.host = "subdomain.test.host"
@thing = mock_model(Thing)
@current_person = mock("person") # <= THE MOCKS IN QUESTION
@current_person.stub!(:things).and_return(Thing)
@current_person.things.stub!(:find).and_return(@thing)
end
def do_get
get :show, :id => "1"
end
it "should find the donation requested" do
# Thing.should_receive(:find).with("1").and_return(@thing)
@current_person.things.should_receive(:find).with("1").and_return
(@thing)
do_get
end
# things_controller.rb
def...
2007 Mar 28
1
extracting common methods out of specs
I have several specs which do more or less the same thing:
describe "GET /users/1/terms" do
controller_name :terms
def do_get
get :index, :user_id => 1
end
it "should be successful" do
controller.should_render :index
do_get
end
...
end
How could I extract this functionality from each spec?
Scott
2006 Dec 24
6
What do you think of this controller spec?
...ed a couple spec helper methods to refactor some of the
common code...for example, require_login_and_correct_user creates two
specifications: one for when the user isn''t logged in, and one when
the user is logged in but requests someone else''s book. do_request
automatically calls do_get/post/put/delete depending on what''s
implemented.
Here''s all the code:
books_controller.rb: http://pastie.caboo.se/29469
books_controller_spec.rb: http://pastie.caboo.se/29470
spec_helper.rb: http://pastie.caboo.se/29471
The specs just feel somewhat unwieldy to me...maybe it'...
2008 Jun 28
19
Stopping example execution?
...ing something here when creating an example that sets an expecation at the top or beginning of an action but requires you to stub / mock everything that follows.
Example:
I want to test that a certain controller is running a before_filter...thats easy:
- controller.should_receive(:require_user)
- do_get
But now i''ve got to mock / stub everything else that comes behind this filter so that I don''t receive ''unexpected method'' errors, or other blowups because I am requesting the whole action. Is there anyway to stop execution after an expectation has been met? It...