Commit ca41bac

mo khan <mo@mokhan.ca>
2015-01-20 05:55:15
use the default of "1" for terms to simplify code.
1 parent d31ec99
app/controllers/registrations_controller.rb
@@ -5,7 +5,6 @@ class RegistrationsController < ApplicationController
 
   def create
     @user = User.new(secure_params)
-    @user.terms_and_conditions = params[:terms_and_conditions]
     if @user.save
       log_in(@user)
       redirect_to dashboard_path
app/models/user.rb
@@ -4,5 +4,5 @@ class User < ActiveRecord::Base
 
   validates :username, presence: true, format: { with: USERNAME_REGEX }, uniqueness: true
   validates :email, presence: true, email: true, uniqueness: true
-  validates_acceptance_of :terms_and_conditions, accept: true
+  validates_acceptance_of :terms_and_conditions
 end
spec/controllers/registrations_controller_spec.rb
@@ -15,7 +15,7 @@ describe RegistrationsController do
 
     context "when valid params are provided" do
       before :each do
-        post :create, user: { username: username, password: password, email: email, terms_and_conditions: true }
+        post :create, user: { username: username, password: password, email: email, terms_and_conditions: '1' }
       end
 
       it 'creates a new user account' do
@@ -40,7 +40,7 @@ describe RegistrationsController do
 
     context "when the parameters provided are invalid" do
       before :each do
-        post :create, user: { username: '', password: password, email: email, terms_and_conditions: true }
+        post :create, user: { username: '', password: password, email: email, terms_and_conditions: '1' }
       end
 
       it 'adds an error to the flash for missing usernames' do
spec/factories/users.rb
@@ -2,6 +2,6 @@ FactoryGirl.define do
   factory :user do
     username Faker::Internet.user_name
     email Faker::Internet.email
-    terms_and_conditions true
+    terms_and_conditions '1'
   end
 end
spec/features/registrations_spec.rb
@@ -33,5 +33,13 @@ feature "Registrations", type: :feature do
         expect(page).to have_content("Email has already been taken")
       end
     end
+
+    context "when the terms and conditions are not accepted" do
+      it 'displays an error' do
+        subject.register_with(accept_terms: false)
+
+        expect(page).to have_content("Terms and conditions must be accepted")
+      end
+    end
   end
 end
spec/models/user_spec.rb
@@ -64,7 +64,7 @@ describe User do
     end
 
     it 'is valid when it is' do
-      user = User.new(username: 'coolio', email: 'notblank@example.com', password: 'legit', terms_and_conditions: true)
+      user = User.new(username: 'coolio', email: 'notblank@example.com', password: 'legit', terms_and_conditions: '1')
       expect(user).to be_valid
     end
   end