Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking out from Cart #163

Merged
merged 4 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def index

def create
Order.from_cart(current_user, @cart.contents)
session[:cart] = {}
flash[:notice] = "Your order was created!"
redirect_to profile_orders_path
end
Expand Down
72 changes: 47 additions & 25 deletions spec/features/cart/show_cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,48 @@

visit cart_path

expect(page).to have_selector('div', id:"cart-item-#{@item_1.id}")
expect(page).to have_selector('div', id:"cart-item-#{@item_2.id}")
expect(page).to have_selector('div', id:"cart-item-#{@item_4.id}")
within "#cart-item-#{@item_1.id}" do
expect(page).to have_selector('div', id:"item-name", text:@item_1.name)
expect(page).to have_selector('div', id:"item-merchant", text:@item_1.user.name)
expect(page).to have_selector('div', id:"item-price", text:@item_1.current_price)
expect(page).to have_selector('div', id:"item-quantity", text:"1")

expect(page).to have_xpath("//img[@src='#{@item_1.image_url}']")
expect(page).to have_field('quantity', with:"1")
expect(page).to have_button("Update Quantity")
expect(page).to have_button("Remove Item")

expect(page).to have_selector('div', id:"subtotal", text:"#{@item_1.current_price}")
end

within "#cart-item-#{@item_2.id}" do
expect(page).to have_selector('div', id:"item-name", text:@item_2.name)
expect(page).to have_selector('div', id:"item-merchant", text:@item_2.user.name)
expect(page).to have_selector('div', id:"item-price", text:@item_2.current_price)
expect(page).to have_selector('div', id:"item-quantity", text:"2")

expect(page).to have_xpath("//img[@src='#{@item_2.image_url}']")
expect(page).to have_field('quantity', with:"2")
expect(page).to have_button("Update Quantity")
expect(page).to have_button("Remove Item")

expect(page).to have_selector('div', id:"subtotal", text:"#{@item_2.current_price * 2}")
end

within "#cart-item-#{@item_4.id}" do
expect(page).to have_selector('div', id:"item-name", text:@item_4.name)
expect(page).to have_selector('div', id:"item-merchant", text:@item_4.user.name)
expect(page).to have_selector('div', id:"item-price", text:@item_4.current_price)
expect(page).to have_selector('div', id:"item-quantity", text:"4")

expect(page).to have_xpath("//img[@src='#{@item_4.image_url}']")
expect(page).to have_field('quantity', with:"4")
expect(page).to have_button("Update Quantity")
expect(page).to have_button("Remove Item")

expect(page).to have_selector('div', id:"subtotal", text:"#{@item_4.current_price * 4}")
end

expect(page).not_to have_selector('div', id:"cart-item-#{@item_3.id}")

total = @item_1.current_price + (@item_2.current_price * 2) + (@item_4.current_price * 4)
Expand Down Expand Up @@ -145,30 +184,13 @@
visit cart_path
click_button "Checkout"

expect(current_path).to eq(profile_orders_path)
expect(page).to have_content("Your order was created!")
end

end
expect(page).to have_content("Cart: 0")

RSpec.describe 'partial for items in cart' ,type: :view do
it 'shows all information' do

item = create(:item)
quantity = 3
render 'carts/cart_item', item:item, quantity:quantity
expect(rendered).to have_selector('div', id:"cart-item-#{item.id}")
expect(rendered).to have_selector('div', id:"item-name", text:item.name)
expect(rendered).to have_selector('div', id:"item-merchant", text:item.user.name)
expect(rendered).to have_selector('div', id:"item-price", text:item.current_price)
expect(rendered).to have_selector('div', id:"item-quantity", text:quantity)

expect(rendered).to have_xpath("//img[@src='#{item.image_url}']")
expect(rendered).to have_field('quantity', with:quantity)
expect(rendered).to have_button("Update Quantity")
expect(rendered).to have_button("Remove Item")



expect(rendered).to have_selector('div', id:"subtotal", text:"#{item.current_price * quantity}")
order = Order.last
expect(order.user_id).to eq(user.id)
expect(page).to have_content("Order ID: #{order.id}")
end
end