added induties

This commit is contained in:
Myat Zin Wai Maw
2019-06-17 17:45:21 +06:30
parent 98bbf419fe
commit 047f2941cb
37 changed files with 822 additions and 24 deletions

View File

@@ -35,6 +35,7 @@
//= require BSBMaterial/demo.js
//= require custom.js
//= require jquery-fileupload/basic
//= require induties/induties.js
$(document).ready(function() {
$('.count-to').countTo();

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

@@ -11,6 +11,7 @@
@import "BSBMaterial/style";
@import "BSBMaterial/themes/all-themes";
@import "reset";
@import "induties/assign_in_duties";
/*@import "bootstrap-select/css/bootstrap-select.min";*/

View File

@@ -0,0 +1,92 @@
// Place all the styles related to the induties/assign_in_duties controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.custom-card-head{
height: 40px;
background-color: grey;
color :#fff;
opacity: 0.8;
padding:5px;
font-weight:400;
align-items: center;
}
.form-group .form-control {
width: 100%;
border: none;
box-shadow: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
-ms-border-radius: 0;
border-radius: 0;
padding-left: 0;
}
.radio-room{
margin-right:2rem;
}
.radio-table{
margin-left:1rem;
}
.bmd-form-group {
position: relative;
padding-top: 0 !important;
}
.btn_create_induty{
display: inline;
padding: 1.5rem;
margin: 0;
}
.create_induty_card{
min-height:500px;
}
#save_induties_by_name{
-webkit-appearance: none;
}
.checkboxLabel:before{
content: '\e40c';
font-family: "Material Icons";
font-size: 25px;
vertical-align: middle;
margin-right: 5px;
color: #2196F3;
}
#save_induties_by_name:checked ~ .checkboxLabel:before{
content: '\e86c';
}
.checkboxLabel {
font-size: 18px !important;
}
.add_more{
content: '\e40c';
font-family: "Material Icons";
font-size: 25px;
vertical-align: middle;
margin-right: 5px;
color: #2196F3;
}
.success-msg {
color: #270;
background-color: #DFF2BF;
margin: 10px 0;
padding: 10px;
border-radius: 3px 3px 3px 3px;
display: none;
margin-right: 0.5rem;
margin-left: 0.5rem;
}
.show_all_commissioner_card{
min-height: 790px;
max-height: 790px;
overflow: scroll;
}
.sweet-alert p {
font-size: 14px !important;
font-weight:bold;
}
.sweet-alert {
top :0;
margin-top: 20px !important;
}

View File

@@ -0,0 +1,54 @@
class Induties::AssignInDutiesController < ApplicationController
def index
@commissioners=Commissioner.active.all.order(created_at: :desc)
@booking_id = params[:booking_id]
end
def get_all_occupied_dining
commissionerIds =params[:id]
@check_in_commissioner =InDuty.select("in_duties.*,dining_facilities.type as dinning_type")
.joins(" LEFT JOIN dining_facilities on dining_facilities.id = in_duties.dinning_id").where('commissioner_ids =? and out_time is null', commissionerIds);
# Rails.logger.info(@check_in_commissioner.to_json)
respond_to do |format|
format.json { render json: @check_in_commissioner.to_json }
end
end
def induties_create
commissioner_ids =params[:commissionerId]
booking_id =params[:booking_id]
dinning_id = params[:dinning_id]
induty = InDuty.new
induty.dinning_id = dinning_id
induty.booking_id = booking_id
induty.commissioner_ids = commissioner_ids
induty.by_name = params[:by_name]
induty.in_time = Time.now
if induty.save
dinning = DiningFacility.find(induty.dinning_id)
@induty= {"id"=>induty.id,
"dinning_id"=>induty.dinning_id,
"in_time"=>induty.in_time,
"out_time"=>induty.out_time,
"dinning_type"=>dinning.type }
respond_to do |format|
format.json { render json: @induty.to_json }
end
end
end
def induties_checkout
induty_id = params[:induty_id]
induty = InDuty.find(induty_id)
induty.out_time = Time.now
induty.save
@induty =induty
respond_to do |format|
format.json { render json: @induty.to_json }
end
end
def induties_remove
induty_id = params[:induty_id]
induty = InDuty.find(induty_id)
induty.destroy
end
end

