Skip to content

Commit

Permalink
Merge pull request #1 from dpaluy/fix/rails6
Browse files Browse the repository at this point in the history
Support rails 6
  • Loading branch information
dpaluy authored Nov 11, 2021
2 parents eb96548 + 2578964 commit 63a25d9
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 123 deletions.
221 changes: 120 additions & 101 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,150 +1,169 @@
PATH
remote: .
specs:
debitcredit (1.0.0.pre.pre.1)
debitcredit (1.1.6)
docile
rails (~> 5.2)
rails (>= 5.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.2)
actionpack (= 5.2.2)
actioncable (6.1.4.1)
actionpack (= 6.1.4.1)
activesupport (= 6.1.4.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
actionmailbox (6.1.4.1)
actionpack (= 6.1.4.1)
activejob (= 6.1.4.1)
activerecord (= 6.1.4.1)
activestorage (= 6.1.4.1)
activesupport (= 6.1.4.1)
mail (>= 2.7.1)
actionmailer (6.1.4.1)
actionpack (= 6.1.4.1)
actionview (= 6.1.4.1)
activejob (= 6.1.4.1)
activesupport (= 6.1.4.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.2)
actionview (= 5.2.2)
activesupport (= 5.2.2)
rack (~> 2.0)
actionpack (6.1.4.1)
actionview (= 6.1.4.1)
activesupport (= 6.1.4.1)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.2)
activesupport (= 5.2.2)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.4.1)
actionpack (= 6.1.4.1)
activerecord (= 6.1.4.1)
activestorage (= 6.1.4.1)
activesupport (= 6.1.4.1)
nokogiri (>= 1.8.5)
actionview (6.1.4.1)
activesupport (= 6.1.4.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.2)
activesupport (= 5.2.2)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.4.1)
activesupport (= 6.1.4.1)
globalid (>= 0.3.6)
activemodel (5.2.2)
activesupport (= 5.2.2)
activerecord (5.2.2)
activemodel (= 5.2.2)
activesupport (= 5.2.2)
arel (>= 9.0)
activestorage (5.2.2)
actionpack (= 5.2.2)
activerecord (= 5.2.2)
marcel (~> 0.3.1)
activesupport (5.2.2)
activemodel (6.1.4.1)
activesupport (= 6.1.4.1)
activerecord (6.1.4.1)
activemodel (= 6.1.4.1)
activesupport (= 6.1.4.1)
activestorage (6.1.4.1)
actionpack (= 6.1.4.1)
activejob (= 6.1.4.1)
activerecord (= 6.1.4.1)
activesupport (= 6.1.4.1)
marcel (~> 1.0.0)
mini_mime (>= 1.1.0)
activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
builder (3.2.3)
byebug (11.0.0)
concurrent-ruby (1.1.4)
crass (1.0.4)
diff-lcs (1.3)
docile (1.3.1)
erubi (1.8.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.5.3)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
builder (3.2.4)
byebug (11.1.3)
concurrent-ruby (1.1.9)
crass (1.0.6)
diff-lcs (1.4.4)
docile (1.4.0)
erubi (1.10.0)
globalid (0.5.2)
activesupport (>= 5.0)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
loofah (2.2.3)
loofah (2.12.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
rack (2.0.6)
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
minitest (5.14.4)
nio4r (2.5.8)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.2)
actioncable (= 5.2.2)
actionmailer (= 5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
activemodel (= 5.2.2)
activerecord (= 5.2.2)
activestorage (= 5.2.2)
activesupport (= 5.2.2)
bundler (>= 1.3.0)
railties (= 5.2.2)
rails (6.1.4.1)
actioncable (= 6.1.4.1)
actionmailbox (= 6.1.4.1)
actionmailer (= 6.1.4.1)
actionpack (= 6.1.4.1)
actiontext (= 6.1.4.1)
actionview (= 6.1.4.1)
activejob (= 6.1.4.1)
activemodel (= 6.1.4.1)
activerecord (= 6.1.4.1)
activestorage (= 6.1.4.1)
activesupport (= 6.1.4.1)
bundler (>= 1.15.0)
railties (= 6.1.4.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.2)
actionpack (= 5.2.2)
activesupport (= 5.2.2)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
railties (6.1.4.1)
actionpack (= 6.1.4.1)
activesupport (= 6.1.4.1)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.2)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rake (>= 0.13)
thor (~> 1.0)
rake (13.0.6)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-rails (3.7.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
sprockets (3.7.2)
rspec-support (~> 3.10.0)
rspec-rails (5.0.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.3)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.0)
thor (0.20.3)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.7.0)
sqlite3 (1.4.2)
thor (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
websocket-extensions (0.1.5)
zeitwerk (2.5.1)

PLATFORMS
ruby

DEPENDENCIES
byebug
debitcredit!
rspec-rails (~> 3.7.2)
rspec-rails (>= 3.7.2)
sqlite3

BUNDLED WITH
1.17.3
2.2.15
22 changes: 11 additions & 11 deletions app/models/debitcredit/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ class Account < ApplicationRecord
validates :name, :balance, presence: true
validate :prevent_overdraft, unless: :overdraft_enabled?

scope :asset, ->{where(type: AssetAccount.name)}
scope :equity, ->{where(type: EquityAccount.name)}
scope :liability, ->{where(type: LiabilityAccount.name)}
scope :expense, ->{where(type: ExpenseAccount.name)}
scope :income, ->{where(type: IncomeAccount.name)}
scope :asset, -> { where(type: AssetAccount.name) }
scope :equity, -> { where(type: EquityAccount.name) }
scope :liability, -> { where(type: LiabilityAccount.name) }
scope :expense, -> { where(type: ExpenseAccount.name) }
scope :income, -> { where(type: IncomeAccount.name) }

scope :by_id, ->{order(:id)}
scope :by_id, -> { order(:id) }

class NotFound < StandardError; end
class BadKind < StandardError; end
class << self
def by_kind kind
def by_kind(kind)
Debitcredit.const_get "#{kind.to_s.capitalize}Account"
end

def find_or_create(name, kind = nil, overdraft = false)

unless account = find_by(name: name)
# Note: reference is automatically provided by association
# when running through an association, e.g. @user.accounts[ .... ]
Expand All @@ -38,11 +37,12 @@ def find_or_create(name, kind = nil, overdraft = false)
raise BadKind if kind && by_kind(kind) != account.class

if overdraft != account.overdraft_enabled?
account.update_attributes! overdraft_enabled: overdraft
account.update_attribute(:overdraft_enabled, overdraft)
end

return account
account
end

alias :[] :find_or_create

def total_balance
Expand Down Expand Up @@ -77,7 +77,7 @@ def overdraft?
def prevent_overdraft
return unless balance_changed?
return unless check_overdraft
return unless balance < 0
return unless overdraft?
return unless balance_was > balance

errors.add(:balance, :overdraft)
Expand Down
4 changes: 2 additions & 2 deletions debitcredit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

s.add_dependency "rails", "~> 5.2"
s.add_dependency "rails", ">= 5.2"
s.add_dependency "docile"

s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails", "~> 3.7.2"
s.add_development_dependency "rspec-rails", ">= 3.7.2"
end
2 changes: 1 addition & 1 deletion lib/debitcredit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Debitcredit
VERSION = '1.0.0-pre.1'
VERSION = '1.1.6'
end
2 changes: 1 addition & 1 deletion spec/models/debitcredit/account_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Debitcredit
RSpec.describe Account do
def described_class; Debitcredit::AssetAccount; end
def valid_attrs; {name: 'foo'} end
def valid_attrs; { name: 'foo' } end

describe '.by_kind' do
it 'should find account class by kind' do
Expand Down
1 change: 1 addition & 0 deletions spec/test_app/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion spec/test_app/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
'Cache-Control' => "public, max-age=3600"
}

# Show full error reports and disable caching.
Expand Down
12 changes: 6 additions & 6 deletions spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150106165647) do
ActiveRecord::Schema.define(version: 2015_01_06_165647) do

create_table "debitcredit_accounts", force: :cascade do |t|
t.string "name", limit: 32, null: false
Expand Down

0 comments on commit 63a25d9

Please sign in to comment.