Skip to content

Commit

Permalink
Merge branch 'more_standard_engine_config' into support_string_tenant_id
Browse files Browse the repository at this point in the history
* more_standard_engine_config:
  Add note about possible breaking changes
  Fix wrong command
  Use standard way of generating migrations in engines
  Move engine into its own file
  And binstub for rails
  Remove double require
  allow destruction of debit/credit amounts from entry objects
  update rails fixture for update jquery-ui requirement
  update changelog
  Add Account#amounts and Account#entries
  update travis build versions
  bundle exec rake for travis
  remove 1.9 travis test
  Travis CI: Use containerized builds
  fix types on note about account lookup when using multitenancy
  note about account lookup when using multitenancy
  Fix issue with plutus requiring the jquery-ui files
  • Loading branch information
ramontayag committed Jul 12, 2016
2 parents 99b66e6 + c1f28c0 commit c3957b9
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 26 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
language: ruby

sudo: false
cache: bundler

rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.2.0
- 2.2.3
- ruby-head
- jruby
- jruby-head
- rbx-2.2
- jruby-9.0.0.0
- rbx-2

matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- rvm: rbx-2.3
- rvm: jruby-9.0.0.0
- rvm: rbx-2

script: rake
script: bundle exec rake
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Changed
- Tenancy is enabled from the get go. Assigning a tenant is optional. See "Previous Versions" in the README on upgrading.
- Required jquery-ui version
- How migrations are done, which may be a breaking change from older versions of Plutus

### Fixed
- Fix loading of jquery-ui files (Fixes https://github.com/mbulat/plutus/issues/58)

### Added
- Add `Account#amounts` and `Account#entries` to get all amounts and entries, respectively
4 changes: 1 addition & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ Installation
============

- Add the gem to your Gemfile `gem "plutus"`

- generate migration files `rails g plutus:install:migrations`

- generate migration files `rake plutus:install:migrations`
- run migrations `rake db:migrate`

Overview
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/plutus/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require jquery-ui/datepicker
//= require_tree .
2 changes: 1 addition & 1 deletion app/assets/stylesheets/plutus/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*= require_tree .
*= require bootstrap.min
*= require bootstrap-theme.min
*= require jquery.ui.datepicker
*= require jquery-ui/datepicker
*= require_self
*/
body { padding-top: 60px; }
2 changes: 2 additions & 0 deletions app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ module Plutus
class Account < ActiveRecord::Base
class_attribute :normal_credit_balance

has_many :amounts
has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount'
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount'
has_many :entries, through: :amounts, source: :entry
has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
has_many :debit_entries, :through => :debit_amounts, :source => :entry, :class_name => 'Plutus::Entry'

Expand Down
6 changes: 2 additions & 4 deletions app/models/plutus/amounts_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ def balance(hash={})
def balance_for_new_record
balance = BigDecimal.new('0')
each do |amount_record|
if amount_record.amount
balance += amount_record.amount
else
balance = nil
if amount_record.amount && !amount_record.marked_for_destruction?
balance += amount_record.amount # unless amount_record.marked_for_destruction?
end
end
return balance
Expand Down
2 changes: 1 addition & 1 deletion app/models/plutus/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Entry < ActiveRecord::Base
validate :amounts_cancel?

# Support construction using 'credits' and 'debits' keys
accepts_nested_attributes_for :credit_amounts, :debit_amounts
accepts_nested_attributes_for :credit_amounts, :debit_amounts, allow_destroy: true
alias_method :credits=, :credit_amounts_attributes=
alias_method :debits=, :debit_amounts_attributes=
# attr_accessible :credits, :debits
Expand Down
16 changes: 8 additions & 8 deletions fixture_rails_root/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
plutus (0.12.2)
jquery-rails (>= 3.0)
jquery-ui-rails (>= 4.0)
jquery-ui-rails (>= 4.2.2)
rails (~> 4.0)

GEM
Expand Down Expand Up @@ -65,18 +65,18 @@ GEM
jquery-rails (3.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (4.2.1)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.1)
mini_portile (0.6.2)
minitest (5.8.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
mini_portile2 (2.0.0)
minitest (5.8.4)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -97,14 +97,14 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.4)
actionpack (= 4.2.4)
activesupport (= 4.2.4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rake (11.1.2)
sass (3.4.18)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand Down
2 changes: 1 addition & 1 deletion plutus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
]
s.add_dependency("rails", "~> 4.0")
s.add_dependency("jquery-rails", ">= 3.0")
s.add_dependency("jquery-ui-rails", ">= 4.0")
s.add_dependency("jquery-ui-rails", ">= 4.2.2")
s.add_development_dependency("yard")
s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE", "Rakefile", "README.markdown"]
s.homepage = %q{http://github.com/mbulat/plutus}
Expand Down
57 changes: 57 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,62 @@ module Plutus
it { should == 0 }
end
end

describe "#amounts" do
it "returns all credit and debit amounts" do
equity = FactoryGirl.create(:equity)
asset = FactoryGirl.create(:asset)
expense = FactoryGirl.create(:expense)

investment = Entry.new(
description: "Initial investment",
date: Date.today,
debits: [{ account_name: equity.name, amount: 1000 }],
credits: [{ account_name: asset.name, amount: 1000 }],
)
investment.save

purchase = Entry.new(
description: "First computer",
date: Date.today,
debits: [{ account_name: asset.name, amount: 900 }],
credits: [{ account_name: expense.name, amount: 900 }],
)
purchase.save

expect(equity.amounts.size).to eq 1
expect(asset.amounts.size).to eq 2
expect(expense.amounts.size).to eq 1
end
end

describe "#entries" do
it "returns all credit and debit entries" do
equity = FactoryGirl.create(:equity)
asset = FactoryGirl.create(:asset)
expense = FactoryGirl.create(:expense)

investment = Entry.new(
description: "Initial investment",
date: Date.today,
debits: [{ account_name: equity.name, amount: 1000 }],
credits: [{ account_name: asset.name, amount: 1000 }],
)
investment.save

purchase = Entry.new(
description: "First computer",
date: Date.today,
debits: [{ account_name: asset.name, amount: 900 }],
credits: [{ account_name: expense.name, amount: 900 }],
)
purchase.save

expect(equity.entries.size).to eq 1
expect(asset.entries.size).to eq 2
expect(expense.entries.size).to eq 1
end
end

end
end
9 changes: 9 additions & 0 deletions spec/models/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ module Plutus
entry.errors['base'].should == ["The credit and debit amounts are not equal"]
end

it "should ignore debit and credit amounts marked for destruction to cancel" do
entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100, :entry => entry)
debit_amount = FactoryGirl.build(:debit_amount, :amount => 100, :entry => entry)
debit_amount.mark_for_destruction
entry.debit_amounts << debit_amount
entry.should_not be_valid
entry.errors['base'].should == ["The credit and debit amounts are not equal"]
end

it "should have a polymorphic commercial document associations" do
mock_document = FactoryGirl.create(:asset) # one would never do this, but it allows us to not require a migration for the test
entry = FactoryGirl.build(:entry_with_credit_and_debit, commercial_document: mock_document)
Expand Down

0 comments on commit c3957b9

Please sign in to comment.