Merge branch 'staging' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2017-08-15 16:42:32 +06:30
50 changed files with 738 additions and 55 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the Settings/ItemSets controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -60,6 +60,7 @@ class Origami::CustomersController < BaseOrigamiController
id = params[:sale_id][0,3]
customer_id = params[:customer_id]
customer = Customer.find(customer_id)
# Check and find with card no
# if(!customer_id.include? "CUS")
@@ -74,7 +75,7 @@ class Origami::CustomersController < BaseOrigamiController
status = sale.update_attributes(customer_id: customer_id)
sale.sale_orders.each do |sale_order|
order = Order.find(sale_order.order_id)
status = order.update_attributes(customer_id: customer_id)
status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type)
end
else
@booking = BookingOrder.find_by_order_id(params[:sale_id])
@@ -82,7 +83,7 @@ class Origami::CustomersController < BaseOrigamiController
@orders.each do |bo|
order = Order.find(bo.order_id)
status = order.update_attributes(customer_id: customer_id)
status = order.update_attributes(customer_id: customer_id,order_type:customer.customer_type)
end
end

View File

@@ -163,6 +163,35 @@ class Origami::PaymentsController < BaseOrigamiController
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print")
end
def foc
cash = params[:cash]
sale_id = params[:sale_id]
sub_total = params[:sub_total]
member_info = nil
rebate_amount = nil
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, @user, cash, "foc")
unique_code = "ReceiptBillPdf"
customer= Customer.find(saleObj.customer_id)
#shop detail
shop_details = Shop.find(1)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC")
end
end
def rounding_adj
saleObj = Sale.find(params[:sale_id])

View File

@@ -66,8 +66,6 @@ class Origami::ShiftsController < BaseOrigamiController
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='')
#other payment details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift)
#t details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift)
# Calculate price_by_accounts
@total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount')

View File

