Created
July 14, 2014 16:17
-
-
Save kshsieh/20e3872578d81c84e8aa to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe RestaurantsController, type: :controller do | |
let!(:restaurant){Restaurant.create(name:"TestRestaurant")} | |
context "GET index" do | |
it "should return all restaurants" do | |
get :index | |
expect(assigns(:restaurants)).to include restaurant | |
end | |
end | |
context "GET show" do | |
visit('/restaurants/show') | |
it "should return the restaurant" do | |
get :show, id: restaurant.id | |
expect(assigns(:restaurant)).to eq restaurant | |
end | |
end | |
context "GET new" do | |
visit('/restaurants/new') | |
it "should be an instance of restaurant" do | |
get :new | |
expect(assigns(:restaurant)).to be_an_instance_of Restaurant | |
end | |
it "should not be persisted" do | |
get :new | |
expect(assigns(:restaurant).persisted?).to be_false | |
end | |
end | |
context "POST create" do | |
visit('/restaurants/new') | |
it "should save" do | |
post :create, name: 'Foo' | |
expect(assigns(:restaurant).persisted?).to be_true | |
end | |
it "should create with name" do | |
post :create, name: 'Foo' | |
expect(assigns(:restaurant).name).to eq 'Foo' | |
end | |
it "should redirect to index on success" do | |
end | |
it "should render the new template on failure" do | |
end | |
end | |
context "GET edit" do | |
visit('/restaurants/edit') | |
end | |
context "PUT update" do | |
visit('/restaurants/edit') | |
end | |
context "DELETE destroy" do | |
before :each do | |
expect(Restaurant.count).to eq 1 | |
delete :destroy, id: restaurant.id | |
end | |
it "should delete that record" do | |
expect(Restaurant.count).to eq 0 | |
end | |
it "should not be persisted" do | |
expect(assigns(:restaurant).persisted?).to be_false | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment