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

Remainders #30

Open
wants to merge 7 commits into
base: anarchy
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem 'localeapp'
gem 'bbq', :github => 'drugpl/bbq'
gem 'paperclip'
gem 'whenever', require: false
gem 'resque'
gem 'sidekiq'

gem 'sqlite3'

Expand All @@ -36,6 +36,7 @@ group :development do
gem 'awesome_print'
gem 'factory_girl_rails', require: false
gem 'minitest-rails'
gem 'letter_opener'
end

group :production do
Expand Down
31 changes: 17 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ GEM
cells (3.8.5)
actionpack (~> 3.0)
railties (~> 3.0)
celluloid (0.12.4)
facter (>= 1.6.12)
timers (>= 1.0.0)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
chronic (0.9.0)
Expand All @@ -74,6 +77,7 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
facter (1.6.17)
factory_girl (4.1.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.1.0)
Expand Down Expand Up @@ -104,6 +108,10 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
kgio (2.7.4)
launchy (2.2.0)
addressable (~> 2.3)
letter_opener (1.1.0)
launchy (~> 2.2.0)
libwebsocket (0.1.7.1)
addressable
websocket
Expand Down Expand Up @@ -164,8 +172,6 @@ GEM
rack (1.4.4)
rack-cache (1.2)
rack (>= 0.4)
rack-protection (1.3.2)
rack
rack-ssl (1.3.2)
rack
rack-test (0.6.2)
Expand All @@ -192,11 +198,6 @@ GEM
redis (3.0.2)
redis-namespace (1.2.1)
redis (~> 3.0.0)
resque (1.23.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rest-client (1.6.7)
mime-types (>= 1.16)
ri_cal (0.8.8)
Expand All @@ -211,10 +212,12 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sidekiq (2.7.2)
celluloid (~> 0.12.0)
connection_pool (~> 1.0)
multi_json (~> 1)
redis (~> 3)
redis-namespace
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -223,6 +226,7 @@ GEM
sqlite3 (1.3.6)
thor (0.16.0)
tilt (1.3.3)
timers (1.1.0)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -234,8 +238,6 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vegas (0.1.11)
rack (>= 1.0.0)
websocket (1.0.6)
whenever (0.8.1)
activesupport (>= 2.3.4)
Expand All @@ -261,6 +263,7 @@ DEPENDENCIES
haml (~> 3.1)
jquery-rails
kaminari
letter_opener
localeapp
minitest-rails
neat (~> 1.0.2)
Expand All @@ -270,9 +273,9 @@ DEPENDENCIES
paperclip
pg
rails (~> 3.2.11)
resque
ri_cal
sass-rails (~> 3.2.3)
sidekiq
sqlite3
uglifier (>= 1.0.3)
unicorn
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/participants_messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
@message.author = current_user
@message.event = @event
@message.save!
Resque.enqueue(ParticipantsMessagesWorker, @message.id)
ParticipantsMessagesWorker.perform_async(@message.id)
redirect_to admin_events_path, notice: "Message sent!"
rescue ActiveRecord::RecordInvalid => invalid
@message = invalid.record
Expand Down
23 changes: 23 additions & 0 deletions app/mailers/remainder_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class RemainderMailer < ActionMailer::Base
default from: ENV['CONTACT_EMAIL']

def day_before(receiver, event)
@event = event
generate_cat_stuff

mail to: receiver.email, subject: "#{@event.title} IS COMING"
end

def today(receiver, event)
@event = event
generate_cat_stuff

mail to: receiver.email, subject: "#{@event.title} IS COMING"
end

private
def generate_cat_stuff
@width = 100 + rand(701)
@height = (@width.to_f * 3 / 4).to_i
end
end
3 changes: 2 additions & 1 deletion app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Person < ActiveRecord::Base
class AlreadySignedException < StandardError; end

attr_accessible :full_name, :irc_nickname, :rss_url, :description
attr_accessible :full_name, :irc_nickname, :rss_url, :description, :remainder_day_before_drug,
:remainder_at_day_of_drug, :remainder_even_if_not_attending

has_and_belongs_to_many :presentations, foreign_key: :person_id
has_many :participations, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Presentation < ActiveRecord::Base
scope :not_postponed, where("status != 'postponed'")
scope :done, where(status: 'done')

delegate :full_name, to: :person, prefix: true
delegate :full_name, to: :lead_speaker, prefix: true
delegate :title, to: :event, prefix: true

def postpone!
Expand Down
11 changes: 11 additions & 0 deletions app/views/people/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
.field
= f.label :description
= f.text_area :description
%h2
Remainders
.field
= f.label :remainder_day_before_drug
= f.check_box :remainder_day_before_drug
.field
= f.label :remainder_at_day_of_drug
= f.check_box :remainder_at_day_of_drug
.field
= f.label :remainder_even_if_not_attending
= f.check_box :remainder_even_if_not_attending
= f.submit


Expand Down
16 changes: 16 additions & 0 deletions app/views/remainder_mailer/day_before.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div style="text-align:center">
<h1><%= @event.title %></h1>
<h2 style="font-style:italic">is coming</h2>

Tomorrow, at 19 in <span style='font-weight:bold'><%= @event.venue_name_with_address %></span>.
We will be talking about:<br>
<% @event.presentations.not_postponed.each do |presentation| %>
<span style='font-weight:bold'><%= presentation.title %></span> (<%= presentation.lead_speaker_full_name %>)<br>
<% end %>
<br>
After official part, as always, there will be unofficial part with moar beer.
<br>
<br>
And since you are programmer, here is nice cat photo for you:<br>
<img src="http://placekitten.com/g/<%= @width %>/<%= @height %>"/>
</div>
10 changes: 10 additions & 0 deletions app/views/remainder_mailer/day_before.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
There will be <%= @event.title %> tommorow.
Are you ready for that?
Be at 19 in <%= @event.venue_name_with_address %>.

We will be talking about:
<% @event.presentations.not_postponed.each do |presentation| %>
<%= presentation.title %> (<%= presentation.lead_speaker_full_name %>)
<% end %>

After official part, as always, there will be unofficial part with moar beer.
16 changes: 16 additions & 0 deletions app/views/remainder_mailer/today.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div style="text-align:center">
<h1><%= @event.title %></h1>
<h2 style="font-style:italic">is coming</h2>

Today, at 19 in <span style='font-weight:bold'><%= @event.venue_name_with_address %></span>.
We will be talking about:<br>
<% @event.presentations.not_postponed.each do |presentation| %>
<span style='font-weight:bold'><%= presentation.title %></span> (<%= presentation.lead_speaker_full_name %>)<br>
<% end %>
<br>
After official part, as always, there will be unofficial part with moar beer.
<br>
<br>
And since you are programmer, here is nice cat photo for you:<br>
<img src="http://placekitten.com/g/<%= @width %>/<%= @height %>"/>
</div>
10 changes: 10 additions & 0 deletions app/views/remainder_mailer/today.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
There will be <%= @event.title %> today.
Are you ready for that?
Be at 19 in <%= @event.venue_name_with_address %>.

We will be talking about:
<% @event.presentations.not_postponed.each do |presentation| %>
<%= presentation.title %> (<%= presentation.lead_speaker_full_name %>)
<% end %>

After official part, as always, there will be unofficial part with moar beer.
4 changes: 2 additions & 2 deletions app/workers/participants_messages_worker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ParticipantsMessagesWorker
@queue = :mailer
include Sidekiq::Worker

def self.perform(participants_message_id)
def perform(participants_message_id)
@message = ParticipantsMessage.find(participants_message_id)
@message.event.participants.each do |person|
ParticipantsMessageMailer.participants_message(@message, person).deliver!
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@

# Local domain
config.action_mailer.default_url_options = { :host => "drug.dev" }

config.action_mailer.delivery_method = :letter_opener
end
5 changes: 5 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@

every 1.day, at: '5:00 am' do
runner 'site=DrugSite.new;site.keep_upcoming_event_alive'
end

every 1.day, at: '7:00am' do
rake "remainders:day_before"
rake "remainders:at_day_of"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddNotificationPreferencesToPeople < ActiveRecord::Migration
def change
add_column :people, :remainder_day_before_drug, :boolean
add_column :people, :remainder_at_day_of_drug, :boolean
add_column :people, :remainder_even_if_not_attending, :boolean
end
end
11 changes: 7 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130126140317) do
ActiveRecord::Schema.define(:version => 20130211112126) do

