diff --git a/.travis.yml b/.travis.yml
index 5cbcbff5..6b755814 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,4 +4,6 @@ rvm:
bundler_args: --without development staging production
sudo: false
before_script:
- - bundle exec rake db:test:prepare
+ - bundle exec rake test:prepare
+ - bundle exec rake db:migrate
+ - export TZ='America/New_York'
diff --git a/Gemfile b/Gemfile
index 8250c27e..d5304fce 100644
--- a/Gemfile
+++ b/Gemfile
@@ -26,6 +26,11 @@ gem 'activeldap', :require => 'active_ldap/railtie'
# For Card-lookup requests
gem 'savon'
+# For delayed jobs
+gem 'daemons'
+gem 'delayed_job'
+gem 'delayed_job_active_record'
+
# For Capistrano deployment
group :development do
gem 'capistrano-rbenv', require: false
@@ -44,6 +49,7 @@ group :development do
# sudo commands in capistrano
gem 'sshkit-sudo'
+
end
# Document attachments
@@ -65,6 +71,9 @@ gem 'twilio-ruby'
# Dossier for reports
gem 'dossier'
+# Single test gem for unit testing
+gem 'single_test'
+
group :development do
# Automatically generate comments in models and such based on schema
gem 'annotate'
@@ -84,6 +93,7 @@ end
group :development, :staging, :production do
gem 'newrelic_rpm'
gem 'mysql2'
+ gem 'capistrano3-delayed-job'
end
group :test do
@@ -113,4 +123,5 @@ end
group :staging, :production do
gem 'passenger'
-end
+
+end
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index 2d8549ef..60dacdc3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -78,6 +78,8 @@ GEM
capistrano-rbenv (2.0.4)
capistrano (~> 3.1)
sshkit (~> 1.3)
+ capistrano3-delayed-job (1.7.2)
+ capistrano (~> 3.0, >= 3.0.0)
carrierwave (0.11.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
@@ -103,6 +105,11 @@ GEM
safe_yaml (~> 1.0.0)
daemons (1.2.3)
debug_inspector (0.0.2)
+ delayed_job (4.1.2)
+ activesupport (>= 3.0, < 5.1)
+ delayed_job_active_record (4.1.1)
+ activerecord (>= 3.0, < 5.1)
+ delayed_job (>= 3.0, < 5)
devise (3.5.6)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@@ -269,6 +276,8 @@ GEM
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
+ single_test (0.6.0)
+ rake
spring (1.6.4)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
@@ -337,9 +346,13 @@ DEPENDENCIES
capistrano-passenger
capistrano-rails
capistrano-rbenv
+ capistrano3-delayed-job
carrierwave
coffee-rails
coveralls
+ daemons
+ delayed_job
+ delayed_job_active_record
devise
dossier
factory_girl_rails
@@ -366,6 +379,7 @@ DEPENDENCIES
shoulda
shoulda-matchers
simple_form
+ single_test
spring
sqlite3
sshkit-sudo
@@ -378,5 +392,8 @@ DEPENDENCIES
will_paginate
will_paginate-bootstrap
+RUBY VERSION
+ ruby 2.3.0p0
+
BUNDLED WITH
- 1.11.2
+ 1.14.5
diff --git a/Rakefile b/Rakefile
index b9fcfc93..b457ecd6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,5 +2,6 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
+require 'single_test/tasks'
Trailerapp::Application.load_tasks
diff --git a/app/controllers/certifications_controller.rb b/app/controllers/certifications_controller.rb
new file mode 100644
index 00000000..682aec0c
--- /dev/null
+++ b/app/controllers/certifications_controller.rb
@@ -0,0 +1,44 @@
+class CertificationsController < ApplicationController
+ load_and_authorize_resource
+
+ before_action :set_participant, only: [:new, :create]
+ before_action :set_certification, only: [:destroy]
+ before_action :check_all_certifications, except: [:destroy]
+
+ def new
+ @certification = Certification.new(:participant => @participant)
+ respond_with @certification
+ end
+
+ def create
+ @certification = Certification.new(certification_params)
+ @certification.participant = @participant
+ @certification.save
+ respond_with @certification, location: -> { @certification.participant }
+ end
+
+ def destroy
+ @certification.destroy
+ respond_with @certification, location: -> { @certification.participant }
+ end
+
+ private
+ def set_participant
+ @participant = Participant.find(params[:participant_id])
+ end
+
+ def set_certification
+ @certification = Certification.find(params[:id])
+ end
+
+ def check_all_certifications
+ if @participant.certifications.size == CertificationType.all.size
+ redirect_to (participant_path @participant), :flash => { :error => @participant.name + " has already gotten all certifications." }
+ end
+ end
+
+ def certification_params
+ params.require(:certification).permit(:participant_id, :certification_type_id)
+ end
+
+end
diff --git a/app/controllers/charge_types_controller.rb b/app/controllers/charge_types_controller.rb
index 1095c4a9..8b4e81ab 100644
--- a/app/controllers/charge_types_controller.rb
+++ b/app/controllers/charge_types_controller.rb
@@ -1,3 +1,20 @@
+# ## Schema Information
+#
+# Table name: `charge_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------------------ | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`default_amount`** | `decimal(8, 2)` |
+# **`description`** | `text(65535)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`requires_booth_chair_approval`** | `boolean` |
+# **`updated_at`** | `datetime` |
+#
+
class ChargeTypesController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/charges_controller.rb b/app/controllers/charges_controller.rb
index 970688cd..6a499db6 100644
--- a/app/controllers/charges_controller.rb
+++ b/app/controllers/charges_controller.rb
@@ -1,5 +1,32 @@
+# ## Schema Information
+#
+# Table name: `charges`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------------- | ------------------ | ---------------------------
+# **`amount`** | `decimal(8, 2)` |
+# **`charge_type_id`** | `integer` |
+# **`charged_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`creating_participant_id`** | `integer` |
+# **`description`** | `text(65535)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_approved`** | `boolean` |
+# **`issuing_participant_id`** | `integer` |
+# **`organization_id`** | `integer` |
+# **`receiving_participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_charges_on_organization_id`:
+# * **`organization_id`**
+#
+
class ChargesController < ApplicationController
- load_and_authorize_resource skip_load_resource only: [:create]
+ load_and_authorize_resource
before_action :set_charge, only: [:show, :edit, :update, :destroy, :approve]
# GET /charges
@@ -32,6 +59,7 @@ def new
# GET /charges/1/edit
def edit
+ @current_receiving_participant = @charge.receiving_participant? ? "" : @charge.receiving_participant.formatted_name
end
# POST /charges
@@ -49,7 +77,7 @@ def create
# PUT /charges/1.json
def update
@charge.is_approved = false
- @charge.update(charge_params)
+ @charge.update_attributes(charge_params)
respond_with(@charge)
end
@@ -69,7 +97,8 @@ def destroy
def approve
@charge.is_approved = !@charge.is_approved
@charge.save
- respond_with @charge, location: -> {charges_path}
+
+ respond_with(@charge, location: @charge.organization)
end
private
diff --git a/app/controllers/checkouts_controller.rb b/app/controllers/checkouts_controller.rb
index ae7688e5..923fde83 100644
--- a/app/controllers/checkouts_controller.rb
+++ b/app/controllers/checkouts_controller.rb
@@ -1,3 +1,26 @@
+# ## Schema Information
+#
+# Table name: `checkouts`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`checked_in_at`** | `datetime` |
+# **`checked_out_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`tool_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_checkouts_on_tool_id`:
+# * **`tool_id`**
+#
+
class CheckoutsController < ApplicationController
# permissions error - when enabled, this tries to find a Checkout with the current related model id on creation
# load_and_authorize_resource
@@ -7,6 +30,7 @@ class CheckoutsController < ApplicationController
def index
@tool = Tool.find(params[:tool_id])
@checkouts = @tool.checkouts
+ authorize! :read, @checkouts
respond_to do |format|
format.html # index.html.erb
@@ -136,8 +160,6 @@ def uncheckin
format.html { redirect_to tool_path(checkout.tool), notice: "Error" }
end
end
-
-
end
@@ -181,5 +203,6 @@ def checkin_bak
end
end
end
+
end
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index 8cbd1ba0..4604a452 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -1,3 +1,21 @@
+# ## Schema Information
+#
+# Table name: `documents`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`document_id`** | `integer` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`organization_id`** | `integer` |
+# **`public`** | `boolean` |
+# **`updated_at`** | `datetime` |
+# **`url`** | `string(255)` |
+#
+
class DocumentsController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
diff --git a/app/controllers/event_types_controller.rb b/app/controllers/event_types_controller.rb
index 062aa102..1ec510d2 100644
--- a/app/controllers/event_types_controller.rb
+++ b/app/controllers/event_types_controller.rb
@@ -1,3 +1,16 @@
+# ## Schema Information
+#
+# Table name: `event_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------- | ------------------ | ---------------------------
+# **`display`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+#
+
class EventTypesController < ApplicationController
load_and_authorize_resource
before_action :set_event_type, only: [:show, :edit, :update, :destroy]
@@ -78,4 +91,4 @@ def set_event_type
def event_type_params
params.require(:event_type).permit(:display, :name)
end
-end
+end
\ No newline at end of file
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb
index 77fdac97..599fcad0 100644
--- a/app/controllers/events_controller.rb
+++ b/app/controllers/events_controller.rb
@@ -1,3 +1,20 @@
+# ## Schema Information
+#
+# Table name: `events`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# --------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`event_type_id`** | `integer` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_done`** | `boolean` |
+# **`participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+
class EventsController < ApplicationController
load_and_authorize_resource
before_action :set_event, only: [:show, :edit, :update, :destroy,:approve]
@@ -16,6 +33,7 @@ def show
# GET /events/new
def new
@event = Event.new
+ @scc_members = Participant.all.scc
end
# PUT
@@ -27,6 +45,7 @@ def approve
# GET /events/1/edit
def edit
+ @scc_members = Participant.all.scc
@event.updated_at = DateTime.now
@event.save
end
@@ -81,6 +100,6 @@ def set_event
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
- params.require(:event).permit(:is_done, :title, :created_at, :description, :updated_at, :display, :event_type_id)
+ params.require(:event).permit(:is_done, :title, :created_at, :description, :updated_at, :display, :event_type_id, :participant_id)
end
-end
+end
\ No newline at end of file
diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb
index 18d1db20..549806e5 100644
--- a/app/controllers/faqs_controller.rb
+++ b/app/controllers/faqs_controller.rb
@@ -1,3 +1,18 @@
+# ## Schema Information
+#
+# Table name: `faqs`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ----------------- | ------------------ | ---------------------------
+# **`answer`** | `text(65535)` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`question`** | `text(65535)` |
+# **`updated_at`** | `datetime` |
+#
+
class FaqsController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
before_action :set_faq, only: [:edit, :update, :destroy]
@@ -6,6 +21,7 @@ class FaqsController < ApplicationController
# GET /faqs.json
def index
@faqs = Faq.all
+ authorize! :read, @faqs
end
# GET /faqs/new
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 5e85a5aa..ad6d3795 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -71,11 +71,13 @@ def dev_login
def hardhats
@organizations = Organization.joins(:tools).distinct
+ authorize! :read, @organizations
@total = Tool.hardhats.checked_out.count
end
def charge_overview
@organizations = Organization.joins(:charges).distinct.includes(:charges)
+ authorize! :read, @organizations
@charge_types = ChargeType.all.includes(:charges)
@approved_total = Charge.approved.sum('amount')
@pending_total = Charge.pending.sum('amount')
@@ -84,6 +86,7 @@ def charge_overview
def downtime
@organizations = Organization.only_categories(['Fraternity', 'Sorority', 'Independent', 'Blitz', 'Concessions'])
+ authorize! :read, @organizations
end
def hardhat_return
diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb
index c5f5cdc0..c3292b79 100644
--- a/app/controllers/memberships_controller.rb
+++ b/app/controllers/memberships_controller.rb
@@ -1,3 +1,28 @@
+# ## Schema Information
+#
+# Table name: `memberships`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------ | ------------------ | ---------------------------
+# **`booth_chair_order`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_booth_chair`** | `boolean` |
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`title`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_memberships_on_organization_id`:
+# * **`organization_id`**
+# * `index_memberships_on_participant_id`:
+# * **`participant_id`**
+#
+
class MembershipsController < ApplicationController
load_and_authorize_resource
skip_load_resource :only => [:create, :update]
diff --git a/app/controllers/organization_aliases_controller.rb b/app/controllers/organization_aliases_controller.rb
index 9eca4d32..441e9e8e 100644
--- a/app/controllers/organization_aliases_controller.rb
+++ b/app/controllers/organization_aliases_controller.rb
@@ -1,3 +1,25 @@
+# ## Schema Information
+#
+# Table name: `organization_aliases`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`organization_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organization_aliases_on_name`:
+# * **`name`**
+# * `index_organization_aliases_on_organization_id`:
+# * **`organization_id`**
+#
+
class OrganizationAliasesController < ApplicationController
# permissions error - when enabled, this tries to find a OrganizationAlias with the current related model id on creation
responders :flash, :http_cache
diff --git a/app/controllers/organization_status_types_controller.rb b/app/controllers/organization_status_types_controller.rb
index 94dd95ac..f4ca6a34 100644
--- a/app/controllers/organization_status_types_controller.rb
+++ b/app/controllers/organization_status_types_controller.rb
@@ -1,3 +1,16 @@
+# ## Schema Information
+#
+# Table name: `organization_status_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------- | ------------------ | ---------------------------
+# **`display`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+#
+
class OrganizationStatusTypesController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/organization_statuses_controller.rb b/app/controllers/organization_statuses_controller.rb
index 39ea3f21..42d881c8 100644
--- a/app/controllers/organization_statuses_controller.rb
+++ b/app/controllers/organization_statuses_controller.rb
@@ -1,3 +1,25 @@
+# ## Schema Information
+#
+# Table name: `organization_statuses`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `string(255)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`organization_status_type_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organization_statuses_on_organization_id`:
+# * **`organization_id`**
+#
+
class OrganizationStatusesController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
before_action :set_organization_status, only: [:show, :edit, :update, :destroy]
diff --git a/app/controllers/organization_timeline_entries_controller.rb b/app/controllers/organization_timeline_entries_controller.rb
index edaac014..6b28d9e9 100644
--- a/app/controllers/organization_timeline_entries_controller.rb
+++ b/app/controllers/organization_timeline_entries_controller.rb
@@ -1,3 +1,26 @@
+# ## Schema Information
+#
+# Table name: `organization_timeline_entries`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`ended_at`** | `datetime` |
+# **`entry_type`** | `integer` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`started_at`** | `datetime` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organization_timeline_entries_on_organization_id`:
+# * **`organization_id`**
+#
+
class OrganizationTimelineEntriesController < ApplicationController
authorize_resource
before_action :set_organization_timeline_entry, only: [:update, :destroy, :end, :show]
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index 6c9db580..f6d0b42e 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -1,3 +1,24 @@
+# ## Schema Information
+#
+# Table name: `organizations`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`organization_category_id`** | `integer` |
+# **`short_name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organizations_on_organization_category_id`:
+# * **`organization_category_id`**
+#
+
class OrganizationsController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/participants_controller.rb b/app/controllers/participants_controller.rb
index 6b0e2b2c..679326de 100644
--- a/app/controllers/participants_controller.rb
+++ b/app/controllers/participants_controller.rb
@@ -1,7 +1,40 @@
+# ## Schema Information
+#
+# Table name: `participants`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------------------------- | ------------------ | ---------------------------
+# **`andrewid`** | `string(255)` |
+# **`cache_updated`** | `datetime` |
+# **`cached_department`** | `string(255)` |
+# **`cached_email`** | `string(255)` |
+# **`cached_name`** | `string(255)` |
+# **`cached_student_class`** | `string(255)` |
+# **`cached_surname`** | `string(255)` |
+# **`created_at`** | `datetime` |
+# **`has_signed_hardhat_waiver`** | `boolean` |
+# **`has_signed_waiver`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`phone_carrier_id`** | `integer` |
+# **`phone_number`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+# **`user_id`** | `integer` |
+# **`waiver_start`** | `datetime` |
+
+#
+# ### Indexes
+#
+# * `index_participants_on_phone_carrier_id`:
+# * **`phone_carrier_id`**
+#
+
class ParticipantsController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
before_action :set_participant, only: [:show, :edit, :update, :destroy]
-
+ before_action :set_wristband_colors
+
# GET /participants
# GET /participants.json
def index
@@ -34,6 +67,24 @@ def lookup
# GET /participants/1.json
def show
@memberships = @participant.memberships.all
+
+ if @memberships.empty?
+ @wristband = "None - No organizations"
+ elsif !@participant.has_signed_waiver
+ @wristband = "None - No waiver signature"
+ else
+ building_statuses = @memberships.map { |m| m.organization.organization_category.is_building }
+ if building_statuses.include?(true)
+ @wristband = @wristband_colors[:building]
+ else
+ @wristband = @wristband_colors[:nonbuilding]
+ end
+
+ certs = @participant.certifications.map { |cert| cert.certification_type }
+ if certs.include?(CertificationType.find_by_name("Scissor Lift"))
+ @wristband += " and " + @wristband_colors[:scissor_lift]
+ end
+ end
end
# GET /participants/new
@@ -80,5 +131,9 @@ def participant_create_params
def participant_update_params
params.require(:participant).permit(:phone_number, :has_signed_waiver, :has_signed_hardhat_waiver)
end
-end
+ def set_wristband_colors
+ @wristband_colors = { :building => "Red", :nonbuilding => "Blue", :scissor_lift => "Green" }
+ end
+
+end
diff --git a/app/controllers/shift_participants_controller.rb b/app/controllers/shift_participants_controller.rb
index be2977bb..7d0419b3 100644
--- a/app/controllers/shift_participants_controller.rb
+++ b/app/controllers/shift_participants_controller.rb
@@ -1,3 +1,26 @@
+# ## Schema Information
+#
+# Table name: `shift_participants`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# --------------------- | ------------------ | ---------------------------
+# **`clocked_in_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`participant_id`** | `integer` |
+# **`shift_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_shift_participants_on_participant_id`:
+# * **`participant_id`**
+# * `index_shift_participants_on_shift_id`:
+# * **`shift_id`**
+#
+
class ShiftParticipantsController < ApplicationController
# DELETE /shift_participants/1
# DELETE /shift_participants/1.json
diff --git a/app/controllers/shifts_controller.rb b/app/controllers/shifts_controller.rb
index 523193af..3fd6377c 100644
--- a/app/controllers/shifts_controller.rb
+++ b/app/controllers/shifts_controller.rb
@@ -1,3 +1,27 @@
+# ## Schema Information
+#
+# Table name: `shifts`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `string(255)` |
+# **`ends_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`required_number_of_participants`** | `integer` |
+# **`shift_type_id`** | `integer` |
+# **`starts_at`** | `datetime` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_shifts_on_organization_id`:
+# * **`organization_id`**
+#
+
class ShiftsController < ApplicationController
load_and_authorize_resource skip_load_resource only: [:create]
before_action :set_shift, only: [:show, :edit, :update, :destroy]
@@ -77,4 +101,5 @@ def set_shift
def shift_params
params.require(:shift).permit(:starts_at, :ends_at, :shift_type_id, :organization_id, :required_number_of_participants, :description)
end
-end
+
+end
\ No newline at end of file
diff --git a/app/controllers/store/purchases_controller.rb b/app/controllers/store/purchases_controller.rb
index 021137b0..f82253fb 100644
--- a/app/controllers/store/purchases_controller.rb
+++ b/app/controllers/store/purchases_controller.rb
@@ -1,13 +1,21 @@
class Store::PurchasesController < ApplicationController
def add_to_cart
- @store_purchase = StorePurchase.new
+ all_store_items = StorePurchase.all.map { |s| s.store_item }
item = StoreItem.find params[:id]
- @store_purchase.quantity_purchased = 1
- @store_purchase.price_at_purchase = item.price
- @store_purchase.store_item = item
- @store_purchase.save
-
+ if all_store_items.include?(item)
+ @old_store_purchase = StorePurchase.where("store_item_id= ?", item.id)
+ @old_store_purchase[0].quantity_purchased += 1
+ @old_store_purchase[0].price_at_purchase = item.price
+ @old_store_purchase[0].store_item = item
+ @old_store_purchase[0].save
+ else
+ @store_purchase = StorePurchase.new
+ @store_purchase.quantity_purchased = 1
+ @store_purchase.price_at_purchase = item.price
+ @store_purchase.store_item = item
+ @store_purchase.save
+ end
#respond_with(@store_purchase)
redirect_to store_url
end
diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
index 5cb5f1fe..0bdf93bf 100644
--- a/app/controllers/tasks_controller.rb
+++ b/app/controllers/tasks_controller.rb
@@ -1,3 +1,21 @@
+# ## Schema Information
+#
+# Table name: `tasks`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`completed_by_id`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`due_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_completed`** | `boolean` |
+# **`name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+
class TasksController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/tool_cart_controller.rb b/app/controllers/tool_cart_controller.rb
index 7edac331..52517d55 100644
--- a/app/controllers/tool_cart_controller.rb
+++ b/app/controllers/tool_cart_controller.rb
@@ -62,6 +62,18 @@ def checkout
locals: {message: "Invalid organization"}
end
+ participant_certs = participant.certifications.map { |cert| cert.certification_type.name }
+ session[:tool_cart].each do |tool|
+ tool = Tool.find_by_barcode(tool)
+ required_certs = tool.tool_type.tool_type_certifications.map { |cert| cert.certification_type.name }
+ required_certs.each do |required_cert|
+ if !participant_certs.include?(required_cert)
+ return render action: 'tool_cart_error',
+ locals: {message: "#{required_cert} certification required for #{tool.name} tool!"}
+ end
+ end
+ end
+
# Add membership
if params[:add_membership]
Membership.create({participant_id: params[:participant_id], organization_id: params[:organization_id]})
diff --git a/app/controllers/tool_types_controller.rb b/app/controllers/tool_types_controller.rb
index 3583a12c..0c2b9ded 100644
--- a/app/controllers/tool_types_controller.rb
+++ b/app/controllers/tool_types_controller.rb
@@ -1,3 +1,17 @@
+# ## Schema Information
+#
+# Table name: `tool_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ----------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+
class ToolTypesController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/tool_waitlists_controller.rb b/app/controllers/tool_waitlists_controller.rb
index 9da55dc1..732c5fc7 100644
--- a/app/controllers/tool_waitlists_controller.rb
+++ b/app/controllers/tool_waitlists_controller.rb
@@ -1,3 +1,27 @@
+# ## Schema Information
+#
+# Table name: `tool_waitlists`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`active`** | `boolean` | `default(TRUE)`
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`note`** | `string(255)` |
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`tool_type_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+# **`wait_start_time`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_tool_waitlists_on_tool_type_id`:
+# * **`tool_type_id`**
+#
+
class ToolWaitlistsController < ApplicationController
# Can't use load_and_authorize_resource until it's fixed in the
# checkout controller as well.
diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb
index d3007786..c5aeebf8 100644
--- a/app/controllers/tools_controller.rb
+++ b/app/controllers/tools_controller.rb
@@ -1,3 +1,26 @@
+# ## Schema Information
+#
+# Table name: `tools`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------- | ------------------ | ---------------------------
+# **`barcode`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`tool_type_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_tools_on_barcode`:
+# * **`barcode`**
+# * `index_tools_on_tool_type_id`:
+# * **`tool_type_id`**
+#
+
class ToolsController < ApplicationController
load_and_authorize_resource
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 190accfa..608fe721 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,3 +1,34 @@
+# ## Schema Information
+#
+# Table name: `users`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ----------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`current_sign_in_at`** | `datetime` |
+# **`current_sign_in_ip`** | `string(255)` |
+# **`email`** | `string(255)` | `default(""), not null`
+# **`encrypted_password`** | `string(255)` | `default(""), not null`
+# **`id`** | `integer` | `not null, primary key`
+# **`last_sign_in_at`** | `datetime` |
+# **`last_sign_in_ip`** | `string(255)` |
+# **`name`** | `string(255)` |
+# **`remember_created_at`** | `datetime` |
+# **`reset_password_sent_at`** | `datetime` |
+# **`reset_password_token`** | `string(255)` |
+# **`sign_in_count`** | `integer` | `default(0), not null`
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_users_on_email` (_unique_):
+# * **`email`**
+# * `index_users_on_reset_password_token` (_unique_):
+# * **`reset_password_token`**
+#
+
class UsersController < ApplicationController
before_filter :authenticate_user!
diff --git a/app/controllers/waivers_controller.rb b/app/controllers/waivers_controller.rb
index cc3eff5b..248f4e61 100644
--- a/app/controllers/waivers_controller.rb
+++ b/app/controllers/waivers_controller.rb
@@ -1,17 +1,21 @@
class WaiversController < ApplicationController
before_filter :require_authenticated_user
-
+
def new
if params[:participant_id].nil? or !current_user.participant.is_scc?
@user = current_user.participant
else
@user = Participant.find params[:participant_id]
end
-
+
if @user.has_signed_waiver
flash[:notice] = "You have already agreed to the release."
+ elsif !flash[:error]
+ @user.start_waiver_timer
end
-
+
+ @should_see_video = !flash[:error] && cannot?(:skip_video, WaiversController)
+
end
@@ -21,16 +25,21 @@ def create
else
@participant = Participant.find params[:participant_id]
end
-
-
- if params[:adult].blank?
+
+ if @participant.is_waiver_cheater? && cannot?(:skip_video, WaiversController)
+ @participant.start_waiver_timer
+ redirect_to '/cheating.html'
+ elsif params[:adult].blank?
flash[:error] = "You must be 18 or older to sign the electronic waiver. Please contact Andrew Greenwald (asgreen@andrew.cmu.edu)."
redirect_to action: :new
elsif params[:agree].blank?
flash[:error] = "You must agree to the terms of the release."
redirect_to action: :new
elsif params[:phone_number] == ""
- flash[:error] = "You must provide a mobile phone number"
+ flash[:error] = "You must provide a mobile phone number."
+ redirect_to action: :new
+ elsif params[:signature] != @participant.name
+ flash[:error] = "You must electronically sign the waiver with your full name as it appears on the waiver."
redirect_to action: :new
else
@participant.phone_number = params[:phone_number]
diff --git a/app/helpers/charges_helper.rb b/app/helpers/charges_helper.rb
index 414ee900..a98835ba 100644
--- a/app/helpers/charges_helper.rb
+++ b/app/helpers/charges_helper.rb
@@ -1,2 +1,29 @@
+# ## Schema Information
+#
+# Table name: `charges`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------------- | ------------------ | ---------------------------
+# **`amount`** | `decimal(8, 2)` |
+# **`charge_type_id`** | `integer` |
+# **`charged_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`creating_participant_id`** | `integer` |
+# **`description`** | `text(65535)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_approved`** | `boolean` |
+# **`issuing_participant_id`** | `integer` |
+# **`organization_id`** | `integer` |
+# **`receiving_participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_charges_on_organization_id`:
+# * **`organization_id`**
+#
+
module ChargesHelper
end
diff --git a/app/helpers/checkouts_helper.rb b/app/helpers/checkouts_helper.rb
index d6ebab7a..b43c9629 100644
--- a/app/helpers/checkouts_helper.rb
+++ b/app/helpers/checkouts_helper.rb
@@ -1,2 +1,25 @@
+# ## Schema Information
+#
+# Table name: `checkouts`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`checked_in_at`** | `datetime` |
+# **`checked_out_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`tool_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_checkouts_on_tool_id`:
+# * **`tool_id`**
+#
+
module CheckoutsHelper
end
diff --git a/app/helpers/memberships_helper.rb b/app/helpers/memberships_helper.rb
index eaf43c73..e0dc0416 100644
--- a/app/helpers/memberships_helper.rb
+++ b/app/helpers/memberships_helper.rb
@@ -1,2 +1,27 @@
+# ## Schema Information
+#
+# Table name: `memberships`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------ | ------------------ | ---------------------------
+# **`booth_chair_order`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_booth_chair`** | `boolean` |
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`title`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_memberships_on_organization_id`:
+# * **`organization_id`**
+# * `index_memberships_on_participant_id`:
+# * **`participant_id`**
+#
+
module MembershipsHelper
end
diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb
index 24cc9a80..6a5fbe91 100644
--- a/app/helpers/organizations_helper.rb
+++ b/app/helpers/organizations_helper.rb
@@ -1,2 +1,23 @@
+# ## Schema Information
+#
+# Table name: `organizations`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`organization_category_id`** | `integer` |
+# **`short_name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organizations_on_organization_category_id`:
+# * **`organization_category_id`**
+#
+
module OrganizationsHelper
end
diff --git a/app/helpers/participants_helper.rb b/app/helpers/participants_helper.rb
index 7059f831..a42cc682 100644
--- a/app/helpers/participants_helper.rb
+++ b/app/helpers/participants_helper.rb
@@ -1,2 +1,32 @@
+# ## Schema Information
+#
+# Table name: `participants`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------------------------- | ------------------ | ---------------------------
+# **`andrewid`** | `string(255)` |
+# **`cache_updated`** | `datetime` |
+# **`cached_department`** | `string(255)` |
+# **`cached_email`** | `string(255)` |
+# **`cached_name`** | `string(255)` |
+# **`cached_student_class`** | `string(255)` |
+# **`cached_surname`** | `string(255)` |
+# **`created_at`** | `datetime` |
+# **`has_signed_hardhat_waiver`** | `boolean` |
+# **`has_signed_waiver`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`phone_carrier_id`** | `integer` |
+# **`phone_number`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+# **`user_id`** | `integer` |
+#
+# ### Indexes
+#
+# * `index_participants_on_phone_carrier_id`:
+# * **`phone_carrier_id`**
+#
+
module ParticipantsHelper
end
diff --git a/app/helpers/shift_participants_helper.rb b/app/helpers/shift_participants_helper.rb
index 7c537d7a..5e1f8581 100644
--- a/app/helpers/shift_participants_helper.rb
+++ b/app/helpers/shift_participants_helper.rb
@@ -1,2 +1,25 @@
+# ## Schema Information
+#
+# Table name: `shift_participants`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# --------------------- | ------------------ | ---------------------------
+# **`clocked_in_at`** | `datetime` |
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`participant_id`** | `integer` |
+# **`shift_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_shift_participants_on_participant_id`:
+# * **`participant_id`**
+# * `index_shift_participants_on_shift_id`:
+# * **`shift_id`**
+#
+
module ShiftParticipantsHelper
end
diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb
index 4f9336b6..5a0755e6 100644
--- a/app/helpers/shifts_helper.rb
+++ b/app/helpers/shifts_helper.rb
@@ -1,2 +1,26 @@
+# ## Schema Information
+#
+# Table name: `shifts`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `string(255)` |
+# **`ends_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`required_number_of_participants`** | `integer` |
+# **`shift_type_id`** | `integer` |
+# **`starts_at`** | `datetime` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_shifts_on_organization_id`:
+# * **`organization_id`**
+#
+
module ShiftsHelper
end
diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb
index ce894d00..3b9a8765 100644
--- a/app/helpers/tasks_helper.rb
+++ b/app/helpers/tasks_helper.rb
@@ -1,2 +1,20 @@
+# ## Schema Information
+#
+# Table name: `tasks`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`completed_by_id`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`due_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_completed`** | `boolean` |
+# **`name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+
module TasksHelper
end
diff --git a/app/helpers/tool_types_helper.rb b/app/helpers/tool_types_helper.rb
index c48d6180..7678d2fd 100644
--- a/app/helpers/tool_types_helper.rb
+++ b/app/helpers/tool_types_helper.rb
@@ -1,2 +1,16 @@
+# ## Schema Information
+#
+# Table name: `tool_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ----------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
+#
+
module ToolTypesHelper
end
diff --git a/app/helpers/tool_waitlists_helper.rb b/app/helpers/tool_waitlists_helper.rb
index 11c36b9b..ac442225 100644
--- a/app/helpers/tool_waitlists_helper.rb
+++ b/app/helpers/tool_waitlists_helper.rb
@@ -1,2 +1,26 @@
+# ## Schema Information
+#
+# Table name: `tool_waitlists`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------- | ------------------ | ---------------------------
+# **`active`** | `boolean` | `default(TRUE)`
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`note`** | `string(255)` |
+# **`organization_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`tool_type_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+# **`wait_start_time`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_tool_waitlists_on_tool_type_id`:
+# * **`tool_type_id`**
+#
+
module ToolWaitlistsHelper
end
diff --git a/app/helpers/tools_helper.rb b/app/helpers/tools_helper.rb
index 6f879599..a7903bbf 100644
--- a/app/helpers/tools_helper.rb
+++ b/app/helpers/tools_helper.rb
@@ -1,2 +1,25 @@
+# ## Schema Information
+#
+# Table name: `tools`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ------------------- | ------------------ | ---------------------------
+# **`barcode`** | `integer` |
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`tool_type_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_tools_on_barcode`:
+# * **`barcode`**
+# * `index_tools_on_tool_type_id`:
+# * **`tool_type_id`**
+#
+
module ToolsHelper
end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 65e22460..5b3c879a 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -5,12 +5,12 @@ def initialize(user)
user ||= User.new # guest user (not logged in)
cannot :manage, :all
-
+
if (user.participant.blank?)
return
end
- can :read, [OrganizationAlias, OrganizationCategory, Organization, Participant,
+ can :read, [OrganizationAlias, OrganizationCategory, Organization, Participant,
ShiftType, Tool, ToolWaitlist, Membership]
can :search
@@ -90,10 +90,12 @@ def initialize(user)
can [:create, :update], Tool
can [:create, :update], ToolType
can [:create, :update , :destroy], ToolWaitlist
+ can [:create, :destroy], Certification
end
if user.has_role? :admin
can :manage, :all
+ can :skip_video, WaiversController
end
end
end
diff --git a/app/models/certification.rb b/app/models/certification.rb
new file mode 100644
index 00000000..442e85de
--- /dev/null
+++ b/app/models/certification.rb
@@ -0,0 +1,4 @@
+class Certification < ActiveRecord::Base
+ belongs_to :certification_type
+ belongs_to :participant
+end
diff --git a/app/models/certification_type.rb b/app/models/certification_type.rb
new file mode 100644
index 00000000..d5df13bd
--- /dev/null
+++ b/app/models/certification_type.rb
@@ -0,0 +1,3 @@
+class CertificationType < ActiveRecord::Base
+ validates :name, :presence => true, :uniqueness => true
+end
diff --git a/app/models/checkout.rb b/app/models/checkout.rb
index d3593823..96c2b6f1 100644
--- a/app/models/checkout.rb
+++ b/app/models/checkout.rb
@@ -22,6 +22,8 @@
#
class Checkout < ActiveRecord::Base
+ include Messenger
+
# For lookups
def card_number=( card_number )
@card_number = card_number
@@ -35,6 +37,7 @@ def card_number
validates_associated :tool, :organization, :participant
before_save :checked_out_at, :presence => true
+ after_update :notify
belongs_to :participant, :touch => true
belongs_to :organization, :touch => true
@@ -44,4 +47,21 @@ def card_number
scope :old, -> { where('checked_in_at IS NOT NULL') }
scope :current, -> { where('checked_in_at IS NULL') }
-end
+ private
+
+ def notify
+ if (self.checked_in_at != nil)
+ toolCategory = self.tool.tool_type
+ waitlist = ToolWaitlist.for_tool_type(toolCategory.id).by_wait_start_time
+ if (waitlist.count != 0)
+ nextPerson = waitlist.first.participant
+ unless (nextPerson.phone_number.blank?)
+ number = nextPerson.phone_number
+ content = "#{toolCategory.name} is now available at the trailer. Please come pick it up within 5 minutes!"
+ send_sms(number, content)
+ end
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/event.rb b/app/models/event.rb
index efaeabbd..2e59a02f 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -4,17 +4,34 @@
#
# ### Columns
#
-# Name | Type | Attributes
-# -------------------- | ------------------ | ---------------------------
-# **`created_at`** | `datetime` |
-# **`description`** | `text(65535)` |
-# **`event_type_id`** | `integer` |
-# **`id`** | `integer` | `not null, primary key`
-# **`is_done`** | `boolean` |
-# **`updated_at`** | `datetime` |
+# Name | Type | Attributes
+# --------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`event_type_id`** | `integer` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_done`** | `boolean` |
+# **`participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
#
-
+include Messenger
class Event < ActiveRecord::Base
- belongs_to :event_type
- scope :displayable, -> { joins(:event_type).where(is_done:false).where('event_types.display = ?', true) }
-end
+ belongs_to :event_type
+ belongs_to :participant
+
+ after_create :send_notifications
+
+ scope :displayable, -> { joins(:event_type).where(is_done:false).where('event_types.display = ?', true) }
+
+ #send notification to assignee if their phone is in system
+ def send_notifications
+ if self.participant != nil
+ if self.participant.phone_number.length == 10
+ #grab first 95 characters of description to serve as a preview
+ description_preview = self.description[0...95]
+ send_sms(self.participant.phone_number, "An event in Binder has been assigned to you: " + description_preview + "...")
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/event_type.rb b/app/models/event_type.rb
index 5eff5f5b..851408e5 100644
--- a/app/models/event_type.rb
+++ b/app/models/event_type.rb
@@ -4,11 +4,11 @@
#
# ### Columns
#
-# Name | Type | Attributes
-# --------------- | ------------------ | ---------------------------
-# **`display`** | `boolean` |
-# **`id`** | `integer` | `not null, primary key`
-# **`name`** | `string(255)` |
+# Name | Type | Attributes
+# -------------- | ------------------ | ---------------------------
+# **`display`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
#
class EventType < ActiveRecord::Base
diff --git a/app/models/membership.rb b/app/models/membership.rb
index 47e43e27..2b6e3973 100644
--- a/app/models/membership.rb
+++ b/app/models/membership.rb
@@ -40,5 +40,5 @@ def organization_name_formatted
organization.name
end
end
-end
-
+
+end
\ No newline at end of file
diff --git a/app/models/organization_alias.rb b/app/models/organization_alias.rb
index 87c878f5..fdafc98d 100644
--- a/app/models/organization_alias.rb
+++ b/app/models/organization_alias.rb
@@ -25,8 +25,8 @@ class OrganizationAlias < ActiveRecord::Base
validates_associated :organization
validates :name, :uniqueness => true
- belongs_to :organization
-
+ belongs_to :organization
+
scope :search, lambda { |term| where('lower(name) LIKE lower(?)', "#{term}%") }
def formatted_name
diff --git a/app/models/organization_category.rb b/app/models/organization_category.rb
index ae501a71..d736af2b 100644
--- a/app/models/organization_category.rb
+++ b/app/models/organization_category.rb
@@ -4,12 +4,13 @@
#
# ### Columns
#
-# Name | Type | Attributes
-# ----------------- | ------------------ | ---------------------------
-# **`created_at`** | `datetime` |
-# **`id`** | `integer` | `not null, primary key`
-# **`name`** | `string(255)` |
-# **`updated_at`** | `datetime` |
+# Name | Type | Attributes
+# ------------------ | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_building`** | `boolean` |
+# **`name`** | `string(255)` |
+# **`updated_at`** | `datetime` |
#
class OrganizationCategory < ActiveRecord::Base
diff --git a/app/models/organization_timeline_entry.rb b/app/models/organization_timeline_entry.rb
index e3befe74..c7a2f3f7 100644
--- a/app/models/organization_timeline_entry.rb
+++ b/app/models/organization_timeline_entry.rb
@@ -36,5 +36,24 @@ def duration
return ended_at.to_i - started_at.to_i unless ended_at.blank?
return DateTime.now.to_i - started_at.to_i
end
-end
+ #notifcations
+ after_create :notifyStart
+ after_update :notifyEnd
+
+ def notifyStart
+ for chair in organization.booth_chairs
+ if chair.phone_number.length == 10
+ send_sms(chair.phone_number, "Downtime for your organization, " +organization.name+", has started.")
+ end
+ end
+ end
+
+ def notifyEnd
+ for chair in organization.booth_chairs
+ if chair.phone_number.length == 10
+ send_sms(chair.phone_number, "Downtime for your organization, " +organization.name+", has ended. You have "+Time.at(organization.remaining_downtime).utc.strftime("%H hours %M minutes")+" left.")
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/participant.rb b/app/models/participant.rb
index bdc4d3f5..6e2de06d 100644
--- a/app/models/participant.rb
+++ b/app/models/participant.rb
@@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
+# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
@@ -30,24 +31,38 @@
class Participant < ActiveRecord::Base
before_save :reformat_phone
-
+
validates :andrewid, :presence => true, :uniqueness => true
# validates :has_signed_waiver, :acceptance => {:accept => true}
validates_format_of :phone_number, :with => /\A\(?\d{3}\)?[-. ]?\d{3}[-.]?\d{4}\Z/, :message => "should be 10 digits (area code needed) and delimited with dashes only", :allow_blank => true
has_many :organizations, :through => :memberships
has_many :shifts, :through => :shift_participants
+ has_many :certs, :through => :certifications, source: :participant
has_many :checkouts, dependent: :destroy
has_many :tools, :through => :checkouts
has_many :memberships, dependent: :destroy
has_many :shift_participants, dependent: :destroy
+ has_many :certifications, dependent: :destroy
has_many :organization_statuses, dependent: :destroy
+ has_many :events
belongs_to :phone_carrier
belongs_to :user, dependent: :destroy
+
default_scope { order('andrewid') }
scope :search, lambda { |term| where('lower(andrewid) LIKE lower(?) OR lower(cached_name) LIKE lower(?)', "%#{term}%", "%#{term}%") }
scope :scc, -> { joins(:organizations).where(organizations: {name: 'Spring Carnival Committee'}) }
+ scope :exec, -> { joins(:organizations).where(organizations: {name: 'Spring Carnival Committee'}).joins(:memberships).where(memberships: {is_booth_chair: true}) }
+
+ def start_waiver_timer
+ self.waiver_start = DateTime.now
+ self.save
+ end
+
+ def is_waiver_cheater?
+ (self.waiver_start + 3.minutes + 30.seconds) > DateTime.now
+ end
def is_booth_chair?
!memberships.booth_chairs.blank?
@@ -197,5 +212,5 @@ def reformat_phone
phone_number.gsub!(/[^0-9]/,"")
self.phone_number = phone_number
end
-end
-
+
+end
\ No newline at end of file
diff --git a/app/models/shift.rb b/app/models/shift.rb
index b32b0512..ec7f896c 100644
--- a/app/models/shift.rb
+++ b/app/models/shift.rb
@@ -21,6 +21,11 @@
# * `index_shifts_on_organization_id`:
# * **`organization_id`**
#
+include Messenger
+require 'twilio-ruby'
+require 'daemons'
+require 'delayed_job'
+require 'delayed_job_active_record'
class Shift < ActiveRecord::Base
validates_presence_of :starts_at, :ends_at, :required_number_of_participants, :shift_type
@@ -47,6 +52,12 @@ class Shift < ActiveRecord::Base
scope :sec_shifts, -> { where('shift_type_id = ?', 2) }
scope :coord_shifts, -> { where('shift_type_id = ?', 3) }
+ @@notify = 1.hour
+ @@notify2 = 5.minutes
+
+ after_create :send_notifications
+ after_create :send_late_notifications
+
def formatted_name
if organization.blank?
shift_type.name + " @ " + starts_at.strftime("%b %e at %l:%M %p")
@@ -58,5 +69,45 @@ def formatted_name
def is_checked_in
return participants.size == required_number_of_participants
end
-end
+ def when_to_run_normal
+ self.starts_at - @@notify
+ end
+
+ def when_to_run_late
+ self.starts_at + @@notify2
+ end
+
+ #send notification to booth chairs of shift's org 1 hour before watch shift starts
+ def send_notifications
+ if shift_type.name == "Watch Shift"
+ for chair in organization.booth_chairs
+ if chair.phone_number.length == 10
+ send_sms(chair.phone_number, "A watch shift for " + organization.name + " starts in 1 hour.")
+ end
+ end
+ end
+ end
+
+ #send notification to booth chairs of shift's org if required # of people haven't clocked in
+ def send_late_notifications
+ if shift_type.name == "Watch Shift" && is_checked_in == false
+ for chair in organization.booth_chairs
+ if chair.phone_number.length == 10
+ send_sms(chair.phone_number, "Only " + participants.size.to_s + " of " + required_number_of_participants.to_s + " people for your watch shift have checked in. Please send more people as soon as possible.")
+ end
+ end
+ elsif shift_type.name == "Watch Shift" && is_checked_in == true
+ for chair in organization.booth_chairs
+ if chair.phone_number.length == 10
+ send_sms(chair.phone_number, "The required number of people for your watch shift have checked in. Thank you!")
+ end
+ end
+ end
+ end
+
+ #delays all jobs using delayed_jobs gem
+ handle_asynchronously :send_notifications, :run_at => Proc.new { |i| i.when_to_run_normal }
+ handle_asynchronously :send_late_notifications, :run_at => Proc.new { |i| i.when_to_run_late }
+
+end
\ No newline at end of file
diff --git a/app/models/shift_participant.rb b/app/models/shift_participant.rb
index 4210cfa2..cb028a3e 100644
--- a/app/models/shift_participant.rb
+++ b/app/models/shift_participant.rb
@@ -38,5 +38,5 @@ def card_number=( card_number )
def card_number
@card_number
end
-end
+end
\ No newline at end of file
diff --git a/app/models/store_item.rb b/app/models/store_item.rb
index 75ea2ec4..df60a6f3 100644
--- a/app/models/store_item.rb
+++ b/app/models/store_item.rb
@@ -9,7 +9,7 @@
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
# **`name`** | `string(255)` |
-# **`price`** | `decimal(10, )` |
+# **`price`** | `decimal(8, 2)` |
# **`quantity`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
#
diff --git a/app/models/store_purchase.rb b/app/models/store_purchase.rb
index 0b335b76..332ef98b 100644
--- a/app/models/store_purchase.rb
+++ b/app/models/store_purchase.rb
@@ -9,7 +9,7 @@
# **`charge_id`** | `integer` |
# **`created_at`** | `datetime` | `not null`
# **`id`** | `integer` | `not null, primary key`
-# **`price_at_purchase`** | `decimal(10, )` |
+# **`price_at_purchase`** | `decimal(8, 2)` |
# **`quantity_purchased`** | `integer` |
# **`store_item_id`** | `integer` |
# **`updated_at`** | `datetime` | `not null`
@@ -23,10 +23,12 @@
#
class StorePurchase < ActiveRecord::Base
+ #relationships
belongs_to :charge
belongs_to :store_item
has_one :organization, through: :charge
+ #methods
def self.items_in_cart
self.where(charge: nil)
end
@@ -34,4 +36,5 @@ def self.items_in_cart
def self.items_in_cart?
items_in_cart.size > 0
end
+
end
diff --git a/app/models/tool_type.rb b/app/models/tool_type.rb
index 3a1167fa..0c8a2181 100644
--- a/app/models/tool_type.rb
+++ b/app/models/tool_type.rb
@@ -15,6 +15,8 @@
class ToolType < ActiveRecord::Base
has_many :tools
has_many :tool_waitlists, dependent: :destroy
+ has_many :certs, :through => :tool_type_certifications, source: :tool_type
+ has_many :tool_type_certifications, dependent: :destroy
validates :name, presence: true, uniqueness: true
default_scope {order(:name)}
diff --git a/app/models/tool_type_certification.rb b/app/models/tool_type_certification.rb
new file mode 100644
index 00000000..7370501c
--- /dev/null
+++ b/app/models/tool_type_certification.rb
@@ -0,0 +1,26 @@
+# ## Schema Information
+#
+# Table name: `tool_type_certifications`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------------- | ------------------ | ---------------------------
+# **`certification_type_id`** | `integer` |
+# **`created_at`** | `datetime` | `not null`
+# **`id`** | `integer` | `not null, primary key`
+# **`tool_type_id`** | `integer` |
+# **`updated_at`** | `datetime` | `not null`
+#
+# ### Indexes
+#
+# * `index_tool_type_certifications_on_certification_type_id`:
+# * **`certification_type_id`**
+# * `index_tool_type_certifications_on_tool_type_id`:
+# * **`tool_type_id`**
+#
+
+class ToolTypeCertification < ActiveRecord::Base
+ belongs_to :tool_type
+ belongs_to :certification_type
+end
diff --git a/app/views/certifications/_form.html.erb b/app/views/certifications/_form.html.erb
new file mode 100644
index 00000000..4fb9198b
--- /dev/null
+++ b/app/views/certifications/_form.html.erb
@@ -0,0 +1,18 @@
+<% current_certs = @participant.certifications.map { |cert| cert.certification_type.name } %>
+
+<%= simple_form_for [@participant, @certification], :html => { :class => 'form-horizontal' } do |f| %>
+
+
+
+ <%= f.button :submit, :class => 'btn-primary' %>
+ <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
+ @participant, :class => 'btn btn-default' %>
+
+<% end %>
diff --git a/app/views/certifications/new.html.erb b/app/views/certifications/new.html.erb
new file mode 100644
index 00000000..41a6ff36
--- /dev/null
+++ b/app/views/certifications/new.html.erb
@@ -0,0 +1,6 @@
+<%- model_class = Certification -%>
+
+
+<%= render 'form' %>
diff --git a/app/views/charges/_form.html.erb b/app/views/charges/_form.html.erb
index 374d0e3d..2b7648d1 100644
--- a/app/views/charges/_form.html.erb
+++ b/app/views/charges/_form.html.erb
@@ -20,11 +20,14 @@ When adding a charge, please ensure that you add a detailed description. This al
<%= f.input_field :amount, :as => :string %>
<% end %>
+
<%= f.input :description, :as => :text, textarea: "{ font-size:16px; }" %>
+
<%= f.association :issuing_participant, :collection => Participant.scc %>
+
<%= f.input :receiving_participant do %>
<%= f.input_field :receiving_participant_id, as: :hidden %>
- <%= text_field_tag 'card-number-input', nil, class: 'form-control' %>
+ <%= text_field_tag 'card-number-input', nil, placeholder: @current_receiving_participant, class: 'form-control'%>
<% end %>
diff --git a/app/views/charges/edit.html.erb b/app/views/charges/edit.html.erb
index afde73d8..5925b190 100644
--- a/app/views/charges/edit.html.erb
+++ b/app/views/charges/edit.html.erb
@@ -1,12 +1,8 @@
-<% if can?(:update, @charge) %>
- <%- model_class = Charge -%>
-
+<%- model_class = Charge -%>
+
- <%= render 'form' %>
+<%= render 'form' %>
-<% else %>
- Not Authorized!
-<% end %>
diff --git a/app/views/charges/index.html.erb b/app/views/charges/index.html.erb
index 8622c13e..517e38e8 100644
--- a/app/views/charges/index.html.erb
+++ b/app/views/charges/index.html.erb
@@ -1,70 +1,65 @@
-<% if can?(:read, Charge) %>
- <%- model_class = Charge -%>
-
+<%- model_class = Charge -%>
+
- <% if can?(:create, Charge) %>
-
- <%= link_to t('.new', :default => t("helpers.links.new_charge")),
- new_charge_path,
- :class => 'btn btn-primary' %>
-
-
- <% end %>
+<% if can?(:create, Charge) %>
+
+ <%= link_to t('.new', :default => t("helpers.links.new_charge")),
+ new_charge_path,
+ :class => 'btn btn-primary' %>
+
+
+<% end %>
-
- If a row is yellow then the charge is still pending approval by an admin.
-
+
+ If a row is yellow then the charge is still pending approval by an admin.
+
-
-
-
- |
- <%= model_class.human_attribute_name(:charge_type) %> |
- <%= model_class.human_attribute_name(:amount) %> |
- <%= "Org" unless !@organization.blank? %> |
- <%= model_class.human_attribute_name(:charged_at) %> |
- <% if can?(:approve, Charge) %>
- Approve |
- <% end %>
-
-
-
- <% @charges.each do |charge| %>
- <% if can?(:read, charge) %>
- >
- <%= link_to "show", charge, class: 'btn btn-info btn-xs' %> |
- <%= charge.charge_type.name %> |
- <%= number_to_currency charge.amount %> |
- <%= link_to charge.organization.short_name, charge.organization unless !@organization.blank? %> |
- <%= date_and_time(charge.charged_at) %> |
- <% if can?(:approve, Charge) %>
-
- <% unless charge.is_approved? %>
- <%= form_tag approve_charge_path(charge), method: :put do -%>
- <%= hidden_field_tag 'url', request.original_fullpath %>
- <%= submit_tag 'Approve', :class => 'btn btn-success btn-xs' %>
- <% end -%>
- <% else %>
- <%= form_tag approve_charge_path(charge), method: :put do -%>
- <%= hidden_field_tag 'url', request.original_fullpath %>
- <%= submit_tag 'Un-Approve', :class => 'btn btn-danger btn-xs' %>
- <% end -%>
- <% end %>
- |
- <% end %>
-
- <% end %>
+
+
+
+ |
+ <%= model_class.human_attribute_name(:charge_type) %> |
+ <%= model_class.human_attribute_name(:amount) %> |
+ <%= "Org" unless !@organization.blank? %> |
+ <%= model_class.human_attribute_name(:charged_at) %> |
+ <% if can?(:approve, Charge) %>
+ Approve |
<% end %>
-
-
+
+
+
+ <% @charges.each do |charge| %>
+ <% if can?(:read, charge) %>
+ >
+ <%= link_to "show", charge, class: 'btn btn-info btn-xs' %> |
+ <%= charge.charge_type.name %> |
+ <%= number_to_currency charge.amount %> |
+ <%= link_to charge.organization.short_name, charge.organization unless !@organization.blank? %> |
+ <%= date_and_time(charge.charged_at) %> |
+ <% if can?(:approve, Charge) %>
+
+ <% unless charge.is_approved? %>
+ <%= form_tag approve_charge_path(charge), method: :put do -%>
+ <%= hidden_field_tag 'url', request.original_fullpath %>
+ <%= submit_tag 'Approve', :class => 'btn btn-success btn-xs' %>
+ <% end -%>
+ <% else %>
+ <%= form_tag approve_charge_path(charge), method: :put do -%>
+ <%= hidden_field_tag 'url', request.original_fullpath %>
+ <%= submit_tag 'Un-Approve', :class => 'btn btn-danger btn-xs' %>
+ <% end -%>
+ <% end %>
+ |
+ <% end %>
+
+ <% end %>
+ <% end %>
+
+
- <%= will_paginate @charges, renderer: BootstrapPagination::Rails %>
-
-<% else %>
- Not Authorized!
-<% end %>
\ No newline at end of file
+<%= will_paginate @charges, renderer: BootstrapPagination::Rails %>
\ No newline at end of file
diff --git a/app/views/charges/new.html.erb b/app/views/charges/new.html.erb
index f45afaf2..6df1eb54 100644
--- a/app/views/charges/new.html.erb
+++ b/app/views/charges/new.html.erb
@@ -1,12 +1,8 @@
-<% if can?(:create, @charge) %>
- <%- model_class = Charge -%>
-
+<%- model_class = Charge -%>
+
- <%= render 'form' %>
+<%= render 'form' %>
-<% else %>
- Not Authorized!
-<% end %>
diff --git a/app/views/charges/show.html.erb b/app/views/charges/show.html.erb
index 1a03ee08..9c7f601d 100644
--- a/app/views/charges/show.html.erb
+++ b/app/views/charges/show.html.erb
@@ -1,58 +1,53 @@
-<% if can?(:read, @charge) %>
- <%- model_class = Charge -%>
-
+<%- model_class = Charge -%>
+
-
- - <%= model_class.human_attribute_name(:description) %>:
- - <%= @charge.description %>
- - <%= model_class.human_attribute_name(:amount) %>:
- - <%= number_to_currency @charge.amount %>
- - <%= model_class.human_attribute_name(:organization) %>:
- - <%= link_to @charge.organization.name, @charge.organization %>
- - <%= model_class.human_attribute_name(:issuing_participant) %>:
- - <%= link_to @charge.issuing_participant.formatted_name, @charge.issuing_participant %>
- - <%= model_class.human_attribute_name(:receiving_participant) %>:
- - <%= link_to @charge.receiving_participant.formatted_name, @charge.receiving_participant unless @charge.receiving_participant.nil? %>
- - <%= model_class.human_attribute_name(:charged_at) %>:
- - <%= date_and_time @charge.charged_at %>
- - <%= model_class.human_attribute_name(:is_approved) %>
- - <%= format_boolean @charge.is_approved %>
-
+
+ - <%= model_class.human_attribute_name(:description) %>:
+ - <%= @charge.description %>
+ - <%= model_class.human_attribute_name(:amount) %>:
+ - <%= number_to_currency @charge.amount %>
+ - <%= model_class.human_attribute_name(:organization) %>:
+ - <%= link_to @charge.organization.name, @charge.organization %>
+ - <%= model_class.human_attribute_name(:issuing_participant) %>:
+ - <%= link_to @charge.issuing_participant.formatted_name, @charge.issuing_participant %>
+ - <%= model_class.human_attribute_name(:receiving_participant) %>:
+ - <%= link_to @charge.receiving_participant.formatted_name, @charge.receiving_participant unless @charge.receiving_participant.nil? %>
+ - <%= model_class.human_attribute_name(:charged_at) %>:
+ - <%= date_and_time @charge.charged_at %>
+ - <%= model_class.human_attribute_name(:is_approved) %>
+ - <%= format_boolean @charge.is_approved %>
+
-
+
<%= link_to t('.back', :default => t("helpers.links.back")),
charges_path, :class => 'btn btn-default' %>
- <% if can?(:approve, Charge) %>
- <% unless @charge.is_approved? %>
- <%= form_tag approve_charge_path(@charge), method: :put, style: "display: inline;", role: "form" do -%>
- <%= hidden_field_tag 'url', request.original_fullpath %>
- <%= submit_tag 'Approve', :class => 'btn btn-success', :type => 'submit' %>
- <% end -%>
- <% else %>
- <%= form_tag approve_charge_path(@charge), method: :put, style: "display: inline;", role: "form" do -%>
- <%= hidden_field_tag 'url', request.original_fullpath %>
- <%= submit_tag 'Un-Approve', :class => 'btn btn-danger', :type => 'submit' %>
- <% end -%>
- <% end %>
+ <% if can?(:approve, Charge) %>
+ <% unless @charge.is_approved? %>
+ <%= form_tag approve_charge_path(@charge), method: :put, style: "display: inline;", role: "form" do -%>
+ <%= hidden_field_tag 'url', request.original_fullpath %>
+ <%= submit_tag 'Approve', :class => 'btn btn-success', :type => 'submit' %>
+ <% end -%>
+ <% else %>
+ <%= form_tag approve_charge_path(@charge), method: :put, style: "display: inline;", role: "form" do -%>
+ <%= hidden_field_tag 'url', request.original_fullpath %>
+ <%= submit_tag 'Un-Approve', :class => 'btn btn-danger', :type => 'submit' %>
+ <% end -%>
<% end %>
+ <% end %>
- <% if can?(:update, @charge) %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
- edit_charge_path(@charge), :class => 'btn btn-primary' %>
- <% end %>
+ <% if can?(:update, @charge) %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ edit_charge_path(@charge), :class => 'btn btn-primary' %>
+ <% end %>
- <% if can?(:destroy, @charge) %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- charge_path(@charge),
- :method => 'delete',
- :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
- :class => 'btn btn-danger' %>
- <% end %>
-
-
-<% else %>
-
Not Authorized!
-<% end %>
+ <% if can?(:destroy, @charge) %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ charge_path(@charge),
+ :method => 'delete',
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
+ :class => 'btn btn-danger' %>
+ <% end %>
+
diff --git a/app/views/checkouts/index.html.erb b/app/views/checkouts/index.html.erb
index ca70e833..85e77715 100644
--- a/app/views/checkouts/index.html.erb
+++ b/app/views/checkouts/index.html.erb
@@ -1,35 +1,32 @@
-<% if can?(:read, Checkout) %>
- <%- model_class = Checkout -%>
-
-
-
-
- <%= model_class.human_attribute_name(:id) %> |
- <%= model_class.human_attribute_name(:tool) %> |
- <%= model_class.human_attribute_name(:checked_out_at) %> |
- <%= model_class.human_attribute_name(:checked_in_at) %> |
- <%= model_class.human_attribute_name(:participant_id) %> |
- <%= model_class.human_attribute_name(:organization_id) %> |
+<%- model_class = Checkout -%>
+
+
+
+
+ <%= model_class.human_attribute_name(:id) %> |
+ <%= model_class.human_attribute_name(:tool) %> |
+ <%= model_class.human_attribute_name(:checked_out_at) %> |
+ <%= model_class.human_attribute_name(:checked_in_at) %> |
+ <%= model_class.human_attribute_name(:participant_id) %> |
+ <%= model_class.human_attribute_name(:organization_id) %> |
-
-
- <% @checkouts.each do |checkout| %>
- <% if can?(:read, checkout) %>
-
- <%= checkout.id %> |
- <%= checkout.tool.name %> |
- <%= date_and_time(checkout.checked_out_at) unless checkout.checked_out_at.nil? %> |
- <%= date_and_time(checkout.checked_in_at) unless checkout.checked_in_at.nil? %> |
- <%= checkout.participant.andrewid unless checkout.participant.nil? %> |
- <%= checkout.organization.name unless checkout.organization.nil?%> |
-
- <% end %>
+
+
+ <% @checkouts.each do |checkout| %>
+ <% if can?(:read, checkout) %>
+
+ <%= checkout.id %> |
+ <%= checkout.tool.name %> |
+ <%= date_and_time(checkout.checked_out_at) unless checkout.checked_out_at.nil? %> |
+ <%= date_and_time(checkout.checked_in_at) unless checkout.checked_in_at.nil? %> |
+ <%= checkout.participant.andrewid unless checkout.participant.nil? %> |
+ <%= checkout.organization.name unless checkout.organization.nil?%> |
+
<% end %>
-
-
-<% else %>
- Not Authorized!
-<% end %>
+ <% end %>
+
+
+
diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb
index 20fb8781..8e8ef7c8 100644
--- a/app/views/documents/edit.html.erb
+++ b/app/views/documents/edit.html.erb
@@ -1,11 +1,7 @@
-<% if can?(:update, @document) %>
- <%- model_class = Document -%>
-
+<%- model_class = Document -%>
+
- <%= render 'form' %>
+<%= render 'form' %>
-<% else %>
- Not Authorized!
-<% end %>
diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb
index f319be1c..fc2a04a6 100644
--- a/app/views/documents/index.html.erb
+++ b/app/views/documents/index.html.erb
@@ -1,61 +1,58 @@
-<% if can?(:read, Document) %>
- <%- model_class = Document -%>
-
- <% if can?(:create, Document) %>
-
- <%= link_to t('.new', :default => t("helpers.links.new_document")),
+<% if can?(:create, Document) %>
+
+ <%= link_to t('.new', :default => t("helpers.links.new_document")),
new_document_path,
:class => 'btn btn-primary' %>
-
-
- <% end %>
+
+
+<% end %>
-
-
-
- <%= model_class.human_attribute_name(:name) %> |
- <%= model_class.human_attribute_name(:public) %> |
- <%= model_class.human_attribute_name(:organization) %> |
- <% if can?(:update, Document) or can?(:destroy, Document) %>
- <%=t '.actions', :default => t("helpers.actions") %> |
- <% end %>
-
-
-
- <% @documents.each do |document| %>
- <% if can?(:read, document) %>
-
- <%= link_to(document.name, document.url.to_s) %> |
- <%= format_boolean document.public %> |
- <%= link_to(document.organization.name, document.organization) unless document.organization.blank? %> |
+
+
+
+ <%= model_class.human_attribute_name(:name) %> |
+ <%= model_class.human_attribute_name(:public) %> |
+ <%= model_class.human_attribute_name(:organization) %> |
+ <% if can?(:update, Document) or can?(:destroy, Document) %>
+ <%=t '.actions', :default => t("helpers.actions") %> |
+ <% end %>
+
+
+
+ <% @documents.each do |document| %>
+ <% if can?(:read, document) %>
+
+ <%= link_to(document.name, document.url.to_s) %> |
+ <%= format_boolean document.public %> |
+ <%= link_to(document.organization.name, document.organization) unless document.organization.blank? %> |
- <% if can?(:update, Document) or can?(:destroy, Document) %>
-
- <% if can?(:edit, document) %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
+ <% if can?(:update, Document) or can?(:destroy, Document) %>
+ |
+ <% if can?(:edit, document) %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_document_path(document), :class => 'btn btn-xs btn-primary' %>
- <% end %>
- <% if can?(:destroy, document) %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
- document_path(document),
- :method => :delete,
- :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
- :class => 'btn btn-xs btn-danger' %>
- <% end %>
- |
- <% end %>
-
- <% end %>
+ <% end %>
+ <% if can?(:destroy, document) %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ document_path(document),
+ :method => :delete,
+ :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
+ :class => 'btn btn-xs btn-danger' %>
+ <% end %>
+
+ <% end %>
+
<% end %>
-
-
+ <% end %>
+
+
-<% else %>
- Not Authorized!
-<% end %>
+
diff --git a/app/views/event_types/index.html.erb b/app/views/event_types/index.html.erb
index 2e334f62..5f76b807 100644
--- a/app/views/event_types/index.html.erb
+++ b/app/views/event_types/index.html.erb
@@ -1,32 +1,32 @@
- Event Types
+Event Types
-
-
-
- Name |
- Display in Sidebar |
- |
-
-
+
+
+
+ Name |
+ Display in Sidebar |
+ |
+
+
-
- <% @event_types.each do |event_type| %>
-
- <%= event_type.name %> |
- <%= event_type.display ? 'Yes':'No' %> |
-
- <% if can?(:edit, EventType) %>
- <%= link_to 'Edit', edit_event_type_path(event_type),:class => 'btn btn-primary btn-xs' %> |
- <% end %>
- <% if can?(:destroy, EventType) %>
+
+ <% @event_types.each do |event_type| %>
+
+ <%= event_type.name %> |
+ <%= event_type.display ? 'Yes':'No' %> |
+
+ <% if can?(:edit, EventType) %>
+ <%= link_to 'Edit', edit_event_type_path(event_type),:class => 'btn btn-primary btn-xs' %> |
+ <% end %>
+ <% if can?(:destroy, EventType) %>
<%= link_to 'Destroy', event_type, method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-danger btn-xs' %>
- <% end %>
-
-
- <% end %>
-
-
+ <% end %>
+
+
+ <% end %>
+
+
-
+
- <%= link_to 'New Event Type', new_event_type_path,:class => 'btn btn-primary' %>
\ No newline at end of file
+<%= link_to 'New Event Type', new_event_type_path,:class => 'btn btn-primary' %>
\ No newline at end of file
diff --git a/app/views/event_types/new.html.erb b/app/views/event_types/new.html.erb
index 2b000813..cbcde165 100644
--- a/app/views/event_types/new.html.erb
+++ b/app/views/event_types/new.html.erb
@@ -1,5 +1,5 @@
-
+
- <%= render 'form' %>
\ No newline at end of file
+ <%= render 'form' %>
\ No newline at end of file
diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb
index 3689a1b2..5e86115f 100644
--- a/app/views/events/_form.html.erb
+++ b/app/views/events/_form.html.erb
@@ -6,6 +6,9 @@
<%= f.association :event_type, :prompt => 'Select an event type', :selected => 1 %>
+
+ <%= f.association :participant, collection: Participant.exec, :prompt => 'Select a member of SCC (optional)' %>
+
<% if can?(:create, EventType) %>
<%= link_to "Or create a new event type", new_event_type_path, class: 'btn btn-primary' %>
@@ -22,4 +25,4 @@
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
@event, :class => 'btn btn-default' %>
-<% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/events/edit.html.erb b/app/views/events/edit.html.erb
index bbf88c8c..4c9199c5 100644
--- a/app/views/events/edit.html.erb
+++ b/app/views/events/edit.html.erb
@@ -1,5 +1,5 @@
-
+
- <%= render 'form' %>
\ No newline at end of file
+<%= render 'form' %>
\ No newline at end of file
diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb
index 748f081f..d8047139 100644
--- a/app/views/events/index.html.erb
+++ b/app/views/events/index.html.erb
@@ -1,50 +1,50 @@
-
+
- <% if can?(:create, Event) %>
-
- <%= link_to 'New Event', new_event_path, :class => 'btn btn-primary' %>
-
-
- <% end %>
+<% if can?(:create, Event) %>
+
+ <%= link_to 'New Event', new_event_path, :class => 'btn btn-primary' %>
+
+
+<% end %>
-
-
-
- |
- Event Type |
- Description |
- Created |
- Actions |
-
-
+
+
+
+ |
+ Event Type |
+ Description |
+ Created |
+ Actions |
+
+
-
- <% @events.each do |event| %>
- >
- <%= link_to 'Show', event, :class => 'btn btn-info btn-xs' %> |
- <%= event.event_type.name %> |
- <%= event.description %> |
- <%= date_and_time event.created_at %> |
-
- <% if can?(:approve, Event) %>
- <%= form_tag approve_event_path(event), :style => "display: inline", method: :put do %>
- <% if !event.is_done %>
- <%= submit_tag 'OK', :class => 'btn btn-success btn-xs' %>
- <% else %>
- <%= submit_tag 'Un-OK', :class => 'btn btn-warning btn-xs' %>
- <% end %>
- <% end %>
+ |
+ <% @events.each do |event| %>
+ >
+ <%= link_to 'Show', event, :class => 'btn btn-info btn-xs' %> |
+ <%= event.event_type.name %> |
+ <%= event.description %> |
+ <%= date_and_time event.created_at %> |
+
+ <% if can?(:approve, Event) %>
+ <%= form_tag approve_event_path(event), :style => "display: inline", method: :post do %>
+ <% if !event.is_done %>
+ <%= submit_tag 'OK', :class => 'btn btn-success btn-xs' %>
+ <% else %>
+ <%= submit_tag 'Un-OK', :class => 'btn btn-warning btn-xs' %>
+ <% end %>
<% end %>
- <% if can?(:update, Event) %>
- <%= link_to 'Edit', edit_event_path(event),:class => 'btn btn-primary btn-xs' %>
- <% end %>
- <% if can?(:destroy, Event) %>
- <%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-danger btn-xs' %>
- <% end %>
- |
-
- <% end %>
-
-
+ <% end %>
+ <% if can?(:update, Event) %>
+ <%= link_to 'Edit', edit_event_path(event),:class => 'btn btn-primary btn-xs' %>
+ <% end %>
+ <% if can?(:destroy, Event) %>
+ <%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-danger btn-xs' %>
+ <% end %>
+
+
+ <% end %>
+
+
diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb
index 74f105f0..84022f25 100644
--- a/app/views/events/show.html.erb
+++ b/app/views/events/show.html.erb
@@ -5,8 +5,10 @@
<%= @event.event_type.name %>
Created At:
<%= date_and_time @event.created_at %>
- Is done:
+ Is Done:
<%= format_boolean @event.is_done %>
+ Assigned To:
+ <%= @event.participant.name if @event.participant != nil %>
Description:
<%= @event.description %>
@@ -25,4 +27,4 @@
:method => 'delete',
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-danger' %>
-<% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/faqs/edit.html.erb b/app/views/faqs/edit.html.erb
index b9840ad9..470fd340 100644
--- a/app/views/faqs/edit.html.erb
+++ b/app/views/faqs/edit.html.erb
@@ -1,11 +1,6 @@
-<% if can?(:update, @faq) %>
- <%- model_class = Faq -%>
-
+<%- model_class = Faq -%>
+
- <%= render :partial => 'form' %>
-
-<% else %>
- Not Authorized!
-<% end %>
+<%= render :partial => 'form' %>
diff --git a/app/views/faqs/index.html.erb b/app/views/faqs/index.html.erb
index 2b342660..245942f3 100644
--- a/app/views/faqs/index.html.erb
+++ b/app/views/faqs/index.html.erb
@@ -1,57 +1,53 @@
-<% if can?(:read, Faq) %>
- <%- model_class = Faq -%>
-
+<%- model_class = Faq -%>
+
- <% if can?(:create, Faq) %>
-
- <%= link_to t('.new', :default => t("helpers.links.new_faq")),
+<% if can?(:create, Faq) %>
+
+ <%= link_to t('.new', :default => t("helpers.links.new_faq")),
new_faq_path,
:class => 'btn btn-primary' %>
-
-
- <% end %>
+
+
+<% end %>
-
- <% @faqs.each do |faq| %>
-
-
-
-
- <%= faq.answer %>
- <% if can?(:update, faq) or can?(:destroy, faq) %>
-
-
- <% if can?(:update, faq) %>
- <%= link_to t('.edit', :default => t("helpers.links.edit")),
+
+ <% @faqs.each do |faq| %>
+
+
+
+
+ <%= faq.answer %>
+ <% if can?(:update, faq) or can?(:destroy, faq) %>
+
+
+ <% if can?(:update, faq) %>
+ <%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_faq_path(faq), :class => "btn btn-xs btn-primary" %>
- <% end %>
+ <% end %>
- <% if can?(:destroy, faq) %>
- <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
+ <% if can?(:destroy, faq) %>
+ <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
faq_path(faq),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => "btn btn-xs btn-danger" %>
- <% end %>
-
- <% end %>
-
+ <% end %>
+
+ <% end %>
- <% end %>
+ <% end %>
+
-<% else %>
-
Not Authorized!
-<% end %>
diff --git a/app/views/participants/show.html.erb b/app/views/participants/show.html.erb
index 016bcc17..0965ab09 100644
--- a/app/views/participants/show.html.erb
+++ b/app/views/participants/show.html.erb
@@ -5,12 +5,14 @@
+ - Wristband:
+ - <%= @wristband %>
+ - <%= model_class.human_attribute_name(:has_signed_waiver) %>:
+ - <%= @participant.has_signed_waiver ? "Yes" : "No" %>
<% if can?(:read_phone_number, @participant) %>
- <%= model_class.human_attribute_name(:phone_number) %>:
- <%= @participant.formatted_phone_number %>
- <% end %>
-
- <%= model_class.human_attribute_name(:has_signed_waiver) %>:
- - <%= @participant.has_signed_waiver ? "yes" : "no" %>
+ <% end %>
- <%= model_class.human_attribute_name(:department) %>:
- <%= @participant.department %>
- <%= model_class.human_attribute_name(:student_class) %>:
@@ -23,12 +25,12 @@
<%= link_to membership.organization_name_formatted, membership.organization %>
<% if can?(:edit, membership) %>
- <%= link_to 'Edit',
- edit_participant_membership_path(@participant, membership),
+ <%= link_to 'Edit',
+ edit_participant_membership_path(@participant, membership),
:class => 'btn btn-primary btn-xs' %>
<% end %>
<% if can?(:destrory, membership) %>
- <%= link_to 'Remove',
+ <%= link_to 'Remove',
participant_membership_path(@participant, membership),
:method => :delete,
:class => 'btn btn-danger btn-xs' %>
@@ -49,7 +51,7 @@
<% end %>
<% end %>
<% end %>
-
+
<% unless @participant.shifts.blank? %>
Shifts:
@@ -60,7 +62,29 @@
<% end %>
-
+
+ Certifications:
+
+
+ <% @participant.certifications.each do |cert| %>
+ -
+ <%= cert.certification_type.name %>
+ <% if can?(:destroy, Certification) %>
+ <%= link_to "Delete",
+ participant_certification_path(@participant, cert),
+ :method => :delete,
+ :class => 'btn btn-danger btn-xs' %>
+ <% end %>
+
+ <% end %>
+ <% if can?(:create, Certification) && @participant.certifications.size < CertificationType.all.size %>
+ - <%= link_to "Add",
+ new_participant_certification_path(@participant),
+ :class => 'btn btn-primary btn-xs' %>
+ <% end %>
+
+
+
<% unless @participant.checkouts.current.blank? %>
Tools:
@@ -72,8 +96,8 @@
<% end %>
-
-
+
+
<%= link_to t('.back', :default => t("helpers.links.back")),
participants_path, :class => 'btn btn-default' %>
@@ -101,4 +125,3 @@
<% else %>
Not Authorized!
<% end %>
-
diff --git a/app/views/tools/show.html.erb b/app/views/tools/show.html.erb
index e44ebd66..b2218605 100644
--- a/app/views/tools/show.html.erb
+++ b/app/views/tools/show.html.erb
@@ -14,6 +14,16 @@
Checked out at:
<%= date_and_time @tool.checkouts.current.first.checked_out_at %>
<% end %>
+ <% if !@tool.tool_type.tool_type_certifications.empty? %>
+ Required Certifications:
+
+
+ <% @tool.tool_type.tool_type_certifications.each do |cert| %>
+ - <%= cert.certification_type.name %>
+ <% end %>
+
+
+ <% end %>
<%= link_to t('.back', :default => t("helpers.links.back")),
diff --git a/app/views/waivers/new.html.erb b/app/views/waivers/new.html.erb
index fb47137a..43aa0d91 100644
--- a/app/views/waivers/new.html.erb
+++ b/app/views/waivers/new.html.erb
@@ -1,108 +1,105 @@
-
-
-<% if !current_user.participant.is_scc? or params[:participant_id]== nil %>
+
You must watch the video prior to signing the waiver.
- <% else %>
-
-<% end %>
-
-
-
<%= Time.now.year %> SPRING CARNIVAL MIDWAY RELEASE OF LIABILITY
-
-
-
- I, <%= @user.name %>, want to participate in Carnegie Mellon University (“CMU”) <%= Time.now.year %> Spring Carnival Midway construction
-
- activities and/or be present on the Midway construction site (collectively, the “Activities.”) I understand
-
- that the Activities may involve climbing, crawling, physical exertion, the use of and/or proximity to hand
-
- and power tools and construction materials and equipment.
-
-
-
- I understand that there are risks (including, but not limited to, the risk of injury, disability and death)
- associated with my participation in the Activities. I voluntarily assume all the risks. In consideration of
+
<%= Time.now.year %> SPRING CARNIVAL MIDWAY RELEASE OF LIABILITY
- the benefits of participation in the Activities, I hereby, on behalf of myself and those acting on my
+
+I, <%= @user.name %>, want to participate in Carnegie Mellon University (“CMU”) <%= Time.now.year %> Spring Carnival Midway construction
+activities and/or be present on the Midway construction site (collectively, the “Activities.”) I understand
+that the Activities may involve climbing, crawling, physical exertion, the use of and/or proximity to hand
+and power tools and construction materials and equipment.
+
- behalf, irrevocably and unconditionally release, waive and promise not to sue CMU from/for any and all
+
+I understand that there are risks (including, but not limited to, the risk of injury, disability and death)
+associated with my participation in the Activities. I voluntarily assume all the risks. In consideration of
+the benefits of participation in the Activities, I hereby, on behalf of myself and those acting on my
+behalf, irrevocably and unconditionally release, waive and promise not to sue CMU from/for any and all
+liabilities, losses, injuries, damages, claims, demands, actions and/or causes of action related to my
+participation in the Activities, including the securing of, or failure to secure, medical treatment for me.
+
- liabilities, losses, injuries, damages, claims, demands, actions and/or causes of action related to my
+
+The laws of Pennsylvania shall apply to this Release. If any of its provisions are declared illegal,
+unenforceable or ineffective, they shall be deemed severable and all other provisions shall remain valid and binding.
+
- participation in the Activities, including the securing of medical treatment for me.
-
-
+<%= form_tag( participant_waiver_path(@user) ) do %>
- The laws of Pennsylvania shall apply to this Release. If any of its provisions are declared illegal,
-
- unenforceable or ineffective, they shall be deemed severable and all other provisions shall remain valid and binding.
-
-
- <%= form_tag( participant_waiver_path(@user) ) do %>
- <%= check_box_tag :agree %> <%= label_tag :agree, "I have read this release and understand it and I voluntarily agree to all its provisions." %>
-
+ <%= check_box_tag :agree %>
+ <%= label_tag :agree, "I have read this release and understand it and I voluntarily agree to all its provisions." %>
+
<%= check_box_tag :adult %>
- <%= label_tag :adult, "I am 18 years of age or older" %>
+ <%= label_tag :adult, "I am 18 years of age or older." %>
Emergency Alert Information
All Spring Carnival participants must provide their mobile phone number, which will be enrolled in the emergency alert system.
-
<%= label_tag :emergency_phone, "Cell Phone:" %> <%= text_field_tag :phone_number %>
-
<%= label_tag :emergency_phone, "Phone Carrier:" %> <%= collection_select(:participant, :phone_carrier_id, PhoneCarrier.all, :id, :name) %>
+
+ <%= label_tag :emergency_phone, "Cell Phone:" %>
+ <%= text_field_tag :phone_number %>
+
+
+ <%= label_tag :emergency_phone, "Phone Carrier:" %>
+ <%= collection_select(:participant, :phone_carrier_id, PhoneCarrier.all, :id, :name) %>
+
- <%= submit_tag "Submit", class: "btn btn-primary" %>
+
By typing your full name below you are digitally signing this document.
+ <%= label_tag :signature, "Required electronic signature:" %>
+ <%= text_field_tag :signature %>
- <% end %>
-
+
+ <%= submit_tag "Submit Waiver", class: "btn btn-primary" %>
+
+<% end %>
+
-<% if !current_user.participant.is_scc? or params[:participant_id]== nil %>
-<% end %>
diff --git a/bin/delayed_job b/bin/delayed_job
new file mode 100755
index 00000000..edf19598
--- /dev/null
+++ b/bin/delayed_job
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
+require 'delayed/command'
+Delayed::Command.new(ARGV).daemonize
diff --git a/config/application.rb b/config/application.rb
index 85cabc84..11edc805 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -24,6 +24,11 @@ class Application < Rails::Application
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ # Enables delay_job gem to queue up tasks
+ config.active_job.queue_adapter = :delayed_job
+
WillPaginate::ViewHelpers.pagination_options[:inner_window] = 1
WillPaginate::ViewHelpers.pagination_options[:outer_window] = 0
end
diff --git a/config/routes.rb b/config/routes.rb
index aff9b4c1..94b7e2e6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -32,6 +32,7 @@
resources :participants do
resources :memberships, :except => [:index, :show]
resource :waiver, :except => [:edit, :destroy, :show, :update]
+ resources :certifications, :only => [:new, :create, :destroy]
post 'lookup', on: :collection
end
diff --git a/db/migrate/20170305040259_add_waiver_start_to_participant.rb b/db/migrate/20170305040259_add_waiver_start_to_participant.rb
new file mode 100644
index 00000000..46f785d0
--- /dev/null
+++ b/db/migrate/20170305040259_add_waiver_start_to_participant.rb
@@ -0,0 +1,5 @@
+class AddWaiverStartToParticipant < ActiveRecord::Migration
+ def change
+ add_column :participants, :waiver_start, :datetime
+ end
+end
diff --git a/db/migrate/20170321154121_create_certification_types.rb b/db/migrate/20170321154121_create_certification_types.rb
new file mode 100644
index 00000000..58a29b36
--- /dev/null
+++ b/db/migrate/20170321154121_create_certification_types.rb
@@ -0,0 +1,9 @@
+class CreateCertificationTypes < ActiveRecord::Migration
+ def change
+ create_table :certification_types do |t|
+ t.string :name
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20170321154153_create_certifications.rb b/db/migrate/20170321154153_create_certifications.rb
new file mode 100644
index 00000000..1db62495
--- /dev/null
+++ b/db/migrate/20170321154153_create_certifications.rb
@@ -0,0 +1,12 @@
+class CreateCertifications < ActiveRecord::Migration
+ def change
+ create_table :certifications do |t|
+ t.datetime :created_at
+ t.datetime :updated_at
+ t.belongs_to :participant, index: true, foreign_key: true
+ t.belongs_to :certification_type, index: true, foreign_key: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20170322031706_create_tool_type_certifications.rb b/db/migrate/20170322031706_create_tool_type_certifications.rb
new file mode 100644
index 00000000..ea595dfc
--- /dev/null
+++ b/db/migrate/20170322031706_create_tool_type_certifications.rb
@@ -0,0 +1,12 @@
+class CreateToolTypeCertifications < ActiveRecord::Migration
+ def change
+ create_table :tool_type_certifications do |t|
+ t.datetime :created_at
+ t.datetime :updated_at
+ t.belongs_to :tool_type, index: true, foreign_key: true
+ t.belongs_to :certification_type, index: true, foreign_key: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/migrate/20170323163001_change_store_item_price_datatype.rb b/db/migrate/20170323163001_change_store_item_price_datatype.rb
new file mode 100644
index 00000000..9b767922
--- /dev/null
+++ b/db/migrate/20170323163001_change_store_item_price_datatype.rb
@@ -0,0 +1,6 @@
+class ChangeStoreItemPriceDatatype < ActiveRecord::Migration
+ def change
+ change_column :store_items, :price, :decimal, :precision => 8, :scale => 2
+ change_column :store_purchases, :price_at_purchase, :decimal, :precision => 8, :scale => 2
+ end
+end
diff --git a/db/migrate/20170326233627_create_delayed_jobs.rb b/db/migrate/20170326233627_create_delayed_jobs.rb
new file mode 100644
index 00000000..27fdcf6c
--- /dev/null
+++ b/db/migrate/20170326233627_create_delayed_jobs.rb
@@ -0,0 +1,22 @@
+class CreateDelayedJobs < ActiveRecord::Migration
+ def self.up
+ create_table :delayed_jobs, force: true do |table|
+ table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
+ table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
+ table.text :handler, null: false # YAML-encoded string of the object that will do work
+ table.text :last_error # reason for last failure (See Note below)
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
+ table.datetime :locked_at # Set when a client is working on this object
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
+ table.string :locked_by # Who is working on this object (if locked)
+ table.string :queue # The name of the queue this job is in
+ table.timestamps null: true
+ end
+
+ add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
+ end
+
+ def self.down
+ drop_table :delayed_jobs
+ end
+end
diff --git a/db/migrate/20170402012413_add_participant_id_to_events.rb b/db/migrate/20170402012413_add_participant_id_to_events.rb
new file mode 100644
index 00000000..26261f14
--- /dev/null
+++ b/db/migrate/20170402012413_add_participant_id_to_events.rb
@@ -0,0 +1,5 @@
+class AddParticipantIdToEvents < ActiveRecord::Migration
+ def change
+ add_column :events, :participant_id, :integer
+ end
+end
diff --git a/db/migrate/20170410184313_add_is_building_to_organization_category.rb b/db/migrate/20170410184313_add_is_building_to_organization_category.rb
new file mode 100644
index 00000000..4ae80946
--- /dev/null
+++ b/db/migrate/20170410184313_add_is_building_to_organization_category.rb
@@ -0,0 +1,5 @@
+class AddIsBuildingToOrganizationCategory < ActiveRecord::Migration
+ def change
+ add_column :organization_categories, :is_building, :boolean
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a1a77c55..2f129a6c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,11 +11,27 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160404161512) do
+ActiveRecord::Schema.define(version: 20170410184313) do
+
+ create_table "certification_types", force: :cascade do |t|
+ t.string "name", limit: 255
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "certifications", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "participant_id", limit: 4
+ t.integer "certification_type_id", limit: 4
+ end
+
+ add_index "certifications", ["certification_type_id"], name: "index_certifications_on_certification_type_id", using: :btree
+ add_index "certifications", ["participant_id"], name: "index_certifications_on_participant_id", using: :btree
create_table "charge_types", force: :cascade do |t|
t.string "name", limit: 255
- t.boolean "requires_booth_chair_approval", limit: 1
+ t.boolean "requires_booth_chair_approval"
t.decimal "default_amount", precision: 8, scale: 2
t.text "description", limit: 65535
t.datetime "created_at"
@@ -32,7 +48,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "charged_at"
- t.boolean "is_approved", limit: 1
+ t.boolean "is_approved"
t.integer "creating_participant_id", limit: 4
end
@@ -50,6 +66,38 @@
add_index "checkouts", ["tool_id"], name: "index_checkouts_on_tool_id", using: :btree
+ create_table "delayed_jobs", force: :cascade do |t|
+ t.integer "priority", limit: 4, default: 0, null: false
+ t.integer "attempts", limit: 4, default: 0, null: false
+ t.text "handler", limit: 65535, null: false
+ t.text "last_error", limit: 65535
+ t.datetime "run_at"
+ t.datetime "locked_at"
+ t.datetime "failed_at"
+ t.string "locked_by", limit: 255
+ t.string "queue", limit: 255
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
+
+ create_table "delayed_jobs", force: :cascade do |t|
+ t.integer "priority", limit: 4, default: 0, null: false
+ t.integer "attempts", limit: 4, default: 0, null: false
+ t.text "handler", limit: 65535, null: false
+ t.text "last_error", limit: 65535
+ t.datetime "run_at"
+ t.datetime "locked_at"
+ t.datetime "failed_at"
+ t.string "locked_by", limit: 255
+ t.string "queue", limit: 255
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
+
create_table "documents", force: :cascade do |t|
t.integer "document_id", limit: 4
t.string "name", limit: 255
@@ -57,21 +105,21 @@
t.datetime "created_at"
t.datetime "updated_at"
t.integer "organization_id", limit: 4
- t.boolean "public", limit: 1
+ t.boolean "public"
end
create_table "event_types", force: :cascade do |t|
- t.boolean "display", limit: 1
- t.string "name", limit: 255
- t.integer "priority", limit: 4
+ t.boolean "display"
+ t.string "name", limit: 255
end
create_table "events", force: :cascade do |t|
- t.boolean "is_done", limit: 1
- t.integer "event_type_id", limit: 4
+ t.boolean "is_done"
+ t.integer "event_type_id", limit: 4
t.datetime "created_at"
- t.text "description", limit: 65535
+ t.text "description", limit: 65535
t.datetime "updated_at"
+ t.integer "participant_id", limit: 4
end
create_table "faqs", force: :cascade do |t|
@@ -115,7 +163,7 @@
t.integer "participant_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "is_booth_chair", limit: 1
+ t.boolean "is_booth_chair"
t.string "title", limit: 255
t.integer "booth_chair_order", limit: 4
end
@@ -134,14 +182,15 @@
add_index "organization_aliases", ["organization_id"], name: "index_organization_aliases_on_organization_id", using: :btree
create_table "organization_categories", force: :cascade do |t|
- t.string "name", limit: 255
+ t.string "name", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
+ t.boolean "is_building"
end
create_table "organization_status_types", force: :cascade do |t|
t.string "name", limit: 255
- t.boolean "display", limit: 1
+ t.boolean "display"
end
create_table "organization_statuses", force: :cascade do |t|
@@ -187,9 +236,9 @@
t.string "andrewid", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "has_signed_waiver", limit: 1
+ t.boolean "has_signed_waiver"
t.string "phone_number", limit: 255
- t.boolean "has_signed_hardhat_waiver", limit: 1
+ t.boolean "has_signed_hardhat_waiver"
t.integer "user_id", limit: 4
t.string "cached_name", limit: 255
t.string "cached_surname", limit: 255
@@ -197,6 +246,7 @@
t.string "cached_department", limit: 255
t.string "cached_student_class", limit: 255
t.datetime "cache_updated"
+ t.datetime "waiver_start"
t.integer "phone_carrier_id", limit: 4
end
@@ -252,19 +302,19 @@
create_table "store_items", force: :cascade do |t|
t.string "name", limit: 255
- t.decimal "price", precision: 10
+ t.decimal "price", precision: 8, scale: 2
t.integer "quantity", limit: 4
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "store_purchases", force: :cascade do |t|
t.integer "charge_id", limit: 4
t.integer "store_item_id", limit: 4
- t.decimal "price_at_purchase", precision: 10
+ t.decimal "price_at_purchase", precision: 8, scale: 2
t.integer "quantity_purchased", limit: 4
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
add_index "store_purchases", ["charge_id"], name: "index_store_purchases_on_charge_id", using: :btree
@@ -277,9 +327,19 @@
t.text "description", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "is_completed", limit: 1
+ t.boolean "is_completed"
end
+ create_table "tool_type_certifications", force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.integer "tool_type_id", limit: 4
+ t.integer "certification_type_id", limit: 4
+ end
+
+ add_index "tool_type_certifications", ["certification_type_id"], name: "index_tool_type_certifications_on_certification_type_id", using: :btree
+ add_index "tool_type_certifications", ["tool_type_id"], name: "index_tool_type_certifications_on_tool_type_id", using: :btree
+
create_table "tool_types", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at"
@@ -292,7 +352,7 @@
t.integer "participant_id", limit: 4
t.integer "organization_id", limit: 4
t.string "note", limit: 255
- t.boolean "active", limit: 1, default: true
+ t.boolean "active", default: true
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -336,10 +396,8 @@
add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree
- add_foreign_key "judgements", "judgement_categories"
- add_foreign_key "judgements", "judges"
- add_foreign_key "judgements", "organizations"
- add_foreign_key "participants", "phone_carriers"
- add_foreign_key "store_purchases", "charges"
- add_foreign_key "store_purchases", "store_items"
+ add_foreign_key "certifications", "certification_types"
+ add_foreign_key "certifications", "participants"
+ add_foreign_key "tool_type_certifications", "certification_types"
+ add_foreign_key "tool_type_certifications", "tool_types"
end
diff --git a/db/seeds.rb b/db/seeds.rb
index f9e6d14b..b0179c41 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -15,14 +15,14 @@
# Organization Categories -----------------------------------------------------
puts 'Organization Categories'
-fraternity = OrganizationCategory.create({ name: 'Fraternity'})
-sorority = OrganizationCategory.create({ name: 'Sorority'})
-independent = OrganizationCategory.create({ name: 'Independent'})
-blitz = OrganizationCategory.create({ name: 'Blitz'})
-concessions = OrganizationCategory.create({ name: 'Concessions'})
-non_building = OrganizationCategory.create({ name: 'Non-Building' })
-scc = OrganizationCategory.create({ name: 'SCC'})
-staff = OrganizationCategory.create({ name: 'Staff' })
+fraternity = OrganizationCategory.create({ name: 'Fraternity', is_building: true })
+sorority = OrganizationCategory.create({ name: 'Sorority', is_building: true })
+independent = OrganizationCategory.create({ name: 'Independent', is_building: true})
+blitz = OrganizationCategory.create({ name: 'Blitz', is_building: true })
+concessions = OrganizationCategory.create({ name: 'Concessions', is_building: true })
+non_building = OrganizationCategory.create({ name: 'Non-Building', is_building: false })
+scc = OrganizationCategory.create({ name: 'SCC', is_building: false })
+staff = OrganizationCategory.create({ name: 'Staff', is_building: false })
# Organizations ---------------------------------------------------------------
puts 'Organizations'
@@ -255,6 +255,14 @@
Membership.create({ organization: tsa_org, participant: Participant.create({ andrewid: 'ppan'}), is_booth_chair: true })
Membership.create({ organization: tsa_org, participant: Participant.create({ andrewid: 'pchao '}), is_booth_chair: true })
+# Certification Types --------------------------------------------------------
+puts 'Certification Types'
+
+golf_cart_cert = CertificationType.new({ name: 'Golf Cart' })
+scissor_lift_cert = CertificationType.new({ name: 'Scissor Lift' })
+Certification.create({ participant: chair, certification_type: golf_cart_cert })
+Certification.create({ participant: chair, certification_type: scissor_lift_cert })
+
# Organization Status Types --------------------------------------------------
puts 'Organization Status Types'
@@ -716,6 +724,9 @@
generate_tools
+ToolTypeCertification.create({ tool_type: ToolType.find_by_name("Golf Cart"), certification_type: golf_cart_cert })
+ToolTypeCertification.create({ tool_type: ToolType.find_by_name("Scissor Lift"), certification_type: scissor_lift_cert })
+
# Store -------------------------------------------------------------------------
puts 'Store'
diff --git a/db/tool_seed.rb b/db/tool_seed.rb
index b380d908..c713d49d 100644
--- a/db/tool_seed.rb
+++ b/db/tool_seed.rb
@@ -2636,5 +2636,12 @@ def generate_tools
{ barcode: 9995, type: 'Socket Wrench Set' },
{ barcode: 9996, type: 'Socket Wrench Set' },
{ barcode: 9997, type: 'Square', description: '12\'' },
- { barcode: 9998, type: 'Square', description: '12\'' }
+ { barcode: 9998, type: 'Square', description: '12\'' },
+ { barcode: 10001, type: 'Golf Cart', description: 'Four seater' },
+ { barcode: 10002, type: 'Golf Cart', description: 'Four seater' },
+ { barcode: 10003, type: 'Golf Cart', description: 'Four seater' },
+ { barcode: 10004, type: 'Golf Cart', description: 'Two seater with bed' },
+ { barcode: 10005, type: 'Golf Cart', description: 'Two seater with bed' },
+ { barcode: 10011, type: 'Scissor Lift', description: '12\' scissor lift' },
+ { barcode: 10012, type: 'Scissor Lift', description: '12\' scissor lift' }
]
diff --git a/lib/messenger.rb b/lib/messenger.rb
new file mode 100644
index 00000000..0c293334
--- /dev/null
+++ b/lib/messenger.rb
@@ -0,0 +1,31 @@
+USER_UNSUBSCRIBED_FROM_TWILIO_ERROR_CODE = 21610
+
+module Messenger
+
+ def send_sms(number, content)
+ sid = ENV["TWILIO_ACCT_SID"]
+ auth = ENV["TWILIO_AUTH"]
+
+ @client = Twilio::REST::Client.new sid, auth
+
+ from = "+14123854063"
+
+ # The following try-rescue block is needed in case user unsubscribe
+ # if the user ubsubscribe and we attempt to message them
+ # the api will report an error
+
+ begin
+ message = @client.account.messages.create(
+ :from => from,
+ :to => '+1'+number,
+ :body => content
+ )
+ rescue Twilio::REST::RequestError => e
+ case e.code
+ when USER_UNSUBSCRIBED_FROM_TWILIO_ERROR_CODE
+ puts e.message
+ end
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/public/cheating.html b/public/cheating.html
new file mode 100644
index 00000000..2e2b3294
--- /dev/null
+++ b/public/cheating.html
@@ -0,0 +1,34 @@
+
+
+
+ You tried to do something suspicious
+
+
+
+
+
+
+
You tried to skip the safety video
+
Please watch the entire safety video before completing the waiver!
+
+
+
+
+
+
diff --git a/public/images/spy.jpg b/public/images/spy.jpg
new file mode 100644
index 00000000..ddac8118
Binary files /dev/null and b/public/images/spy.jpg differ
diff --git a/test/factories.rb b/test/factories.rb
index ce241aed..bb376658 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -28,7 +28,7 @@
# checkout
factory :checkout do
- checked_out_at Time.now
+ checked_out_at Time.now - 1.hour
association :tool
association :organization
@@ -40,6 +40,16 @@
url "MyString"
end
+ #event
+ factory :event do
+ association :event_type
+ end
+
+ #event_type
+ factory :event_type do
+ name { generate(:random_string) }
+ end
+
# faq
factory :faq do
question "MyText"
@@ -73,6 +83,19 @@
name { generate(:random_string) }
end
+ # organization_status
+ factory :organization_status do
+ association :organization
+ association :organization_status_type
+ association :participant
+ end
+
+ # organization_status_type
+ factory :organization_status_type do
+ name { generate(:random_string) }
+ display false
+ end
+
# organization_timeline_entry
factory :organization_timeline_entry do
description { generate(:random_string) }
@@ -85,6 +108,7 @@
# participant
factory :participant, :aliases => [:completed_by, :issuing_participant, :receiving_participant] do
andrewid { generate(:random_string) }
+ waiver_start DateTime.now
end
# shift
@@ -127,6 +151,16 @@
association :tool_type
end
+ # tool waitlist
+ factory :tool_waitlist do
+ wait_start_time Time.now
+ tool_type_id 1
+
+ association :tool_type
+ association :organization
+ association :participant
+ end
+
# user
factory :user do
name "Default Factory User"
@@ -135,4 +169,16 @@
association :participant
end
+ #store_purchase
+ factory :store_purchase do
+
+ association :store_item
+ end
+
+ #store_item
+ factory :store_item do
+ name "Hammer"
+
+ end
+
end
diff --git a/test/integration/participant_test.rb b/test/integration/participant_test.rb
index 841bb698..4cab6619 100644
--- a/test/integration/participant_test.rb
+++ b/test/integration/participant_test.rb
@@ -4,7 +4,7 @@ class ParticipantTest < ActiveSupport::TestCase
context "With a refreshed ldap cache, " do
setup do
- @participant = FactoryGirl.create(:participant, :andrewid => "meribyte")
+ @participant = FactoryGirl.create(:participant, :andrewid => "erwilson")
end
teardown do
@@ -16,23 +16,23 @@ class ParticipantTest < ActiveSupport::TestCase
end
should "return name from directory" do
- assert_equal "Margaret Richards", @participant.name
+ assert_equal "Eleanor Wilson", @participant.name
end
should "return surname from directory" do
- assert_equal "Richards", @participant.surname
+ assert_equal "Wilson", @participant.surname
end
should "return email from directory" do
- assert_equal "mouse@cmu.edu", @participant.email
+ assert_equal "erwilson@andrew.cmu.edu", @participant.email
end
should "return department from directory" do
- assert_equal "Eberly Center, Teaching Excellence & Educational Innovation", @participant.department
+ assert_equal "Dietrich College Interdisciplinary", @participant.department
end
should "return student class from directory" do
- assert_equal "Masters", @participant.student_class
+ assert_equal "Junior", @participant.student_class
end
end
end
diff --git a/test/models/store_item_test.rb b/test/models/store_item_test.rb
deleted file mode 100644
index dd66a54b..00000000
--- a/test/models/store_item_test.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# ## Schema Information
-#
-# Table name: `store_items`
-#
-# ### Columns
-#
-# Name | Type | Attributes
-# ----------------- | ------------------ | ---------------------------
-# **`created_at`** | `datetime` | `not null`
-# **`id`** | `integer` | `not null, primary key`
-# **`name`** | `string(255)` |
-# **`price`** | `decimal(10, )` |
-# **`quantity`** | `integer` |
-# **`updated_at`** | `datetime` | `not null`
-#
-
-require 'test_helper'
-
-class StoreItemTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index e7d175b3..ba9ed8c3 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -8,6 +8,8 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
+ActiveRecord::Migration.maintain_test_schema!
+
class ActiveSupport::TestCase
def deny(condition)
diff --git a/test/unit/charge_test.rb b/test/unit/charge_test.rb
index db76547a..390302fd 100644
--- a/test/unit/charge_test.rb
+++ b/test/unit/charge_test.rb
@@ -32,23 +32,41 @@ class ChargeTest < ActiveSupport::TestCase
should belong_to(:organization)
should belong_to(:issuing_participant)
should belong_to(:receiving_participant)
+ should belong_to(:creating_participant)
should belong_to(:charge_type)
# Validations
+ should validate_presence_of(:charged_at)
+ should validate_presence_of(:issuing_participant)
+ should validate_presence_of(:organization)
+ should validate_presence_of(:charge_type)
+ should validate_presence_of(:amount)
+
+ should validate_numericality_of(:amount)
# Methods
context "With a proper context, " do
setup do
# Create a charges
- @fine = FactoryGirl.create(:charge)
+ @fine = FactoryGirl.create(:charge, :is_approved => false)
+ @fine2 = FactoryGirl.create(:charge, :is_approved => false)
+ @fine3 = FactoryGirl.create(:charge, :is_approved => true)
end
teardown do
end
should "show that all factories are properly created" do
- assert_equal 1, Charge.all.size
+ assert_equal 3, Charge.all.size
+ end
+
+ should "show that pending scope works" do
+ assert_equal 2, Charge.pending.size
+ end
+
+ should "show that approved scope works" do
+ assert_equal 1, Charge.approved.size
end
context "Testing charges" do
diff --git a/test/unit/charge_type_test.rb b/test/unit/charge_type_test.rb
index f66e1a12..06329edb 100644
--- a/test/unit/charge_type_test.rb
+++ b/test/unit/charge_type_test.rb
@@ -23,9 +23,13 @@ class ChargeTypeTest < ActiveSupport::TestCase
# Validations
+ should validate_presence_of(:name)
+ should validate_uniqueness_of(:name)
+
context "With a proper context, " do
setup do
- FactoryGirl.create(:charge_type)
+ @charge = FactoryGirl.create(:charge_type)
+ @charge_type = FactoryGirl.create(:charge, :charge_type => @charge)
end
teardown do
@@ -35,8 +39,12 @@ class ChargeTypeTest < ActiveSupport::TestCase
assert_equal 1, ChargeType.all.size
end
- # Scopes
+ should "show dependency on charge" do
+ assert_equal 1, Charge.all.size
+ @charge_type.destroy
+ assert_equal 0, Charge.all.size
+ end
+
- # Methods
end
end
diff --git a/test/unit/checkout_test.rb b/test/unit/checkout_test.rb
index 24f97a6c..dec960f3 100644
--- a/test/unit/checkout_test.rb
+++ b/test/unit/checkout_test.rb
@@ -35,18 +35,33 @@ class CheckoutTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
- FactoryGirl.create(:checkout)
+ @org = FactoryGirl.create(:organization, name: "bruce")
+ @person = FactoryGirl.create(:participant)
+ @type1 = FactoryGirl.create(:tool_type, name: "hammer")
+ @type2 = FactoryGirl.create(:tool_type, name: "drill")
+ @type3 = FactoryGirl.create(:tool_type, name: "lmao")
+ @t1 = FactoryGirl.create(:tool, barcode: 1111, tool_type: @type1)
+ @t2 = FactoryGirl.create(:tool, barcode: 2222, tool_type: @type2)
+ @t3 = FactoryGirl.create(:tool, barcode: 3333, tool_type: @type3)
+ @checkout1 = FactoryGirl.create(:checkout, :checked_in_at => Time.now, organization: @org, participant: @person, tool: @t1)
+ @checkout2 = FactoryGirl.create(:checkout, :checked_in_at => Time.now, organization: @org, participant: @person, tool: @t2)
+ @checkout3 = FactoryGirl.create(:checkout, :checked_in_at => nil, organization: @org, participant: @person, tool: @t3)
end
teardown do
end
should "show that all factories are properly created" do
- assert_equal 1, Checkout.all.size
+ assert_equal 3, Checkout.all.size
end
# Scopes
+ should "show that current scope works" do
+ assert_equal 1, Checkout.current.size
+ end
- # Methods
+ should "show that old scope works" do
+ assert_equal 2, Checkout.old.size
+ end
end
end
diff --git a/test/unit/document_test.rb b/test/unit/document_test.rb
index 069b43d4..45bec4eb 100644
--- a/test/unit/document_test.rb
+++ b/test/unit/document_test.rb
@@ -20,11 +20,30 @@
class DocumentTest < ActiveSupport::TestCase
# Relationships
+ should belong_to(:organization)
- # Validations
+ context "With a proper context, " do
+ setup do
+ @org = FactoryGirl.create(:organization_alias, :id => 123)
+ @document = FactoryGirl.create(:document, :organization_id => @org.id, :name => "Booth")
+ @document2 = FactoryGirl.create(:document, :organization_id => @org.id, :name => "Electric")
+ end
- # Scopes
+ teardown do
+ end
- # Methods
+ # Validations- is there a better way to test this?
+ should "show that a document has an organization assocaited with it" do
+ assert_equal 123, @document.organization_id
+ end
+
+ #scopes
+ should "show that search scope works" do
+ @doc = Document.search('booth')
+ assert_equal 'Booth', @doc[0].name
+
+ end
+
+ end
end
diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb
new file mode 100644
index 00000000..efec1250
--- /dev/null
+++ b/test/unit/event_test.rb
@@ -0,0 +1,40 @@
+# ## Schema Information
+#
+# Table name: `events`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# --------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `text(65535)` |
+# **`event_type_id`** | `integer` |
+# **`id`** | `integer` | `not null, primary key`
+# **`is_done`** | `boolean` |
+# **`participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+
+class EventTest < ActiveSupport::TestCase
+ # Relationships
+ should belong_to(:event_type)
+
+ # Scopes
+ context "With a proper context, " do
+ setup do
+ @type1 = FactoryGirl.create(:event_type, :display => false)
+ @type2 = FactoryGirl.create(:event_type, :display => true)
+ @event1 = FactoryGirl.create(:event, :is_done => true, :event_type_id => @type1.id)
+ @event2 = FactoryGirl.create(:event, :is_done => false, :event_type_id => @type2.id)
+ end
+
+ teardown do
+ end
+
+ #scopes
+ should "show that displayable scope works" do
+ assert_equal 1, Event.displayable.size
+ end
+ end
+
+end
diff --git a/test/unit/event_type_test.rb b/test/unit/event_type_test.rb
new file mode 100644
index 00000000..2d2877ab
--- /dev/null
+++ b/test/unit/event_type_test.rb
@@ -0,0 +1,20 @@
+# ## Schema Information
+#
+# Table name: `event_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# --------------- | ------------------ | ---------------------------
+# **`display`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`priority`** | `integer` |
+#
+
+class EventTypeTest < ActiveSupport::TestCase
+ # Relationships
+ should have_many(:events)
+
+
+end
diff --git a/test/unit/faq_test.rb b/test/unit/faq_test.rb
index 806633fb..5c7e9854 100644
--- a/test/unit/faq_test.rb
+++ b/test/unit/faq_test.rb
@@ -16,12 +16,22 @@
require 'test_helper'
class FaqTest < ActiveSupport::TestCase
- # Relationships
- # Validations
+ context "With a proper context, " do
+ setup do
+ @faq1 = FactoryGirl.create(:faq, :question => "how to sign a waiver?")
+ @faq2 = FactoryGirl.create(:faq, :question => "how to build a booth?")
+ end
- # Scopes
+ teardown do
+ end
- # Methods
+ # Scope
+ should "show that a search scope works" do
+ @ans = Faq.search("sign a waiver?")
+ assert_equal "how to sign a waiver?", @ans[0].question
+ end
+
+ end
end
diff --git a/test/models/judge_test.rb b/test/unit/judge_test.rb
similarity index 100%
rename from test/models/judge_test.rb
rename to test/unit/judge_test.rb
diff --git a/test/models/judgement_category_test.rb b/test/unit/judgement_category_test.rb
similarity index 100%
rename from test/models/judgement_category_test.rb
rename to test/unit/judgement_category_test.rb
diff --git a/test/models/judgement_test.rb b/test/unit/judgement_test.rb
similarity index 91%
rename from test/models/judgement_test.rb
rename to test/unit/judgement_test.rb
index 204c7690..e62ac5d9 100644
--- a/test/models/judgement_test.rb
+++ b/test/unit/judgement_test.rb
@@ -27,7 +27,7 @@
require 'test_helper'
class JudgementTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
+ # Relationships
+ should belong_to(:judgement_category)
+ should belong_to(:judge)
+end
\ No newline at end of file
diff --git a/test/unit/membership_test.rb b/test/unit/membership_test.rb
index 4ab77ae8..dc10977c 100644
--- a/test/unit/membership_test.rb
+++ b/test/unit/membership_test.rb
@@ -34,28 +34,32 @@ class MembershipTest < ActiveSupport::TestCase
should validate_presence_of(:participant)
should validate_presence_of(:organization)
- context "With a proper context, " do
+ context 'With a proper context, ' do
setup do
- FactoryGirl.create(:membership)
- @chair = FactoryGirl.create(:membership, :is_booth_chair => true)
+ @org1 = FactoryGirl.create(:organization)
+ @org2 = FactoryGirl.create(:organization)
+ @nonchair = FactoryGirl.create(:membership, organization: @org1)
+ @chair = FactoryGirl.create(:membership, organization: @org2, :is_booth_chair => true)
end
teardown do
+ @nonchair = nil
+ @chair = nil
end
- should "show that all factories are properly created" do
+ should 'show that all factories are properly created' do
assert_equal 2, Membership.all.size
end
# Scopes
+ should 'booth_chair scope should return all booth chairs' do
+ assert_equal 1, Membership.booth_chairs.size
+ end
# Methods
- context "Testing memberships" do
- should "know booth chairs" do
- #puts Membership.booth_chairs.map{ |bc| bc.participant.andrewid }
- assert_equal 1, Membership.booth_chairs.size
- assert_equal @chair, Membership.booth_chairs.first
- end
+ should 'formatted_name should return the organization followed and indication if this member is booth chair' do
+ assert_equal "#{@org1.name}", @nonchair.organization_name_formatted
+ assert_equal "#{@org2.name} - Booth Chair", @chair.organization_name_formatted
end
end
end
diff --git a/test/unit/organization_alias_test.rb b/test/unit/organization_alias_test.rb
index 3448024a..3e5ac9a2 100644
--- a/test/unit/organization_alias_test.rb
+++ b/test/unit/organization_alias_test.rb
@@ -27,22 +27,47 @@ class OrganizationAliasTest < ActiveSupport::TestCase
should belong_to(:organization)
# Validations
+ should validate_presence_of(:name)
+ should validate_presence_of(:organization)
+ should validate_uniqueness_of(:name)
- context "With a proper context, " do
+ context 'With a proper context, ' do
setup do
- FactoryGirl.create(:organization_alias)
+ @alias1 = FactoryGirl.create(:organization_alias, name: 'winner')
+ @alias2 = FactoryGirl.create(:organization_alias, name: 'loser')
+ @org1 = FactoryGirl.create(:organization)
+ @org2 = FactoryGirl.create(:organization)
+ @alias1.organization = @org1
+ @alias2.organization = @org2
end
teardown do
+ @alias1 = nil
+ @alias2 = nil
+ @org1 = nil
+ @org2 = nil
end
- should "show that all factories are properly created" do
- assert_equal 1, OrganizationAlias.all.size
+ should 'show that all factories are properly created' do
+ assert_equal 2, OrganizationAlias.all.size
end
# Scopes
+ # Search scope
+ should 'the search by term function should work correctly' do
+ assert_equal 1, OrganizationAlias.search("winner").size
+ assert_equal 1, OrganizationAlias.search("loser").size
+ assert_equal 0, Organization.search("blah").size
+ end
+
# Methods
+ should 'formatted name should return the organization name followed by the alias in parathesis' do
+ answer1 = "#{@org1.name} (winner)"
+ answer2 = "#{@org2.name} (loser)"
+ assert_equal answer1, @alias1.formatted_name
+ assert_equal answer2, @alias2.formatted_name
+ end
end
end
diff --git a/test/unit/organization_category_test.rb b/test/unit/organization_category_test.rb
index 9e5fdc1b..55549921 100644
--- a/test/unit/organization_category_test.rb
+++ b/test/unit/organization_category_test.rb
@@ -19,22 +19,32 @@ class OrganizationCategoryTest < ActiveSupport::TestCase
should have_many(:organizations)
# Validations
+ should validate_presence_of(:name)
+ should validate_uniqueness_of(:name)
- context "With a proper context, " do
+ context 'With a proper context, ' do
setup do
- FactoryGirl.create(:organization_category)
+ @cat1 = FactoryGirl.create(:organization_category)
+ @cat2 = FactoryGirl.create(:organization_category)
end
teardown do
+ @cat1 = nil
+ @cat2 = nil
end
- should "show that all factories are properly created" do
- assert_equal 1, OrganizationCategory.all.size
+ should 'show that all factories are properly created' do
+ assert_equal 2, OrganizationCategory.all.size
end
- # Scopes
-
- # Methods
-
+ # dependency
+ should 'remove all associated organizations once this organization category is removed' do
+ @org1 = FactoryGirl.create(:organization, organization_category: @cat1)
+ @org2 = FactoryGirl.create(:organization, organization_category: @cat1)
+ @org3 = FactoryGirl.create(:organization, organization_category: @cat2)
+ assert_equal 3, Organization.all.size
+ @cat1.destroy
+ assert_equal 1, Organization.all.size
+ end
end
end
diff --git a/test/unit/organization_status_test.rb b/test/unit/organization_status_test.rb
new file mode 100644
index 00000000..04ef62b4
--- /dev/null
+++ b/test/unit/organization_status_test.rb
@@ -0,0 +1,70 @@
+# ## Schema Information
+#
+# Table name: `organization_statuses`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ---------------------------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` |
+# **`description`** | `string(255)` |
+# **`id`** | `integer` | `not null, primary key`
+# **`organization_id`** | `integer` |
+# **`organization_status_type_id`** | `integer` |
+# **`participant_id`** | `integer` |
+# **`updated_at`** | `datetime` |
+#
+# ### Indexes
+#
+# * `index_organization_statuses_on_organization_id`:
+# * **`organization_id`**
+#
+
+require 'test_helper'
+
+class OrganizationStatusTest < ActiveSupport::TestCase
+
+ # Relationships
+ should belong_to(:organization_status_type)
+ should belong_to(:organization)
+ should belong_to(:participant)
+
+ # Validations
+ should validate_presence_of(:organization_status_type)
+ should validate_presence_of(:organization)
+ should validate_presence_of(:participant)
+
+ context 'With a proper context,' do
+ setup do
+ @status_type1 = FactoryGirl.create(:organization_status_type)
+ @status_type2 = FactoryGirl.create(:organization_status_type, :display => true)
+ @org = FactoryGirl.create(:organization)
+ @p = FactoryGirl.create(:participant)
+ @status1 = FactoryGirl.create(:organization_status,
+ :organization_status_type => @status_type1,
+ :organization => @org, :participant => @p)
+ @status2 = FactoryGirl.create(:organization_status,
+ :organization_status_type => @status_type2,
+ :organization => @org, :participant => @p)
+ end
+
+ teardown do
+ @status_type1 = nil
+ @status_type2 = nil
+ @org = nil
+ @p = nil
+ @status1 = nil
+ @status2 = nil
+ end
+
+ should 'show that all factories are properly created' do
+ assert_equal 2, OrganizationStatus.all.size
+ end
+
+ # Scope
+ should 'display statuses that are only displayable' do
+ assert_equal 1, OrganizationStatus.displayable.size
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/test/unit/organization_status_type_test.rb b/test/unit/organization_status_type_test.rb
new file mode 100644
index 00000000..da8df923
--- /dev/null
+++ b/test/unit/organization_status_type_test.rb
@@ -0,0 +1,58 @@
+# ## Schema Information
+#
+# Table name: `organization_status_types`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# -------------- | ------------------ | ---------------------------
+# **`display`** | `boolean` |
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+## ## Schema Information
+#
+
+
+require 'test_helper'
+
+class OrganizationStatusTypeTest < ActiveSupport::TestCase
+
+ # Relationships
+ should have_many(:organization_statuses)
+
+ # Validations
+ should validate_presence_of(:name)
+ should validate_uniqueness_of(:name)
+
+ context 'With a proper context, ' do
+ setup do
+ @type1 = FactoryGirl.create(:organization_status_type)
+ @person = FactoryGirl.create(:participant)
+ @org = FactoryGirl.create(:organization)
+ @status = FactoryGirl.create(:organization_status,
+ participant: @person, organization: @org, organization_status_type: @type1)
+ end
+
+ teardown do
+ @type1 = nil
+ @person = nil
+ @org = nil
+ @status = nil
+ end
+ #
+ should 'show that all factories are properly created' do
+ assert_equal 1, OrganizationStatusType.all.size
+ end
+
+ # Dependency
+ should 'delete status if status type is destroyed' do
+ @type1.update_attribute(:display, true)
+ assert(@status.valid?)
+ assert_equal 1, OrganizationStatus.all.size
+
+ @type1.destroy
+ assert_equal 0, OrganizationStatus.all.size
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index 68f870c9..5969993d 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -21,6 +21,7 @@
require 'test_helper'
+
class OrganizationTest < ActiveSupport::TestCase
# Relationships
should belong_to(:organization_category)
@@ -42,7 +43,7 @@ class OrganizationTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
- @short_org = FactoryGirl.create(:organization, :name => 'longer name', :short_name => 'name')
+ @short_org = FactoryGirl.create(:organization, :name => 'short name', :short_name => 'name')
@long_org = FactoryGirl.create(:organization, :name => 'long name', :short_name => nil)
end
@@ -54,11 +55,127 @@ class OrganizationTest < ActiveSupport::TestCase
end
# Scopes
+ # only_categories
+ should "show that the only_categories functions correctly" do
+ short_org_category = @short_org.organization_category.name
+ long_org_category = @long_org.organization_category.name
+ assert_equal ['short name'], Organization.only_categories(short_org_category).map {|org| org.name}
+ assert_equal ['long name'], Organization.only_categories(long_org_category).map {|org| org.name}
+ end
+
+ # search
+ should "show that the search scope functions correcly" do
+ assert_equal ['long name'], Organization.search('long name').map {|org| org.name }
+ assert_equal ['long name', 'short name'], Organization.search('name').map {|org| org.name}
+ end
+
+ # ---------------------------- End of scope testing
# Methods
should 'have a short_name method' do
assert_equal('name', @short_org.short_name)
assert_equal('long name', @long_org.short_name)
end
+
+ should 'give back the correct booth chair for this organization' do
+ chair_person = FactoryGirl.create(:participant)
+ short_chair = FactoryGirl.create(:membership,
+ is_booth_chair: true,
+ organization: @short_org,
+ participant: chair_person)
+ assert_equal [chair_person.andrewid], @short_org.booth_chairs.map { |bc| bc.andrewid }
+ assert_equal [], @long_org.booth_chairs
+ end
+
+ should 'give back the correct hour of current downtime' do
+ t = Time.now
+ entry = FactoryGirl.create(:organization_timeline_entry, entry_type: 2,
+ started_at: t - 2.hours, ended_at: t, organization: @short_org)
+
+ assert_equal 2.hours, @short_org.downtime
+ end
+
+ should 'give back the correct hour of remaining downtime' do
+ t = Time.now
+ entry = FactoryGirl.create(:organization_timeline_entry, entry_type: 2,
+ started_at: t - 3.hours, ended_at: t, organization: @short_org)
+
+ assert_equal 1.hours, @short_org.remaining_downtime
+ end
+
+ # --------------------------- End of Methods testing
+
+ # Dependencies
+ should 'delete all associated organization_aliases once the organization is removed' do
+ alias1 = FactoryGirl.create(:organization_alias, organization: @short_org)
+ alias2 = FactoryGirl.create(:organization_alias, organization: @short_org)
+ alias3 = FactoryGirl.create(:organization_alias, organization: @long_org)
+ assert_equal 3, OrganizationAlias.all.size
+
+ @short_org.destroy
+ assert_equal 1, OrganizationAlias.all.size
+ end
+
+ should 'delete all associated organization_statuses once the organization is removed' do
+ person1 = FactoryGirl.create(:participant)
+ person2 = FactoryGirl.create(:participant)
+ status_type = FactoryGirl.create(:organization_status_type)
+ status1 = FactoryGirl.create(:organization_status, organization: @short_org,
+ participant: person1, organization_status_type: status_type)
+ status2 = FactoryGirl.create(:organization_status, organization: @long_org,
+ participant: person2, organization_status_type: status_type)
+
+ assert_equal 2, OrganizationStatus.all.size
+
+ @short_org.destroy
+ assert_equal 1, OrganizationStatus.all.size
+ end
+
+ should 'delete all associated organization_timeline_entries once the organization is removed' do
+ entry1 = FactoryGirl.create(:organization_timeline_entry, organization: @short_org)
+ entry2 = FactoryGirl.create(:organization_timeline_entry, organization: @short_org)
+ entry3 = FactoryGirl.create(:organization_timeline_entry, organization: @long_org)
+
+ assert_equal 3, OrganizationTimelineEntry.all.size
+ @short_org.destroy
+ assert_equal 1, OrganizationTimelineEntry.all.size
+ end
+
+ should 'delete all associated charges once the organization is removed' do
+ issuer = FactoryGirl.create(:participant)
+ type = FactoryGirl.create(:charge_type)
+
+ charge1 = FactoryGirl.create(:charge,
+ organization: @short_org, issuing_participant: issuer, charge_type: type)
+ charge2 = FactoryGirl.create(:charge,
+ organization: @short_org, issuing_participant: issuer,
+ charge_type: type, is_approved: true)
+ charge3 = FactoryGirl.create(:charge,
+ organization: @long_org, issuing_participant: issuer, charge_type: type)
+
+ assert_equal 3, Charge.all.size
+
+ @short_org.destroy
+
+ assert_equal 1, Charge.all.size
+ end
+
+ should 'delete all associated documents once the organization is removed' do
+ doc1 = FactoryGirl.create(:document, organization: @short_org)
+ doc2 = FactoryGirl.create(:document, organization: @short_org)
+ doc3 = FactoryGirl.create(:document, organization: @long_org)
+ assert_equal 3, Document.all.size
+ @short_org.destroy
+ assert_equal 1, Document.all.size
+ end
+
+ should 'delete all checkouts once the organization is removed' do
+ type = FactoryGirl.create(:tool_type)
+ tool = FactoryGirl.create(:tool, tool_type: type)
+ checkout = FactoryGirl.create(:checkout, tool: tool, organization: @short_org)
+ assert_equal 1, Checkout.all.size
+ @short_org.destroy
+ assert_equal 0, Checkout.all.size
+ end
end
end
diff --git a/test/unit/organization_timeline_entry_test.rb b/test/unit/organization_timeline_entry_test.rb
index ecf4007b..a9bc0bfa 100644
--- a/test/unit/organization_timeline_entry_test.rb
+++ b/test/unit/organization_timeline_entry_test.rb
@@ -32,23 +32,28 @@ class OrganizationTimelineEntryTest < ActiveSupport::TestCase
should validate_presence_of(:entry_type)
should validate_presence_of(:organization)
- context "With a proper context, " do
+ context 'With a proper context, ' do
setup do
time = Time.now
- @finished = FactoryGirl.create(:organization_timeline_entry, :started_at => time - 1.hour, :ended_at => time)
- @not_finished = FactoryGirl.create(:organization_timeline_entry, :started_at => DateTime.now - 12.hours, :ended_at => nil)
+ @finished = FactoryGirl.create(:organization_timeline_entry,
+ :started_at => time - 1.hour, :ended_at => time)
+ @not_finished = FactoryGirl.create(:organization_timeline_entry,
+ :started_at => DateTime.now - 12.hours, :ended_at => nil)
end
teardown do
+ @finished = nil
+ @not_finished = nil
end
- should "show that all factories are properly created" do
+ should 'show that all factories are properly created' do
assert_equal 2, OrganizationTimelineEntry.all.size
end
- # Scopes
+ should 'the current scope should return the ongoing entry' do
+ assert_equal 1, OrganizationTimelineEntry.current.size
+ end
- # Methods
should 'show that the duration method works' do
assert_equal 1.hour, @finished.duration
assert_equal 12.hour, (@not_finished.duration / 1.hour).round * 1.hour
diff --git a/test/unit/participant_test.rb b/test/unit/participant_test.rb
index c0c950ca..2fa66161 100644
--- a/test/unit/participant_test.rb
+++ b/test/unit/participant_test.rb
@@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
+# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
@@ -45,8 +46,16 @@ class ParticipantTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
- @participant = FactoryGirl.create(:participant, :phone_number => 1234567890)
+ @participant = FactoryGirl.create(:participant, :phone_number => 1234567890, :andrewid => "agoradia", :cached_name => "Akshay Goradia", :waiver_start => DateTime.now - 10.minutes)
+ @organization_category = FactoryGirl.create(:organization_category)
+ @organization = FactoryGirl.create(:organization, :name => "Spring Carnival Committee", :organization_category => @organization_category)
@temp_participant = FactoryGirl.create(:participant)
+ @membership = FactoryGirl.create(:membership, :is_booth_chair => true, :participant => @participant, :organization => @organization)
+ @checkout = FactoryGirl.create(:checkout, :participant => @participant)
+ @shift_participant = FactoryGirl.create(:shift_participant, :participant => @participant)
+ @organization_status = FactoryGirl.create(:organization_status, :participant => @participant)
+ @user = FactoryGirl.create(:user, :participant => @participant)
+
end
teardown do
@@ -57,12 +66,94 @@ class ParticipantTest < ActiveSupport::TestCase
end
context "Testing participants" do
+
+
+ should "show that dependency on checkout works" do
+ assert_equal 1, Checkout.all.size
+ @participant.destroy
+ assert_equal 0, Checkout.all.size
+ end
+
+ should "show that dependency on membership works" do
+ assert_equal 1, Membership.all.size
+ @participant.destroy
+ assert_equal 0, Membership.all.size
+ end
+
+ should "show that dependency on shift_participant works" do
+ assert_equal 1, ShiftParticipant.all.size
+ @participant.destroy
+ assert_equal 0, ShiftParticipant.all.size
+ end
+
+ should "show that dependency on organization_status works" do
+ assert_equal 1, OrganizationStatus.all.size
+ @participant.destroy
+ assert_equal 0, OrganizationStatus.all.size
+ end
+
+ should "show that dependency on user works" do
+ assert_equal 1, User.all.size
+ @participant.destroy
+ assert_equal 0, User.all.size
+ end
+
+ should "show that search scope works properly" do
+ assert_equal [@participant], Participant.search("agoradia")
+ assert_equal [], Participant.search("rkelly")
+ end
+
+ should "show that scc scope works properly" do
+ assert_equal [@participant], Participant.scc
+ end
+
should "correctly format a participant's phone number" do
assert_equal "(123) 456-7890", @participant.formatted_phone_number
-
assert_equal "N/A", @temp_participant.formatted_phone_number
end
+
+ should "correctly determine if participant skipped video" do
+ assert_equal false, @participant.is_waiver_cheater?
+
+ assert_equal true, @temp_participant.is_waiver_cheater?
+ end
+
+ should "show that is_booth_chair method works correctly" do
+ assert_equal true, @participant.is_booth_chair?
+ end
+
+ should "show that is_scc method works correctly" do
+ assert_equal true, @participant.is_scc?
+ end
+
+ should "show that name method works correctly" do
+ assert_equal "Akshay Goradia", @participant.name
+ end
+
+ should "show that surname method works correctly" do
+ assert_equal "Goradia", @participant.surname
+ end
+
+ should "show that email method works correctly" do
+ assert_equal "agoradia@cmu.edu", @participant.email
+ end
+
+ should "show that department method works correctly" do
+ assert_equal "Dietrich College Interdisciplinary, Human-Computer Interaction", @participant.department
+ end
+
+ should "show that student_class method works correctly" do
+ assert_equal "Junior", @participant.student_class
+ end
+
+ should "show that formatted_phone_number method works correctly" do
+ assert_equal "(123) 456-7890", @participant.formatted_phone_number
+ end
+
+ should "show that formatted_name method works correctly" do
+ assert_equal "Akshay Goradia (agoradia)", @participant.formatted_name
+ end
+
end
-
end
end
diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb
index ef52f5bd..dd1b5e6c 100644
--- a/test/unit/role_test.rb
+++ b/test/unit/role_test.rb
@@ -28,6 +28,8 @@
class RoleTest < ActiveSupport::TestCase
# Relationships
+ should have_and_belong_to_many(:users)
+
# Validations
# Scopes
diff --git a/test/unit/shift_participant_test.rb b/test/unit/shift_participant_test.rb
index a71c5730..20a9476e 100644
--- a/test/unit/shift_participant_test.rb
+++ b/test/unit/shift_participant_test.rb
@@ -35,19 +35,30 @@ class ShiftParticipantTest < ActiveSupport::TestCase
context "With a proper context, " do
setup do
- FactoryGirl.create(:shift_participant)
+ @shift = FactoryGirl.create(:shift, :ends_at => Time.zone.now + 2.hour, :starts_at => Time.zone.now)
+ @late= FactoryGirl.create(:shift_participant, :shift_id => @shift.id, :clocked_in_at => Time.zone.now + 1.hour)
+ @not_late= FactoryGirl.create(:shift_participant, :shift_id => @shift.id, :clocked_in_at => Time.zone.now)
end
teardown do
end
should "show that all factories are properly created" do
- assert_equal 1, ShiftParticipant.all.size
+ assert_equal 2, ShiftParticipant.all.size
end
# Scopes
+ should "show that scope 'checked in late' is working" do
+ assert_equal @late.id , ShiftParticipant.checked_in_late[0].id
+ end
# Methods
end
end
+
+
+
+
+
+
diff --git a/test/unit/shift_test.rb b/test/unit/shift_test.rb
index 3d903a2a..ac2e3803 100644
--- a/test/unit/shift_test.rb
+++ b/test/unit/shift_test.rb
@@ -35,16 +35,22 @@ class ShiftTest < ActiveSupport::TestCase
#does not need to have an organization
should validate_presence_of(:starts_at)
should validate_presence_of(:ends_at)
+ should validate_presence_of(:shift_type)
should validate_presence_of(:required_number_of_participants)
context "With a proper context, " do
setup do
# Create 3 shifts
- @upcomming = FactoryGirl.create(:shift, :ends_at => Time.local(2021,1,1,15,0,0), :starts_at => Time.now + 1.hour)
- @current = FactoryGirl.create(:shift, :ends_at => Time.local(2020,1,1,15,0,0), :starts_at => Time.local(2014,1,1,13,4,0))
- @past = FactoryGirl.create(:shift, :ends_at => Time.local(2001,1,1,15,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
- @not_checked_in = FactoryGirl.create(:shift, :required_number_of_participants => 1 )
- @checked_in = FactoryGirl.create(:shift, :required_number_of_participants => 2)
+ @type1 = FactoryGirl.create(:shift_type, :id => 1)
+ @type2 = FactoryGirl.create(:shift_type, :id => 2)
+ @type3 = FactoryGirl.create(:shift_type, :id => 3)
+
+ @upcomming = FactoryGirl.create(:shift, :shift_type_id => @type1.id, :ends_at => Time.local(2021,1,1,16,0,0), :starts_at => Time.zone.now + 1.hour)
+ @future = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :ends_at => Time.local(2021,1,1,16,0,0), :starts_at => Time.zone.now + 7.hour)
+ @current = FactoryGirl.create(:shift, :shift_type_id => @type3.id, :ends_at => Time.local(2020,1,1,16,0,0), :starts_at => Time.local(2016,1,1,13,4,0))
+ @past = FactoryGirl.create(:shift, :shift_type_id => @type1.id, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
+ @not_checked_in = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :required_number_of_participants => 1, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
+ @checked_in = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :required_number_of_participants => 2, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
FactoryGirl.create(:shift_participant, :shift => @checked_in)
FactoryGirl.create(:shift_participant, :shift => @checked_in)
end
@@ -53,7 +59,7 @@ class ShiftTest < ActiveSupport::TestCase
end
should "show that all factories are properly created" do
- assert_equal 5, Shift.all.size
+ assert_equal 6, Shift.all.size
end
# Scopes
@@ -65,11 +71,42 @@ class ShiftTest < ActiveSupport::TestCase
assert_equal 1, Shift.upcoming.size
end
+ should "have a scope 'future' that works" do
+ assert_equal 2, Shift.future.size
+ end
+
+ should "have a scope 'past' that works" do
+ assert_equal 3, Shift.past.size
+ end
+
+ should "have a scope 'missed' that works" do
+ assert_equal 5, Shift.missed.size
+ end
+
+ should "have a scope 'watch_shifts' that works" do
+ assert_equal 2, Shift.watch_shifts.size
+ end
+
+ should "have a scope 'sec_shifts' that works" do
+ assert_equal 3, Shift.sec_shifts.size
+ end
+
+ should "have a scope 'coord_shifts' that works" do
+ assert_equal 1, Shift.coord_shifts.size
+ end
+
# Methods
should "have a method 'is_checked_in' that works" do
assert_equal true, @checked_in.is_checked_in
assert_equal false, @not_checked_in.is_checked_in
end
+
+ should "have a method 'formatted_name' that works" do
+ @type = FactoryGirl.create(:shift_type, :name => "Bob")
+ @ex = FactoryGirl.create(:shift, :shift_type_id => @type.id, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.new(2000,1,1))
+ assert_equal 'Bob @ Jan 1 at 12:00 AM', @ex.formatted_name
+
+ end
end
end
diff --git a/test/unit/store_item_test.rb b/test/unit/store_item_test.rb
new file mode 100644
index 00000000..4de416bd
--- /dev/null
+++ b/test/unit/store_item_test.rb
@@ -0,0 +1,44 @@
+# ## Schema Information
+#
+# Table name: `store_items`
+#
+# ### Columns
+#
+# Name | Type | Attributes
+# ----------------- | ------------------ | ---------------------------
+# **`created_at`** | `datetime` | `not null`
+# **`id`** | `integer` | `not null, primary key`
+# **`name`** | `string(255)` |
+# **`price`** | `decimal(10, )` |
+# **`quantity`** | `integer` |
+# **`updated_at`** | `datetime` | `not null`
+#
+
+require 'test_helper'
+
+class StoreItemTest < ActiveSupport::TestCase
+
+ #relationships
+
+ should have_many(:store_purchases)
+
+ #methods
+
+ context "With a proper context, " do
+ setup do
+ # Create store
+ @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :quantity => 5)
+ # Create charge
+ @charge = FactoryGirl.create(:charge, :is_approved => true)
+ # Create store_purchase
+ @store_purchase = FactoryGirl.create(:store_purchase, :price_at_purchase => 20, :quantity_purchased => 1, :store_item_id => @store_item.id)
+ end
+
+ teardown do
+ end
+
+ should "show that quantity_available method works correctly" do
+ assert_equal 4, @store_item.quantity_available
+ end
+ end
+end
diff --git a/test/models/store_purchase_test.rb b/test/unit/store_purchase_test.rb
similarity index 52%
rename from test/models/store_purchase_test.rb
rename to test/unit/store_purchase_test.rb
index b4141ae9..e994189e 100644
--- a/test/models/store_purchase_test.rb
+++ b/test/unit/store_purchase_test.rb
@@ -25,7 +25,31 @@
require 'test_helper'
class StorePurchaseTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+
+ #relationships
+ should have_one(:organization).through(:charge)
+ should belong_to(:charge)
+ should belong_to(:store_item)
+
+ #methods
+
+ context "With a proper context, " do
+ setup do
+ # Create store
+ @store_item = FactoryGirl.create(:store_item, :name => "Hammer", :price => 20, :quantity => 3)
+ # Create store_purchase
+ @store_purchase = FactoryGirl.create(:store_purchase, :price_at_purchase => 20, :quantity_purchased => 1, :store_item_id => @store_item.id)
+ end
+
+ teardown do
+ end
+
+ should "show that items_in_cart works properly" do
+ assert_equal [@store_purchase], StorePurchase.items_in_cart
+ end
+
+ should "show that items_in_cart? works properly" do
+ assert_equal true, StorePurchase.items_in_cart?
+ end
+ end
end
diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb
index 8452c8df..7ea30d68 100644
--- a/test/unit/task_test.rb
+++ b/test/unit/task_test.rb
@@ -46,6 +46,13 @@ class TaskTest < ActiveSupport::TestCase
assert_equal 2, Task.upcoming.size
end
+ should "have a scope 'is_incomplete' that works" do
+ assert_equal 2, Task.is_incomplete.size
+ end
+
+ should "have a scope 'is_complete' that works" do
+ assert_equal 1, Task.is_complete.size
+ end
# Methods
should "show that the is_past_due method works" do
assert_equal true, @assign_rides.is_past_due
diff --git a/test/unit/tool_test.rb b/test/unit/tool_test.rb
index 9c0654a8..0d936f65 100644
--- a/test/unit/tool_test.rb
+++ b/test/unit/tool_test.rb
@@ -31,8 +31,8 @@ class ToolTest < ActiveSupport::TestCase
should belong_to(:tool_type)
# Validations
- # should validate_uniqueness_of(:barcode)
- # should validate_uniqueness_of(:name)
+ should validate_uniqueness_of(:barcode)
+ should validate_presence_of(:tool_type_id)
context "With a proper context, " do
setup do
@@ -44,7 +44,7 @@ class ToolTest < ActiveSupport::TestCase
@shannon_participant = FactoryGirl.create(:participant)
# Create 6 tools
- @hammer = FactoryGirl.create(:tool)
+ @hammer = FactoryGirl.create(:tool, :barcode => 12811)
@saw_type = FactoryGirl.create(:tool_type, name: 'Saw')
@saw = FactoryGirl.create(:tool, :barcode => 12390, :description => "SAW", tool_type: @saw_type)
@@ -57,7 +57,7 @@ class ToolTest < ActiveSupport::TestCase
@hard_hat_2 = FactoryGirl.create(:tool, :barcode => 12809, :description => "HARD HAT 2", tool_type: @hard_hat_type)
@radio_type = FactoryGirl.create(:tool_type, name: 'Radio')
- @radio = FactoryGirl.create(:tool, tool_type: @radio_type)
+ @radio = FactoryGirl.create(:tool, :barcode => 12810, tool_type: @radio_type, :description => "RADIO")
# Create 4 checkouts
@hammer_checkout1 = FactoryGirl.create(:checkout, :checked_in_at => DateTime.now + 3.days, :tool => @hammer, :organization => @sdc)
@@ -68,39 +68,66 @@ class ToolTest < ActiveSupport::TestCase
teardown do
end
+ #scopes
should "show that all factories are properly created" do
assert_equal 6, Tool.all.size
end
+ should "show that the by barcode scope works" do
+ assert_equal 12012, Tool.by_barcode[0].barcode
+ assert_equal 12811, Tool.by_barcode[5].barcode
+ end
+
+ should "show that the by type scope works" do
+ assert_equal [@hard_hat_1, @hard_hat_2], Tool.by_type(@hard_hat_type)
+ assert_equal [@radio], Tool.by_type(@radio_type)
+ assert_equal [@ladder], Tool.by_type(@ladder_type)
+ end
+
should "have a scope 'hardhats' that works" do
assert_equal 2, Tool.hardhats.size
end
-
should "have a scope 'radios' that works" do
assert_equal 1, Tool.radios.size
end
-
should "have a scope 'just_tools' that works" do
assert_equal 3, Tool.just_tools.size
end
- should "show that the 'current_participant' method works" do
- assert_equal nil, @hammer.current_participant
- assert_equal @shannon_participant, @saw.current_participant
- assert_equal nil, @hard_hat_1.current_participant
- assert_equal nil, @ladder.current_participant
+ should "have a scope 'search' that works" do
+ assert_equal @radio.barcode, Tool.search('radio')[0].barcode
+ end
+
+ should "have a scope 'checked_in' that works" do
+ @radio_checkin = FactoryGirl.create(:checkout, :tool => @radio, :checked_out_at => Time.now - 1.hour, :checked_in_at => Time.now + 1.hour)
+ @ladder_checkin = FactoryGirl.create(:checkout, :tool => @ladder, :checked_out_at => Time.now - 1.hour, :checked_in_at => Time.now + 1.hour)
+ @hardhat2_checkin = FactoryGirl.create(:checkout, :tool => @hard_hat_2, :checked_out_at => Time.now - 1.hour, :checked_in_at => Time.now + 1.hour)
+ assert_equal 3, Tool.checked_in.size
+ end
+
+ should "have a scope 'checked_out' that works" do
+ assert_equal 3, Tool.checked_out.size
end
- should "show that the 'current_organization' method works" do
+ #methods
+
+ should "show that the 'current_organization' method works" do
assert_equal @sdc, @hammer.current_organization
assert_equal @theta, @saw.current_organization
assert_equal @theta, @hard_hat_1.current_organization
assert_equal nil, @ladder.current_organization
end
-
+
+ should "show that the 'current_participant' method works" do
+ assert_equal nil, @hammer.current_participant
+ assert_equal @shannon_participant, @saw.current_participant
+ assert_equal nil, @hard_hat_1.current_participant
+ assert_equal nil, @ladder.current_participant
+ end
+
should "show that the is_checked_out? method works" do
assert @hammer.is_checked_out?
assert @saw.is_checked_out?
@@ -108,14 +135,29 @@ class ToolTest < ActiveSupport::TestCase
deny @ladder.is_checked_out?
end
+ should "show that is_waitlist_critical works" do
+ @wait1 = FactoryGirl.create(:tool_waitlist, :tool_type_id => @saw.id)
+ @wait2 = FactoryGirl.create(:tool_waitlist, :tool_type_id => @saw.id)
+ assert_equal true, @saw.is_waitlist_critical?
+ assert_equal false, @ladder.is_waitlist_critical?
+ end
+
+ should "show that is_hardhat works" do
+ assert @hard_hat_1.is_hardhat?
+ deny @radio.is_hardhat?
+ end
+
should "show that the 'self.checked_out_by_organization(organization)' method works" do
assert_equal [@saw, @hard_hat_1], Tool.checked_out_by_organization(@theta)
end
- should "show that the by type scope works" do
- assert_equal [@hard_hat_1, @hard_hat_2], Tool.by_type(@hard_hat_type)
- assert_equal [@radio], Tool.by_type(@radio_type)
- assert_equal [@ladder], Tool.by_type(@ladder_type)
+ should "show that name works" do
+ assert_equal 'Radio', @radio.name
+ end
+
+ should "show that that the method formatted name works" do
+ assert_equal '12810: Radio - RADIO', @radio.formatted_name
+ assert_equal '12012: Ladder - LADDER', @ladder.formatted_name
end
end
diff --git a/test/unit/tool_type_test.rb b/test/unit/tool_type_test.rb
index c7d7b156..f4762e3c 100644
--- a/test/unit/tool_type_test.rb
+++ b/test/unit/tool_type_test.rb
@@ -17,6 +17,7 @@
class ToolTypeTest < ActiveSupport::TestCase
should have_many(:tools)
+ should have_many(:tool_waitlists)
should validate_presence_of(:name)
should validate_uniqueness_of(:name)
diff --git a/test/unit/tool_waitlist_test.rb b/test/unit/tool_waitlist_test.rb
index 5911841e..e085215e 100644
--- a/test/unit/tool_waitlist_test.rb
+++ b/test/unit/tool_waitlist_test.rb
@@ -25,7 +25,62 @@
require 'test_helper'
class ToolWaitlistTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+#Relationships
+ should belong_to(:tool_type)
+ should belong_to(:organization)
+ should belong_to(:participant)
+
+ #Validations
+ should validate_presence_of(:tool_type)
+ should validate_presence_of(:organization)
+ should validate_presence_of(:participant)
+ should validate_presence_of(:wait_start_time)
+
+ context "With a proper context, " do
+ setup do
+ # creating people for waitlist
+ # @person1 = FactoryGirl.create(:participant, :andrewid => 'ersmith')
+ @person2 = FactoryGirl.create(:participant, :andrewid => 'erbob')
+ @person3 = FactoryGirl.create(:participant, :andrewid => 'ersam')
+
+ #making tool types
+ @saw = FactoryGirl.create(:tool_type, name: 'Saw')
+ @hammer = FactoryGirl.create(:tool_type, name: 'Hammer')
+
+ # making waitlist
+ @wait1 = FactoryGirl.create(:tool_waitlist, :tool_type_id => @saw.id)
+ @wait2 = FactoryGirl.create(:tool_waitlist, :tool_type_id => @saw.id, :wait_start_time => (Time.now + 1.hour) )
+ @wait3 = FactoryGirl.create(:tool_waitlist, :tool_type_id => @hammer.id, :wait_start_time => (Time.now + 2.hour))
+ end
+
+ teardown do
+ end
+
+ should "show that all factories are properly created" do
+ assert_equal 3, ToolWaitlist.all.size
+ end
+ # Scopes
+
+ should "show that for_tool_type scope works" do
+ assert_equal 2, ToolWaitlist.for_tool_type(1).size
+ assert_equal 1, ToolWaitlist.for_tool_type(1)[0].tool_type_id
+ assert_equal 1, ToolWaitlist.for_tool_type(1)[1].tool_type_id
+ end
+
+ should "show that by_wait_start_time scope works" do
+ assert_equal @wait1.id, ToolWaitlist.by_wait_start_time[0].id
+ assert_equal @wait3.id, ToolWaitlist.by_wait_start_time[2].id
+ end
+
+ #Methods
+ should "show that duration method works" do
+ @wait = FactoryGirl.create(:tool_waitlist, :tool_type_id => @saw.id, :wait_start_time => (Time.now - 1.hour) )
+ assert_equal 60, @wait.duration_waiting.round
+ end
+
+
+
+
+ end
+
end