diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb
index d296d04b..d8331121 100644
--- a/app/controllers/subscriptions_controller.rb
+++ b/app/controllers/subscriptions_controller.rb
@@ -78,6 +78,31 @@ class SubscriptionsController < ApplicationController
return redirect_to :back
end
+ # If this is the first time this user is subscribing to Premium, gift them (and their referrer, if applicable) feature votes and space
+ existing_premium_subscriptions = current_user.subscriptions.where(billing_plan_id: [2, 3, 4, 5, 6])
+ unless existing_premium_subscriptions.any?
+ referring_user = current_user.referrer
+
+ # First-time premium!
+ # +100 MB
+ current_user.update upload_bandwidth_kb: current_user.upload_bandwidth_kb + 100_000
+ current_user.reload
+
+ # +1 vote
+ current_user.votes.create
+ # +1 vote if referred
+ current_user.votes.create if referring_user.present?
+
+ if referring_user
+ # +100MB
+ referring_user.update upload_bandwidth_kb: referring_user.upload_bandwidth_kb + 100_000
+
+ # +2 votes
+ referring_user.votes.create
+ referring_user.votes.create
+ end
+ end
+
if current_user.selected_billing_plan_id.nil?
old_billing_plan = BillingPlan.new(name: 'No billing plan')
else
diff --git a/app/models/raffle_entry.rb b/app/models/raffle_entry.rb
new file mode 100644
index 00000000..602c5e55
--- /dev/null
+++ b/app/models/raffle_entry.rb
@@ -0,0 +1,3 @@
+class RaffleEntry < ActiveRecord::Base
+ belongs_to :user
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index a6297f09..d8db0eec 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -19,12 +19,14 @@ class User < ActiveRecord::Base
has_many :image_uploads
has_one :referral_code
+ has_many :referrals, foreign_key: :referrer_id
def referrer
referral = Referral.find_by(referred_id: self.id)
referral.referrer unless referral.nil?
end
has_many :votes
+ has_many :raffle_entries
after_create :initialize_stripe_customer, unless: -> { Rails.env == 'test' }
after_create :initialize_referral_code
diff --git a/app/views/main/for_friends.html.erb b/app/views/main/for_friends.html.erb
index 2cabfcd5..4c7e9eb3 100644
--- a/app/views/main/for_friends.html.erb
+++ b/app/views/main/for_friends.html.erb
@@ -199,7 +199,7 @@
Get extra votes for Notebook.ai's first community feature
- Worldbuilding is better with a world of diverse experiences and ideas. For the first time, all Premium users have been given a vote to decide what Notebook.ai's first community-based feature will be! You can cast your vote at <%= link_to 'the voting page', '#' %>, and you can earn additional votes with each referral.
+ Worldbuilding is better with a world of diverse experiences and ideas. For the first time, all Premium users have been given a vote to decide what Notebook.ai's first community-based feature will be! You can cast your vote at <%= link_to 'the voting page', community_voting_path %>, and you can earn additional votes with each referral.
@@ -250,7 +250,7 @@
- <%= link_to 'Cast your vote and see results on our voting page', '#' %>
+ <%= link_to 'Cast your vote and see results on our voting page', community_voting_path %>
diff --git a/db/migrate/20170417190318_create_raffle_entries.rb b/db/migrate/20170417190318_create_raffle_entries.rb
new file mode 100644
index 00000000..ea2e2916
--- /dev/null
+++ b/db/migrate/20170417190318_create_raffle_entries.rb
@@ -0,0 +1,9 @@
+class CreateRaffleEntries < ActiveRecord::Migration
+ def change
+ create_table :raffle_entries do |t|
+ t.references :user, index: true, foreign_key: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5d7d825a..ad7863fc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170415192437) do
+ActiveRecord::Schema.define(version: 20170417190318) do
create_table "archenemyships", force: :cascade do |t|
t.integer "user_id"
@@ -544,6 +544,14 @@ ActiveRecord::Schema.define(version: 20170415192437) do
t.integer "race_id"
end
+ create_table "raffle_entries", force: :cascade do |t|
+ t.integer "user_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "raffle_entries", ["user_id"], name: "index_raffle_entries_on_user_id"
+
create_table "referral_codes", force: :cascade do |t|
t.integer "user_id"
t.string "code"
diff --git a/docs/creating_votes.md b/docs/creating_votes.md
new file mode 100644
index 00000000..fe878166
--- /dev/null
+++ b/docs/creating_votes.md
@@ -0,0 +1,10 @@
+Votes are created the following ways:
+
+- During the Referral release, each currently-premium user will be given 1 feature vote.
+- Whenever a user signs up for Premium that hasn't signed up for Premium before, they are given 1 feature vote.
+- Whenever a user that was referred by another user signs up for Premium for the first time,
+ - the user that referred that user is given 2 additional feature votes
+ - the user that signed up for Premium is given an additional feature vote (2 in total)
+
+Votes are never destroyed/deleted, even when cancelling a Premium subscription. They are only ever "used" when voting, and can
+only be used once per vote.
\ No newline at end of file
diff --git a/test/fixtures/raffle_entries.yml b/test/fixtures/raffle_entries.yml
new file mode 100644
index 00000000..d9098d99
--- /dev/null
+++ b/test/fixtures/raffle_entries.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ user_id:
+
+two:
+ user_id:
diff --git a/test/models/raffle_entry_test.rb b/test/models/raffle_entry_test.rb
new file mode 100644
index 00000000..82107ffc
--- /dev/null
+++ b/test/models/raffle_entry_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RaffleEntryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end