forked from turingschool-projects/little_shop_v2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from tnodland/story_14
Story 14
- Loading branch information
Showing
8 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ItemsController < ApplicationController | ||
def index | ||
@items = Item.enabled_items | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h1>All Items:</h1> | ||
|
||
<% @items.each do |item| %> | ||
<section id="item-<%= item.id %>"> | ||
<h3><%= link_to "#{item.name}", item_path(item) %></h3> | ||
<%= image_tag "#{item.image_url}", size: "100x100" %> | ||
<p>Sold by: <%= item.user.name %></p> | ||
<p>Quantity: <%= item.quantity %></p> | ||
<p>Price: <%= number_to_currency(item.current_price) %></p> | ||
</section> | ||
<% end %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
resources :items, only: [:index, :show] | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
FactoryBot.define do | ||
factory :order do | ||
user | ||
|
||
status { 0 } | ||
end | ||
|
||
factory :packaged_order, parent: :order do | ||
status { 1 } | ||
end | ||
|
||
factory :shipped_order, parent: :order do | ||
status { 2 } | ||
end | ||
|
||
factory :cancelled_order, parent: :order do | ||
status { 3 } | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "Items index page" do | ||
context "as any kind of user" do | ||
it "can see all enabled items" do | ||
merchant1 = create(:merchant) | ||
merchant2 = create(:merchant) | ||
item1 = create(:item, user: merchant1) | ||
item2 = create(:item, user: merchant2) | ||
item3 = create(:inactive_item, user: merchant1) | ||
|
||
visit items_path | ||
|
||
within "#item-#{item1.id}" do | ||
expect(page).to have_link(item1.name) | ||
expect(page).to have_xpath("//img[@src='https://vignette.wikia.nocookie.net/animalcrossing/images/7/72/Tom_Nook.png/revision/latest?cb=20101105231130']") | ||
expect(page).to have_content("Sold by: #{merchant1.name}") | ||
expect(page).to have_content("Quantity: #{item1.quantity}") | ||
expect(page).to have_content("Price: $#{item1.current_price}") | ||
end | ||
|
||
within "#item-#{item2.id}" do | ||
expect(page).to have_link(item2.name) | ||
expect(page).to have_xpath("//img[@src='https://vignette.wikia.nocookie.net/animalcrossing/images/7/72/Tom_Nook.png/revision/latest?cb=20101105231130']") | ||
expect(page).to have_content(merchant2.name) | ||
expect(page).to have_content(item2.quantity) | ||
expect(page).to have_content(item2.current_price) | ||
end | ||
|
||
expect(page).to_not have_content(item3.name) | ||
end | ||
end | ||
end |
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