Commit fa5c1a37 by Vijay Gawariya

add factory test case

parent 578a0f12
...@@ -51,6 +51,11 @@ group :development do ...@@ -51,6 +51,11 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
end end
group :test do
gem 'factory_bot_rails'
gem 'faker'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
...@@ -53,6 +53,13 @@ GEM ...@@ -53,6 +53,13 @@ GEM
diff-lcs (1.4.4) diff-lcs (1.4.4)
erubi (1.9.0) erubi (1.9.0)
execjs (2.7.0) execjs (2.7.0)
factory_bot (5.2.0)
activesupport (>= 4.2.0)
factory_bot_rails (5.2.0)
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
faker (2.12.0)
i18n (>= 1.6, < 2)
ffi (1.13.1) ffi (1.13.1)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
...@@ -185,6 +192,8 @@ PLATFORMS ...@@ -185,6 +192,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bootsnap (>= 1.1.0) bootsnap (>= 1.1.0)
byebug byebug
factory_bot_rails
faker
jbuilder (~> 2.5) jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
pg (>= 0.18, < 2.0) pg (>= 0.18, < 2.0)
......
FactoryBot.define do
factory :employee do
firstName { 'vijay' }
lastName {'Gawariya'}
email {'vijay@getnada.com'}
phone {'92394798237'}
dob {'11/11/1111'}
address {'Noide, UP'}
end
factory :random_employee, class: Employee do
firstName { Faker::Name.firstName }
lastName { Faker::Name.lastName }
email { Faker::Name.email }
phone { Faker::Name.phone }
dob { Faker::Name.dob }
address { Faker::Name.address }
end
end
require 'rails_helper' require 'rails_helper'
RSpec.describe Employee, type: :model do RSpec.describe Employee, type: :model do
pending "add some examples to (or delete) #{__FILE__}" context 'Validation Test Case' do
let(:employee) { build(:employee) }
it 'firstName validation' do
# employee = Employee.new(lastName: 'last', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
employee.firstName = nil
expect(employee.save).to eq(false)
end
it 'lastName validation' do
# employee = Employee.new(firstName: 'vijay', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
employee.lastName = nil;
expect(employee.save).to eq(false)
end
it 'email validation' do
employee = Employee.new(firstName: 'vijay', lastName: 'last', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
expect(employee).to eq(false)
end
it 'phone validation' do
employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com', dob: '11/11/1111', address: 'Noida').save
expect(employee).to eq(false)
end
it 'null validation' do
employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com').save
expect(employee).to eq(false)
end
end
context 'Employee Table Operations Test Case' do
it 'Save Data Test' do
employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
expect(employee).to eq(true)
end
# it 'Delete Data Test' do
# employee = Employee.delete(firstName: 'vv')
# expect(employee).to eq(true)
# end
end
# pending "add some examples to (or delete) #{__FILE__}"
end end
# context 'scope test' do
# let(:employee) { create_list(:random_employee, 5)}
# it 'should return active user' do
# expect(Employee.active_employee.size).to eq(5)
# end
# end
# RSpec.describe Employee, type: :model do
# context 'Validation Test Case' do
# let(:employee) { build(:random_employee, firstName: 'vijay') }
# it 'firstName validation' do
# # employee = Employee.new(lastName: 'last', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
# employee.firstName = nil
# expect(employee.save).to eq(false)
# end
# it 'lastName validation' do
# # employee = Employee.new(firstName: 'vijay', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
# employee.lastName = nil;
# expect(employee.save).to eq(false)
# end
# it 'email validation' do
# employee = Employee.new(firstName: 'vijay', lastName: 'last', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
# expect(employee).to eq(false)
# end
# it 'phone validation' do
# employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com', dob: '11/11/1111', address: 'Noida').save
# expect(employee).to eq(false)
# end
# it 'null validation' do
# employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com').save
# expect(employee).to eq(false)
# end
# end
# context 'Employee Table Operations Test Case' do
# it 'Save Data Test' do
# employee = Employee.new(firstName: 'vijay', lastName: 'last', email: 'vijay@getnada.com', phone: '0909128031', dob: '11/11/1111', address: 'Noida').save
# expect(employee).to eq(true)
# end
# # it 'Delete Data Test' do
# # employee = Employee.delete(firstName: 'vv')
# # expect(employee).to eq(true)
# # end
# end
# # pending "add some examples to (or delete) #{__FILE__}"
# end
...@@ -20,7 +20,9 @@ require 'rspec/rails' ...@@ -20,7 +20,9 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually # directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary. # require only the support files necessary.
# #
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } #Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run. # Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines. # If you are not using ActiveRecord, you can remove these lines.
......
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment