Skip to content

Commit

Permalink
Implement voluntary contribution form and email
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Feb 8, 2016
1 parent a49e48e commit 022509d
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 9 deletions.
6 changes: 4 additions & 2 deletions app/assets/stylesheets/controller/registrations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
width: 17.5em;
}

fieldset > ol > li.radio fieldset ol li {
margin: 0.1em 0.5em 0.5em 0;
display: inline-block;
}

// Responsive stuff
@include at-breakpoint($bp-tablet) {
Expand Down Expand Up @@ -145,5 +149,3 @@ ul.checklist {
.Accordion .Accordion-item > .Accordion-content .Accordion-step.free_transport_step {
overflow: visible;
}


8 changes: 8 additions & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def new
respond_with self.resource
end

def create
super
if resource.valid? && resource.voluntary_contribution.present?
RegistrationsMailer.voluntary_contribution_email(params[:user][:email],
params[:user][:voluntary_contribution].to_i).deliver
end
end

def edit
@user = User.find(current_user.id)
check_incomplete_profile!(@user)
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ def inline_logos
}
end
end

def voluntary_contribution_link(amount)
case amount
when 3
'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-1'
when 5
'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-2'
when 10
'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-3'
else
''
end
end
end
14 changes: 14 additions & 0 deletions app/mailers/registrations_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2012-2016, Fairmondo eG. This file is
# licensed under the GNU Affero General Public License version 3 or later.
# See the COPYRIGHT file for details.

class RegistrationsMailer < ActionMailer::Base
helper MailerHelper

default from: EMAIL_ADDRESSES['default']

def voluntary_contribution_email(email, amount)
@amount = amount
mail(to: email, subject: 'Dein freiwilliger Grundbeitrag für Fairmondo')
end
end
2 changes: 2 additions & 0 deletions app/models/user/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ module User::Validations
validates :about_me, length: { maximum: 2500, tokenizer: tokenizer_without_html }

validates :type, inclusion: { in: ['LegalEntity'] }, if: :is_ngo?

validates :voluntary_contribution, inclusion: { in: [nil, 3, 5, 10] }
end
end
2 changes: 1 addition & 1 deletion app/refineries/user_refinery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create
[
:email, :password, :new_terms_confirmed,
# and custom fields apart from devise internal stuff:
:nickname, :type, :newsletter, :legal, :privacy
:nickname, :type, :newsletter, :legal, :privacy, :voluntary_contribution
]
end

Expand Down
5 changes: 5 additions & 0 deletions app/views/devise/registrations/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ h1= t('common.actions.sign_up')
- legal_link = checkbox_link_helper t('users.legal_abbr'), '/agb'
- privacy_link = checkbox_link_helper t('users.privacy'), '/datenschutz'
= f.input :legal, as: :boolean, required: true, label: t("users.i_accept_both", legal: legal_link, privacy: privacy_link).html_safe

= f.input :voluntary_contribution, required: false,
as: :radio, tooltip: true,
collection: { 'Kein Beitrag' => '', '3 €' => 3, '5 €' => 5, '10 €' => 10 }

= f.input :newsletter, as: :boolean, label: 'Ich möchte den monatlichen Newsletter mit besonderen Produktvorstellungen erhalten (jederzeit abbestellbar).', required: false, tooltip: false

= f.actions do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Liebe neue Nutzerin, lieber neuer Nutzer,

vielen Dank für Deine Bereitschaft, die Weiterentwicklung von Fairmondo zu unterstützen!

Bitte schließe den Prozess auf der Seite unseres Partners Fastbill ab:

<%= voluntary_contribution_link(@amount) %>

Dein freiwilliger Grundbeitrag wird stets zum ersten des Monats gebucht. Er ist jederzeit kündbar.

Mit fairen Grüßen,

Dein Fairmondo-Team

--

Fairmondo eG
Glogauer Str. 21
10999 Berlin

www.fairmondo.de
Gutes einfach entdecken

Registergericht: Amtsgericht Berlin-Charlottenburg, GnR 738 B USt-IdNr.: DE 290376380

Vorstand: Felix Weth, Richard Schmid
Aufsichtsratsvorsitzender: Kim Stattaus

Facebook: www.facebook.com/fairmondo
Beteiligung an der Genossenschaft: mitmachen.fairmondo.de/anteile-zeichnen/
2 changes: 2 additions & 0 deletions config/locales/old/gems/formtastic/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ de:
nickname: Nutzername
type: Ein gewerbliches Nutzerkonto anlegen
email: E-Mail-Adresse
voluntary_contribution: "Ich möchte Fairmondo mit einem freiwilligen monatlichen Grundbeitrag unterstützen (inkl. 19% MwSt., jederzeit kündbar)."
image: Profilbild
password: "Passwort"
password_confirmation: "Passwort wiederholen"
Expand Down Expand Up @@ -277,6 +278,7 @@ de:
nickname: "Diesen Namen sehen auch andere Nutzer*innen."
password: "Dein Passwort muss mindestens 6 Zeichen haben. Dein Account wird sicherer, wenn Du auch Zahlen und Großbuchstaben fürs Passwort verwendest."
password_confirmation: "Wiederhole Dein gewünschtes Passwort."
voluntary_contribution: "Mit Fairmondo möchten wir eine faire Alternative zu den Riesen im Online-Handel aufbauen. Das ist ein sehr großes Projekt, gerade in der Startphase sind wir auf möglichst breite Unterstützung angewiesen. Mit Deinem Beitrag ermöglichst Du unsere Arbeit und die Weiterentwicklung unseres Marktplatzes."
newsletter: "Mit unserem Newsletter erhältst Du Produktempfehlungen und Informationen zu Themen wie Nachhaltigkeit und bewusstem Konsum. Der Newsletter erscheint einmal im Monat."

create: *new_user
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVoluntaryContributionToUser < ActiveRecord::Migration
def change
add_column :users, :voluntary_contribution, :integer
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: 20150420132406) do
ActiveRecord::Schema.define(version: 20160128144253) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -550,6 +550,7 @@
t.integer "total_purchase_donations_cents", limit: 8, default: 0
t.string "belboon_tracking_token"
t.datetime "belboon_tracking_token_set_at"
t.integer "voluntary_contribution"
end