@@ -0,0 +1,74 @@
class Settings::ItemSetsController < ApplicationController
before_action :set_settings_item_set, only: [:show, :edit, :update, :destroy]
# GET /settings/item_sets
# GET /settings/item_sets.json
def index
@settings_item_sets = ItemSet.all
end
# GET /settings/item_sets/1
# GET /settings/item_sets/1.json
def show
end
# GET /settings/item_sets/new
def new
@settings_item_set = ItemSet.new
end
# GET /settings/item_sets/1/edit
def edit
end
# POST /settings/item_sets
# POST /settings/item_sets.json
def create
@settings_item_set = ItemSet.new(settings_item_set_params)
respond_to do |format|
if @settings_item_set.save
format.html { redirect_to @settings_item_set, notice: 'Item set was successfully created.' }
format.json { render :show, status: :created, location: @settings_item_set }
else
format.html { render :new }
format.json { render json: @settings_item_set.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /settings/item_sets/1
# PATCH/PUT /settings/item_sets/1.json
def update
respond_to do |format|
if @settings_item_set.update(settings_item_set_params)
format.html { redirect_to @settings_item_set, notice: 'Item set was successfully updated.' }
format.json { render :show, status: :ok, location: @settings_item_set }
else
format.html { render :edit }
format.json { render json: @settings_item_set.errors, status: :unprocessable_entity }
end
end
end
# DELETE /settings/item_sets/1
# DELETE /settings/item_sets/1.json
def destroy
@settings_item_set.destroy
respond_to do |format|
format.html { redirect_to settings_item_sets_url, notice: 'Item set was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_settings_item_set
@settings_item_set = ItemSet.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def settings_item_set_params
params.require(:settings_item_set).permit(:name, :min_selectable_qty, :max_selectable_qty)
end
end

View File

@@ -0,0 +1,2 @@
module Settings::ItemSetsHelper
end

View File

@@ -56,6 +56,8 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :foc, :payment
can :move_dining, :movetable
can :moving, :movetable
@@ -96,17 +98,13 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :foc, :payment
can :move_dining, :movetable
can :moving, :movetable
can :move_dining, :moveroom
can :first_bill, :payment
can :show, :payment
can :create, :payment
can :reprint, :payment
can :manage, DiningQueue
elsif user.role == "account"

7
app/models/item_set.rb Normal file
View File

@@ -0,0 +1,7 @@
class ItemSet < ApplicationRecord
has_many :menu_item_sets
has_many :menu_items, through: :menu_item_sets
has_many :menu_instance_item_sets
has_many :menu_item_instances, through: :menu_instance_item_sets
end

View File

@@ -1,5 +1,5 @@
class MenuCategory < ApplicationRecord
before_create :generate_menu_category_code
# before_create :generate_menu_category_code
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
@@ -37,7 +37,7 @@ class MenuCategory < ApplicationRecord
private
def generate_menu_category_code
self.code = SeedGenerator.generate_code(self.class.name, "C")
end
# def generate_menu_category_code
# self.code = SeedGenerator.generate_code(self.class.name, "C")
# end
end

View File

@@ -0,0 +1,4 @@
class MenuInstanceItemSet < ApplicationRecord
belongs_to :item_set
belongs_to :menu_item_instance
end

View File

@@ -1,6 +1,5 @@
class MenuItem < ApplicationRecord
before_create :generate_menu_item_code
# before_create :generate_menu_item_code
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
@@ -8,6 +7,9 @@ class MenuItem < ApplicationRecord
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :account
has_many :menu_item_sets
has_many :item_sets, through: :menu_item_sets
validates_presence_of :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
default_scope { order('item_code asc') }
@@ -73,10 +75,10 @@ class MenuItem < ApplicationRecord
end
private
# private
def generate_menu_item_code
self.item_code = SeedGenerator.generate_code(self.class.name, "I")
end
# def generate_menu_item_code
# self.item_code = SeedGenerator.generate_code(self.class.name, "I")
# end
end

View File

@@ -1,6 +1,6 @@
class MenuItemInstance < ApplicationRecord
belongs_to :menu_item
before_create :generate_menu_item_instance_code
# before_create :generate_menu_item_instance_code
def self.findParentCategory(item)
if item.menu_category_id
@@ -11,9 +11,9 @@ class MenuItemInstance < ApplicationRecord
end
end
private
# private
def generate_menu_item_instance_code
self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II")
end
# def generate_menu_item_instance_code
# self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II")
# end
end

View File

@@ -0,0 +1,4 @@
class MenuItemSet < ApplicationRecord
belongs_to :item_set
belongs_to :menu_item
end

View File

@@ -65,7 +65,6 @@ class Order < ApplicationRecord
end
def adding_line_items
if self.items
#re-order to
ordered_list = re_order_items(self.items)

View File

@@ -91,7 +91,7 @@ class Sale < ApplicationRecord
add_item(item)
end
# link_order_sale(order.id)
link_order_sale(order.id)
end
self.save!

View File

@@ -46,6 +46,8 @@ class SalePayment < ApplicationRecord
payment_status = giftcard_payment
when "paypar"
payment_status = paypar_payment
when "foc"
payment_status = foc_payment
else
puts "it was something else"
end
@@ -164,6 +166,17 @@ class SalePayment < ApplicationRecord
return payment_status
end
def foc_payment
payment_status = false
self.payment_method = "foc"
self.payment_amount = self.received_amount
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.payment_status = "paid"
payment_method = self.save!
sale_update_payment_status(self.received_amount)
return payment_status
end
def creditnote_payment(customer_id)
payment_status = false
@@ -257,11 +270,15 @@ class SalePayment < ApplicationRecord
all_received_amount = 0.0
sObj = Sale.find(self.sale_id)
is_credit = 0
is_foc = 0
sObj.sale_payments.each do |spay|
all_received_amount += spay.payment_amount.to_f
if spay.payment_method == "creditnote"
is_credit = 1
end
if spay.payment_method == "foc"
is_foc = 1
end
end
if (self.sale.grand_total <= all_received_amount)
if is_credit == 0
@@ -269,9 +286,16 @@ class SalePayment < ApplicationRecord
else
self.sale.payment_status = "outstanding"
end
if is_foc == 0
self.sale.payment_status = "paid"
else
self.sale.payment_status = "foc"
end
self.sale.sale_status = "completed"
if MembershipSetting.find_by_rebate(1)
if MembershipSetting.find_by_rebate(1) && is_foc == 0
response = rebat(sObj)
if !response.nil?

View File

@@ -105,7 +105,8 @@ class ShiftSale < ApplicationRecord
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id)

View File

@@ -223,6 +223,14 @@ class CloseCashierPdf < Prawn::Document
text "#{other.paypar_amount.round(2)}", :size => self.item_font_size, :align => :right
end
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
text "FOC :", :size => self.item_font_size, :align => :right
end
bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
text "#{other.foc_amount.round(2)}", :size => self.item_font_size, :align => :right
end
end
else

View File

@@ -54,8 +54,9 @@ class ReceiptBillPdf < Prawn::Document
end
items_account(item_price_by_accounts,printer_settings.precision,delimiter)
sign(sale_data)
footer(printed_status)
end
@@ -409,6 +410,43 @@ class ReceiptBillPdf < Prawn::Document
end
end
def sign(sale_data)
SalePayment.where('sale_id = ?', sale_data.sale_id).each do |payment|
if payment.payment_method == "creditnote"
y_position = cursor
stroke_horizontal_rule
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 70
stroke_horizontal_rule
end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 73
text "Approved By" , :size => self.item_font_size,:align => :center
end
end
end
if sale_data.payment_status == "foc"
y_position = cursor
stroke_horizontal_rule
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 70
stroke_horizontal_rule
end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 73
text "Acknowledged By" , :size => self.item_font_size,:align => :center
end
end
end
def footer(printed_status)
move_down 5
stroke_horizontal_rule
@@ -416,7 +454,7 @@ class ReceiptBillPdf < Prawn::Document
y_position = cursor
bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do
text "#{printed_status}", :size => self.item_font_size,:align => :left
text "#{printed_status}",:style => :bold, :size => self.header_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Thank You! See you Again", :left_margin => -10, :size => self.item_font_size,:align => :left

View File

@@ -1,16 +1,19 @@
<br>
<div class="row">
<div class="col-md-6">
<%= form_tag oqs_root_path, :method => :get do %>
<div class="form-group col-md-4">
<input type="text" name="filter" class="form-control input-sm" placeholder="" style="margin-right: 10px">
</div>
<div class="form-group col-md-8">
<input type="text" name="filter" class="form-control input-md" placeholder="">
</div>
<div class="form-group col-md-1">
<input type="submit" value="Search" class='btn btn-primary btn-sm'>
</div>
<% end %>
<div class="form-group col-md-1">
<input type="submit" value="Search" class='btn btn-primary btn-md'>
</div>
<% end %>
</div>
</div>
<hr>
<!-- Column One -->
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">

View File

@@ -109,7 +109,7 @@
<button id="cash_out" type="button" class="btn btn-block btn-primary"> Cash Out </button>
<!-- Temporary Disabled -->
<%if current_login_employee.role == "cashier" && @shop.quick_sale_summary == true%>
<button id="sale_summary" type="button" class="btn btn-block btn-primary">Sale Sammary</button>
<button id="sale_summary" type="button" class="btn btn-block btn-primary">Sale Summary</button>
<%end%>
<button id="close_cashier" type="button" class="btn btn-block btn-primary"> Close Cashier </button>

View File

@@ -41,24 +41,24 @@
<% sub_total = 0
count = 0
%>
<% @sale_data.sale_items.each do |sale_item|
<% @sale_data.sale_items.each do |sale_item|
count += 1
%>
<% sub_total += sale_item.price%>
<tr>
<% sub_total += sale_item.price%>
<tr>
<td><%= count %></td>
<td style="width:60%; text-align:left">
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-qty"><%=sale_item.qty%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-total-price"><%=(sale_item.price)%></span>
</td>
</tr>
<%end %>
<td style="width:60%; text-align:left">
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-qty"><%=sale_item.qty%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-total-price"><%=(sale_item.price)%></span>
</td>
</tr>
<%end %>
</tbody>
</table>
</div>
@@ -75,7 +75,7 @@
<%else%>
<td style="width:80%; text-align:left; border-top:none"><strong>(Discount)</strong></td>
<%end%>
<td style="width:20%; text-align:right; border-top:none"><strong><span>(<%=@sale_data.total_discount rescue 0%>)</span></strong></td>
</tr>
<tr>
@@ -258,7 +258,7 @@
<!-- Waiter Buttons -->
<button type="button" class="btn btn-primary btn-block" onclick="localStorage.removeItem('cash');window.location.href = '/origami';"> Back </button>
<button type="button" class="btn btn-primary btn-block"> FOC </button>
<button type="button" class="btn btn-primary btn-block" id="foc"> FOC </button>
<button type="button" class="btn btn-primary btn-block" id="void"> Void </button>
</div>
@@ -443,4 +443,44 @@ function update_balance(){
$('#balance').text(result.toFixed(2));
}
$('#foc').click(function() {
$( "#loading_wrapper" ).show();
// payment
var cash = $('#amount_due').text();
var sub_total = $('#sub-total').text();
var sale_id = $('#sale_id').text();
var params = { 'cash':cash,'sale_id':sale_id,'sub_total':sub_total };
$.ajax({type: "POST",
url: "<%= origami_payment_foc_path %>",
data: params,
success:function(result){
localStorage.removeItem("cash");
if (result.status) {
var msg = result.message;
}
else{
var msg = '';
}
$( "#loading_wrapper" ).hide();
$.confirm({
title: 'Infomation!',
content: 'Thank you !',
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
window.location.href = '/origami';
}
}
}
});
}
});
});
</script>