View File

@@ -18,6 +18,7 @@ class Settings::CommissionersController < ApplicationController
def new
@commissioner = Commissioner.new
@employee = Employee.all.order('name asc')
end
# GET /commissioners/1/edit
@@ -35,6 +36,8 @@ class Settings::CommissionersController < ApplicationController
unless @commissioner.resigned_date.nil?
@commissioner.resigned_date = @commissioner.resigned_date.utc.getlocal.strftime('%Y-%b-%d')
end
# puts params[:from_induty].length
if (params[:from_induty] != "true")
respond_to do |format|
if @commissioner.save
format.html {redirect_to settings_commissioners_path, notice: 'Commissioner was successfully created.'}
@@ -44,6 +47,11 @@ class Settings::CommissionersController < ApplicationController
format.json {render json: @commissioner.errors, status: :unprocessable_entity}
end
end
else
@commissioner.save
flash[:notice] = 'Commissioner was successfully created.'
redirect_to induties_assign_in_duties_path(params[:booking_id])
end
end
# PATCH/PUT /commissioners/1

View File

@@ -0,0 +1,2 @@
module Induties::AssignInDutiesHelper
end

5
app/models/induties.rb Normal file
View File

@@ -0,0 +1,5 @@
module Induties
def self.table_name_prefix
'induties_'
end
end

View File

@@ -0,0 +1,2 @@
class Induties::AssignInDuty < ApplicationRecord
end

View File

@@ -0,0 +1,10 @@
<%= simple_form_for(@induties_assign_in_duty) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>

View File

@@ -0,0 +1,2 @@
json.extract! induties_assign_in_duty, :id, :created_at, :updated_at
json.url induties_assign_in_duty_url(induties_assign_in_duty, format: :json)

View File

@@ -0,0 +1,6 @@
<h1>Editing Induties Assign In Duty</h1>
<%= render 'form', induties_assign_in_duty: @induties_assign_in_duty %>
<%= link_to 'Show', @induties_assign_in_duty %> |
<%= link_to 'Back', induties_assign_in_duties_path %>

View File

