Skip to content

Instantly share code, notes, and snippets.

View graves's full-sized avatar

Thomas Graves graves

View GitHub Profile
require 'csv'
require 'logger'
class OfficeMaker
attr_reader :input_file, :site_number, :offices, :log, :params
def initialize(input_file, site_number, params={})
@input_file = input_file
@site_number = site_number
@params = params
def index
...
...
if @site.cc_processing_fee
if @site.cc_processing_fee_type == "FLAT RATE"
@fee_string = "#{view_context.number_to_currency(@site.cc_processing_fee_amount)}"
else # In the above/below lines 'view_context' lets us use helper methods available in the view
@fee_string = "#{view_context.number_to_percentage(@site.cc_processing_fee_amount, precision: 2)}"
end
...
...
private
def generate_processing_fee_warning(site)
return unless fee = site.cc_processing_fee
flat_rate = site.cc_processing_fee_type == "FLAT RATE"
return convert_fee_to_currency(fee) if flat_rate
convert_fee_to_percentage(site.cc_processing_fee_amount)
end
class Clients::MakePaymentController < Clients::BaseController
def index
@site = current_customer.accounts.first.site
@customer = current_customer
@accounts = current_customer.accounts
@current_user = current_user
@fee_string = generate_processing_fee_warning(@site)
@account_choices = account_choices_for_dropdown
@card_types = ["VISA", "MASTERCARD", "AMEX"]
end
app
├── controllers
│   └── clients
│   └── make_payment_controller.rb
├── models
│   ├── account.rb
│   ├── credit_card_gateway.rb
│   ├── credit_card_transaction.rb
│   ├── customer.rb
│   ├── payment.rb
require "uri"
require "net/http"
require 'json'
class Clients::MakePaymentController < Clients::BaseController
def index
@site = current_customer.accounts.first.site
@customer = current_customer
@accounts = current_customer.accounts
@current_user = current_user
RSpec.describe Clients::MakePaymentController, :type => :controller do
...
...
it "creates a new transaction using form params" do
allow(CreditCardGateway)
.to receive(:payment_from_params) { payment }
allow(site).to receive(:credit_card_gateway) { gateway }
...
...
it "creates a new transaction using form params" do
allow(CreditCardGateway)
.to receive(:payment_from_params) { payment }
allow(site).to receive(:credit_card_gateway) { gateway }
allow(payment).to receive(:store_transaction_id)
@graves
graves / client_can_make_credit_card_payment_spec.rb
Last active August 29, 2015 14:13
Friday morning refactor - tests finally pass
require 'rails_helper'
RSpec.describe "client can make credit card payment", :type => :feature do
let(:sign_in_page) { ClientsSignInPage.new }
let(:make_payment_page) { ClientsMakePaymentPage.new }
let(:sign_in) do
lambda { |email, password|
sign_in_page.visit_page.sign_in(email, password)
}
end
@graves
graves / make_payment_controller.rb
Last active August 29, 2015 14:13
Friday morning refactor - tests finally pass
class Clients::MakePaymentController < Clients::BaseController
def index
@site = current_customer.accounts.first.site
@customer = current_customer
@accounts = current_customer.accounts
@current_user = current_user
@fee_string = generate_processing_fee_warning(@site)
@account_choices = account_choices_for_dropdown
@card_types = ["VISA", "MASTERCARD", "AMEX"]
end