View File

@@ -153,6 +153,12 @@
<td><%=other.paypar_amount.round(2) rescue 0.0 %></td>
<% @total_amount = @total_amount+other.paypar_amount rescue 0.0 %>
</tr>
<tr>
<th></th>
<td style="text-align: right;"><strong>FOC </strong></td>
<td><%=other.foc_amount.round(2) rescue 0.0 %></td>
<% @total_amount = @total_amount+other.foc_amount rescue 0.0 %>
</tr>
<%end%>
<tr>

View File

@@ -0,0 +1,13 @@
<%= simple_form_for(@settings_item_set) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :min_selectable_qty %>
<%= f.input :max_selectable_qty %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>

View File

@@ -0,0 +1,2 @@
json.extract! settings_item_set, :id, :name, :min_selectable_qty, :max_selectable_qty, :created_at, :updated_at
json.url settings_item_set_url(settings_item_set, format: :json)

View File

@@ -0,0 +1,6 @@
<h1>Editing Settings Item Set</h1>
<%= render 'form', settings_item_set: @settings_item_set %>
<%= link_to 'Show', @settings_item_set %> |
<%= link_to 'Back', settings_item_sets_path %>

View File

@@ -0,0 +1,31 @@
<p id="notice"><%= notice %></p>
<h1>Settings Item Sets</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Min selectable qty</th>
<th>Max selectable qty</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @settings_item_sets.each do |settings_item_set| %>
<tr>
<td><%= settings_item_set.name %></td>
<td><%= settings_item_set.min_selectable_qty %></td>
<td><%= settings_item_set.max_selectable_qty %></td>
<td><%= link_to 'Show', settings_item_set %></td>
<td><%= link_to 'Edit', edit_settings_item_set_path(settings_item_set) %></td>
<td><%= link_to 'Destroy', settings_item_set, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Settings Item Set', new_settings_item_set_path %>

