Skip to content

Commit

Permalink
created the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrobert committed Jun 24, 2020
1 parent f7a8a47 commit bbbbd4e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 13 deletions.
24 changes: 24 additions & 0 deletions spec/models/group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'rails_helper'

RSpec.describe Group, type: :model do

test_user = User.create!(name: 'peter robert', email: '[email protected]', password: 'hsjoarty067')
test_group = Group.create!(name: 'test_group', icon: 'https://testicons.com/testicon.png', user_id:test_user.id)


it 'should fail to create a group without name' do
ev = Group.create(icon: 'https://testicons.com/testicon.png')
expect(ev.persisted?).to eql(false)
end

it 'should fail to create a group user' do
ev = Group.create(name: 'test_group',icon: 'https://testicons.com/testicon.png')
expect(ev.persisted?).to eql(false)
end

it 'should create group' do
ev = Group.create(name: 'test_group',icon: 'https://testicons.com/testicon.png', user_id:test_user.id)
expect(ev.persisted?).to eql(true)
end

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

RSpec.describe Transaction, type: :model do

test_user = User.create!(name: 'peter robert', email: '[email protected]', password: 'hsjoarty067')
test_group = test_user.groups.create!(name: 'test_group', icon: 'https://testicons.com/testicon.png')
test_transaction = Transaction.create!(name: 'test_transaction', amount: 100, user_id: test_user.id, group_id: test_group.id)


it 'should fail to create a transaction without amount' do
ev = Transaction.create(name: 'test event')
expect(ev.persisted?).to eql(false)
end

it 'should fail to create a transaction without name' do
ev = Transaction.create(amount: 200)
expect(ev.persisted?).to eql(false)
end

it 'should fail to create a transaction without user' do
ev = Transaction.create(name: 'test event', amount: 100, group_id: test_group.id )
expect(ev.persisted?).to eql(false)
end

it 'should be saved with all users' do
ev = Transaction.create(name: 'test event', amount: 100, user_id: test_user.id, group_id: test_group.id )
expect(ev.persisted?).to eql(true)
end


end
31 changes: 18 additions & 13 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
RSpec.describe User, type: :model do
context 'validation tests' do
it 'ensures name presence' do

end
require 'rails_helper'

it 'ensures email presence' do

end
RSpec.describe User, type: :model do

it 'ensures password presence' do

test_user = User.create!(name: 'peter robert', email: '[email protected]', password: 'hsjoarty067')

it 'should fail to create account without name' do
ev = User.create(email: '[email protected]', password: 'hsjoarty067')
expect(ev.persisted?).to eql(false)
end

it 'ensures confirm password presence' do
it 'should fail to create account without email' do
ev = User.create(name: 'peter robert', password: 'hsjoarty067')
expect(ev.persisted?).to eql(false)
end

it 'should fail to create account without password' do
ev = User.create(name: 'peter robert', email: '[email protected]')
expect(ev.persisted?).to eql(false)
end
end
end



end
17 changes: 17 additions & 0 deletions spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with :truncation, except: %w[ar_internal_metadata]
end

config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
end
end

0 comments on commit bbbbd4e

Please sign in to comment.