From 99f4d9f9d692ee2e6e6ca444b318914f0fdb67a8 Mon Sep 17 00:00:00 2001 From: Stephen Yeargin Date: Mon, 24 Aug 2015 23:03:30 -0500 Subject: [PATCH] Adds Facebook sign-in / registration Fixes #222 (as far as Facebook at least) This was fairly straightforward with a few hiccups. I implemented Facebook because that is the one in the tutorial. I attempted to move some other stuff around (`RegistrationsController`) to match the submodule approach. Things it does not support - [ ] Newsletter preference (isn't passed through) - [ ] Group invitation code (personalized group code) - [ ] Group signup code (the group "public" signup code) - [ ] Entity registration (skip search for team in group creation) --- .env-dist | 3 + Gemfile | 3 + Gemfile.lock | 19 ++ app/assets/stylesheets/login.css.scss | 25 ++- app/assets/stylesheets/registrations.css.scss | 9 + app/controllers/registrations_controller.rb | 162 ---------------- .../users/omniauth_callbacks_controller.rb | 20 ++ .../users/registrations_controller.rb | 178 ++++++++++++++++++ app/mailers/group_notifier.rb | 2 +- app/models/user.rb | 26 ++- app/views/devise/registrations/new.html.erb | 4 + app/views/devise/sessions/new.html.erb | 2 + app/views/devise/shared/_links.erb | 4 +- config/initializers/devise.rb | 1 + config/routes.rb | 14 +- .../20150825013516_add_omniauth_to_users.rb | 8 + db/schema.rb | 120 ++++++------ .../registrations_controller_test.rb | 4 + 18 files changed, 369 insertions(+), 235 deletions(-) create mode 100644 app/assets/stylesheets/registrations.css.scss delete mode 100644 app/controllers/registrations_controller.rb create mode 100644 app/controllers/users/omniauth_callbacks_controller.rb create mode 100644 app/controllers/users/registrations_controller.rb create mode 100644 db/migrate/20150825013516_add_omniauth_to_users.rb rename test/controllers/{ => users}/registrations_controller_test.rb (95%) diff --git a/.env-dist b/.env-dist index 8f9f990..5da12d1 100644 --- a/.env-dist +++ b/.env-dist @@ -16,6 +16,9 @@ export TWILIO_ACCOUNT_SID=some_sid export TWILIO_AUTH_TOKEN=some_token export TWILIO_OUTBOUND_NUMBER=the_number +export OMNIAUTH_FACEBOOK_APP_ID=the_app_id +export OMNIAUTH_FACEBOOK_APP_SECRET=the_app_secret + export SLACK_WEBHOOK_URL=webook_url # These values are production only diff --git a/Gemfile b/Gemfile index 5817d0f..ed7fce0 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,9 @@ gem 'newrelic_rpm', group: :production # Select2 gem 'select2-rails' +# OmniAuth +gem 'omniauth-facebook' + # ActiveAdmin gem 'activeadmin', github: 'activeadmin' diff --git a/Gemfile.lock b/Gemfile.lock index 5f3b650..9744569 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -127,6 +127,8 @@ GEM eventmachine (1.0.8) excon (0.45.4) execjs (2.5.2) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) ffi (1.9.10) font-awesome-rails (4.4.0.0) railties (>= 3.2, < 5.0) @@ -170,6 +172,7 @@ GEM has_scope (0.6.0) actionpack (>= 3.2, < 5) activesupport (>= 3.2, < 5) + hashie (3.4.2) hike (1.2.3) http-cookie (1.0.2) domain_name (~> 0.5) @@ -217,6 +220,7 @@ GEM railties (>= 3.1) multi_json (1.11.2) multi_xml (0.5.5) + multipart-post (2.0.0) nenv (0.2.0) net-scp (1.2.1) net-ssh (>= 2.6.5) @@ -228,6 +232,20 @@ GEM notiffany (0.0.7) nenv (~> 0.1) shellany (~> 0.0) + oauth2 (1.0.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) + omniauth (1.2.2) + hashie (>= 1.2, < 4) + rack (~> 1.0) + omniauth-facebook (2.0.1) + omniauth-oauth2 (~> 1.2) + omniauth-oauth2 (1.3.1) + oauth2 (~> 1.0) + omniauth (~> 1.2) orm_adapter (0.5.0) paperclip (4.2.4) activemodel (>= 3.2.0) @@ -404,6 +422,7 @@ DEPENDENCIES mailchimp-api (~> 2.0.5) momentjs-rails newrelic_rpm + omniauth-facebook paperclip (~> 4.2.1) pg pry-nav diff --git a/app/assets/stylesheets/login.css.scss b/app/assets/stylesheets/login.css.scss index 71e6e20..33e3852 100644 --- a/app/assets/stylesheets/login.css.scss +++ b/app/assets/stylesheets/login.css.scss @@ -56,7 +56,18 @@ body.login { } - div.logo { + .facebook_signin { + margin-bottom: 1.5em; + i { + margin-right: 1em; + } + a, a:hover { + color: #fff; + text-decoration: none; + } + } + + .logo { background-image: image-url('seatshare-inverted.svg'); background-repeat: no-repeat; background-position: center; @@ -67,11 +78,13 @@ body.login { margin-left: auto; margin-right: auto; overflow-y: hidden; - } - div.logo a { - display: block; - width: 290px; - padding-top: 100px; + a { + display: block; + width: 290px; + padding-top: 100px; + } + } + } \ No newline at end of file diff --git a/app/assets/stylesheets/registrations.css.scss b/app/assets/stylesheets/registrations.css.scss new file mode 100644 index 0000000..d1a4778 --- /dev/null +++ b/app/assets/stylesheets/registrations.css.scss @@ -0,0 +1,9 @@ +.facebook_register { + text-align:center; + margin: 3em 0; + a { + i { + margin-right: 2em; + } + } +} diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb deleted file mode 100644 index 3368b90..0000000 --- a/app/controllers/registrations_controller.rb +++ /dev/null @@ -1,162 +0,0 @@ -## -# Registrations controller -class RegistrationsController < Devise::RegistrationsController - skip_before_filter :require_no_authentication - before_filter :redirect_to_join_if_signed_in, if: :user_signed_in? - - ## - # New registration form - def new - @user = User.new - if params[:invite_code] - @invite = GroupInvitation.find_by_invitation_code(params[:invite_code]) - else - @invite = nil - end - if params[:entity_id] - @entity = Entity.find_by_id(params[:entity_id]) - else - @entity = nil - end - if params[:group_code] - @group = Group.find_by_invitation_code(params[:group_code]) - else - @group = nil - end - super - end - - ## - # Process new registration - def create - build_resource(sign_up_params) - - if resource.save - - # Send welcome email - WelcomeEmail.welcome(resource).deliver_now - - # Newsletter signup - if params[:newsletter_signup] == '1' && !ENV['MAILCHIMP_LIST_ID'].nil? - subscribe_newsletter - end - - send_conversion - notify_slack(resource) - - yield resource if block_given? - if resource.active_for_authentication? - set_flash_message :notice, :signed_up if is_flashing_format? - sign_up(resource_name, resource) - if params[:user][:invite_code] - register_with_invitation_code(params[:user][:invite_code], resource) - elsif params[:user][:entity_id] - entity_id = params[:user][:entity_id] - respond_with( - resource, - location: groups_new_path + '?entity_id=' + entity_id - ) - else - respond_with resource, location: groups_new_path - end - else - set_flash_message( - :notice, :"signed_up_but_#{resource.inactive_message}" - ) if is_flashing_format? - expire_data_after_sign_in! - respond_with( - resource, - location: after_inactive_sign_up_path_for(resource) - ) && return - end - else - flash[:alert] = 'There were errors with your registration.' - clean_up_passwords resource - respond_with resource - end - end - - ## - # Process email and password updates - def update - super - end - - private - - ## - # Redirect to Join if Signed In - def redirect_to_join_if_signed_in - if params[:group_code] || params[:invite_code] - redirect_to( - controller: 'groups', - action: 'join', - invite_code: "#{params[:group_code]}#{params[:invite_code]}" - ) && return - end - require_no_authentication unless %w(edit update).include? params[:action] - end - - ## - # Register with Invitation Code - def register_with_invitation_code(invitation_code = nil, resource = nil) - group = Group.join_with_invitation_code(invitation_code, resource) - if group - respond_with( - resource, - location: group_path(id: group.id) - ) && return - end - respond_with( - resource, - location: root_path - ) && return - end - - ## - # Subscribe Newsletter - def subscribe_newsletter - require 'mailchimp' - mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API_KEY']) - merge_vars = { - 'FNAME' => sign_up_params[:first_name], - 'LNAME' => sign_up_params[:last_name] - } - mailchimp.lists.subscribe( - ENV['MAILCHIMP_LIST_ID'], - { 'email' => sign_up_params[:email] }, - merge_vars, - 'html', - false, - true, - false, - false - ) - rescue Mailchimp::Error => e - # Sign up failed - logger.info e.message - end - - ## - # Send Conversion - def send_conversion - # Measure in Google Analytics - GoogleAnalyticsApi.new.event('user', 'signup', params[:ga_client_id]) - - # Mark as Converted for Google AdWords - flash[:conversion] = true - end - - ## - # Notify Slack - def notify_slack(user = nil) - return if user.nil? || ENV['SLACK_WEBHOOK_URL'].nil? || - Rails.env != 'production' - notifier = Slack::Notifier.new ENV['SLACK_WEBHOOK_URL'] - notifier.ping "New user: #{user.display_name} <#{user.email}>", - icon_emoji: ':bust_in_silhouette:', - username: 'Signup Notifications' - rescue StandardError => e - logger.info e.message - end -end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 0000000..dc1c158 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,20 @@ +## +# Users :: OminiAuth Callbacks Controller +module Users + ## + # Users :: OminiAuth Callbacks Controller + class OmniauthCallbacksController < Devise::OmniauthCallbacksController + def facebook + @user = User.from_omniauth(request.env['omniauth.auth']) + if @user.persisted? + sign_in_and_redirect @user + set_flash_message( + :notice, :success, kind: 'Facebook' + ) if is_navigational_format? + else + session['devise.facebook_data'] = request.env['omniauth.auth'] + redirect_to new_user_registration_url + end + end + end +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 0000000..fe4ba8b --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,178 @@ +## +# Users +module Users + ## + # Registrations controller + class RegistrationsController < Devise::RegistrationsController + skip_before_filter :require_no_authentication + before_filter :redirect_to_join_if_signed_in, if: :user_signed_in? + + ## + # New registration form + def new + @user = User.new + if params[:invite_code] + @invite = GroupInvitation.find_by_invitation_code(params[:invite_code]) + else + @invite = nil + end + if params[:entity_id] + @entity = Entity.find_by_id(params[:entity_id]) + else + @entity = nil + end + if params[:group_code] + @group = Group.find_by_invitation_code(params[:group_code]) + else + @group = nil + end + super + end + + ## + # Process new registration + def create + build_resource(sign_up_params) + + if resource.save + + # Send welcome email + WelcomeEmail.welcome(resource).deliver_now + + # Newsletter signup + if params[:newsletter_signup] == '1' && !ENV['MAILCHIMP_LIST_ID'].nil? + subscribe_newsletter + end + + send_conversion + notify_slack(resource) + + yield resource if block_given? + if resource.active_for_authentication? + set_flash_message :notice, :signed_up if is_flashing_format? + sign_up(resource_name, resource) + if params[:user][:invite_code] + register_with_invitation_code(params[:user][:invite_code], resource) + elsif params[:user][:entity_id] + entity_id = params[:user][:entity_id] + respond_with( + resource, + location: groups_new_path + '?entity_id=' + entity_id + ) + else + respond_with resource, location: groups_new_path + end + else + set_flash_message( + :notice, :"signed_up_but_#{resource.inactive_message}" + ) if is_flashing_format? + expire_data_after_sign_in! + respond_with( + resource, + location: after_inactive_sign_up_path_for(resource) + ) && return + end + else + flash[:alert] = 'There were errors with your registration.' + clean_up_passwords resource + respond_with resource + end + end + + ## + # Process email and password updates + def update + super + end + + ## + # Overwrite update_resource to let users to update their user + # without giving their password + def update_resource(resource, params) + if current_user.provider == 'facebook' + params.delete('current_password') + resource.update_without_password(params) + else + resource.update_with_password(params) + end + end + + private + + ## + # Redirect to Join if Signed In + def redirect_to_join_if_signed_in + if params[:group_code] || params[:invite_code] + redirect_to( + controller: 'groups', + action: 'join', + invite_code: "#{params[:group_code]}#{params[:invite_code]}" + ) && return + end + require_no_authentication unless %w(edit update).include? params[:action] + end + + ## + # Register with Invitation Code + def register_with_invitation_code(invitation_code = nil, resource = nil) + group = Group.join_with_invitation_code(invitation_code, resource) + if group + respond_with( + resource, + location: group_path(id: group.id) + ) && return + end + respond_with( + resource, + location: root_path + ) && return + end + + ## + # Subscribe Newsletter + def subscribe_newsletter + require 'mailchimp' + mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API_KEY']) + merge_vars = { + 'FNAME' => sign_up_params[:first_name], + 'LNAME' => sign_up_params[:last_name] + } + mailchimp.lists.subscribe( + ENV['MAILCHIMP_LIST_ID'], + { 'email' => sign_up_params[:email] }, + merge_vars, + 'html', + false, + true, + false, + false + ) + rescue Mailchimp::Error => e + # Sign up failed + logger.info e.message + end + + ## + # Send Conversion + def send_conversion + # Measure in Google Analytics + GoogleAnalyticsApi.new.event('user', 'signup', params[:ga_client_id]) + + # Mark as Converted for Google AdWords + flash[:conversion] = true + end + + ## + # Notify Slack + def notify_slack(user = nil) + return if user.nil? || ENV['SLACK_WEBHOOK_URL'].nil? || + Rails.env != 'production' + notifier = Slack::Notifier.new ENV['SLACK_WEBHOOK_URL'] + notifier.ping "New user: #{user.display_name} <#{user.email}>", + icon_emoji: ':bust_in_silhouette:', + username: 'Signup Notifications' + rescue StandardError => e + logger.info e.message + end + end +end diff --git a/app/mailers/group_notifier.rb b/app/mailers/group_notifier.rb index 5a3d334..52967ce 100644 --- a/app/mailers/group_notifier.rb +++ b/app/mailers/group_notifier.rb @@ -16,7 +16,7 @@ def create_invite(invite, message = nil) @personalized = message @view_action = { url: url_for( - controller: 'registrations', action: 'new', + controller: 'users/registrations', action: 'new', invite_code: @invite.invitation_code, only_path: false ), action: 'Accept Invitation', diff --git a/app/models/user.rb b/app/models/user.rb index 6d413ab..a33e23a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,8 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, + :omniauthable, omniauth_providers: [:facebook] has_many :tickets has_many :user_aliases has_many :memberships @@ -70,6 +71,7 @@ def bio_md # - user: instance of user to see if they have a common group def user_can_view?(user) return false if user.nil? + return true if user.id == id shared_users = [] groups.collect do |group| group.members.collect do |u| @@ -80,6 +82,28 @@ def user_can_view?(user) false end + ## + # From OmniAuth + def self.from_omniauth(auth) + if where(email: auth.info.email).exists? + return_user = where(email: auth.info.email).first + return_user.provider = auth.provider + return_user.uid = auth.uid + else + return_user = create({}) do |user| + user.provider = auth.provider + user.uid = auth.uid + name_part = auth.info.name.split ' ' + user.email = auth.info.email + user.password = Devise.friendly_token[0, 20] + user.first_name = name_part[0] + user.last_name = name_part[1..-1].join(' ') + end + end + + return_user + end + private ## diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index a44e82e..d4998b2 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -22,6 +22,10 @@ <% end %> +
+ <%= link_to raw(' Sign Up With Facebook'), user_omniauth_authorize_path(:facebook), class: 'btn btn-lg btn-primary' %> +
+ <%= form_for(resource, html: {class: "form-horizontal", role: "form"}, as: resource_name, url: registration_path(resource_name)) do |f| %>
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index ee87cae..ec7aa22 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -4,6 +4,8 @@ <%= render 'layouts/flash' %> + +
<%= f.email_field :email, autofocus: true, :class => 'form-control input-lg', :placeholder => 'Email address', :autocapitalize => 'off', :autocorrect => 'off' %>
diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb index d84bdde..15d069a 100644 --- a/app/views/devise/shared/_links.erb +++ b/app/views/devise/shared/_links.erb @@ -2,11 +2,11 @@ <%= link_to "Sign in", new_session_path(resource_name) %>
<% end -%> -<%- if devise_mapping.registerable? && controller_name != 'registrations' %> +<%- if devise_mapping.registerable? && controller_name != 'users/registrations' %> <%= link_to "Sign up", new_registration_path(resource_name) %>
<% end -%> -<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'users/registrations' %> <%= link_to "Forgot your password?", new_password_path(resource_name) %>
<% end -%> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index f1ea984..50819e0 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -230,6 +230,7 @@ # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :facebook, ENV['OMNIAUTH_FACEBOOK_APP_ID'], ENV['OMNIAUTH_FACEBOOK_APP_SECRET'], scope: 'email', info_fields: 'email, name' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/routes.rb b/config/routes.rb index c9bb6f1..381642d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,13 @@ SeatShare::Application.routes.draw do - ActiveAdmin.routes(self) devise_for :admin_users, ActiveAdmin::Devise.config - devise_for :users, :controllers => {:registrations => "registrations"}, :path => '/', :path_names => { :sign_in => 'login', :sign_out => 'logout', :sign_up => 'register' } + devise_for :users, controllers: { + registrations: 'users/registrations', + omniauth_callbacks: 'users/omniauth_callbacks' + }, path: '/', path_names: { + sign_in: 'login', sign_out: 'logout', sign_up: 'register' + } root 'public#index' @@ -15,9 +19,9 @@ post 'contact' => 'public#do_contact' devise_scope :user do - get "register/group/:group_code", to: "registrations#new", as: 'register_with_group_code' - get "register/invite/:invite_code", to: "registrations#new", as: 'register_with_invite_code' - get "register/:entity_slug/:entity_id", to: "registrations#new", as: 'register_with_entity_id' + get "register/group/:group_code", to: "users/registrations#new", as: 'register_with_group_code' + get "register/invite/:invite_code", to: "users/registrations#new", as: 'register_with_invite_code' + get "register/:entity_slug/:entity_id", to: "users/registrations#new", as: 'register_with_entity_id' end get 'groups/' => 'groups#index' diff --git a/db/migrate/20150825013516_add_omniauth_to_users.rb b/db/migrate/20150825013516_add_omniauth_to_users.rb new file mode 100644 index 0000000..a736e7e --- /dev/null +++ b/db/migrate/20150825013516_add_omniauth_to_users.rb @@ -0,0 +1,8 @@ +class AddOmniauthToUsers < ActiveRecord::Migration + def change + add_column :users, :provider, :string + add_index :users, :provider + add_column :users, :uid, :string + add_index :users, :uid + end +end diff --git a/db/schema.rb b/db/schema.rb index 4d8b633..aa26831 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,18 +11,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150504021139) do +ActiveRecord::Schema.define(version: 20150825013516) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "active_admin_comments", force: true do |t| - t.string "namespace" + create_table "active_admin_comments", force: :cascade do |t| + t.string "namespace", limit: 255 t.text "body" - t.string "resource_id", null: false - t.string "resource_type", null: false + t.string "resource_id", limit: 255, null: false + t.string "resource_type", limit: 255, null: false t.integer "author_id" - t.string "author_type" + t.string "author_type", limit: 255 t.datetime "created_at" t.datetime "updated_at" end @@ -31,17 +31,17 @@ add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree - create_table "admin_users", force: true do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "admin_users", force: :cascade do |t| + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 255, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 t.datetime "created_at" t.datetime "updated_at" end @@ -49,45 +49,45 @@ add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree - create_table "entities", force: true do |t| - t.string "entity_name" - t.integer "status", default: 0, null: false + create_table "entities", force: :cascade do |t| + t.string "entity_name", limit: 255 + t.integer "status", default: 0, null: false t.datetime "created_at" t.datetime "updated_at" - t.string "import_key", default: "", null: false - t.integer "entity_type_id", default: 0 + t.string "import_key", limit: 255, default: "", null: false + t.integer "entity_type_id", default: 0 end add_index "entities", ["import_key"], name: "index_entities_on_import_key", unique: true, using: :btree - create_table "entity_types", force: true do |t| - t.string "entity_type_name" - t.string "entity_type_abbreviation" + create_table "entity_types", force: :cascade do |t| + t.string "entity_type_name", limit: 255 + t.string "entity_type_abbreviation", limit: 255 t.integer "sort" t.datetime "created_at" t.datetime "updated_at" end - create_table "events", force: true do |t| + create_table "events", force: :cascade do |t| t.integer "entity_id" - t.string "event_name" + t.string "event_name", limit: 255 t.text "description" t.datetime "start_time" t.integer "date_tba" t.integer "time_tba" t.datetime "created_at" t.datetime "updated_at" - t.string "import_key", default: "", null: false + t.string "import_key", limit: 255, default: "", null: false end add_index "events", ["entity_id"], name: "index_events_on_entity_id", using: :btree add_index "events", ["import_key"], name: "index_events_on_import_key", unique: true, using: :btree - create_table "group_invitations", force: true do |t| + create_table "group_invitations", force: :cascade do |t| t.integer "user_id" t.integer "group_id" - t.string "email" - t.string "invitation_code" + t.string "email", limit: 255 + t.string "invitation_code", limit: 255 t.integer "status" t.datetime "created_at" t.datetime "updated_at" @@ -97,16 +97,16 @@ add_index "group_invitations", ["invitation_code"], name: "index_group_invitations_on_invitation_code", unique: true, using: :btree add_index "group_invitations", ["user_id"], name: "index_group_invitations_on_user_id", using: :btree - create_table "groups", force: true do |t| + create_table "groups", force: :cascade do |t| t.integer "entity_id" - t.string "group_name" + t.string "group_name", limit: 255 t.integer "creator_id" - t.string "invitation_code" + t.string "invitation_code", limit: 255 t.integer "status" t.datetime "created_at" t.datetime "updated_at" - t.string "avatar_file_name" - t.string "avatar_content_type" + t.string "avatar_file_name", limit: 255 + t.string "avatar_content_type", limit: 255 t.integer "avatar_file_size" t.datetime "avatar_updated_at" end @@ -115,10 +115,10 @@ add_index "groups", ["entity_id"], name: "index_groups_on_entity_id", using: :btree add_index "groups", ["invitation_code"], name: "index_groups_on_invitation_code", unique: true, using: :btree - create_table "memberships", id: false, force: true do |t| + create_table "memberships", id: false, force: :cascade do |t| t.integer "group_id" t.integer "user_id" - t.string "role" + t.string "role", limit: 255 t.integer "daily_reminder" t.integer "weekly_reminder" t.datetime "created_at" @@ -128,18 +128,18 @@ add_index "memberships", ["group_id", "user_id"], name: "index_memberships_on_group_id_and_user_id", using: :btree - create_table "ticket_files", force: true do |t| + create_table "ticket_files", force: :cascade do |t| t.integer "user_id" t.integer "ticket_id" - t.string "path" - t.string "file_name" + t.string "path", limit: 255 + t.string "file_name", limit: 255 t.datetime "created_at" t.datetime "updated_at" end add_index "ticket_files", ["ticket_id"], name: "index_ticket_files_on_ticket_id", using: :btree - create_table "ticket_histories", force: true do |t| + create_table "ticket_histories", force: :cascade do |t| t.integer "ticket_id" t.integer "group_id" t.integer "event_id" @@ -149,15 +149,15 @@ t.datetime "updated_at" end - create_table "tickets", force: true do |t| + create_table "tickets", force: :cascade do |t| t.integer "group_id" t.integer "event_id" t.integer "owner_id" t.integer "user_id" t.integer "alias_id" - t.string "section" - t.string "row" - t.string "seat" + t.string "section", limit: 255 + t.string "row", limit: 255 + t.string "seat", limit: 255 t.decimal "cost" t.text "note" t.datetime "created_at" @@ -170,39 +170,43 @@ add_index "tickets", ["owner_id"], name: "index_tickets_on_owner_id", using: :btree add_index "tickets", ["user_id"], name: "index_tickets_on_user_id", using: :btree - create_table "user_aliases", force: true do |t| - t.string "first_name" - t.string "last_name" + create_table "user_aliases", force: :cascade do |t| + t.string "first_name", limit: 255 + t.string "last_name", limit: 255 t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" end - create_table "users", force: true do |t| - t.string "first_name" - t.string "last_name" + create_table "users", force: :cascade do |t| + t.string "first_name", limit: 255 + t.string "last_name", limit: 255 t.integer "status" t.datetime "created_at" t.datetime "updated_at" - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email", limit: 255, default: "", null: false + t.string "encrypted_password", limit: 255, default: "", null: false + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "timezone" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 + t.string "timezone", limit: 255 t.text "bio" - t.string "location" - t.string "mobile" + t.string "location", limit: 255 + t.string "mobile", limit: 255 t.boolean "sms_notify" - t.string "calendar_token" + t.string "calendar_token", limit: 255 + t.string "provider" + t.string "uid" end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["provider"], name: "index_users_on_provider", using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_index "users", ["uid"], name: "index_users_on_uid", using: :btree end diff --git a/test/controllers/registrations_controller_test.rb b/test/controllers/users/registrations_controller_test.rb similarity index 95% rename from test/controllers/registrations_controller_test.rb rename to test/controllers/users/registrations_controller_test.rb index 0997c40..ca6a54d 100644 --- a/test/controllers/registrations_controller_test.rb +++ b/test/controllers/users/registrations_controller_test.rb @@ -3,6 +3,10 @@ ## # Registrations controller test class RegistrationsControllerTest < ActionController::TestCase + def setup + @controller = Users::RegistrationsController.new + end + test 'get register route' do @request.env['devise.mapping'] = Devise.mappings[:user]