Skip to content

Instantly share code, notes, and snippets.

View bhserna's full-sized avatar

Benito Serna bhserna

View GitHub Profile
@bhserna
bhserna / Carros.rb
Created June 24, 2017 19:09
tarea_clase_3
#-Crear una clase Auto, al instanciar un objeto de la clase dale la oportunidad al usuario de definir variables de instancia como año, color y modelo.También crea una variable de instancia seteada en 0 durante la instanciación del objeto para realizar un seguimiento de la velocidad actual del auto. Crear métodos de instancia que permitan al auto acelerar, frenar, y estacionar (apagar el auto, velocidad 0).
#-Método de instancia de encender el auto, y métodos de obtener la marca y setear una marca.
#-Añadir método accessor a la clase de autos para cambiar y ver el color de su auto. A continuación, añadir otro método accessor que
#le permite ver, pero no modificar, el año de su auto
car = Car.new(2013, :red, "Yaris")
car.brand = "Toyota"
puts car.brand
puts car.color
car.color = :green
@bhserna
bhserna / hashes.rb
Created June 24, 2017 17:14
clase3
# Crear un arreglo de hashes, cada hash contiene los datos de la persona:
# - Nombre Completo
# - País
# - Continente
# - Género
#
# Poblar con muchos datos
# 2.- Contar la cantidad de personas de la lista
# 3.- Generar un array con cada continente, eliminar repeticiones, considerar
# que pueden haber nombres escritos con mayúscula y minúscula
def portfolio_with(attrs)
FakePortfolio.new(attrs)
end
class FakePortfolio
attr_reader :projects_with_investment, :principal_invested,
:current_value, :generated_value, :value_of_received_payments,
:count_of_received_payments
def initialize(attrs)
def portfolio_with(*projects, current_date)
projects_finder = FakeProjectFinder.new(*(projects + [refunded_project]))
UserPortfolio.portfolio_for_user(user, current_date, projects_finder)
end
describe "implements investments value interface" do
subject { portfolio_with(project) }
it_behaves_like "investments value interface"
end
RSpec.shared_examples "investments value interface" do
it { expect(subject).to respond_to(:principal_invested) }
it { expect(subject).to respond_to(:generated_value) }
it { expect(subject).to respond_to(:current_value) }
it { expect(subject).to respond_to(:has_current_value_with_adjustment?) }
it { expect(subject).to respond_to(:value_of_received_payments) }
it { expect(subject).to respond_to(:count_of_received_payments) }
end
@bhserna
bhserna / test.rb
Created November 11, 2016 17:58
5 Rules - Tests without active record
before do
@user = user_with(first_name: "Maria")
@project_one = project_with(
fixed_annual_rate: 11,
execution_date: Date.new(2015, 10, 8),
investments: [investment_with(amount: 100_000, user: user)])
end
def project_with(attrs)
FakeProject.new({ fixed_annual_rate: 11 }.merge(attrs))
@bhserna
bhserna / test.rb
Created November 11, 2016 17:48
5 Rules - Test through module functions
it "(when project is refunded)" do
portfolio = portfolio_on(Date.new(2018, 2, 4))
date = next_payment_date_for_project(
portfolio,
refunded_project,
formatter: ->(date) { "My date: #{date}" },
not_executed_message: "No se ha ejecutado",
no_payments_left_message: "No hay más pagos",
project_refunded_message: "No aplica"
)
@bhserna
bhserna / controller.rb
Created November 11, 2016 17:43
5 Rules - Inject dependencies
class Admin::ProjectFundingTerminationsController < Admin::BaseController
def destroy
Projects.revert_funding_termination(
find_project,
projects_store: Project,
receipts_cancelator: ReceiptsCancelator
)
redirect_to admin_projects_path
end
@bhserna
bhserna / controller.rb
Created November 11, 2016 17:37
5 Rules - Call Module functions on Rails components
class Admin::ProjectFundingTerminationsController < Admin::BaseController
def new
project = find_project
form = Projects.terminate_funding_form(project)
render locals: { project: project, form: form }, layout: false
end
def create
termination = Projects.terminate_funding(
find_project.id,
@bhserna
bhserna / projects.rb
Last active November 11, 2016 17:26
5 Rules - Module functions
module Projects
def self.publish_project
end
def self.add_termination_date_form
end
def self.add_termination_date
end
def self.details_page_for_project
end
def self.terminate_funding_form