View File

@@ -0,0 +1 @@
json.array! @settings_item_sets, partial: 'settings_item_sets/settings_item_set', as: :settings_item_set

View File

@@ -0,0 +1,5 @@
<h1>New Settings Item Set</h1>
<%= render 'form', settings_item_set: @settings_item_set %>
<%= link_to 'Back', settings_item_sets_path %>

View File

@@ -0,0 +1,19 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @settings_item_set.name %>
</p>
<p>
<strong>Min selectable qty:</strong>
<%= @settings_item_set.min_selectable_qty %>
</p>
<p>
<strong>Max selectable qty:</strong>
<%= @settings_item_set.max_selectable_qty %>
</p>
<%= link_to 'Edit', edit_settings_item_set_path(@settings_item_set) %> |
<%= link_to 'Back', settings_item_sets_path %>

View File

@@ -0,0 +1 @@
json.partial! "settings_item_sets/settings_item_set", settings_item_set: @settings_item_set

View File

@@ -1,6 +1,6 @@
<div class="page-header">
<ul class="breadcrumb">
<li><a href="<%= %>">Home</a></li>
<li><a href="<%= settings_menus_path %>">Home</a></li>
<li><a href="<%= settings_menu_categories_path %>">Menus Categories</a></li>
<li>Details</li>
<span style="float: right">

