Skip to content

Instantly share code, notes, and snippets.

@roolo
Created January 23, 2012 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roolo/1664264 to your computer and use it in GitHub Desktop.
Save roolo/1664264 to your computer and use it in GitHub Desktop.
RSpec test
require 'spec_helper'
describe "Books" do
describe "PUT /books/:id" do
it "updates a book" do
book = {name: 'Alchandira', description: 'Something'}
updated_book = {name: 'Cave', description: 'Something'}
# Create book
post books_path, book: book
response.status.should eq(302)
# Verify creation
new_book = Book.find_by_name book[:name]
new_book.nil?.should_not eq true
# Update book
put book_path(new_book), book: updated_book
response.status.should eq(302)
# Verify the change
new_book_updated = Book.find_by_name updated_book[:name]
new_book_updated.nil?.should_not eq true
new_book_updated.id.should eq new_book.id
new_book_updated.name.should eq updated_book[:name]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment