-
Notifications
You must be signed in to change notification settings - Fork 15
Homework done #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JulianPasquale
wants to merge
1
commit into
lucashour:master
Choose a base branch
from
JulianPasquale:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| FactoryBot.define do | ||
| # Implementar factory | ||
| factory :post do | ||
| title { Faker::Lorem.sentence } | ||
| body { Faker::Lorem.paragraph } | ||
| association :user | ||
|
|
||
| factory :admin_user_post do | ||
| user { create(:admin_user) } | ||
| end | ||
|
|
||
| factory :regular_user_post do | ||
| user { create(:regular_user) } | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,31 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Post, type: :model do | ||
| # En base al modelo de test propuesto para el modelo User, | ||
| # implementar los tests para el modelo Post. | ||
| describe 'Factory' do | ||
| it 'has a valid factory' do | ||
| expect(create(:post)).to be_valid | ||
| end | ||
| end | ||
|
|
||
| describe 'Associations' do | ||
| it 'belong to an user' do | ||
| expect belong_to(:user) | ||
| end | ||
| end | ||
|
|
||
| describe 'Presence validations' do | ||
| it 'has a not empty title' do | ||
| expect validate_presence_of(:title) | ||
| end | ||
|
|
||
| it 'has a not empty body' do | ||
| expect validate_presence_of(:body) | ||
| end | ||
| end | ||
|
|
||
| describe 'Uniqueness validations' do | ||
| it 'has a unique title' do | ||
| expect validate_uniqueness_of(:title) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,87 +1,119 @@ | ||
| require 'rails_helper' | ||
|
|
||
| # Los skips sirven para prevenir la ejecución del it, así que es necesario | ||
| # borrarlos (en su lugar implementen los tests, no sean vagos). | ||
|
|
||
| RSpec.describe ApiLoginManager do | ||
| # Idealmente la contraseña del usuario estaría encriptada en la base | ||
| # de datos, por lo que no vamos a poder recuperarla del usuario para | ||
| # utilizarla. Es por eso que conviene usarla desde una variable con | ||
| # let!(:password) { SecureRandom.hex }. Al crear el usuario, | ||
| # en let!(:user) { ... }, usar esta variable. | ||
| let!(:password) { SecureRandom.hex } | ||
|
|
||
| let!(:user) { } # -- crear usuario con FactoryBot -- # | ||
| let!(:user) { create(:user, password: password) } | ||
|
|
||
| describe '#call' do | ||
| context 'when user provided data is valid' do | ||
| before do | ||
| # Realizar un stub del ExternalValidator para que se ejecuta realmente | ||
| allow(ExternalValidator).to receive(:call).and_return(true) | ||
| end | ||
|
|
||
| subject do | ||
| described_class.new(email: user.email, password: password).call | ||
| end | ||
|
|
||
| it "update user's auth_token" do | ||
| skip 'Una vez que definan a user, este test va a fallar. ¿Por qué?' | ||
| expect { subject }.to change { user.auth_token } | ||
| # skip 'Una vez que definan a user, este test va a fallar. ¿Por qué?' | ||
|
|
||
| # Esto es porque el registro no se actualizo con los datos modificados | ||
| # luego de la llamada a ApiLoginManager, por lo que es necesario hacer | ||
| # un reload | ||
|
|
||
| expect { subject }.to change { user.reload.auth_token } | ||
| end | ||
|
|
||
| it 'returns the auth_token' do | ||
| skip 'Implementar' | ||
| expect(subject).to eq(user.reload.auth_token) | ||
| # Por qué esto no anda pero lo de arriba si? | ||
| # expect(user.reload.auth_token).to eq(subject) | ||
| end | ||
| end | ||
|
|
||
| context 'when no email is provided' do | ||
| subject { } # implementar | ||
| subject do | ||
| described_class.new(password: password) | ||
| end | ||
|
|
||
| let!(:subject_response) { subject.call } | ||
|
|
||
| it 'returns false' do | ||
| skip 'Implementar' | ||
| expect(subject_response).to be false | ||
| end | ||
|
|
||
| it 'returns EMPTY_EMAIL error with a reader' do | ||
| skip 'Implementar' | ||
| expect(subject.error).to eq(ApiLoginManager::EMPTY_EMAIL) | ||
| end | ||
| end | ||
|
|
||
| context 'when no password is provided' do | ||
| subject { } # implementar | ||
| subject do | ||
| described_class.new(email: user.email) | ||
| end | ||
|
|
||
| let!(:subject_response) { subject.call } | ||
|
|
||
| it 'returns false' do | ||
| skip 'Implementar' | ||
| expect(subject_response).to be false | ||
| end | ||
|
|
||
| it 'returns EMPTY_PASSWORD error with a reader' do | ||
| skip 'Implementar' | ||
| expect(subject.error).to eq(ApiLoginManager::EMPTY_PASSWORD) | ||
| end | ||
| end | ||
|
|
||
| context 'when the email is incorrect' do | ||
| subject { } # implementar | ||
| subject do | ||
| described_class.new(email: Faker::Internet.email, password: password) | ||
| end | ||
|
|
||
| let!(:subject_response) { subject.call } | ||
|
|
||
| it 'returns false' do | ||
| skip 'Implementar' | ||
| expect(subject_response).to be false | ||
| end | ||
|
|
||
| it 'returns USER_NOT_FOUND error with a reader' do | ||
| skip 'Implementar' | ||
| expect(subject.error).to eq(ApiLoginManager::USER_NOT_FOUND) | ||
| end | ||
| end | ||
|
|
||
| context 'when the password is incorrect' do | ||
| subject { } # implementar | ||
| subject do | ||
| described_class.new(email: user.email, password: SecureRandom.uuid) | ||
| end | ||
|
|
||
| let!(:subject_response) { subject.call } | ||
|
|
||
| it 'returns false' do | ||
| skip 'Implementar' | ||
| expect(subject_response).to be false | ||
| end | ||
|
|
||
| it 'returns WRONG_PASSWORD error with a reader' do | ||
| skip 'Implementar' | ||
| expect(subject.error).to eq(ApiLoginManager::WRONG_PASSWORD) | ||
| end | ||
| end | ||
|
|
||
| # Definir un nuevo context para cuando la conexión | ||
| # con ExternalValidator falla. Acá los quiero ver... | ||
| context 'when ExternalValidator conection fails' do | ||
| before do | ||
| allow(ExternalValidator).to receive(:call).and_return(false) | ||
| end | ||
|
|
||
| subject do | ||
| described_class.new(email: user.email, password: password) | ||
| end | ||
|
|
||
| let!(:subject_response) { subject.call } | ||
|
|
||
| it 'returns false' do | ||
| expect(subject_response).to be false | ||
| end | ||
|
|
||
| it 'returns EXTERNAL_VALIDATOR error with a reader' do | ||
| expect(subject.error).to eq(ApiLoginManager::EXTERNAL_VALIDATOR) | ||
| end | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.