Displaying 20 results from an estimated 22 matches for "do_post".
2007 Aug 17
11
[rspec] looking for a simple refresher
...plicationController
def new
Ticket.new
end
end
describe TicketsController, "handling POST /tickets" do
before do
@ticket = mock_model(Ticket, :to_param => ''1'', :save => true)
Ticket.stub!(:new).and_return(@ticket)
@params = {}
end
def do_post
post :create, :ticket => @params
end
it "should create a new ticket" do
@ticket.should_receive(:new).with(@params).and_return(@ticket)
do_post
end
end
Would someone provide with an explanation what I have to do to make this
spec pass?
Peepcode hasn''t relea...
2007 Jul 12
3
Agh, this is annoying. Why is this happening?
...@task = mock_model(Task, :to_param => "1", :save => true)
Task.stub!(:new).and_return(@task)
@user = mock_model(User)
@user.stub!(:id).and_return(1)
@user.stub!(:login).and_return("moo")
User.stub!(:find).and_return(@user)
@params = {}
end
def do_post
@request.session[:user] = @user.id
post :create, :task => @params
end
it "should create a new task" do
Task.should_receive(:user_id).with(@user.id).and_return(true)
Task.should_receive(:new).with(@params).and_return(@task)
do_post
end
it "should redir...
2008 Feb 04
1
Error on nil.build
...be AccountsController, "POST" do
before :each do
@user = mock_model(User)
@account = mock_model(Account, :id => 1, :valid => true, :save =>
true, :users => mock("users", :build => @user))
Account.should_receive(:new).and_return(@account)
end
def do_post
post "create", {:account => {}, :user => {}}
end
it "should make the relation to the users" do
@account.should_receive(:users).and_return
do_post
end
#this test passes
it "should receive the save method call" do
@account.should_receive...
2007 Aug 21
2
using restful_authentication current_user inside controller specs
...redirect_to tickets_path
else
render new_ticket_path(params[:user_id])
end
end
describe TicketsController, "handling POST /tickets" do
before do
@ticket = mock_model(Ticket, :save => true)
@current_user = mock_model(User)
@params = {}
end
def do_post
post :create, :ticket => @params
end
it "should create a new ticket and assign current user as ticket''s user"
do
@ticket.should_receive(:new).with(@params).and_return(@ticket)
assigns[:ticket].user.should equal(@current_user)
do_post
end
end
1)
No...
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
2007 Nov 21
6
How thorough do you test?
Testing models is great and would not be able to create anything without
it, but I am finding testing the controllers and views is a pain.
Rest based controllers don''t seem to change that much when compared to
the auto-generated code that obviously works.
As for views I fail to see why testing it with a mock model does
anything. Nothing is ensuring that when changes are made to the
2011 Dec 02
2
problem setting expectation for test with delayed::job
...rer.new(post, post.user))
end
...
# post_sharer.rb
class PostSharer < Struct.new(:post, user)
def perform
# Delayed::Job calls .perform on the object passed into enqueue
end
end
# post_controller_spec.rb
it "shares the post" do
PostSharer.expects(:new).once
lambda { do_post }.should change(Delayed::Job, :count).by(1)
end
...
This fails due to the expectation put on PostSharer receiving .new --- if I
remove that, then it all works fine... And if I look at the test database,
Delayed::Job has created a job for PostSharer, so it is all working as
desired.. I just wan...
2008 Mar 08
7
ridding away with do_request
I''m heading out of town, but had a quick thought I wanted to share.
Rather then using ambiguous named request helpers in controller specs
like "do_request", I''ve been using more readable helpers like
"post_create".
For example...
describe ProjectController do
def post_create
post :create, ...
end
before do
end
it "creates a new
2008 Apr 23
0
How i write the respec in this situation??
..._return(@topic)
Reply.stub!(:new).and_return(@reply)
@params = {
:topic_id => @topic.id,
:forum_id => @forum.id,
:title => ''Ragnarok'',
:body => ''ragnarokrangarkratnonfgdsakl''
}
end
def do_post
post :create,:reply =>@params
end
it "should call Reply modl with new values" do
Reply.should_receive(:new).with(anything()).and_return(@reply)
do_post
end
it "should add reply to the topic" do
do_post
response.should redirect_to...
2007 Jan 08
2
thoughts on mocks and specs
I spent the last couple of days getting my sea legs with Rails and
RSpec. I''d been waiting til things seemed calmer before jumping in,
and I''m overall very happy with my experience so far.
My only real annoyance so far has been forgetting to call "do_post" or
"do_create" from my specify blocks. My mocks don''t get the calls they
want, and it usually isn''t until I''ve mucked around in my application
code for a bit that I realize the real problem.
Wouldn''t it be nice to be able to define a callback tha...
2007 Jan 30
5
errors while testing resource controller using rpec
...======
context "Requesting /venues using POST" do
controller_name :venues
setup do
@mock_venue = mock(''Venue'')
@mock_venue.stub!(:save).and_return(true)
@mock_venue.stub!(:to_param).and_return(1)
Venue.stub!(:new).and_return(@mock_venue)
end
def do_post
post :create, :venue => {:name => ''Venue''}
end
specify "should create a new venue" do
Venue.should_receive(:new).with({''name'' => ''Venue''}).and_return(@mock_venue)
do_post
end
end
==========================...
2007 Nov 28
6
Newbie question
I installed Rspec and am getting the following failure:
$ sudo gem install rspec
Successfully installed rspec-1.0.8
Installing ri documentation for rspec-1.0.8...
Installing RDoc documentation for rspec-1.0.8...
$ spec -v
RSpec-1.0.8 (r2338) - BDD for Ruby
http://rspec.rubyforge.org/
$ cat acct.rb
describe Account, " when first created" do
it "should have a balance of $0"
2005 Jan 19
1
Problem with ActiveRecordStore
...process''
gems/gems/actionpack-1.3.1/lib/action_controller/base.rb:241:in `process''
gems/gems/rails-0.9.4.1/lib/webrick_server.rb:101:in `load''
gems/gems/rails-0.9.4.1/lib/webrick_server.rb:80:in `handle_mapped''
gems/gems/rails-0.9.4.1/lib/webrick_server.rb:34:in `do_POST''
./script/server:48
The relevant section of the login_controller is this:
@session["user"] = name
This works fine when I use the default Pstore session.
Has anyone else seen this?
--
Daniel Hobe
2007 Nov 08
0
Models for external REST services
...On the side of the controlloer I have no idea how to start, this is
what I think it should look like,
def do_sign_in
@sign_in_form #this should come from the form in the view, I have no
idea how to get this object
api_url = "www.example.com/some_api.php"
response = some_object.do_post (api_url, :params =>{ "api_key" =>
@key, "param1" => @sign_in_form.field1, "param2" =>
@sign_in_form.field2, } )
# after this we should go to a do_sign_in.rjs and do all the ajax
updates
end
#============================
--~--~---------~--~----~------...
2007 Sep 23
4
Story Runner, autoincrementing
I''ve written a story and I run into a snag.
I''ve written the create_forum method and told it to set the id to 1
but when it creates the forum the id is autoincremented.
My forums table is empty but the id keeps incrementing the newest record on
creation.
When I run the story it comes out as something like 59 which fails my story
because I''m asking it to look at /forums/1
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
2007 Oct 30
1
xen xm list: DomUs blocked
...line 522, in __init__
self.handle()
File "BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "BaseHTTPServer.py", line 310, in handle_one_request
method()
File "/usr/lib/python2.5/site-packages/xen/util/xmlrpclib2.py", line 66, in
do_POST
self.send_response(200)
File "BaseHTTPServer.py", line 368, in send_response
(self.protocol_version, code, message))
File "socket.py", line 262, in write
self.flush()
File "socket.py", line 249, in flush
self._sock.sendall(buffer)
error: (32, '...
2008 Jun 11
1
xen migrate never ends
...()
File "/usr/lib/python2.5/BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "/usr/lib/python2.5/BaseHTTPServer.py", line 310, in
handle_one_request
method()
File "/usr/lib/python2.5/site-packages/xen/util/xmlrpclib2.py", line
82, in do_POST
self.send_response(200)
File "/usr/lib/python2.5/BaseHTTPServer.py", line 368, in send_response
(self.protocol_version, code, message))
File "/usr/lib/python2.5/socket.py", line 262, in write
self.flush()
File "/usr/lib/python2.5/socket.py", line 249,...
2006 Dec 02
3
Bug#401249: xen-utils-common: xenbr0 not being created
..., line 521, in __init__
self.handle()
File "BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "BaseHTTPServer.py", line 310, in handle_one_request
method()
File "/usr/lib/xen-3.0.3-1/lib/python/xen/util/xmlrpclib2.py", line 66, in do_POST
self.send_response(200)
File "BaseHTTPServer.py", line 367, in send_response
self.wfile.write("%s %d %s\r\n" %
File "socket.py", line 248, in write
self.flush()
File "socket.py", line 235, in flush
self._sock.sendall(buffer)
error: (32,...
2007 May 31
16
Could anyone please help with rspec/nested resource behavior checking?
My problem has been listed here:
http://railsforum.com/viewtopic.php?pid=25439#p25439
Don''t think it would be required to completely re-type it here :)
Thanks!
--
-Daniel Fischer
http://danielfischer.com - Geek Blog
http://abigfisch.com - Portfolio
http://writersbeat.com - Writing Community