mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 08:55:36 -04:00 
			
		
		
		
	Merge pull request #121 from ilya-konanykhin/issue-120
Issue #120: user email is nullable now. Closes #121.
This commit is contained in:
		
						commit
						21fba7251f
					
				
							
								
								
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							| @ -40,7 +40,7 @@ end | ||||
| group :test do | ||||
|   gem 'shoulda-matchers', '~> 1.0.0' | ||||
|   gem 'capybara', '~> 2.2.1' | ||||
|   gem 'poltergeist', '~> 1.5.0' | ||||
|   gem 'poltergeist', '~> 1.10.0' | ||||
|   gem 'database_cleaner', '~> 1.2.0' | ||||
|   gem 'launchy', '~> 2.4.2' | ||||
|   gem 'spork', '~> 0.9.2' | ||||
|  | ||||
| @ -159,10 +159,9 @@ GEM | ||||
|       mime-types | ||||
|       mimemagic (= 0.3.0) | ||||
|     pg (0.17.1) | ||||
|     poltergeist (1.5.1) | ||||
|     poltergeist (1.10.0) | ||||
|       capybara (~> 2.1) | ||||
|       cliver (~> 0.3.1) | ||||
|       multi_json (~> 1.0) | ||||
|       websocket-driver (>= 0.2.0) | ||||
|     polyglot (0.3.5) | ||||
|     pry (0.9.12.6) | ||||
| @ -238,7 +237,7 @@ GEM | ||||
|       json (>= 1.8.0) | ||||
|     warden (1.1.1) | ||||
|       rack (>= 1.0) | ||||
|     websocket-driver (0.6.3) | ||||
|     websocket-driver (0.6.5) | ||||
|       websocket-extensions (>= 0.1.0) | ||||
|     websocket-extensions (0.1.2) | ||||
|     will_paginate (3.0.7) | ||||
| @ -273,7 +272,7 @@ DEPENDENCIES | ||||
|   netzke-core (~> 0.8.0) | ||||
|   paperclip (~> 4.3) | ||||
|   pg (~> 0.17.1) | ||||
|   poltergeist (~> 1.5.0) | ||||
|   poltergeist (~> 1.10.0) | ||||
|   pry (~> 0.9.8) | ||||
|   rails (= 3.2.13) | ||||
|   rake (< 11.0) | ||||
|  | ||||
| @ -54,6 +54,11 @@ class User < ActiveRecord::Base | ||||
|     roles.include?(role) | ||||
|   end | ||||
| 
 | ||||
|   # try keeping the email field in DB clear and consistent, without empty strings (NULLs instead) | ||||
|   def email=(other) | ||||
|     super(other.blank? ? nil : other) | ||||
|   end | ||||
| 
 | ||||
| ### TODO methods below probably belong somewhere else | ||||
| 
 | ||||
|   def completed_build_bikes | ||||
|  | ||||
							
								
								
									
										15
									
								
								db/migrate/20170131164224_user_email_can_be_null.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								db/migrate/20170131164224_user_email_can_be_null.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| class UserEmailCanBeNull < ActiveRecord::Migration | ||||
|   def up | ||||
|     change_table :users do |t| | ||||
|       t.change :email, :string, default: nil, null: true | ||||
|     end | ||||
| 
 | ||||
|     User.where(email: '').update_all(email: nil) | ||||
|   end | ||||
| 
 | ||||
|   def down | ||||
|     change_table :users do |t| | ||||
|       t.change :email, :string, default: '', null: false | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @ -11,7 +11,7 @@ | ||||
| # | ||||
| # It's strongly recommended to check this file into your version control system. | ||||
| 
 | ||||
| ActiveRecord::Schema.define(:version => 20170118112258) do | ||||
| ActiveRecord::Schema.define(:version => 20170131164224) do | ||||
| 
 | ||||
|   create_table "bike_actions", :force => true do |t| | ||||
|     t.string   "action",     :limit => 128, :null => false | ||||
| @ -183,7 +183,7 @@ ActiveRecord::Schema.define(:version => 20170118112258) do | ||||
|   end | ||||
| 
 | ||||
|   create_table "users", :force => true do |t| | ||||
|     t.string   "email",                  :default => "", :null => false | ||||
|     t.string   "email" | ||||
|     t.string   "encrypted_password",     :default => "", :null => false | ||||
|     t.string   "reset_password_token" | ||||
|     t.datetime "reset_password_sent_at" | ||||
|  | ||||
| @ -13,7 +13,9 @@ describe "New User Registrations" do | ||||
|     before do | ||||
|       visit new_user_registration_path | ||||
|     end | ||||
| 
 | ||||
|     it 'should have the additional user fields on the registration page' do | ||||
|       page.should have_field 'user_username' | ||||
|       page.should have_field 'user_first_name' | ||||
|       page.should have_field 'user_last_name' | ||||
|       page.should have_field 'user_email' | ||||
| @ -29,6 +31,13 @@ describe "New User Registrations" do | ||||
|         fill_in 'user_password_confirmation', :with => 'password' | ||||
|       end | ||||
| 
 | ||||
|       it 'should require username' do | ||||
|         fill_in 'user_first_name', :with => 'Frank' | ||||
|         fill_in 'user_last_name', :with => 'Footer' | ||||
|         click_button 'Sign up' | ||||
|         page.should have_content "Username can't be blank" | ||||
|       end | ||||
| 
 | ||||
|       it 'should require first name' do | ||||
|         fill_in 'user_last_name', :with => 'Footer' | ||||
|         click_button 'Sign up' | ||||
| @ -41,5 +50,21 @@ describe "New User Registrations" do | ||||
|         page.should have_content "Last name can't be blank" | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     it 'should allow registering many users with empty emails' do | ||||
|       expect do | ||||
|         FactoryGirl.create :user, email: '' | ||||
|         FactoryGirl.create :user, email: nil | ||||
| 
 | ||||
|         fill_in 'user_username', :with => 'test3' | ||||
|         fill_in 'user_first_name', :with => 'Frank3' | ||||
|         fill_in 'user_last_name', :with => 'Footer3' | ||||
|         fill_in 'user_password', :with => 'password3' | ||||
|         fill_in 'user_password_confirmation', :with => 'password3' | ||||
|         click_button 'Sign up' | ||||
|       end.to change { User.count }.by(3) | ||||
| 
 | ||||
|       expect(User.where(email: nil).count).to eq(3) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user