Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6 support #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 1.1.6
- Rails 6 fixes
- fix specs

* 1.0.0
- regenerated gem template with latest Rails (5.1.4)
- removed spork (to be replaced by spring later)
Expand Down
219 changes: 123 additions & 96 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,142 +1,169 @@
PATH
remote: .
specs:
debitcredit (1.0.0.pre.pre.1)
debitcredit (1.1.6)
docile
rails (~> 5.1.4)
rails (>= 5.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.4)
actionpack (= 5.1.4)
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.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
websocket-driver (>= 0.6.1)
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.1.4)
actionview (= 5.1.4)
activesupport (= 5.1.4)
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.1.4)
activesupport (= 5.1.4)
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.1.4)
activesupport (= 5.1.4)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.4.1)
activesupport (= 6.1.4.1)
globalid (>= 0.3.6)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activesupport (5.1.4)
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)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
builder (3.2.3)
byebug (9.1.0)
concurrent-ruby (1.0.5)
crass (1.0.3)
diff-lcs (1.3)
docile (1.1.5)
erubi (1.7.0)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.1)
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.1.1)
loofah (2.12.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.1)
nio4r (2.2.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
rack (2.0.3)
rack-test (0.8.2)
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.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
activemodel (= 5.1.4)
activerecord (= 5.1.4)
activesupport (= 5.1.4)
bundler (>= 1.3.0)
railties (= 5.1.4)
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.3)
loofah (~> 2.0)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
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.18.1, < 2.0)
rake (12.3.0)
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.0)
sprockets (3.7.1)
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.3.13)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.4)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
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.16.1
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
2 changes: 1 addition & 1 deletion app/models/debitcredit/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Entry < ApplicationRecord

def self.prepare(opts = {}, &block)
new(opts).tap do |t|
Docile.dsl_eval(Dsl.new(t), &block)
Docile.dsl_eval(Debitcredit::Entry::Dsl.new(t), &block)
end
end

Expand Down
1 change: 1 addition & 0 deletions app/models/debitcredit/entry/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def credit(account, amount, comment = nil)
end

private

def build_item(debit, account, amount, comment)
account = entry.reference.accounts[account] if account.is_a?(Symbol) && entry.reference.try(:respond_to?, :accounts)
entry.items.build debit: debit, account: account, amount: amount, comment: comment
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.1.4"
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
Loading