View File

@@ -130,6 +130,7 @@ Rails.application.routes.draw do
get 'sale/:sale_id/first_bill' => 'payments#first_bill', :defaults => { :format => 'json' }
get 'sale/:sale_id/payment' => 'payments#show'
post 'payment/foc' => 'payments#foc', :defaults => { :format => 'json' }
post 'payment/cash' => 'payments#create'
post 'payment/mpu' => "mpu#create"
post 'payment/jcb' => "jcb#create"
@@ -216,6 +217,10 @@ Rails.application.routes.draw do
resources :menu_categories, only: [:new, :create, :edit,:delete]
end
resources :item_sets
resources :menu_item_sets
#accounts
resources :accounts

View File

@@ -0,0 +1,11 @@
class CreateItemSets < ActiveRecord::Migration[5.1]
def change
create_table :item_sets do |t|
t.string :name
t.integer :min_selectable_qty
t.integer :max_selectable_qty
t.timestamps
end
end
end

View File

@@ -0,0 +1,10 @@
class CreateMenuItemSets < ActiveRecord::Migration[5.1]
def change
create_table :menu_item_sets do |t|
t.references :item_set, foreign_key: true
t.references :menu_item, foreign_key: true
t.timestamps
end
end
end

View File

@@ -0,0 +1,10 @@
class CreateMenuInstanceItemSets < ActiveRecord::Migration[5.1]
def change
create_table :menu_instance_item_sets do |t|
t.references :item_set, foreign_key: true
t.references :menu_item_instance, foreign_key: true
t.timestamps
end
end
end

View File

@@ -0,0 +1,141 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
#
# Also compared to earlier versions of this generator, there are no longer any
# expectations of assigns and templates rendered. These features have been
# removed from Rails core in Rails 5, but can be added back in via the
# `rails-controller-testing` gem.
RSpec.describe Settings::ItemSetsController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Settings::ItemSet. As you add validations to Settings::ItemSet, be sure to
# adjust the attributes here as well.
let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
}
let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
}
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# Settings::ItemSetsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "returns a success response" do
item_set = Settings::ItemSet.create! valid_attributes
get :index, params: {}, session: valid_session
expect(response).to be_success
end
end
describe "GET #show" do
it "returns a success response" do
item_set = Settings::ItemSet.create! valid_attributes
get :show, params: {id: item_set.to_param}, session: valid_session
expect(response).to be_success
end
end
describe "GET #new" do
it "returns a success response" do
get :new, params: {}, session: valid_session
expect(response).to be_success
end
end
describe "GET #edit" do
it "returns a success response" do
item_set = Settings::ItemSet.create! valid_attributes
get :edit, params: {id: item_set.to_param}, session: valid_session
expect(response).to be_success
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new Settings::ItemSet" do
expect {
post :create, params: {settings_item_set: valid_attributes}, session: valid_session
}.to change(Settings::ItemSet, :count).by(1)
end
it "redirects to the created settings_item_set" do
post :create, params: {settings_item_set: valid_attributes}, session: valid_session
expect(response).to redirect_to(Settings::ItemSet.last)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'new' template)" do
post :create, params: {settings_item_set: invalid_attributes}, session: valid_session
expect(response).to be_success
end
end
end
describe "PUT #update" do
context "with valid params" do
let(:new_attributes) {
skip("Add a hash of attributes valid for your model")
}
it "updates the requested settings_item_set" do
item_set = Settings::ItemSet.create! valid_attributes
put :update, params: {id: item_set.to_param, settings_item_set: new_attributes}, session: valid_session
item_set.reload
skip("Add assertions for updated state")
end
it "redirects to the settings_item_set" do
item_set = Settings::ItemSet.create! valid_attributes
put :update, params: {id: item_set.to_param, settings_item_set: valid_attributes}, session: valid_session
expect(response).to redirect_to(item_set)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'edit' template)" do
item_set = Settings::ItemSet.create! valid_attributes
put :update, params: {id: item_set.to_param, settings_item_set: invalid_attributes}, session: valid_session
expect(response).to be_success
end
end
end
describe "DELETE #destroy" do
it "destroys the requested settings_item_set" do
item_set = Settings::ItemSet.create! valid_attributes
expect {
delete :destroy, params: {id: item_set.to_param}, session: valid_session
}.to change(Settings::ItemSet, :count).by(-1)
end
it "redirects to the settings_item_sets list" do
item_set = Settings::ItemSet.create! valid_attributes
delete :destroy, params: {id: item_set.to_param}, session: valid_session
expect(response).to redirect_to(settings_item_sets_url)
end
end
end

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Settings::ItemSetsHelper. For example:
#
# describe Settings::ItemSetsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Settings::ItemSetsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ItemSet, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe MenuInstanceItemSet, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe MenuItemSet, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Settings::ItemSet, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,10 @@
require 'rails_helper'
RSpec.describe "Settings::ItemSets", type: :request do
describe "GET /settings_item_sets" do
it "works! (now write some real specs)" do
get settings_item_sets_path
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,39 @@
require "rails_helper"
RSpec.describe Settings::ItemSetsController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/settings/item_sets").to route_to("settings/item_sets#index")
end
it "routes to #new" do
expect(:get => "/settings/item_sets/new").to route_to("settings/item_sets#new")
end
it "routes to #show" do
expect(:get => "/settings/item_sets/1").to route_to("settings/item_sets#show", :id => "1")
end
it "routes to #edit" do
expect(:get => "/settings/item_sets/1/edit").to route_to("settings/item_sets#edit", :id => "1")
end
it "routes to #create" do
expect(:post => "/settings/item_sets").to route_to("settings/item_sets#create")
end
it "routes to #update via PUT" do
expect(:put => "/settings/item_sets/1").to route_to("settings/item_sets#update", :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "/settings/item_sets/1").to route_to("settings/item_sets#update", :id => "1")
end
it "routes to #destroy" do
expect(:delete => "/settings/item_sets/1").to route_to("settings/item_sets#destroy", :id => "1")
end
end
end

