Displaying 20 results from an estimated 237 matches similar to: "rails associations"
2008 Nov 18
8
Mocking and stubbing model relationships
Before writing specs for a one-to-many relationship between two
models, I did some research and found that some people were creating
proxy mocks, and others were using Matthew Heidemann's
#stub_association! (which essentially does that for, but in a nice,
DRY way):
2007 Jul 12
3
Agh, this is annoying. Why is this happening?
My problem:
Mock 'Task_1005' received unexpected message :user_id= with (1)
No matter what I do to try to stub that out it will still fail out and give
me that message.
Here is my spec
describe TasksController, "handling POST /tasks" do
before(:each) do
@task = mock_model(Task, :to_param
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')
2007 Aug 17
11
[rspec] looking for a simple refresher
I've been off the rspec for a few months and I'm trying to get back on it.
1)
Spec::Mocks::MockExpectationError in 'TicketsController handling POST
/tickets should create a new ticket'
Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 times
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
2007 Aug 21
2
using restful_authentication current_user inside controller specs
I'm using restful_authentication in my app and I have the before filters in
my application rhtml:
before_filter :login_required
around_filter :set_timezone
around_filter :catch_errors
Currently I have them commented out while rspec'in but I'll need to add them
in my specs.
def create
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
2008 Feb 04
1
Error on nil.build
I can't figure out why I am getting an error for one of the tests below:
========================
describe AccountsController, "POST" do
before :each do
@user = mock_model(User)
@account = mock_model(Account, :id => 1, :valid => true, :save =>
true, :users => mock("users", :build =>
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
2007 Jan 30
5
errors while testing resource controller using rpec
I am testing a resource called venue in this piece of code (generated
using script/rspec_resource)
====================
context "Requesting /venues using POST" do
controller_name :venues
setup do
@mock_venue = mock('Venue')
@mock_venue.stub!(:save).and_return(true)
2011 Jul 21
1
question regarding how to test posting form data with Net::HTTP
So I have a class that does this:
def perform
@response = Net::HTTP.new(url.host, url.port).start {|http| http.request(do_post) }
unless @response.is_a?(Net::HTTPSuccess) || @response.is_a?(Net::HTTPRedirection)
@response.error!
end
end
def do_post
2007 Feb 06
2
Login systems : stubbing accounts and AR
My Rails site has a fair amount of login and 'ownership' logic. For
instance, we have a number of clients (companies), each of which has
several accounts. A client owns a number of different types of
resources, and shouldn't see any other clients' resources, so, for
example, our
2009 Aug 04
2
render_template with a non-standard view name
Hi, all.
I am perplexed. The problem I'm having seems to be related to
rendering a "non-standard" view. In our controllers, the 'new' and
'edit' actions share a template, as shown here.
Controller:
def new
@location = Location.new
respond_to do |format|
format.html { render
2011 Dec 02
2
problem setting expectation for test with delayed::job
I've got something like this:
# post_observer.rb
after_create
# ...stuff
Delayed::Job.enqueue(PostSharer.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
#
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
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
2008 Feb 22
6
Problems with redirect_to
Hello guys,
I have the following spec:
describe 'With successful save' do
it 'Should redirect to the new page' do
do_post
response.should be_redirect
response.should redirect_to( :action => 'show', :id =>
@static_page.permalink ) ## this is the line 118
end
2010 Nov 29
0
[TDD] [Rails] - Rspec test for application_helper.rb fails when trying to access application_controller method.
In a method named logo in my application helper, I reference an application controller method (current_account) that has been marked as a helper method with the following syntax:
helper_method :current_account
When I test out the setup in the browser (without rspec), rails is happy with this
2010 Oct 21
1
Prob
Good morning,
I have a little problem trying to install centos 5.5 on Xen, when I run the
command xm create-c / etc/xen/domu1 it starts to install the VM but can not
complete because the following error in the formatting of the disk:
Traceback (most recent call last):
File
2010 Oct 20
1
Suporte
Good morning,
I have a little problem trying to install centos 5.5 on Xen, when I run the
command xm create-c / etc/xen/domu1 it starts to install the VM but can not
complete because the following error in the formatting of the disk:
Traceback (most recent call last):
File