create_table "contacts", :force => true do |t|
t.string "name", :null => false
Expand Down Expand Up @@ -60,18 +60,21 @@
end

create_table "people", :force => true do |t|
t.string "email", :default => ""
t.string "email", :default => ""
t.datetime "created_at"
t.datetime "updated_at"
t.string "full_name"
t.string "facebook_uid"
t.string "github_uid"
t.boolean "publicized", :default => false
t.integer "irc_points", :default => 0
t.boolean "publicized", :default => false
t.integer "irc_points", :default => 0
t.string "irc_nickname"
t.string "github_nickname"
t.string "rss_url"
t.text "description"
t.boolean "remainder_day_before_drug"
t.boolean "remainder_at_day_of_drug"
t.boolean "remainder_even_if_not_attending"
end

create_table "people_presentations", :force => true do |t|
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/resque.rake

This file was deleted.

25 changes: 25 additions & 0 deletions lib/tasks/whenever.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace :remainders do
desc "Send remainders 'day_before' to people."
task :day_before => :environment do
event = Event.closest_upcoming

if Date.today.tomorrow == event.starting_at.to_date
Person.where(remainder_day_before_drug: true).each do |person|
RemainderMailer.day_before(person, event).deliver! if
person.remainder_even_if_not_attending || person.attend?(event)
end
end
end

desc "Send remainders 'at_day_of' to people."
task :at_day_of => :environment do
event = Event.closest_upcoming

if Date.today == event.starting_at.to_date
Person.where(remainder_at_day_of_drug: true).each do |person|
RemainderMailer.today(person, event).deliver! if
person.remainder_even_if_not_attending || person.attend?(event)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/factories/presentations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
FactoryGirl.define do
factory :presentation do
sequence(:title) { |n| "presentation_title_#{n}" }
association :person
association :speakers
end
end
12 changes: 8 additions & 4 deletions test/unit/event_test.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'minitest_helper'

class TestMeme < MiniTest::Unit::TestCase
class EventTest < MiniTest::Unit::TestCase
def setup
@event = Event.new
end

# I know that these tests are pretty dumb and basic,
# but I use minitest first time, so I wanted to write sth simple.
def test_future_if_event_not_happened
@event.starting_at = Time.now + 1.month
assert @event.future?
Expand All @@ -17,5 +15,11 @@ def test_future_if_event_happened
refute @event.future?
end


def test_closest_upcoming
event1 = FactoryGirl.create(:event, starting_at: (Time.now + 1.month))
event2 = FactoryGirl.create(:event, starting_at: (Time.now + 2.months))
closest = Event.closest_upcoming

assert_equal closest, event1
end
end
Loading