View File

@@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe "settings/item_sets/edit", type: :view do
before(:each) do
@settings_item_set = assign(:settings_item_set, Settings::ItemSet.create!(
:name => "MyString",
:min_selectable_qty => 1,
:max_selectable_qty => 1
))
end
it "renders the edit settings_item_set form" do
render
assert_select "form[action=?][method=?]", settings_item_set_path(@settings_item_set), "post" do
assert_select "input[name=?]", "settings_item_set[name]"
assert_select "input[name=?]", "settings_item_set[min_selectable_qty]"
assert_select "input[name=?]", "settings_item_set[max_selectable_qty]"
end
end
end

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe "settings/item_sets/index", type: :view do
before(:each) do
assign(:settings_item_sets, [
Settings::ItemSet.create!(
:name => "Name",
:min_selectable_qty => 2,
:max_selectable_qty => 3
),
Settings::ItemSet.create!(
:name => "Name",
:min_selectable_qty => 2,
:max_selectable_qty => 3
)
])
end
it "renders a list of settings/item_sets" do
render
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => 2.to_s, :count => 2
assert_select "tr>td", :text => 3.to_s, :count => 2
end
end

View File

@@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe "settings/item_sets/new", type: :view do
before(:each) do
assign(:settings_item_set, Settings::ItemSet.new(
:name => "MyString",
:min_selectable_qty => 1,
:max_selectable_qty => 1
))
end
it "renders new settings_item_set form" do
render
assert_select "form[action=?][method=?]", settings_item_sets_path, "post" do
assert_select "input[name=?]", "settings_item_set[name]"
assert_select "input[name=?]", "settings_item_set[min_selectable_qty]"
assert_select "input[name=?]", "settings_item_set[max_selectable_qty]"
end
end
end

View File

@@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe "settings/item_sets/show", type: :view do
before(:each) do
@settings_item_set = assign(:settings_item_set, Settings::ItemSet.create!(
:name => "Name",
:min_selectable_qty => 2,
:max_selectable_qty => 3
))
end
it "renders attributes in <p>" do
render
expect(rendered).to match(/Name/)
expect(rendered).to match(/2/)
expect(rendered).to match(/3/)
end
end

View File

@@ -0,0 +1,9 @@
require "application_system_test_case"
class Settings::ItemSetsTest < ApplicationSystemTestCase
# test "visiting the index" do
# visit settings_item_sets_url
#
# assert_selector "h1", text: "Settings::ItemSet"
# end
end