Skip to content

Commit

Permalink
Converting tests to RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
gregdaynes committed Feb 14, 2017
1 parent f5e2015 commit 3d8a13e
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 393 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--color
--require spec_helper
--format documentation
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gem 'bootstrap', '~> 4.0.0.alpha6'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'rspec-rails', '~> 3.5'
end

group :development do
Expand Down
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.4)
debug_inspector (0.0.2)
diff-lcs (1.3)
erubis (2.7.0)
execjs (2.7.0)
ffi (1.9.17)
Expand Down Expand Up @@ -117,6 +118,23 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
sass (3.4.23)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
Expand Down Expand Up @@ -169,6 +187,7 @@ DEPENDENCIES
listen (~> 3.0.5)
puma (~> 3.0)
rails (~> 5.0.1)
rspec-rails (~> 3.5)
sass-rails (~> 5.0)
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
4 changes: 4 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Person < ApplicationRecord
presence: true,
length: { minimum: 6 },
if: lambda { new_record? || !password.nil? }
validates :password_confirmation,
presence: true,
length: { minimum: 6 },
if: lambda { new_record? || !password_confirmation.nil? }

has_secure_password
end
5 changes: 0 additions & 5 deletions spec/controllers/staff_members_controller_spec.rb

This file was deleted.

157 changes: 0 additions & 157 deletions spec/controllers/users_controller_spec.rb

This file was deleted.

12 changes: 0 additions & 12 deletions spec/controllers/welcome_controller_spec.rb

This file was deleted.

11 changes: 0 additions & 11 deletions spec/factories/staff_members.rb

This file was deleted.

16 changes: 0 additions & 16 deletions spec/factories/users.rb

This file was deleted.

14 changes: 0 additions & 14 deletions spec/models/language_spec.rb

This file was deleted.

90 changes: 90 additions & 0 deletions spec/models/person_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require 'rails_helper'

RSpec.describe Person, type: :model do
subject {
described_class.new(
first_name: 'Gregory',
last_name: 'Daynes',
email: '[email protected]',
password: 'abc123',
password_confirmation: 'abc123',
date_of_birth: Date.new(1986,11,04),
gender: 'Male'
)
}

let!(:staff) {
Staff.new(
:pod => 1,
:started_at_company => Date.new(2017,02,01),
:person => subject
)
}

describe "validations" do
it "expects valid attributes" do
expect(subject).to be_valid
end
it "expects first_name" do
subject.first_name = nil
expect(subject).to_not be_valid
end
it "expects first_name to be longer than 1 character" do
subject.first_name = "A"
expect(subject).to_not be_valid
end
it "expects email" do
subject.email = nil
expect(subject).to_not be_valid
end
it "expects valid email" do
subject.email = "greg@stembolt"
expect(subject).to_not be_valid
end
it "expects unique email" do
duplicate_person = subject.dup
subject.save
expect(duplicate_person).to_not be_valid
end
it "expects emails to be stored lower-case" do
subject.email = "[email protected]"
subject.save
expect(subject.email).to eq(subject.email.downcase)
end
it "expects date_of_birth" do
subject.date_of_birth = nil
expect(subject).to_not be_valid
end
it "accepts date_of_birth as Date" do
expect(subject).to be_valid
end
it "accepts date_of_birth as String" do
subject.date_of_birth = '1986/11/04'
expect(subject).to be_valid
end
it "expects gender" do
subject.gender = nil
expect(subject).to_not be_valid
end
it "expects gender to be stored lower-case" do
subject.save
expect(subject.gender).to eq(subject.gender.downcase)
end
it "expects password" do
subject.password = nil
expect(subject).to_not be_valid
end
it "expects password_confirmation" do
subject.password_confirmation = nil
expect(subject).to_not be_valid
end
it "expects password == password_confirmation" do
subject.password_confirmation = "123abc"
expect(subject).to_not be_valid
end
end

describe "associations" do
it "should have one staff"
end
end
21 changes: 0 additions & 21 deletions spec/models/role_spec.rb

This file was deleted.

Loading

0 comments on commit 3d8a13e

Please sign in to comment.