Skip to content

Commit

Permalink
Merge pull request #19 from Sage/add-appraisal
Browse files Browse the repository at this point in the history
Add appraisals gem to support different versions of Rails
  • Loading branch information
tapan-sh authored Jun 21, 2024
2 parents a43ab7e + 81f6423 commit df11da1
Show file tree
Hide file tree
Showing 29 changed files with 220 additions and 153 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,36 @@ on: [push]
jobs:
test:
runs-on: ubuntu-latest

env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
strategy:
matrix:
ruby-version: ['2.7', '3.0', '3.1', '3.2']
gemfile:
- rails_4
- rails_5
- rails_6
- rails_7
rubygems:
- default
ruby:
- '2.7'
- '3.2'
exclude:
- gemfile: rails_4
ruby: '3.2'
- gemfile: rails_6
ruby: '2.7'
- gemfile: rails_7
ruby: '2.7'
name: ${{ matrix.gemfile }}, Ruby ${{ matrix.ruby }}

steps:
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby-version }}
- name: Set up Ruby and Bundle
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
ruby-version: ${{ matrix.ruby }}
rubygems: ${{ matrix.rubygems }}
bundler-cache: true

- name: Export ENV
Expand All @@ -37,7 +56,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2.0'
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Clear any existing packages
run: rm -f $GEMS_PATH
Expand All @@ -49,4 +68,4 @@ jobs:
- name: Build gem
run: bundle exec rake build zuora.gemspec
- name: Publish
run: gem push $GEMS_PATH
run: gem push $GEMS_PATH
29 changes: 20 additions & 9 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
appraise "rails30" do
gem 'activesupport', '~> 3.0.0'
gem 'activemodel', '~> 3.0.0'
appraise "rails-4" do
gem 'activemodel', '~> 4.2'
gem 'bigdecimal', '~> 1.4'
gem 'sqlite3', '~> 1.3'
gem 'rack', '~> 2.0'
end

appraise "rails31" do
gem 'activesupport', '~> 3.1.0'
gem 'activemodel', '~> 3.1.0'
appraise "rails-5" do
gem 'activemodel', '~> 5.2'
gem 'sqlite3', '~> 1.4.0'
gem 'i18n', '~> 1.5.1'
gem 'rack', '~> 2.0'
end

appraise "rails32" do
gem 'activesupport', '~> 3.2.0'
gem 'activemodel', '~> 3.2.0'
appraise "rails-6" do
gem 'activemodel', '~> 6.0'
gem 'sqlite3'
gem 'httpi', '~> 4.0'
end

appraise "rails-7" do
gem 'activemodel', '~> 7.0'
gem 'sqlite3'
gem 'httpi', '~> 4.0'
end
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
ARG RUBY_VERSION=${RUBY_VERSION:-3.2.0}
ARG RUBY_VERSION=${RUBY_VERSION:-3.2}
FROM ruby:${RUBY_VERSION}-alpine

RUN apk --update add --no-cache build-base bash && \
apk add git && \
apk add --no-cache libffi-dev && \
apk add --no-cache libxml2 && \
apk add --no-cache libxml2-dev && \
apk add --no-cache sqlite-dev
apk add --no-cache sqlite-dev && \
apk add --no-cache musl-dev && \
apk add --no-cache libc6-compat

RUN gem install nokogiri -v '1.15.6' -- --use-system-libraries

RUN gem update --system 3.3.22 --no-document && \
gem install bundler --no-document
Expand Down
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@
source 'https://rubygems.org'

gemspec

gem 'akami', '~> 1.3.2'
gem 'nokogiri', '~> 1.15.6'
gem 'wasabi', '>= 3.7'
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '2'

services:
client:
build:
Expand Down
10 changes: 10 additions & 0 deletions gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activemodel", "~> 4.2"
gem "bigdecimal", "~> 1.4"
gem "sqlite3", "~> 1.3"
gem "rack", "~> 2.0"

gemspec path: "../"
10 changes: 10 additions & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activemodel", "~> 5.2"
gem "sqlite3", "~> 1.4.0"
gem "i18n", "~> 1.5.1"
gem "rack", "~> 2.0"

gemspec path: "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activemodel", "~> 6.0"
gem "sqlite3"
gem "httpi", "~> 4.0"

gemspec path: "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activemodel", "~> 7.0"
gem "sqlite3"
gem "httpi", "~> 4.0"

gemspec path: "../"
27 changes: 13 additions & 14 deletions lib/zuora/attributes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Zuora
module Attributes

def self.included(base)
base.send(:include, ActiveModel::Naming)
base.send(:include, ActiveModel::Conversion)
Expand Down Expand Up @@ -39,19 +40,17 @@ def define_attributes(&block)
# generate association overrides for complex object handling
# and cache the objects so that they may be modified and updated
class_variable_get(:@@complex_attributes).each do |var, scope|
# set up the instance variable for the new assoc collection
# for new records, but call the original one for existing
# records and cache/return the result for subsequent calls.
class_eval <<-EVAL
def #{scope}_with_complex
if new_record? || @#{scope}_cached
@#{scope} ||= []
else
@#{scope}_cached = true
@#{scope} = #{scope}_without_complex
class_eval <<~EVAL
prepend(Module.new do
def #{scope}
if new_record? || @#{scope}_cached
@#{scope} ||= []
else
@#{scope}_cached = true
@#{scope} = super
end
end
end
alias_method_chain :#{scope}, :complex
end)
EVAL
end
end
Expand Down Expand Up @@ -209,7 +208,7 @@ def attributes

# remove all dirty tracking for the object and return self for chaining.
def clear_changed_attributes!
@changed_attributes = {}
clear_changes_information
self
end

Expand All @@ -218,4 +217,4 @@ def remote_name
self.class.name.base_name
end
end
end
end
2 changes: 1 addition & 1 deletion lib/zuora/objects/amendment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def apply_response(response_hash, type)
self.invoice_id = result[:invoice_id]
self.payment_transaction_number = result[:payment_transaction_number]
@previously_changed = changes
@changed_attributes.clear
clear_changes_information
return true
else
self.errors.add(:base, result[:errors][:message])
Expand Down
8 changes: 4 additions & 4 deletions lib/zuora/objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def reload!
self.send("#{k}=", v)
}
@previously_changed = changes
@changed_attributes.clear
clear_changes_information
self
end

Expand Down Expand Up @@ -84,9 +84,9 @@ def self.select(select)
def self.all
keys = (attributes - unselectable_attributes).map(&:to_s).map(&:zuora_camelize)
sql = "select #{keys.join(', ')} from #{remote_name}"

result = self.connector.query(sql)

generate(result.to_hash, :query_response)
end

Expand Down Expand Up @@ -191,7 +191,7 @@ def apply_response(response_hash, type)
if result[:success]
self.id = result[:id]
@previously_changed = changes
@changed_attributes.clear
clear_changes_information
return true
else
raise StandardError.new(result[:errors][:message])
Expand Down
2 changes: 1 addition & 1 deletion lib/zuora/objects/subscribe_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def apply_response(response_hash, type)
subscription.name = result[:subscription_number]
subscription.clear_changed_attributes!
@previously_changed = changes
@changed_attributes.clear
clear_changes_information
else
self.errors.add(:base, result[:errors][:message])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/zuora/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def self.included(base)
class DateTimeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless [DateTime, Time].any? { |klass| value.is_a?(klass) }
record.errors[attribute] << (options[:message] || "is not a valid datetime")
record.errors.add(attribute, (options[:message] || "is not a valid datetime"))
end
end
end

class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless [Date].any? { |klass| value.is_a?(klass) }
record.errors[attribute] << (options[:message] || "is not a valid date")
record.errors.add(attribute, (options[:message] || "is not a valid date"))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/accounts.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FactoryGirl.define do
FactoryBot.define do
factory :account, :class => Zuora::Objects::Account do
sequence(:name){|n| "Test Account #{n}"}
sequence(:account_number){|n| "test_account_#{n}" }
end

factory :active_account, :parent => :account do
after_create do |account|
contact = FactoryGirl.create(:contact, :account => account, :country => "GB")
contact = FactoryBot.create(:contact, :account => account, :country => "GB")
account.bill_to = contact
account.sold_to = contact
account.status = "Active"
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/contacts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
FactoryBot.define do
factory :contact, :class => Zuora::Objects::Contact do
first_name "Example"
first_name { "Example" }
sequence(:last_name){|n| "User #{n}" }
end
end
52 changes: 27 additions & 25 deletions spec/factories/payment_methods.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
FactoryGirl.define do
FactoryBot.define do
factory :payment_method_credit_card, :class => Zuora::Objects::PaymentMethod do
type "CreditCard"
credit_card_address1 "123 Testing Lane"
credit_card_city "San Francisco"
credit_card_state "California"
credit_card_postal_code "95611"
credit_card_holder_name "Example User"
credit_card_number "4111111111111111"
credit_card_type "Visa"
credit_card_expiration_month "9"
credit_card_expiration_year "2018"
type { "CreditCard" }
credit_card_address1 { "123 Testing Lane" }
credit_card_city { "San Francisco" }
credit_card_state { "California" }
credit_card_postal_code { "95611" }
credit_card_holder_name { "Example User" }
credit_card_number { "4111111111111111" }
credit_card_type { "Visa" }
credit_card_expiration_month { "9" }
credit_card_expiration_year { "2018" }
end

factory :payment_method_debit_card, :parent => :payment_method_credit_card do
type "DebitCard"
type { "DebitCard" }
end

factory :payment_method_ach, :class => Zuora::Objects::PaymentMethod do
type "ACH"
ach_aba_code '123456789'
ach_account_name 'My Checking Account'
ach_account_number '987654321'
ach_bank_name 'Bank of Zuora'
ach_account_type 'BusinessChecking'
end
FactoryBot.define do
factory :payment_method_ach, class: Zuora::Objects::PaymentMethod do
type { "ACH" }
ach_aba_code { '123456789' }
ach_account_name { 'My Checking Account' }
ach_account_number { '987654321' }
ach_bank_name { 'Bank of Zuora' }
ach_account_type { 'BusinessChecking' }
end

factory :payment_method_paypal, :class => Zuora::Objects::PaymentMethod do
type 'PayPal'
paypal_baid "ExampleBillingAgreementId"
paypal_email "[email protected]"
paypal_type "ExpressCheckout"
factory :payment_method_paypal, class: Zuora::Objects::PaymentMethod do
type { 'PayPal' }
paypal_baid { "ExampleBillingAgreementId" }
paypal_email { "[email protected]" }
paypal_type { "ExpressCheckout" }
end
end
end
8 changes: 4 additions & 4 deletions spec/factories/product_rate_plan_charge_tiers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
FactoryBot.define do
factory :product_rate_plan_charge_tier, :class => Zuora::Objects::ProductRatePlanChargeTier do
price 0
starting_unit 0
ending_unit 10
price { 0 }
starting_unit { 0 }
ending_unit { 10 }
end
end
Loading

0 comments on commit df11da1

Please sign in to comment.