Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart waiver #247

Merged
merged 4 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/controllers/waivers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def new

if @user.has_signed_waiver
flash[:notice] = "You have already agreed to the release."
else
@user.start_waiver_timer
end

end
Expand All @@ -21,9 +23,11 @@ def create
else
@participant = Participant.find params[:participant_id]
end


if params[:adult].blank?

if @participant.is_waiver_cheater?
@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 (<a target='_blank' href='mailto:[email protected]'>[email protected]</a>)."
redirect_to action: :new
elsif params[:agree].blank?
Expand Down
10 changes: 10 additions & 0 deletions app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
Expand Down Expand Up @@ -49,6 +50,15 @@ class Participant < ActiveRecord::Base
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'}) }

def start_waiver_timer
self.waiver_start = DateTime.now
self.save
end

def is_waiver_cheater?
(self.waiver_start + 3.minutes + 37.seconds) > DateTime.now
end

def is_booth_chair?
!memberships.booth_chairs.blank?
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170305040259_add_waiver_start_to_participant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWaiverStartToParticipant < ActiveRecord::Migration
def change
add_column :participants, :waiver_start, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160404161512) do
ActiveRecord::Schema.define(version: 20170305040259) do

create_table "charge_types", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -196,6 +196,7 @@
t.string "cached_department"
t.string "cached_student_class"
t.datetime "cache_updated"
t.datetime "waiver_start"
t.integer "phone_carrier_id"
end

Expand Down
34 changes: 34 additions & 0 deletions public/cheating.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>You tried to do something suspicious</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog, div.minion {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
div.minion {
width: 640px;
margin: 0 auto 0 auto;
border: none;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>

<body>
<!-- This file lives in public/cheating.html -->
<div class="dialog">
<h1>You tried to do skip the safety videos</h1>
<p>Please watch the entire safety video before completing the waiver!</p>
</div>
<div class="minion" style="text-align:center;">
<img src="/images/spy.jpg" />
</div>
</body>
</html>
Binary file added public/images/spy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
# participant
factory :participant, :aliases => [:completed_by, :issuing_participant, :receiving_participant] do
andrewid { generate(:random_string) }
waiver_start DateTime.now
end

# shift
Expand Down
9 changes: 8 additions & 1 deletion test/unit/participant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# **`phone_number`** | `string(255)` |
# **`updated_at`** | `datetime` |
# **`user_id`** | `integer` |
# **`waiver_start`** | `datetime` |
#
# ### Indexes
#
Expand All @@ -45,7 +46,7 @@ class ParticipantTest < ActiveSupport::TestCase

context "With a proper context, " do
setup do
@participant = FactoryGirl.create(:participant, :phone_number => 1234567890, :andrewid => "agoradia", :cached_name => "Akshay Goradia",)
@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)
Expand Down Expand Up @@ -111,6 +112,12 @@ class ParticipantTest < ActiveSupport::TestCase
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
Expand Down