forked from sunny-moore/little-esty-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
177 additions
and
17 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
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,25 @@ | ||
class HolidayDiscountsController < ApplicationController | ||
|
||
def new | ||
@holiday_name = params[:holiday_name] | ||
@merchant = Merchant.find(params[:merchant_id]) | ||
end | ||
|
||
def create | ||
if holiday_discount_params[:percent_discount] == "" || holiday_discount_params[:quantity_threshold] == "" | ||
flash[:notice] = "Error - please complete all fields" | ||
|
||
redirect_to new_merchant_holiday_discount_path(holiday_discount_params[:merchant_id]) | ||
else | ||
HolidayDiscount.create(percent_discount: holiday_discount_params[:percent_discount], quantity_threshold: holiday_discount_params[:quantity_threshold], holiday_name: holiday_discount_params[:holiday_name],merchant_id: holiday_discount_params[:merchant_id]) | ||
|
||
redirect_to merchant_bulk_discounts_path(holiday_discount_params[:merchant_id]) | ||
end | ||
end | ||
|
||
private | ||
def holiday_discount_params | ||
params.permit(:merchant_id, :percent_discount, :quantity_threshold, :holiday_name) | ||
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,7 @@ | ||
class HolidayDiscount < ApplicationRecord | ||
|
||
belongs_to :merchant | ||
has_many :items, through: :merchant | ||
has_many :invoice_items, through: :items | ||
|
||
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
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,12 @@ | ||
<h1> New Holiday Discount Page </h1> | ||
|
||
Discount Name: <%=@holiday_name%> Discount | ||
|
||
<%= form_with url: "/merchants/#{@merchant.id}/holiday_discounts",method: :post, class: "holiday_discount_form" do |form|%> | ||
<%=form.label :percent_discount, "Percent Discount" %> | ||
<%=form.number_field :percent_discount, value: 30%> | ||
<%=form.label :quantity_threshold, "Quantity Threshold" %> | ||
<%=form.number_field :quantity_threshold, value: 2%> | ||
<%=form.hidden_field :holiday_name, value: @holiday_name%> | ||
<%=form.submit "Submit" %> | ||
<% 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,12 @@ | ||
class CreateHolidayDiscounts < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :holiday_discounts do |t| | ||
t.string :holiday_name | ||
t.integer :percent_discount, default: 30 | ||
t.integer :quantity_threshold, default: 2 | ||
t.references :merchant, foreign_key: true | ||
|
||
t.timestamps | ||
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
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
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,46 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'merchant new holiday discount page' do | ||
|
||
it 'has pre-filled percent discount, quantity threshold, and holiday name fields, and reroutes to the discount index page where the new discount is shown' do | ||
merchant1 = Merchant.create!(name: "Snake Shop") | ||
|
||
bulk_discount1 = BulkDiscount.create!(percent_discount: 10, quantity_threshold: 5, merchant_id: merchant1.id) | ||
|
||
visit merchant_bulk_discounts_path(merchant1.id) | ||
|
||
within "#upcoming-holiday-1" do | ||
click_on "New Discount" | ||
end | ||
|
||
expect(current_path).to eq(new_merchant_holiday_discount_path(merchant1)) | ||
|
||
expect(page).to have_content("Discount Name: Labor Day Discount") | ||
expect(page).to have_field(:percent_discount, :with => 30) | ||
expect(page).to have_field(:quantity_threshold, :with => 2) | ||
|
||
click_on "Submit" | ||
|
||
expect(current_path).to eq(merchant_bulk_discounts_path(merchant1.id)) | ||
|
||
within "#holiday-discount-list" do | ||
expect(page).to have_content("Labor Day Discount") | ||
expect(page).to have_content("Percent Discount: 30") | ||
expect(page).to have_content("Quantity Threshold: 2") | ||
end | ||
end | ||
end | ||
|
||
# Create a Holiday Discount | ||
|
||
# As a merchant, | ||
# when I visit the discounts index page, | ||
# In the Holiday Discounts section, I see a `create discount` button next to each of the 3 upcoming holidays. | ||
# When I click on the button I am taken to a new discount form that has the form fields auto populated with the following: | ||
|
||
# Discount name: <name of holiday> discount | ||
# Percentage Discount: 30 | ||
# Quantity Threshold: 2 | ||
|
||
# I can leave the information as is, or modify it before saving. | ||
# I should be redirected to the discounts index page where I see the newly created discount added to the list of discounts. |
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,9 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe HolidayDiscount do | ||
describe 'relationships' do | ||
it { should belong_to :merchant} | ||
it { should have_many(:items).through(:merchant)} | ||
it { should have_many(:invoice_items).through(: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