From 7397e14a5714a5926af45b45bb1567cba59cfd27 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 12 Oct 2014 20:54:13 +0200 Subject: [PATCH] Remove old user sign up code --- app/controllers/users_controller.rb | 31 --------- app/views/users/new.html.slim | 38 ----------- spec/controllers/users_controller_spec.rb | 83 ----------------------- spec/factories/users.rb | 2 - 4 files changed, 154 deletions(-) delete mode 100644 app/views/users/new.html.slim diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 80bf34d..1d6c162 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,10 +4,6 @@ class UsersController < ApplicationController attr_reader :user - def new - @user = build_user - end - def show if params[:username] user = User.for_username!(params[:username]) @@ -18,18 +14,6 @@ class UsersController < ApplicationController render locals: { page: UserPagePresenter.build(user, current_user, params[:page]) } end - def create - @user = build_user - - if @user.save - store.delete(:new_user_email) - self.current_user = @user - redirect_to docs_path('getting-started'), notice: "Welcome to Asciinema!" - else - render :new, :status => 422 - end - end - def edit @user = current_user authorize @user @@ -48,21 +32,6 @@ class UsersController < ApplicationController private - def store - session - end - - def build_user - user = User.new(create_params) - user.email = store[:new_user_email] - - user - end - - def create_params - params.fetch(:user, {}).permit(:username, :name) - end - def update_params params.require(:user).permit(:username, :name, :email, :theme_name) end diff --git a/app/views/users/new.html.slim b/app/views/users/new.html.slim deleted file mode 100644 index 3d01ce4..0000000 --- a/app/views/users/new.html.slim +++ /dev/null @@ -1,38 +0,0 @@ -.container - .row - .col-md-6.new-user - h1 New user? - - p - ' Every Asciinema user gets a profile page at - br - a href="#" - | #{root_url}~ - strong username - ' . Pick a desired username below. - - = form_for @user, url: user_path do |f| - .form-group - = f.label :username, 'Pick a username:' - = f.text_field :username, required: true, 'class' => 'form-control', 'data-behavior' => 'focus' - .form-group - = f.submit 'Start recording', class: 'btn btn-primary' - - .col-md-6.returning-user - h1 Returning user? - - p - ' There is no account associated with the email - strong = @user.email - ' . - - p - ' However, if you have been previously signing in to Asciinema via - ' Github or Twitter then click a proper button below so we can locate - ' your existing account: - - ul.login - li = link_to "Sign in via Github", github_auth_path, :class => 'btn-auth btn-github' - li = link_to "Sign in via Twitter", twitter_auth_path, :class => 'btn-auth btn-twitter' - - p Note: this is one-time task. You won't be asked to do it again. diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 8fdbcb6..5032c17 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -2,89 +2,6 @@ require 'rails_helper' describe UsersController do - let(:store) { {} } - - before do - allow(controller).to receive(:store) { store } - end - - describe '#new' do - before do - store[:new_user_email] = 'foo@bar.com' - - get :new - end - - it 'assigns user with a stored email' do - expect(assigns(:user).email).to eq('foo@bar.com') - end - - it 'renders new template' do - should render_template('new') - end - end - - describe "#create" do - let!(:user) { stub_model(User) } - - subject { post :create, user: { username: 'jola' } } - - before do - allow(controller).to receive(:current_user=) - allow(User).to receive(:new).with('username' => 'jola') { user } - store[:new_user_email] = 'foo@bar.com' - end - - context "when user is persisted" do - before do - allow(user).to receive(:save) { true } - - subject - end - - it 'removes the email from the store' do - expect(store.key?(:new_user_email)).to be(false) - end - - it 'assigns the stored email to the user' do - expect(user.email).to eq('foo@bar.com') - end - - it 'sets the current_user' do - expect(controller).to have_received(:current_user=).with(user) - end - - it 'redirects to the "getting started" page with a notice' do - expect(flash[:notice]).to_not be_blank - should redirect_to(docs_path('getting-started')) - end - end - - context "when user isn't persisted" do - before do - allow(user).to receive(:save) { false } - - subject - end - - it "doesn't remove the email from the store" do - expect(store.key?(:new_user_email)).to be(true) - end - - it "doesn't set the current_user" do - expect(controller).to_not have_received(:current_user=) - end - - it 'assigns user with a stored email' do - expect(assigns(:user).email).to eq('foo@bar.com') - end - - it 'renders "new" template' do - should render_template('new') - end - end - end - describe '#show' do subject { get :show, username: username } diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 28111d8..29a29fe 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -5,8 +5,6 @@ FactoryGirl.define do sequence(:username) { |n| "user#{n}" } factory :user do - provider "twitter" - uid sequence(:username) { generate(:username) } sequence(:email) { |n| "foo#{n}@bar.com" } end