diff --git a/CHANGELOG b/CHANGELOG index b60e594..afb2420 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/Gemfile.lock b/Gemfile.lock index ce16876..ce04540 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,133 +1,160 @@ 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 @@ -135,8 +162,8 @@ PLATFORMS DEPENDENCIES byebug debitcredit! - rspec-rails (~> 3.7.2) + rspec-rails (>= 3.7.2) sqlite3 BUNDLED WITH - 1.16.1 + 2.2.15 diff --git a/app/models/debitcredit/account.rb b/app/models/debitcredit/account.rb index 49a8246..ae8112d 100644 --- a/app/models/debitcredit/account.rb +++ b/app/models/debitcredit/account.rb @@ -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[ .... ] @@ -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 @@ -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) diff --git a/app/models/debitcredit/entry.rb b/app/models/debitcredit/entry.rb index e99c0fd..bad5786 100644 --- a/app/models/debitcredit/entry.rb +++ b/app/models/debitcredit/entry.rb @@ -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 diff --git a/app/models/debitcredit/entry/dsl.rb b/app/models/debitcredit/entry/dsl.rb index d15df3e..8a8c15c 100644 --- a/app/models/debitcredit/entry/dsl.rb +++ b/app/models/debitcredit/entry/dsl.rb @@ -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 diff --git a/debitcredit.gemspec b/debitcredit.gemspec index ecec060..16d06f9 100644 --- a/debitcredit.gemspec +++ b/debitcredit.gemspec @@ -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 diff --git a/lib/debitcredit/version.rb b/lib/debitcredit/version.rb index 6becff9..a7922f0 100644 --- a/lib/debitcredit/version.rb +++ b/lib/debitcredit/version.rb @@ -1,3 +1,3 @@ module Debitcredit - VERSION = '1.0.0-pre.1' + VERSION = '1.1.6' end diff --git a/spec/models/debitcredit/account_spec.rb b/spec/models/debitcredit/account_spec.rb index e52b006..41a0dbc 100644 --- a/spec/models/debitcredit/account_spec.rb +++ b/spec/models/debitcredit/account_spec.rb @@ -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 diff --git a/spec/test_app/app/assets/config/manifest.js b/spec/test_app/app/assets/config/manifest.js new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/spec/test_app/app/assets/config/manifest.js @@ -0,0 +1 @@ +{} diff --git a/spec/test_app/config/environments/test.rb b/spec/test_app/config/environments/test.rb index 6fd7f98..36c3748 100644 --- a/spec/test_app/config/environments/test.rb +++ b/spec/test_app/config/environments/test.rb @@ -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. diff --git a/spec/test_app/db/schema.rb b/spec/test_app/db/schema.rb index 3f1e6e9..27f067d 100644 --- a/spec/test_app/db/schema.rb +++ b/spec/test_app/db/schema.rb @@ -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