spec/builders/nested_builder_spec.rb in exposure-0.1.1 vs spec/builders/nested_builder_spec.rb in exposure-0.1.2

- old
+ new

@@ -39,6 +39,53 @@ end it { should assign_to(:ship).with(@ship) } it { should assign_to(:resource).with(@ship) } +end + +describe "deeply nested builders", :type => :controller do + setup = lambda { + class CannonsController < ActionController::Base + expose_many(:cannons, :nested => [:pirates, :ships]) + end + + ActionController::Routing::Routes.draw do |map| + map.resources :pirates do |pirate| + pirate.resources :ships do |ship| + ship.resources :cannons + end + end + end + } + + setup.call + controller_name :cannons + Object.remove_class(CannonsController) + + before(:each) do + setup.call + @controller = CannonsController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @pirate = Factory.create(:pirate) + @ship = Factory.create(:ship, :pirate => @pirate) + @cannon = Factory.build(:cannon) + + Pirate.stub!(:find).and_return(@pirate) + @pirate.ships.stub!(:find).and_return(@ship) + @ship.cannons.stub!(:build).and_return(@cannon) + + + params = {:pirate_id => @pirate.id, :ship_id => @ship.id, :cannon => Factory.attributes_for(:cannon)} + + get(:new, params) + end + + after(:each) do + Object.remove_class(CannonsController) + end + + it { should assign_to(:cannon).with(@cannon) } + it { should assign_to(:resource).with(@cannon) } end \ No newline at end of file