add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
Expand Down
39 changes: 34 additions & 5 deletions test/controllers/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,42 @@
before(:each) do
@valid_params = {
user: {
nickname: 'johndoe',
email: 'jdoe@example.com',
password: 'password',
legal: '1',
type: 'PrivateUser'
nickname: 'johndoe',
email: 'jdoe@example.com',
password: 'password',
legal: '1',
type: 'PrivateUser',
voluntary_contribution: ''
}
}

@valid_params2 = {
user: {
nickname: 'johndoe',
email: 'jdoe@example.com',
password: 'password',
legal: '1',
type: 'PrivateUser',
voluntary_contribution: '5'
}
}

ActionMailer::Base.deliveries.clear
end

it 'should send out an extra email if voluntary contribution was checked' do
post :create, @valid_params2
assert_equal 2, ActionMailer::Base.deliveries.size
email = ActionMailer::Base.deliveries.last
assert_equal 'Dein freiwilliger Grundbeitrag für Fairmondo', email.subject
assert_equal ['jdoe@example.com'], email.to
assert_match(/vielen Dank für Deine Bereitschaft, die Weiterentwicklung von Fairmondo zu unterstützen!/,
email.body.to_s)
end

it 'should not send out an extra email if voluntary contribution was not checked' do
post :create, @valid_params
assert_equal 1, ActionMailer::Base.deliveries.size
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/features/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
fill_in 'user_email', with: 'email@example.com'
fill_in 'user_password', with: 'password'
check 'user_type'
choose 'user_voluntary_contribution_5'
check 'user_legal'
end
assert_difference 'User.count', 1 do
click_button 'sign_up'
end

assert_equal 5, User.last.voluntary_contribution
end
end

Expand Down
33 changes: 33 additions & 0 deletions test/mailers/registrations_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2012-2016, Fairmondo eG. This file is
# licensed under the GNU Affero General Public License version 3 or later.
# See the COPYRIGHT file for details.

require_relative '../test_helper'

describe RegistrationsMailer do
include EmailSpec::Helpers
include EmailSpec::Matchers

let(:email) { 'mail@example.com' }

it '#voluntary_contribution_email with amount of 3' do
mail = RegistrationsMailer.voluntary_contribution_email(email, 3)
mail.must deliver_to email
mail.subject.must_equal('Dein freiwilliger Grundbeitrag für Fairmondo')
mail.must have_body_text 'vielen Dank für Deine Bereitschaft, die Weiterentwicklung von '\
'Fairmondo zu unterstützen!'
mail.must have_body_text 'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-1'
end

it '#voluntary_contribution_email with amount of 5' do
mail = RegistrationsMailer.voluntary_contribution_email(email, 5)
mail.must deliver_to email
mail.must have_body_text 'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-2'
end

it '#voluntary_contribution_email with amount of 10' do
mail = RegistrationsMailer.voluntary_contribution_email(email, 10)
mail.must deliver_to email
mail.must have_body_text 'https://automatic.fastbill.com/purchase/7f1d4c9a3c8e6ec21543fde6377132d6/25-3'
end
end
10 changes: 10 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
it { subject.must_respond_to :admin }
it { subject.must_respond_to :heavy_uploader }
it { subject.must_respond_to :belboon_tracking_token }
it { subject.must_respond_to :voluntary_contribution }
end

describe 'associations' do
Expand All @@ -90,6 +91,15 @@
it { subject.must validate_acceptance_of :legal }
end

describe 'voluntary_contribution' do
it { user.must allow_value(nil).for :voluntary_contribution }
it { user.must allow_value(3).for :voluntary_contribution }
it { user.must allow_value(5).for :voluntary_contribution }
it { user.must allow_value(10).for :voluntary_contribution }
it { user.wont allow_value(6).for :voluntary_contribution }
it { user.wont allow_value(-1).for :voluntary_contribution }
end

describe 'on update' do
describe 'zip code validation' do
before :each do
Expand Down

0 comments on commit 022509d

Please sign in to comment.