-
Notifications
You must be signed in to change notification settings - Fork 17
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
Vaga Para Desenvolvedor #42
base: master
Are you sure you want to change the base?
Conversation
@@ -2,3 +2,4 @@ log/* | |||
tmp/* | |||
db/development.sqlite3 | |||
db/test.sqlite3 | |||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retirando a pasta da IDE
@@ -16,6 +16,7 @@ RUN apk --update add less | |||
|
|||
COPY Gemfile /app/Gemfile | |||
COPY Gemfile.lock /app/Gemfile.lock | |||
RUN gem install bundler:2.4.21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quando subi o container ele pediu pra usar essa versão do Bundler
|
||
class CalculosController < ApplicationController | ||
def performance | ||
valor_performance = Calculos.performance(params[:valor_meta], params[:valor_realizado]) | ||
valor_performance = Calculos.performance(BigDecimal(params[:valor_meta]), BigDecimal(params[:valor_realizado])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
como os parâmetros são string, usei o BigDecimal para converter para decimal
@@ -1,18 +1,14 @@ | |||
class ClientesController < ApplicationController | |||
before_action :set_cliente, only: [:show, :edit, :update, :destroy] | |||
rescue_from ActiveRecord::RecordNotFound, with: :not_found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quando se pesquisava por um id inexistente ele estoura um erro, então coloquei isso pra só retornar um 404
|
||
def index | ||
@clientes = Cliente.all | ||
render json: {clientes: @clientes} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como o restante da aplicação renderiza um json, ajustei esse metodo para fazer o mesmo
end | ||
|
||
def edit | ||
render json: {cliente: @cliente} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como o restante da aplicação renderiza um json, ajustei esse metodo para fazer o mesmo
@@ -48,4 +44,8 @@ def set_cliente | |||
def cliente_params | |||
params.require(:cliente).permit(:nome) | |||
end | |||
|
|||
def not_found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esse é o metodo para renderizar um 404
@@ -1,18 +1,15 @@ | |||
class ResultadosController < ApplicationController | |||
before_action :set_resultado, only: [:show, :edit, :update, :destroy] | |||
rescue_from ActiveRecord::RecordNotFound, with: :not_found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quando se pesquisava por um id inexistente ele estoura um erro, então coloquei isso pra só retornar um 404
|
||
def new | ||
@resultado = Resultado.new | ||
render json: {resultados: @resultados} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como o restante da aplicação renderiza um json, ajustei esse metodo para fazer o mesmo
end | ||
|
||
def edit | ||
def show | ||
render json: { resultado: @resultado } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como o restante da aplicação renderiza um json, ajustei esse metodo para fazer o mesmo
@@ -46,6 +43,10 @@ def set_resultado | |||
|
|||
# Never trust parameters from the scary internet, only allow the white list through. | |||
def resultado_params | |||
params.require(:resultado).permit(:periodo, :valor_meta, :valor_realizado) | |||
params.require(:resultado).permit(:cliente_id, :periodo, :valor_meta, :valor_realizado) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
precisei adicionar o cliente_id por ter dependencia do cliente
params.require(:resultado).permit(:cliente_id, :periodo, :valor_meta, :valor_realizado) | ||
end | ||
|
||
def not_found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esse é o metodo para renderizar um 404
@@ -1,5 +1,13 @@ | |||
class Calculos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Calculos eu coloquei algumas validações para que retorno 0 se não tiver com os dados Ok, e trouxe o calculo do "realizado" para dentro de Calculos para manter em um lugar só
@@ -1,19 +1,17 @@ | |||
class Resultados |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na resultados coloquei para buscar os calculos da lib Calculos
@@ -11,14 +11,56 @@ def match_periodo(periodo) | |||
end | |||
|
|||
def self.data(data) | |||
/^((([1-2][0-9]{3})[\-](0[13578]|10|12)[\-](0[1-9]|1[0-9]|2[0-9]|30|31))|(([1-2][0-9]{3})[\-](0?[469]|11)[\-](0?[1-9]|1[0-9]|2[0-9]|30))|(([1-2][0-9](0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9[26]))[\-](0?[2])[\-](0?[1-9]|1[0-9]|2[0-9]))|(([1-2][0-9]{3})[\-](0?[2])[\-](0?[1-9]|1[0-9]|2[0-8])))$/.match?(data) | |||
regex_yyyy_mm_dd = /\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])\z/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu fiz algumas alterações nas regex para se adequar ao que foi pedido nos testes, simplifiquei um pouco, para fazer a validação de dia por mês em uma função mais abaixo
end | ||
|
||
def self.valor(valor) | ||
/([+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+))/.match?(valor) | ||
regex_inteiro = /^-?\d+$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Também separei as regez por tipo de numero que foi pedido nos testes
end | ||
|
||
def self.email(email) | ||
/([A-Za-z0-9]*((_*[\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,}))/.match?(email) | ||
regex_email = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refatorei a regex de e-mail
end | ||
|
||
private | ||
def self.valida_dia(ano,mes,dia) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aqui está a função que valida dia, inclusive se o Fevereiro é de um ano bisexto
@@ -9,7 +9,7 @@ | |||
{ cliente_id: cliente.id, periodo: Date.today, valor_meta: 10.5, valor_realizado: 12.7 } | |||
} | |||
|
|||
let(:invalid_valid_attributes) { | |||
let(:invalid_attributes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ajustei o nome da variavel
expect(response).to be_successful | ||
expect(json_response['valor_performance']).to eq('1.21') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar o resultado também
expect(response).to be_successful | ||
expect(json_response['valor_performance']).to eq(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar o resultado também
expect(response).to be_successful | ||
expect(json_response['clientes']).to include(JSON.parse(cliente.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o cliente no json
expect(response).to be_successful | ||
expect(json_response['cliente']).to include(JSON.parse(cliente.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o cliente no json
expect(json_response['cliente']).to include(JSON.parse(cliente.to_json)) | ||
end | ||
|
||
it "returns not a success response" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adicionei o teste para o caso de não encontrar o cliente
expect(response).to have_http_status(:ok) | ||
expect(response.content_type).to eq('application/json') | ||
expect(json_response['location']).to include(JSON.parse(cliente.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o cliente no json
expect(response).to have_http_status(:ok) | ||
expect(response.content_type).to eq('application/json') | ||
expect(json_response['location']).to include(JSON.parse(cliente.to_json)) | ||
expect(cliente.nome).to eq("Josué") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se realmente alterava o dado
expect(response).to be_successful | ||
expect(json_response['resultados']).to include(JSON.parse(resultado.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o resultado no json
expect(response).to be_successful | ||
expect(json_response['resultado']).to include(JSON.parse(resultado.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o resultado no json
expect(json_response['resultado']).to include(JSON.parse(resultado.to_json)) | ||
end | ||
|
||
it "returns not a success response" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adicionei o teste para o caso de não encontrar o resultado
expect(response).to have_http_status(:ok) | ||
expect(response.content_type).to eq('application/json') | ||
expect(json_response['location']).to include(JSON.parse(resultado.to_json)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se trazia o resultado no json
expect(response).to have_http_status(:ok) | ||
expect(response.content_type).to eq('application/json') | ||
expect(json_response['location']).to include(JSON.parse(resultado.to_json)) | ||
expect(resultado.valor_realizado).to eq(15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coloquei para validar se realmente alterava o dado
@@ -73,7 +86,7 @@ | |||
|
|||
describe "Teste final!" do | |||
it "qual a resposta para a vida o universo e tudo mais?" do | |||
resposta = Base64.encode64("ESCREVA AQUI A RESPOSTA") | |||
resposta = Base64.encode64("42") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fiz um decode para descobrir esse valor, só depois que pesquisando vi que tem relação com o livro guia do mochileiro da galaxia, desculpe, não li esse livro rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aqui só ajustei alguns resultados, e fiz mais alguns cenarios de Calculo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Criei o teste para validar o calculo pelo arquivo valido, e repliquei os teste para o arquivo invalido.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiz um ajuste nos resultados do calcula perfomance e repliquei os testes para validar o calcula realizado
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Criei os testes de acordo com o descritivo
Segue as minha alterações
Está todo comentado no PR para entender melhor a minha logica