Skip to content

Commit

Permalink
Added specs and implementation code for creating new resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
baphled committed May 14, 2010
1 parent daf088c commit bc7f652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/parking_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ def new
def tickets
@tickets = Lighthouse::Ticket.find(:all, :params => { :project_id => '50164', :q => "state:open tagged:#{params[:tag]}" })
end

def create
@resource = Resource.new(params[:resource])
if @resource.save
redirect_to parking_index_path
end
end
end
25 changes: 25 additions & 0 deletions spec/controllers/parking_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,29 @@
get :new
end
end

describe "POST, create" do
before(:each) do
@resource = mock_model(Resource, :name => "Some new parked feature").as_null_object
Resource.stub!(:new).and_return @resource
end

context "input is valid" do
it "should create a new resource" do
Resource.should_receive(:new)
post :create
end

it "should save the new resource" do
@resource.should_receive(:save)
post :create, {:resource => @resource}
end

it "should redirect to the parking index view" do
@resource.stub!(:save).and_return true
post :create, {:resource => @resource}
response.should redirect_to parking_index_path
end
end
end
end

0 comments on commit bc7f652

Please sign in to comment.