@@ -0,0 +1,306 @@
<!-- <div class="page-header">
<ol class="breadcrumb">
<span class="float-right">
<a href="" id="back">Back</a>
</span>
</ol>
</div> -->
<div class="row">
<div class="col-md-12 col-sm-12 col-lg-8">
<div class="card show_all_commissioner_card">
<div class="card-block row" style="margin:0.5rem;">
<% @commissioners.each do |com| %>
<div class="col-md-6 col-sm-6 col-lg-3 mt-3 touch_commissioner" commissionerId='<%= com.id %>' commissionerName='<%= com.name %>'>
<div class="card custom-card testimonial-card fadeInRight" style="height:100%;background-image:url(<%= com.image_path.url%>);background-repeat: no-repeat; background-size: cover;">
<div class="custom-card-head card-head row" style="line-height:14px;margin:0px;">
<div class="col-md-10 " style="padding:0px !important;"><%=com.name %>
</div>
</div>
<div class="add_icon p-t-65 p-b-65 m-r-">
</div>
</div>
</div>
<% end %>
<div class="col-md-6 col-sm-6 col-lg-3 mt-3 add_more_commissioner">
<div class="card custom-card testimonial-card fadeInRight" style="height:100%;width: 100%;">
<div class="row" style="margin: auto;">
<i class="material-icons" style="color: gray;font-size: 9rem;">add</i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12 col-sm-12 col-lg-4" id="show_list_induty_card">
<div class="card" >
<div class="alert success-msg" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<i class="fa fa-check"></i>
Successed!
</div>
<div class="card-header row" style="margin-right: 0;margin-left: 0">
<div class="col-7 commissionerName"><label>Create In Duty</label></div>
<div class="col-5"><button type="button" class="btn btn-block btn-default waves-effect" id="back"><i class="material-icons">reply</i>Back to Order</button></div>
</div>
<input type="hidden" name="booking_id" value="<%=@booking_id %>" id="booking_id">
<input type="hidden" name="commissionerId" value="" id="commissionerId">
<div class="row create_induty_card" style="margin-left:1rem;margin-right: 1rem;">
<table class="table table-striped" id="show_in_duty_table">
<thead >
<tr>
<th>Dining</th>
<th>Check In At</th>
<th>Action</th>
</tr>
</thead>
<tbody class="occupide_dining">
</tbody>
</table>
</div>
<div class="row form-inputs form-group" style="margin: auto;">
<hr style="width :100%">
<div class="col-12 " style="margin-top: 1rem;">
<div class="row form-inputs form-group" style="margin: auto;">
<div class="col-12" >
<label class="radio-room"><input type="radio" name="radio" id="radio-room" value="room" checked="checked" /> Room</label>
<label class="radio-table"><input type="radio" name="radio" id="radio-table" value="table" /> Table</label>
</div>
</div>
<div class="row form-inputs form-group room_collection" style="margin: auto;">
<div class="col-12 ">
<%= simple_form_for 'zone', :method => :get do |f| %>
<%= f.collection_select :dinning_id, Room.all, :id, :name, {prompt: 'Select Room'},:class=>'form-control',:required => true %>
<%end %>
</div>
</div>
<div class="row form-inputs form-group table_collection" style="margin: auto;">
<div class="col-12 ">
<%= simple_form_for 'zone_t', :method => :get do |f| %>
<%= f.collection_select :dinning_id, Table.all, :id, :name, {prompt: 'Select Table'},:class=>'form-control',:required => true %>
<%end %>
</div>
</div>
</div>
</div>
<div class="row form-inputs form-group" style="margin: auto;">
<div class=" col-12 ">
<%= simple_form_for 'save_induties', :url => induties_induties_create_path, :method => :post do |f| %>
<%= f.check_box :by_name,:class=>'form-control'%>
<label class="checkboxLabel" for="save_induties_by_name">By Name</label>
<% end %>
</div>
</div>
<a href="" id="btn_create_induty" class=" btn bg-blue form-actions btn_create_induty">Create In Duty</a>
</div>
</div>
</div>
<script type="text/javascript">
$(".table_collection").hide();
$('#back').on('click',function(){
event.preventDefault();
var dinning_id = localStorage.getItem('dinning_id');
var dinning_type = localStorage.getItem('dinning_type');
window.location.href = '/origami/'+dinning_type+'/'+dinning_id;
});
$( document ).ready(function() {
document.getElementById("btn_create_induty").disabled = true;
});
$(document).on('click', '.btn_create_induty', function(event){
event.preventDefault();
var str=document.getElementById("zone_dinning_id").value;
var str_t=document.getElementById("zone_t_dinning_id").value;
if (str == ""){
zone_dinning_id =document.getElementById("zone_t_dinning_id").value;
}
if (str_t == ""){
zone_dinning_id =document.getElementById("zone_dinning_id").value;
}
if(str == "" && str_t == ""){
document.getElementById('zone_dinning_id').focus();
$('#zone_dinning_id').css('border-color', 'red');
$('#zone_t_dinning_id').css('border-color', 'red');
return false
}
else{
var booking_id=document.getElementById("booking_id").value
var commissionerId=document.getElementById("commissionerId").value
var by_name =document.getElementById("save_induties_by_name").checked
$.ajax({
type: "POST",
url: "assign_create",
dataType: "json",
data: {booking_id:booking_id,commissionerId:commissionerId,dinning_id:zone_dinning_id,by_name:by_name},
success: function (data) {
in_time = changDateFormat(data.in_time);
d_type = data.dinning_type.charAt(0);
row ='<tr>'
+'<td>'+d_type+'-'+data.dinning_id+'</td>'
+'<td>'+in_time+'</td>'
+'<td><a href="" onclick = "checkout_induty(this)" class="btn checkout_induty" style= "background-color: #3F51B5;"indutyId="'+ data.id +'" >Check Out</a>&nbsp;<a href="" onclick = "remove_induty(this)" class="btn remove_induty" style= "background-color: red;"indutyId="'+ data.id +'" >Remove</a></td>'
+'</tr>';
$('.occupide_dining').append(row);
$('#zone_dinning_id').val("");
document.getElementById("save_induties_by_name").checked = false;
var scrollTo = document.getElementById('show_list_induty_card');
$("HTML, body").animate({scrollTop: scrollTo.offsetTop - 60 }, 500 );
$(".success-msg").css('display','block');
}
});
}
});
$(document).on('click', '.touch_commissioner', function(event){
$(".success-msg").css('display','none');
document.getElementById("btn_create_induty").disabled = false;
var commissionerId = this.getAttribute("commissionerId");
var commissionerName = this.getAttribute("commissionerName");
var url = "get_all_occupied_dining_path" ;
$('.occupide_dining').html("");
$('.commissionerName').html("");
booking_id=document.getElementById("booking_id").value
$.ajax({
type: "GET",
url: "/induties/assign_in_duties/get_all_occupied_dining/"+commissionerId,
dataType: "json",
success: function (data) {
$('.commissionerName').append('<label>'+commissionerName+' ('+booking_id+' )</label');
data.forEach(function(items) {
in_time = changDateFormat(items.in_time);
d_type = items.dinning_type.charAt(0);
// console.log(d_type);
// if(items.out_time == null){
row ='<tr>'
+'<td>'+d_type+'-'+items.dinning_id+'</td>'
+'<td>'+in_time+'</td>'
+'<td><a href="" onclick = "checkout_induty(this)" class="btn checkout_induty" style= "background-color: #3F51B5;"indutyId="'+ items.id +'" >Check Out</a>&nbsp;<a href="" onclick = "remove_induty(this)" class="btn remove_induty" style= "background-color: red;"indutyId="'+ items.id +'" >Remove</a></td>'
+'</tr>';
// }
// else{
// out_time = changDateFormat(items.out_time);
// row ='<tr>'
// +'<td>'+items.dinning_id+'</td>'
// +'<td>'+in_time+'</td>'
// +'<td>'+out_time+'</td>'
// +'</tr>';
// }
$('.occupide_dining').append(row);
});
$('#commissionerId').val(commissionerId);
var scrollTo = document.getElementById('show_list_induty_card');
$("HTML, body").animate({scrollTop: scrollTo.offsetTop - 60 }, 500 );
}
});
});
function changDateFormat(date){
datetime = new Date(date);
day = datetime.getDate();
month = datetime.getMonth() + 1; //month: 0-11
year = datetime.getFullYear();
date = year + "-" + day + "-" + month;
var hours = datetime.getHours();
var minutes = datetime.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var in_time = date +' '+hours + ':' + minutes + ' ' + ampm;
return in_time;
}
$('input[type=radio]').change(function() {
if(this.value == "room"){
// $(".table_collection").hide();
$(".table_collection").css('display','none');
// $(".room_collection").show();
$(".room_collection").css('display','block');
}
else{
// $(".room_collection").hide();
$(".room_collection").css('display','none');
// $(".table_collection").show();
$(".table_collection").css('display','block');
}
});
function checkout_induty(row){
event.preventDefault();
var indutyId = row.getAttribute("indutyId");
var booking_id=document.getElementById("booking_id").value
datetime = new Date();
datetime = changDateFormat(datetime);
swal({
title: '',
text: 'Are you sure want to checkout at ' +datetime,
html:true,
confirmButtonColor: "#3F51B5",
confirmButtonText: "OK",
closeOnConfirm: true,
showCancelButton: true,
cancelButtonColor: '#d33',
}, function(isConfirm){
if(isConfirm){
$.ajax({
type: "POST",
url: "assign_checkout/"+indutyId,
dataType: "json",
success: function (data) {
var d = row.parentNode.parentNode.rowIndex;
document.getElementById('show_in_duty_table').deleteRow(d);
// in_time = changDateFormat(data.in_time);
// out_time = changDateFormat(data.out_time);
// row ='<tr>'
// +'<td>'+data.dinning_id+'</td>'
// +'<td>'+in_time+'</td>'
// +'<td>'+out_time+'</td>'
// +'</tr>';
// $('.occupide_dining').append(row);
var scrollTo = document.getElementById('show_list_induty_card');
$("HTML, body").animate({scrollTop: scrollTo.offsetTop - 60 }, 500 );
$(".success-msg").css('display','block');
}
});
}
});
}
function remove_induty(row){
event.preventDefault();
var indutyId = row.getAttribute("indutyId");
var booking_id=document.getElementById("booking_id").value
swal({
title: '',
text: 'Are you sure want to remove induties ',
html:true,
confirmButtonColor: "#3F51B5",
confirmButtonText: "OK",
closeOnConfirm: true,
showCancelButton: true,
cancelButtonColor: '#d33',
}, function(isConfirm){
if(isConfirm){
$.ajax({
type: "DELETE",
url: "assign_remove/"+indutyId,
dataType: "json",
success: function (data) {
var d = row.parentNode.parentNode.rowIndex;
document.getElementById('show_in_duty_table').deleteRow(d);
var scrollTo = document.getElementById('show_list_induty_card');
$("HTML, body").animate({scrollTop: scrollTo.offsetTop - 60 }, 500 );
$(".success-msg").css('display','block');
}
});
}
});
}
$(document).on('click', '.add_more_commissioner', function(event){
localStorage.setItem('from_induty', true);
localStorage.setItem('booking_id', document.getElementById("booking_id").value);
window.location.href ='/settings/commissioners/new';
});
localStorage.setItem('from_induty', false);
</script>

