Skip to content

Instantly share code, notes, and snippets.

@mytrile
Created January 7, 2009 21:18
Show Gist options
  • Select an option

  • Save mytrile/44441 to your computer and use it in GitHub Desktop.

Select an option

Save mytrile/44441 to your computer and use it in GitHub Desktop.
def index
@category = Category.find(:all)
@cat = Category.new
respond_to do |format|
format.html
format.xml { render :xml => @category }
format.json { render :json => @category }
end
end
def create
@category = Category.new(params[:category])
if @category.save(params)
flash[:notice] = 'Category successfully added !'
redirect_to '/categories'
else
flash[:notice] = 'There was an error processing your request'
render :action => "index"
end
end
context "on POST to :create " do
setup { post :create, :category => { :name => 'Flowers', :description => 'I Like flowers' } }
should_assign_to :category
should_set_the_flash_to "Category successfully added !"
end
context "on POST to :create without values" do
setup { post :create,
:category => { :name => nil, :description => nil } }
should_assign_to :category
should_set_the_flash_to "There was an error processing your request"
should_render_template :index
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment