Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

input email before creating a repository

  • Loading branch information...
commit c5b4d9b6d1eee3ad6c75f615d68d57cea0d5b800 1 parent 393c156
Richard Huang flyerhzm authored
4 app/controllers/application_controller.rb
View
@@ -6,6 +6,10 @@ class ApplicationController < ActionController::Base
redirect_to '/', alert: exception.message
end
+ rescue_from UserNoEmailException do |exception|
+ redirect_to edit_user_registration_path, alert: "Your must input your email before creating a repository! It is only used to receive notification."
+ end
+
rescue_from ActiveRecord::RecordNotFound do |exception|
render_404
end
5 app/controllers/repositories_controller.rb
View
@@ -2,6 +2,7 @@ class RepositoriesController < ApplicationController
load_and_authorize_resource except: [:sync, :sync_proxy]
before_filter :authenticate_user!, except: [:show, :sync, :sync_proxy]
before_filter :load_repository, only: [:show, :edit, :update]
+ before_filter :force_input_email, only: [:new, :create]
def show
end
@@ -78,4 +79,8 @@ def load_repository
def branch_name
params[:ref].split("/").last
end
+
+ def force_input_email
+ raise UserNoEmailException if current_user.fakemail?
+ end
end
2  app/views/users/registrations/edit.html.haml
View
@@ -5,6 +5,6 @@
= render_cell :account, :tabs, "account"
= simple_form_for @user, url: registration_path(@user), html: {class: "form-horizontal", method: :put} do |form|
- = form.input :email, hint: "We promise we won't share your email with anyone. It's only used to receive payment receipt", input_html: {class: "span5"}
+ = form.input :email, hint: "We promise we won't share your email with anyone. It's only used to receive notifications", input_html: {class: "span5"}
.form-actions
= form.submit class: "btn btn-primary"
2  lib/user_no_email_exception.rb
View
@@ -0,0 +1,2 @@
+class UserNoEmailException < Exception
+end
14 spec/controllers/repositories_controller_spec.rb
View
@@ -24,6 +24,13 @@
response.should be_ok
assigns(:repository).should_not be_nil
end
+
+ it "should redirect to user/edit page if current_user didn't input email" do
+ user = Factory(:user, nickname: "flyerhzm", email: "flyerhzm@fakemail.com")
+ sign_in user
+ get :new
+ response.should redirect_to(edit_user_registration_path)
+ end
end
context "POST :create" do
@@ -43,6 +50,13 @@
post :create, repository: {github_name: ""}
response.should render_template(action: "new")
end
+
+ it "should redirect to user/edit page if current_user didn't input email", focus: true do
+ user = Factory(:user, nickname: "flyerhzm", email: "flyerhzm@fakemail.com")
+ sign_in user
+ post :create, repository: {github_name: "flyerhzm/railsbp.com"}
+ response.should redirect_to(edit_user_registration_path)
+ end
end
context "POST :sync" do
Please sign in to comment.
Something went wrong with that request. Please try again.