Last active
August 29, 2015 14:23
-
-
Save acaporrini/6decaa1c96819beea567 to your computer and use it in GitHub Desktop.
Product controller 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' | |
describe ProductsController, type: :controller do | |
describe "POST # products" do | |
before do | |
@user = User.create(email: "demo@demo.com", password: "12345678") | |
@user.confirm | |
sign_in @user | |
end | |
it "create a new product" do | |
expect{ post :create, { product: { name: "aaaa" } } }.to change{Product.count}.by(1) | |
end | |
end | |
describe "DELETE # products" do | |
before do | |
@user = User.create(email: "demo@demo.com", password: "12345678") | |
@user.confirm | |
sign_in @user | |
@product = Product.create(name: "bike",description: "cool bycicle",image_url: "bike.jpg",colour: "red",price: "2,99") | |
end | |
it "delete an existing product" do | |
expect{ delete :destroy, id: @product.id }.to change{Product.count}.by(-1) | |
end | |
end | |
describe "UPDATE # products" do | |
before do | |
@user = User.create(email: "demo@demo.com", password: "12345678") | |
@user.confirm | |
sign_in @user | |
@product = Product.create(name: "bike",description: "cool bycicle",image_url: "bike.jpg",colour: "red",price: "2,99") | |
put :update, id: @product.id, product: { name: "bycicle" } | |
@product.reload | |
end | |
it "update an existing product" do | |
expect( @product.name ).to eq("bycicle") | |
end | |
end | |
# describe "UPDATE # products" do | |
# before do | |
# @user = User.create(email: "demo@demo.com", password: "12345678") | |
# @user.confirm | |
# sign_in @user | |
# @product = Product.create(name: "bike",description: "cool bycicle",image_url: "bike.jpg",colour: "red",price: "2,99") | |
# end | |
# it "update an existing product" do | |
# expect{ put :update, id: @product.id, product: { name: "bycicle" } }.to change{@product.name} | |
# end | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment