From ef814518f413acacc15b9672a69bd777818583d7 Mon Sep 17 00:00:00 2001 From: Michael Parrish Date: Thu, 25 Jun 2015 18:06:36 -0500 Subject: [PATCH] Set User#zooniverse_id for panoptes-only users --- app/models/user.rb | 5 +++++ spec/models/user_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index feeb472fe..bd104d068 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -53,6 +53,7 @@ class User < ActiveRecord::Base before_validation :setup_unsubscribe_token, on: [:create] before_validation :update_ouroboros_created before_save :update_ouroboros_created + after_create :set_zooniverse_id can_be_linked :membership, :all can_be_linked :user_group, :all @@ -196,6 +197,10 @@ def update_ouroboros_created end end + def set_zooniverse_id + self.zooniverse_id ||= "panoptes-#{ id }" + end + def setup_unsubscribe_token if self.login self.unsubscribe_token ||= UserUnsubscribeMessageVerifier.create_access_token(self.login) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 80b224096..5f929035e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -567,6 +567,12 @@ end end + describe '#set_zooniverse_id' do + let(:user){ create :user } + subject{ user.zooniverse_id } + it{ is_expected.to eql "panoptes-#{ user.id }" } + end + describe "#unsubscribe_token" do it "should not build one automatically on build" do