similar to: checking associated objects have been deleted

Displaying 20 results from an estimated 8000 matches similar to: "checking associated objects have been deleted"

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 ./spec/controllers/tickets_controller_spec.rb:16: script/spec:4: class
2011 May 27
14
[rails] undefined method `model_name' for NilClass:Class
Never seen the error above before, code: describe "edit action" do it "edit action should render edit template" do food = Food.create(:name=>''mooo'') # Food.any_instance.stubs(:valid?).returns(true) get :edit, :id => food.id response.should render_template(:edit) end end -------------- next part
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here''s the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number =>
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following error 2) NoMethodError in ''/games/_game.rhtml should show game name'' undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in `matches?''
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 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 Sep 30
9
Problems with testing nested routes using mocking
Hello forum I have there to files #----- virtual_host_controller.rb class VirtualHostsController < ApplicationController before_filter :capture_domain # GET /domain/1/virtual_hosts/1 def show @virtual_host = @domain.virtual_hosts.find(params[:id]) respond_to do |format| format.html # show.rhtml end end private def capture_domain if
2007 Sep 18
2
rSpec / Nested Routes / Mocks
I''m having a terrible time trying to test a nested route with rSpec. I can''t seem to tell rSpec to expect the call @item.user. The following error message plagues me not matter how I try to fuss with the mock: Spec::Mocks::MockExpectationError in ''ItemsController handling POST / items should redirect to the new course on successful save'' Mock
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble understanding how i should mock my user. The user has a habtm relationship to a roles model (acl_system2 plugin), but I''m not sure how to tell rspec about a model. My code: describe UsersController do integrate_views before(:each) do @user = mock_model(User)
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 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
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
2007 Dec 03
18
Need help mocking this out
Let''s say you''re using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it''ll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that user owns. How would you properly spec this out? Thanks for the help!
2007 Nov 21
7
describe AddressesController, "handling GET /addresses" do
Hello, I''m working with scaffold generated controller test code for handling GET requests. Address is the model being tested. Address belongs_to Company, Company has_many addresses. In my addresses_controller I have: before_filter :get_company def index @addresses = @company.addresses.find(:all) respond_to do |format| format.html # index.html.erb format.xml {
2007 Apr 30
4
Mocking with Calculated Results
I am setting up an AR mock object and wanted to sanity check it. My intent is to mix this into all my examples and then override/add methods where necessary. Note that I''ve anticipated three cases for find: find with one numeric argument => object find with :all => Array find with anything else => nil This roughly approximates how ActiveRecord::find works in this case
2007 Sep 04
3
Model Specs: Fixtures vs Mocks + Stubs?
What is the general opinion about fixtures versus mocking and stubbing in model specs? I heard from agile on IRC that they save the database testing for integration testing, but I also see that the caboose sample applicaiton uses fixtures. I also noticed that on the rspec site, it says "Ironically (for the traditional TDD''er) these are the only specs that we feel should actually
2007 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model? I''m assuming i need to say @mock_thing = mock_model(Thing) @mock_thing_errors = mock("errors") @mock_thing_errors.should_receive(:full_messages).and_return("An error") @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) Just wanted to check the best practice on this kind of thing and how
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
2008 Jan 23
18
Not seeing the failure
All, I''m missing something simple, I think. I am writing a spec to say that my CouponController should create a new coupon from the form parameters, then set the current user. Here''s the spec: describe CouponController, "When posting to save_coupon" do before(:each) do @expectedName = "pepper''s" @expectedAmount = 5 coupon =
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 => "1", :save => true)