View File

@@ -0,0 +1 @@
json.array! @induties_assign_in_duties, partial: 'induties_assign_in_duties/induties_assign_in_duty', as: :induties_assign_in_duty

View File

@@ -0,0 +1,5 @@
<h1>New Induties Assign In Duty</h1>
<%= render 'form', induties_assign_in_duty: @induties_assign_in_duty %>
<%= link_to 'Back', induties_assign_in_duties_path %>

View File

@@ -0,0 +1,4 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_induties_assign_in_duty_path(@induties_assign_in_duty) %> |
<%= link_to 'Back', induties_assign_in_duties_path %>

View File

@@ -0,0 +1 @@
json.partial! "induties_assign_in_duties/induties_assign_in_duty", induties_assign_in_duty: @induties_assign_in_duty

View File

@@ -219,6 +219,7 @@
getCreditSales("","","cashier"); //credit sales script data binding
$(".tables").on('click', function(){
localStorage.setItem('dinning_type','table');
var dining_id = $(this).attr("data-id");
window.location.href = '/origami/table/' + dining_id;
});
@@ -229,6 +230,7 @@
});
$(".rooms").on('click', function(){
localStorage.setItem('dinning_type','room');
var dining_id = $(this).attr("data-id");
window.location.href = '/origami/room/' + dining_id;
});

