Skip to content
Open
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
25 changes: 18 additions & 7 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,39 @@ def update


def index
@products = Product.all.where("stock > 0")
end
=begin
None of these should ever be hit because the index
page doesn't take parameters.
Plus the logic of showing products of a specific
category or merchant is handled elsewhere.
if params[:merchant_id]
unless allowed_user(params[:merchant_id])
raise
return
end
end

if params[:merchant_id] && params[:category_id]
@merchant = Merchant.find_by(id: params[:merchant_id])
@category = Category.find_by(id: params[:category_id])
@products = @category.products.where(merchant: @merchant)
raise
@merchant = Merchant.find_by(id: params[:merchant_id])
@category = Category.find_by(id: params[:category_id])
@products = @category.products.where(merchant: @merchant)
elsif params[:category_id]
category = Category.find_by(id: params[:category_id])
@products = category.products
raise
category = Category.find_by(id: params[:category_id])
@products = category.products
elsif params[:merchant_id]
raise
@merchant = Merchant.find_by(id: params[:merchant_id])
@products = @merchant.products
render :merchant_products
else
@products = Product.all

end
end

=end
def index_by_merchant
@merchant = Merchant.find_by(id: params[:id])
@products = @merchant.products
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def readable_date(date)
end

def format_money(amount)
Money.new(amount, "USD").format
#Money.new(amount, "USD").format
end

module_function :set_class
Expand Down
28 changes: 28 additions & 0 deletions app/jobs/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module ApplicationHelper
def set_class(rating)
case rating
when 0
"zero-stars"
when 1
"one-star"
when 2
"two-stars"
when 3
"three-stars"
when 4
"four-stars"
when 5
"five-stars"
end
end

def readable_date(date)
("<span class='date'>" + date.strftime("%b. %d, %Y %I:%M %p (%Z)") + "</span>").html_safe
end

def format_money(amount)
Money.new(amount, "USD").format
end

module_function :set_class
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CategoriesHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/main_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MainHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/merchants_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MerchantsHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/order_items_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OrderItemsHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/orders_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module OrdersHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/products_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProductsHelper
end
2 changes: 2 additions & 0 deletions app/jobs/helpers/reviews_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ReviewsHelper
end
28 changes: 23 additions & 5 deletions test/controllers/products_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@
must_respond_with :success
end

it "checking if auth works this way" do
OmniAuth.config.test_mode = true
merchant = merchants(:eva)
auth_hash = {
provider: merchant.provider,
uid: merchant.uid,
info: {
nickname: merchant.username,
email: merchant.email
}
}
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(mock_auth_hash(merchant))
get auth_callback_path(:github)

Merchant.find_by(uid: merchant.uid).uid.must_equal merchant.uid
test_merchant = Merchant.find_by(uid: merchant.uid)

get products_path
must_respond_with :success
end

it "returns success for no products" do
Product.destroy_all
get products_path
Expand Down Expand Up @@ -171,11 +192,8 @@


it "renders bad_request and does not update the DB for bogus data" do
product_data = {
product: {
name: ""
}
}


start_count = Product.count

post products_path, params: product_data
Expand Down
13 changes: 12 additions & 1 deletion test/fixtures/products.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# below each fixture, per the syntax in the comments below
#
one:
id: 1
name: product
price: 2.0
stock: 3
Expand All @@ -14,6 +15,7 @@ one:
merchant: eva

two:
id: 2
name: product2
price: 3.0
stock: 4
Expand All @@ -23,6 +25,7 @@ two:
merchant: eva

three:
id: 3
name: product3
price: 4.0
stock: 5
Expand All @@ -32,6 +35,7 @@ three:
merchant: eva

four:
id: 4
name: product4
price: 6.0
stock: 7
Expand All @@ -41,6 +45,7 @@ four:
merchant: emma

five:
id: 5
name: product5
price: 8.0
stock: 9
Expand All @@ -50,6 +55,7 @@ five:
merchant: emma

six:
id: 6
name: product6
price: 10.0
stock: 11
Expand All @@ -59,6 +65,7 @@ six:
merchant: emma

seven:
id: 7
name: product7
price: 12.0
stock: 13
Expand All @@ -68,6 +75,7 @@ seven:
merchant: emma

eight:
id: 8
name: product8
price: 14.0
stock: 15
Expand All @@ -77,6 +85,7 @@ eight:
merchant: emma

nine:
id: 9
name: product9
price: 16.0
stock: 17
Expand All @@ -86,6 +95,7 @@ nine:
merchant: emma

ten:
id: 10
name: product9
price: 18.0
stock: 19
Expand All @@ -94,7 +104,8 @@ ten:
image_url: http://www.fillmurray.com/
merchant: emma

ninty:
eleven:
id: 11
id: 90
name: product90
price: 18.0
Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class ActiveSupport::TestCase
}

OmniAuth.config.add_mock(:github, omniauth_hash)




# Add more helper methods to be used by all tests here...
def setup
OmniAuth.config.test_mode = true
Expand Down