Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Respect the rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Sep 16, 2016
1 parent 594d72b commit 4c71be0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 56 deletions.
5 changes: 2 additions & 3 deletions app/controllers/api/member_authentications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

class Api::MemberAuthenticationsController < ApplicationController

def new
@page = Page.find params[:page_id]
view = File.read("#{Rails.root}/app/liquid/views/layouts/member_registration.liquid")
template = Liquid::Template.parse(view)
@rendered = template.render('page_id' => params[:page_id], 'email' => params[:email]).html_safe

render "pages/show", layout: 'sumofus'
render 'pages/show', layout: 'sumofus'
end

def create
Expand All @@ -19,7 +18,7 @@ def create
)

if auth.valid?
render js: "window.location = '#{ follow_up_page_path(params[:page_id]) }'"
render js: "window.location = '#{follow_up_page_path(params[:page_id])}'"
else
render json: auth.errors, status: :unprocessable_entity
end
Expand Down
13 changes: 4 additions & 9 deletions app/controllers/api/payment/braintree_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def referer_url
end

def build_params
params.permit( fields + base_params ).merge(donation: true)
params.permit(fields + base_params).merge(donation: true)
end

def base_params
%w{page_id form_id name source akid referring_akid email}
%w(page_id form_id name source akid referring_akid email)
end

def fields
Expand Down Expand Up @@ -67,7 +67,6 @@ def attributes
end
end


class DonationActionParamsWrapper
def self.params(params)
new(params).params
Expand All @@ -84,7 +83,6 @@ def params
end
end


module Json
class BraintreeCreditCard
def initialize(card)
Expand All @@ -93,7 +91,7 @@ def initialize(card)

def to_builder
Jbuilder.new do |json|
json.(@card, :token)
json.call(@card, :token)
end
end
end
Expand Down Expand Up @@ -122,7 +120,6 @@ def to_builder
end
end


class BraintreeOneClickService
attr_reader :params

Expand All @@ -134,9 +131,7 @@ def run
create_action
sale = make_sale

if sale.success?
store_sale_locally(sale)
end
store_sale_locally(sale) if sale.success?
end

private
Expand Down
23 changes: 11 additions & 12 deletions app/services/manage_donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def create
end
end


class DonationActionBuilder
def initialize(params, &block)
@params = params
Expand Down Expand Up @@ -66,11 +65,11 @@ def previous_action
end

def existing_member
@existing_member ||= Member.find_by( email: @params[:email] )
@existing_member ||= Member.find_by(email: @params[:email])
end

def existing_member?
!!existing_member
!existing_member.nil?
end

def member
Expand All @@ -86,11 +85,11 @@ def member

def filtered_params
hash = @params.try(:to_unsafe_hash) || @params.to_h # for ActionController::Params
hash.symbolize_keys.compact.keep_if{ |k| permitted_keys.include? k }
hash.symbolize_keys.compact.keep_if { |k| permitted_keys.include? k }
end

def permitted_keys
Member.new.attributes.keys.map(&:to_sym).reject!{|k| k == :id}
Member.new.attributes.keys.map(&:to_sym).reject! { |k| k == :id }
end

def page
Expand All @@ -103,23 +102,23 @@ def update_member_fields
ak_user_id = AkidParser.parse(@params[:akid], Settings.action_kit.akid_secret)[:actionkit_user_id]
@user.actionkit_user_id = ak_user_id unless ak_user_id.blank?

@user.name = @params[:name] if @params.has_key? :name
@user.name = @params[:name] if @params.key? :name
@user.assign_attributes(filtered_params)
end

def update_donor_status
return unless is_donation?
return unless donation?
return if @user.recurring_donor?
new_status = is_recurring_donation? ? 'recurring_donor' : 'donor'
new_status = recurring_donation? ? 'recurring_donor' : 'donor'
@user.donor_status = new_status
end

def is_donation?
def donation?
return false if @extra_attrs.blank?
!!@extra_attrs[:donation]
!@extra_attrs[:donation].nil?
end

def is_recurring_donation?
!!@params[:is_subscription]
def recurring_donation?
!@params[:is_subscription].nil?
end
end
15 changes: 5 additions & 10 deletions app/services/member_authentication_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ def initialize(email:, password:, password_confirmation:)
@password_confirmation = password_confirmation
end


def build
auth = MemberAuthentication.new({
member: member,
password: @password,
password_confirmation: @password_confirmation
})

if auth.save
send_confirmation_email
end
auth = MemberAuthentication.new(member: member,
password: @password,
password_confirmation: @password_confirmation)

send_confirmation_email if auth.save

auth
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
end

context 'unsuccessfully creates authentication' do
let(:auth) { double('auth', valid?: false, errors: [{foo: :bar}]) }
let(:auth) { double('auth', valid?: false, errors: [{ foo: :bar }]) }

it 'returns errors as json' do
expect(response.status).to eq(422)
expect(response.body).to eq([{foo: :bar}].to_json)
expect(response.body).to eq([{ foo: :bar }].to_json)
end
end
end
Expand Down
33 changes: 14 additions & 19 deletions spec/requests/api/braintree/braintree_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'

describe "Express Donation" do
describe 'Express Donation' do
let(:page) { create(:page, slug: 'hello-world', title: 'Hello World') }
let(:form) { create(:form) }

Expand All @@ -17,22 +17,20 @@
end

before do
VCR.use_cassette("braintree_express_donation") do
post api_payment_braintree_one_click_path(page.id), {
payment: {
amount: 2.00
},
user: {
form_id: form.id,
email: 'test@example.com',
name: 'John Doe'
}
}
VCR.use_cassette('braintree_express_donation') do
post api_payment_braintree_one_click_path(page.id), payment: {
amount: 2.00
},
user: {
form_id: form.id,
email: 'test@example.com',
name: 'John Doe'
}
end
end

it 'returns success, always - FIXME' do
expect(response.body).to eq({success: true}.to_json)
expect(response.body).to eq({ success: true }.to_json)
end

it 'creates an action' do
Expand All @@ -48,10 +46,8 @@
end

it 'records local record of transaction' do
expect(payment_method.transactions.first.attributes.symbolize_keys).to include({
transaction_type: 'sale',
transaction_id: /[a-z0-9]{8}/
})
expect(payment_method.transactions.first.attributes.symbolize_keys).to include(transaction_type: 'sale',
transaction_id: /[a-z0-9]{8}/)
end

it 'creates transaction on braintree' do
Expand All @@ -68,8 +64,7 @@
end
end

describe "Braintree API" do

describe 'Braintree API' do
let(:page) { create(:page, title: 'Cash rules everything around me') }
let(:form) { create(:form) }
let(:four_digits) { /[0-9]{4}/ }
Expand Down
1 change: 0 additions & 1 deletion spec/services/member_authentication_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@
end
end
end

0 comments on commit 4c71be0

Please sign in to comment.