View File

@@ -825,7 +825,7 @@
window.location.href = '/origami/table/' + dining_id + "/table_invoice/" + sale_id;
})
$(".tables").on('click', function () {
localStorage.setItem('dinning_type','table');
var customer_id = $(".customer-id").text();
show_customer_details(customer_id);
@@ -843,7 +843,7 @@
});
$(".rooms").on('click', function () {
localStorage.setItem('dinning_type','room');
var customer_id = $(".customer-id").text();
show_customer_details(customer_id);
@@ -1207,9 +1207,10 @@
});
$('#in_duties').on('click', function () {
localStorage.setItem('dinning_id',<%= @dining.id %>);
var dining_id = "<%= @dining.id %>";
var booking_id = "<%= @booking.booking_id rescue "" %>";
window.location.href = '/origami/assign_in_duty/'+ booking_id;
window.location.href = '/induties/'+ booking_id +'/assign';
});
$('#void').on('click', function () {

View File

@@ -1,9 +1,6 @@
<div class="row">
<div class="col-md-8">
<br/>
<div class="card">
<div class="card-header">
<label>Dining Name:</label>

View File

@@ -914,6 +914,7 @@ $(document).ready(function(){
show_customer_details(customer_id);
var dining_id = $(this).attr("data-id");
localStorage.setItem('dinning_type','table');
window.location.href = '/origami/table/' + dining_id;
});
@@ -932,6 +933,7 @@ $(document).ready(function(){
show_customer_details(customer_id);
var dining_id = $(this).attr("data-id");
localStorage.setItem('dinning_type','room');
window.location.href = '/origami/room/' + dining_id;
});
@@ -1367,9 +1369,10 @@ $('#add_invoice').on('click',function(){
});
$('#in_duties').on('click', function () {
localStorage.setItem('dinning_id',<%= @room.id %>);
var dining_id = "<%= @room.id %>";
var booking_id = "<%= @booking.booking_id rescue "" %>";
window.location.href = '/origami/assign_in_duty/'+ booking_id;
window.location.href = '/induties/'+ booking_id +'/assign';
});
// Ordering

View File

@@ -36,6 +36,8 @@
<%= f.label :resigned_date %><br/>
<%= f.text_field :resigned_date, {class: 'form-control datepicker', id: 'resigned_date', readonly: true} %><br/>
<%= f.input :is_active %>
<input type="hidden" name="from_induty" value="" class="from_induty">
<input type="hidden" name="booking_id" value="" class="booking_id">
</div>
<div class="form-actions">
@@ -70,3 +72,7 @@
</div>
</div>
</div>
<script type="text/javascript">
$('.from_induty').val(localStorage.getItem('from_induty'));
$('.booking_id').val(localStorage.getItem('booking_id'));
</script>

View File

@@ -10,3 +10,4 @@
</div>
<%= render 'form', commissioner: @commissioner %>

View File

@@ -1,10 +1,10 @@
application_path="#{File.expand_path("../..", __FILE__)}"
directory application_path
#environment ENV.fetch("RAILS_ENV") { "production" }
environment "production"
pidfile "#{application_path}/tmp/puma/pid"
state_path "#{application_path}/tmp/puma/state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
port ENV.fetch("PORT") { 62158 }
workers 2
preload_app!
# application_path="#{File.expand_path("../..", __FILE__)}"
# directory application_path
# #environment ENV.fetch("RAILS_ENV") { "production" }
# environment "production"
# pidfile "#{application_path}/tmp/puma/pid"
# state_path "#{application_path}/tmp/puma/state"
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
# port ENV.fetch("PORT") { 62158 }
# workers 2
# preload_app!

View File

@@ -2,6 +2,14 @@ require 'sidekiq/web'
Rails.application.routes.draw do
namespace :induties do
# resources :assign_in_duties
get ':booking_id/assign' => 'assign_in_duties#index', as: :assign_in_duties
get "/assign_in_duties/get_all_occupied_dining/:id" =>'assign_in_duties#get_all_occupied_dining', as: :get_all_occupied_dining
post ':booking_id/assign_create' => 'assign_in_duties#induties_create', as: :induties_create
post ':booking_id/assign_checkout/:induty_id' => 'assign_in_duties#induties_checkout', as: :induties_checkout
delete ':booking_id/assign_remove/:induty_id' => 'assign_in_duties#induties_remove', as: :induties_remove
end
scope "(:locale)", locale: /en|mm/ do
root 'home#index'
mount Sidekiq::Web => '/kiq'

View File

@@ -0,0 +1,5 @@
class AddBynameToInduties < ActiveRecord::Migration[5.1]
def change
add_column :in_duties, :by_name, :boolean, default: false
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 Induties::AssignInDutiesController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Induties::AssignInDuty. As you add validations to Induties::AssignInDuty, 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
# Induties::AssignInDutiesController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe "GET #index" do
it "returns a success response" do
assign_in_duty = Induties::AssignInDuty.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
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
get :show, params: {id: assign_in_duty.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
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
get :edit, params: {id: assign_in_duty.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 Induties::AssignInDuty" do
expect {
post :create, params: {induties_assign_in_duty: valid_attributes}, session: valid_session
}.to change(Induties::AssignInDuty, :count).by(1)
end
it "redirects to the created induties_assign_in_duty" do
post :create, params: {induties_assign_in_duty: valid_attributes}, session: valid_session
expect(response).to redirect_to(Induties::AssignInDuty.last)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'new' template)" do
post :create, params: {induties_assign_in_duty: 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 induties_assign_in_duty" do
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
put :update, params: {id: assign_in_duty.to_param, induties_assign_in_duty: new_attributes}, session: valid_session
assign_in_duty.reload
skip("Add assertions for updated state")
end
it "redirects to the induties_assign_in_duty" do
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
put :update, params: {id: assign_in_duty.to_param, induties_assign_in_duty: valid_attributes}, session: valid_session
expect(response).to redirect_to(assign_in_duty)
end
end
context "with invalid params" do
it "returns a success response (i.e. to display the 'edit' template)" do
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
put :update, params: {id: assign_in_duty.to_param, induties_assign_in_duty: invalid_attributes}, session: valid_session
expect(response).to be_success
end
end
end
describe "DELETE #destroy" do
it "destroys the requested induties_assign_in_duty" do
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
expect {
delete :destroy, params: {id: assign_in_duty.to_param}, session: valid_session
}.to change(Induties::AssignInDuty, :count).by(-1)
end
it "redirects to the induties_assign_in_duties list" do
assign_in_duty = Induties::AssignInDuty.create! valid_attributes
delete :destroy, params: {id: assign_in_duty.to_param}, session: valid_session
expect(response).to redirect_to(induties_assign_in_duties_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 Induties::AssignInDutiesHelper. For example:
#
# describe Induties::AssignInDutiesHelper 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 Induties::AssignInDutiesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "induties/assign_in_duties/edit", type: :view do
before(:each) do
@induties_assign_in_duty = assign(:induties_assign_in_duty, Induties::AssignInDuty.create!())
end
it "renders the edit induties_assign_in_duty form" do
render
assert_select "form[action=?][method=?]", induties_assign_in_duty_path(@induties_assign_in_duty), "post" do
end
end
end

View File

@@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "induties/assign_in_duties/index", type: :view do
before(:each) do
assign(:induties_assign_in_duties, [
Induties::AssignInDuty.create!(),
Induties::AssignInDuty.create!()
])
end
it "renders a list of induties/assign_in_duties" do
render
end
end

View File

@@ -0,0 +1,14 @@
require 'rails_helper'
RSpec.describe "induties/assign_in_duties/new", type: :view do
before(:each) do
assign(:induties_assign_in_duty, Induties::AssignInDuty.new())
end
it "renders new induties_assign_in_duty form" do
render
assert_select "form[action=?][method=?]", induties_assign_in_duties_path, "post" do
end
end
end

View File

@@ -0,0 +1,11 @@
require 'rails_helper'
RSpec.describe "induties/assign_in_duties/show", type: :view do
before(:each) do
@induties_assign_in_duty = assign(:induties_assign_in_duty, Induties::AssignInDuty.create!())
end
it "renders attributes in <p>" do
render
end
end

View File

@@ -0,0 +1,9 @@
require "application_system_test_case"
class Induties::AssignInDutiesTest < ApplicationSystemTestCase
# test "visiting the index" do
# visit induties_assign_in_duties_url
#
# assert_selector "h1", text: "Induties::AssignInDuty"
# end
end