-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from fabianoflorentino/development
Development to Main
- Loading branch information
Showing
17 changed files
with
236 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
db/migrate/20240310004513_add_email_and_password_to_customers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
# Add Email and Password to Customers class | ||
class AddEmailAndPasswordToCustomers < ActiveRecord::Migration[7.1] | ||
def change | ||
change_table :customers, bulk: true do |t| | ||
t.string :email | ||
t.string :password | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
# Add Index Email to Customers class | ||
class AddIndexEmailToCustomers < ActiveRecord::Migration[7.1] | ||
def up | ||
add_index :customers, :email, unique: true | ||
end | ||
|
||
def down | ||
remove_index :customers, :email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
# Add an index to the name column in the customers table to improve the performance of the application. | ||
class AddIndexNameToCustomers < ActiveRecord::Migration[7.1] | ||
def up | ||
add_index :customers, :name, unique: true | ||
end | ||
|
||
def down | ||
remove_index :customers, :name | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ | |
require 'rails_helper' | ||
|
||
RSpec.describe Customer do | ||
let(:customer) { described_class.new } | ||
let(:customer) { create(:customer) } | ||
|
||
it { is_expected.to have_many(:transactions) } | ||
it { is_expected.to validate_presence_of(:name) } | ||
it { is_expected.to validate_presence_of(:limit) } | ||
it { is_expected.to validate_presence_of(:balance) } | ||
it { is_expected.to validate_presence_of(:email) } | ||
it { is_expected.to validate_presence_of(:password) } | ||
|
||
it 'validates the presence of the name' do | ||
customer.name = nil | ||
|
@@ -17,6 +19,16 @@ | |
expect(customer.errors[:name]).to include("can't be blank") | ||
end | ||
|
||
it 'validates the uniqueness of the name' do | ||
customer.name = 'Customer' | ||
customer.save | ||
|
||
new_customer = described_class.new(name: 'Customer') | ||
new_customer.valid? | ||
|
||
expect(new_customer.errors[:name]).to include('has already been taken') | ||
end | ||
|
||
it 'validates limit is greater than 0' do | ||
customer.limit = -1 | ||
|
||
|
@@ -37,4 +49,42 @@ | |
customer.valid? | ||
expect(customer.errors[:balance]).to include('is not a number') | ||
end | ||
|
||
it 'validates the presence of the email' do | ||
customer.email = nil | ||
|
||
customer.valid? | ||
expect(customer.errors[:email]).to include("can't be blank") | ||
end | ||
|
||
it 'validates the uniqueness of the email' do | ||
customer.email = '[email protected]' | ||
customer.save | ||
|
||
new_customer = described_class.new(email: '[email protected]') | ||
new_customer.valid? | ||
|
||
expect(new_customer.errors[:email]).to include('has already been taken') | ||
end | ||
|
||
it 'validates the presence of the password' do | ||
customer.password = nil | ||
|
||
customer.valid? | ||
expect(customer.errors[:password]).to include("can't be blank") | ||
end | ||
|
||
it 'validates the minimum of the password' do | ||
customer.password = '1234567' | ||
|
||
customer.valid? | ||
expect(customer.errors[:password]).to include('is too short (minimum is 8 characters)') | ||
end | ||
|
||
it 'validates the maximum of the password' do | ||
customer.password = '1234567890123456789012345' | ||
|
||
customer.valid? | ||
expect(customer.errors[:password]).to include('is too long (maximum is 22 characters)') | ||
end | ||
end |
Oops, something went wrong.