Commit 8f276fe
Changed files (2)
spec
controllers
models
spec/controllers/registrations_controller_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe RegistrationsController do
describe "#new" do
@@ -9,9 +9,9 @@ describe RegistrationsController do
end
describe "#create" do
- let(:username) { 'username' }
- let(:password) { 'password' }
- let(:email) { 'email@example.com' }
+ let(:username) { "username" }
+ let(:password) { "password" }
+ let(:email) { "email@example.com" }
context "when valid params are provided" do
before :each do
@@ -19,26 +19,26 @@ describe RegistrationsController do
username: username,
password: password,
email: email,
- terms_and_conditions: '1'
+ terms_and_conditions: "1"
}
end
- it 'creates a new user account' do
+ it "creates a new user account" do
expect(User.count).to eql(1)
first_user = User.first
expect(first_user.username).to eql(username)
expect(first_user.email).to eql(email)
end
- it 'redirects them to the dashboard' do
+ it "redirects them to the dashboard" do
expect(response).to redirect_to(dashboard_path)
end
- it 'logs them in' do
+ it "logs them in" do
expect(session[:user_id]).to eql(User.first.id)
end
- it 'does not display any errors' do
+ it "does not display any errors" do
expect(flash[:error]).to be_nil
end
end
@@ -46,23 +46,23 @@ describe RegistrationsController do
context "when the parameters provided are invalid" do
before :each do
post :create, user: {
- username: '',
+ username: "",
password: password,
email: email,
- terms_and_conditions: '1'
+ terms_and_conditions: "1"
}
end
- it 'adds an error to the flash for missing usernames' do
+ it "adds an error to the flash for missing usernames" do
expect(flash[:error]).to_not be_nil
expect(flash[:error]).to_not be_empty
end
- it 'does not log them in' do
+ it "does not log them in" do
expect(session[:user_id]).to be_nil
end
- it 'renders the registration page' do
+ it "renders the registration page" do
expect(response).to render_template(:new)
end
end
spec/models/user_spec.rb
@@ -1,80 +1,80 @@
-require 'rails_helper'
+require "rails_helper"
describe User do
describe "#create" do
- it 'saves a new user to the database' do
- user = User.create!(username: 'blah', email: 'blah@example.com', password: 'password')
+ it "saves a new user to the database" do
+ user = User.create!(username: "blah", email: "blah@example.com", password: "password")
saved_user = User.find(user.id)
- expect(saved_user.username).to eql('blah')
- expect(saved_user.email).to eql('blah@example.com')
+ expect(saved_user.username).to eql("blah")
+ expect(saved_user.email).to eql("blah@example.com")
expect(saved_user.password).to be_nil
end
end
describe "validations" do
context "username" do
- it 'is invalid when the username is missing' do
+ it "is invalid when the username is missing" do
user = User.new(username: nil)
expect(user).to_not be_valid
expect(user.errors[:username]).to_not be_empty
end
- it 'is invalid if invalid characters are in the username' do
- user = User.new(username: '$()')
+ it "is invalid if invalid characters are in the username" do
+ user = User.new(username: "$()")
expect(user).to_not be_valid
expect(user.errors[:username]).to_not be_empty
end
- it 'is invalid if the username is already taken' do
- User.create(username: 'blah', email: 'blah@example.com')
- second_user = User.create(username: 'blah', email: 'blahblah@example.com')
+ it "is invalid if the username is already taken" do
+ User.create(username: "blah", email: "blah@example.com")
+ second_user = User.create(username: "blah", email: "blahblah@example.com")
expect(second_user.errors[:username]).to_not be_empty
end
end
describe "#email" do
- it 'is invalid when the email is missing' do
+ it "is invalid when the email is missing" do
user = User.new(email: nil)
expect(user).to_not be_valid
expect(user.errors[:email]).to_not be_empty
end
- it 'is invalid when the email is not in the correct format' do
- user = User.new(email: 'blah')
+ it "is invalid when the email is not in the correct format" do
+ user = User.new(email: "blah")
expect(user).to_not be_valid
expect(user.errors[:email]).to_not be_empty
end
- it 'is invalid if the email address is already registered' do
- User.create(username: 'blahblah', email: 'blah@example.com')
- second_user = User.create(username: 'blah', email: 'blah@example.com')
+ it "is invalid if the email address is already registered" do
+ User.create(username: "blahblah", email: "blah@example.com")
+ second_user = User.create(username: "blah", email: "blah@example.com")
expect(second_user.errors[:email]).to_not be_empty
end
end
describe "terms_and_conditions" do
- it 'is invalid if terms and conditions is unchecked' do
+ it "is invalid if terms and conditions is unchecked" do
user = User.new(terms_and_conditions: false)
expect(user).to_not be_valid
expect(user.errors[:terms_and_conditions]).to_not be_empty
end
end
- it 'is valid when it is' do
+ it "is valid when it is" do
user = User.new(
- username: 'coolio',
- email: 'notblank@example.com',
- password: 'legit',
- terms_and_conditions: '1')
+ username: "coolio",
+ email: "notblank@example.com",
+ password: "legit",
+ terms_and_conditions: "1")
expect(user).to be_valid
end
end
describe "USERNAME_REGEX" do
- it 'does not match' do
+ it "does not match" do
expect(User::USERNAME_REGEX).to_not match("$username")
expect(User::USERNAME_REGEX).to_not match("!username")
expect(User::USERNAME_REGEX).to_not match("@username")