plutus 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.yardopts +2 -0
  2. data/LICENSE +23 -0
  3. data/README.markdown +194 -0
  4. data/Rakefile +24 -0
  5. data/VERSION.yml +5 -0
  6. data/app/controllers/accounts_controller.rb +43 -0
  7. data/app/controllers/transactions_controller.rb +42 -0
  8. data/app/models/account.rb +57 -0
  9. data/app/models/asset.rb +81 -0
  10. data/app/models/equity.rb +82 -0
  11. data/app/models/expense.rb +81 -0
  12. data/app/models/liability.rb +76 -0
  13. data/app/models/revenue.rb +81 -0
  14. data/app/models/transaction.rb +27 -0
  15. data/app/views/accounts/index.html.erb +27 -0
  16. data/app/views/accounts/show.html.erb +69 -0
  17. data/app/views/layouts/accounts.html.erb +68 -0
  18. data/app/views/layouts/transactions.html.erb +68 -0
  19. data/app/views/transactions/index.html.erb +27 -0
  20. data/app/views/transactions/show.html.erb +24 -0
  21. data/doc/Account.html +300 -0
  22. data/doc/AccountsController.html +317 -0
  23. data/doc/Asset.html +610 -0
  24. data/doc/Equity.html +610 -0
  25. data/doc/Expense.html +610 -0
  26. data/doc/Liability.html +588 -0
  27. data/doc/Revenue.html +610 -0
  28. data/doc/Transaction.html +156 -0
  29. data/doc/TransactionsController.html +317 -0
  30. data/doc/_index.html +166 -0
  31. data/doc/class_list.html +36 -0
  32. data/doc/css/common.css +1 -0
  33. data/doc/css/full_list.css +53 -0
  34. data/doc/css/style.css +310 -0
  35. data/doc/file.README.html +250 -0
  36. data/doc/file_list.html +38 -0
  37. data/doc/frames.html +13 -0
  38. data/doc/index.html +250 -0
  39. data/doc/js/app.js +202 -0
  40. data/doc/js/full_list.js +149 -0
  41. data/doc/js/jquery.js +154 -0
  42. data/doc/method_list.html +235 -0
  43. data/doc/top-level-namespace.html +88 -0
  44. data/generators/plutus/USAGE +11 -0
  45. data/generators/plutus/plutus_generator.rb +9 -0
  46. data/generators/plutus/templates/plutus.rb +33 -0
  47. data/lib/plutus.rb +1 -0
  48. data/plutus.gemspec +122 -0
  49. data/rails/init.rb +1 -0
  50. data/spec/controllers/accounts_controller_spec.rb +25 -0
  51. data/spec/controllers/transactions_controller_spec.rb +25 -0
  52. data/spec/factories/account_factory.rb +29 -0
  53. data/spec/factories/transaction_factory.rb +6 -0
  54. data/spec/lib/plutus_spec.rb +0 -0
  55. data/spec/models/account_spec.rb +43 -0
  56. data/spec/models/asset_spec.rb +46 -0
  57. data/spec/models/equity_spec.rb +46 -0
  58. data/spec/models/expense_spec.rb +46 -0
  59. data/spec/models/liability_spec.rb +46 -0
  60. data/spec/models/revenue_spec.rb +46 -0
  61. data/spec/models/transaction_spec.rb +48 -0
  62. data/spec/rcov.opts +2 -0
  63. data/spec/routing/accounts_routing_spec.rb +29 -0
  64. data/spec/routing/transactions_routing_spec.rb +29 -0
  65. data/spec/schema.rb +31 -0
  66. data/spec/spec.opts +4 -0
  67. data/spec/spec_helper.rb +57 -0
  68. data/tasks/plutus_tasks.rake +4 -0
  69. metadata +150 -0
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'plutus'
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe AccountsController do
4
+
5
+ def mock_account(stubs={})
6
+ @mock_account ||= mock_model(Account, stubs)
7
+ end
8
+
9
+ describe "GET index" do
10
+ it "assigns all accounts as @accounts" do
11
+ Account.stub(:find).with(:all).and_return([mock_account])
12
+ get :index
13
+ assigns[:accounts].should == [mock_account]
14
+ end
15
+ end
16
+
17
+ describe "GET show" do
18
+ it "assigns the requested account as @account" do
19
+ Account.stub(:find).with("37").and_return(mock_account)
20
+ get :show, :id => "37"
21
+ assigns[:account].should equal(mock_account)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe TransactionsController do
4
+
5
+ def mock_transaction(stubs={})
6
+ @mock_transaction ||= mock_model(Transaction, stubs)
7
+ end
8
+
9
+ describe "GET index" do
10
+ it "assigns all transactions as @transactions" do
11
+ Transaction.stub(:find).with(:all).and_return([mock_transaction])
12
+ get :index
13
+ assigns[:transactions].should == [mock_transaction]
14
+ end
15
+ end
16
+
17
+ describe "GET show" do
18
+ it "assigns the requested transaction as @transaction" do
19
+ Transaction.stub(:find).with("37").and_return(mock_transaction)
20
+ get :show, :id => "37"
21
+ assigns[:transaction].should equal(mock_transaction)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,29 @@
1
+ Factory.define :account do |account|
2
+ account.name 'factory name'
3
+ account.contra false
4
+ end
5
+
6
+ Factory.define :asset do |account|
7
+ account.name 'factory name'
8
+ account.contra false
9
+ end
10
+
11
+ Factory.define :equity do |account|
12
+ account.name 'factory name'
13
+ account.contra false
14
+ end
15
+
16
+ Factory.define :expense do |account|
17
+ account.name 'factory name'
18
+ account.contra false
19
+ end
20
+
21
+ Factory.define :liability do |account|
22
+ account.name 'factory name'
23
+ account.contra false
24
+ end
25
+
26
+ Factory.define :revenue do |account|
27
+ account.name 'factory name'
28
+ account.contra false
29
+ end
@@ -0,0 +1,6 @@
1
+ Factory.define :transaction do |transaction|
2
+ transaction.description 'factory description'
3
+ transaction.credit_account {|credit_account| credit_account.association(:asset)}
4
+ transaction.debit_account {|debit_account| debit_account.association(:revenue)}
5
+ transaction.amount BigDecimal.new('100')
6
+ end
File without changes
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Account do
4
+
5
+ it "should not allow creating an account without a subtype" do
6
+ account = Factory.build(:account)
7
+ account.should_not be_valid
8
+ end
9
+
10
+ it "should not have a balance method" do
11
+ lambda{Account.balance}.should raise_error(NoMethodError)
12
+ end
13
+
14
+ it "should have a trial balance" do
15
+ Account.should respond_to(:trial_balance)
16
+ Account.trial_balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should report a trial balance of 0 with correct transactions" do
20
+ # credit accounts
21
+ liability = Factory(:liability)
22
+ equity = Factory(:equity)
23
+ revenue = Factory(:revenue)
24
+ contra_asset = Factory(:asset, :contra => true)
25
+ contra_expense = Factory(:expense, :contra => true)
26
+
27
+ # debit accounts
28
+ asset = Factory(:asset)
29
+ expense = Factory(:expense)
30
+ contra_liability = Factory(:liability, :contra => true)
31
+ contra_equity = Factory(:equity, :contra => true)
32
+ contra_revenue = Factory(:revenue, :contra => true)
33
+
34
+ Factory(:transaction, :credit_account => liability, :debit_account => asset, :amount => 100000)
35
+ Factory(:transaction, :credit_account => equity, :debit_account => expense, :amount => 1000)
36
+ Factory(:transaction, :credit_account => revenue, :debit_account => contra_liability, :amount => 40404)
37
+ Factory(:transaction, :credit_account => contra_asset, :debit_account => contra_equity, :amount => 2)
38
+ Factory(:transaction, :credit_account => contra_expense, :debit_account => contra_revenue, :amount => 333)
39
+
40
+ Account.trial_balance.should == 0
41
+ end
42
+
43
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Asset do
4
+
5
+ it "should allow creating an asset account" do
6
+ asset = Factory(:asset)
7
+ end
8
+
9
+ it "should report a balance for the asset account" do
10
+ asset = Factory(:asset)
11
+ asset.balance.should be_kind_of(BigDecimal)
12
+ end
13
+
14
+ it "should report a balance for the class of accounts" do
15
+ Asset.should respond_to(:balance)
16
+ Asset.balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should not report a trial balance" do
20
+ lambda{Asset.trial_balance}.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should not be valid without a name" do
24
+ asset = Factory.build(:asset, :name => nil)
25
+ asset.should_not be_valid
26
+ end
27
+
28
+ it "should have many credit transactions" do
29
+ asset = Factory(:asset)
30
+ asset.should respond_to(:credit_transactions)
31
+ end
32
+
33
+ it "should have many debit transactions" do
34
+ asset = Factory(:asset)
35
+ asset.should respond_to(:debit_transactions)
36
+ end
37
+
38
+ it "a contra account should reverse the normal balance" do
39
+ asset = Factory(:asset)
40
+ contra_asset = Factory(:asset, :contra => true)
41
+ transaction = Factory(:transaction, :credit_account => contra_asset, :debit_account => asset, :amount => 1000)
42
+ contra_asset.balance.should > 0
43
+ Asset.balance.should == 0
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Equity do
4
+
5
+ it "should allow creating a equity account" do
6
+ equity = Factory(:equity)
7
+ end
8
+
9
+ it "should report a balance for the equity account" do
10
+ equity = Factory(:equity)
11
+ equity.balance.should be_kind_of(BigDecimal)
12
+ end
13
+
14
+ it "should report a balance for the class of accounts" do
15
+ Equity.should respond_to(:balance)
16
+ Equity.balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should not report a trial balance" do
20
+ lambda{Equity.trial_balance}.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should not be valid without a name" do
24
+ equity = Factory.build(:equity, :name => nil)
25
+ equity.should_not be_valid
26
+ end
27
+
28
+ it "should have many credit transactions" do
29
+ equity = Factory(:equity)
30
+ equity.should respond_to(:credit_transactions)
31
+ end
32
+
33
+ it "should have many debit transactions" do
34
+ equity = Factory(:equity)
35
+ equity.should respond_to(:debit_transactions)
36
+ end
37
+
38
+ it "a contra account should reverse the normal balance" do
39
+ equity = Factory(:equity)
40
+ contra_equity = Factory(:equity, :contra => true)
41
+ transaction = Factory(:transaction, :credit_account => equity, :debit_account => contra_equity, :amount => 1000)
42
+ contra_equity.balance.should > 0
43
+ Equity.balance.should == 0
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Expense do
4
+
5
+ it "should allow creating an expense account" do
6
+ expense = Factory(:expense)
7
+ end
8
+
9
+ it "should report a balance for the expense account" do
10
+ expense = Factory(:expense)
11
+ expense.balance.should be_kind_of(BigDecimal)
12
+ end
13
+
14
+ it "should report a balance for the class of accounts" do
15
+ Expense.should respond_to(:balance)
16
+ Expense.balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should not report a trial balance" do
20
+ lambda{Expense.trial_balance}.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should not be valid without a name" do
24
+ expense = Factory.build(:expense, :name => nil)
25
+ expense.should_not be_valid
26
+ end
27
+
28
+ it "should have many credit transactions" do
29
+ expense = Factory(:expense)
30
+ expense.should respond_to(:credit_transactions)
31
+ end
32
+
33
+ it "should have many debit transactions" do
34
+ expense = Factory(:expense)
35
+ expense.should respond_to(:debit_transactions)
36
+ end
37
+
38
+ it "a contra account should reverse the normal balance" do
39
+ expense = Factory(:expense)
40
+ contra_expense = Factory(:expense, :contra => true)
41
+ transaction = Factory(:transaction, :credit_account => contra_expense, :debit_account => expense, :amount => 1000)
42
+ contra_expense.balance.should > 0
43
+ Expense.balance.should == 0
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liability do
4
+
5
+ it "should allow creating a liability account" do
6
+ liability = Factory(:liability)
7
+ end
8
+
9
+ it "should report a balance for the liability account" do
10
+ liability = Factory(:liability)
11
+ liability.balance.should be_kind_of(BigDecimal)
12
+ end
13
+
14
+ it "should report a balance for the class of accounts" do
15
+ Liability.should respond_to(:balance)
16
+ Liability.balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should not report a trial balance" do
20
+ lambda{Liability.trial_balance}.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should not be valid without a name" do
24
+ liability = Factory.build(:liability, :name => nil)
25
+ liability.should_not be_valid
26
+ end
27
+
28
+ it "should have many credit transactions" do
29
+ liability = Factory(:liability)
30
+ liability.should respond_to(:credit_transactions)
31
+ end
32
+
33
+ it "should have many debit transactions" do
34
+ liability = Factory(:liability)
35
+ liability.should respond_to(:debit_transactions)
36
+ end
37
+
38
+ it "a contra account should reverse the normal balance" do
39
+ liability = Factory(:liability)
40
+ contra_liability = Factory(:liability, :contra => true)
41
+ transaction = Factory(:transaction, :credit_account => liability, :debit_account => contra_liability, :amount => 1000)
42
+ contra_liability.balance.should > 0
43
+ Liability.balance.should == 0
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Revenue do
4
+
5
+ it "should allow creating a revenue account" do
6
+ revenue = Factory(:revenue)
7
+ end
8
+
9
+ it "should report a balance for the revenue account" do
10
+ revenue = Factory(:revenue)
11
+ revenue.balance.should be_kind_of(BigDecimal)
12
+ end
13
+
14
+ it "should report a balance for the class of accounts" do
15
+ Revenue.should respond_to(:balance)
16
+ Revenue.balance.should be_kind_of(BigDecimal)
17
+ end
18
+
19
+ it "should not report a trial balance" do
20
+ lambda{Revenue.trial_balance}.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should not be valid without a name" do
24
+ revenue = Factory.build(:revenue, :name => nil)
25
+ revenue.should_not be_valid
26
+ end
27
+
28
+ it "should have many credit transactions" do
29
+ revenue = Factory(:revenue)
30
+ revenue.should respond_to(:credit_transactions)
31
+ end
32
+
33
+ it "should have many debit transactions" do
34
+ revenue = Factory(:revenue)
35
+ revenue.should respond_to(:debit_transactions)
36
+ end
37
+
38
+ it "a contra account should reverse the normal balance" do
39
+ revenue = Factory(:revenue)
40
+ contra_revenue = Factory(:revenue, :contra => true)
41
+ transaction = Factory(:transaction, :credit_account => revenue, :debit_account => contra_revenue, :amount => 1000)
42
+ contra_revenue.balance.should > 0
43
+ Revenue.balance.should == 0
44
+ end
45
+
46
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transaction do
4
+
5
+ it "should create a transaction" do
6
+ transaction = Factory(:transaction)
7
+ end
8
+
9
+ it "should not be valid without a credit account" do
10
+ transaction = Factory.build(:transaction, :credit_account => nil)
11
+ transaction.should_not be_valid
12
+ end
13
+
14
+ it "should not be valid without a valid credit account" do
15
+ bad_account = Factory.build(:asset, :name => nil)
16
+ transaction = Factory.build(:transaction, :credit_account => bad_account)
17
+ transaction.should_not be_valid
18
+ end
19
+
20
+ it "should not be valid without a debit account" do
21
+ transaction = Factory.build(:transaction, :debit_account => nil)
22
+ transaction.should_not be_valid
23
+ end
24
+
25
+ it "should not be valid without a valid credit account" do
26
+ bad_account = Factory.build(:asset, :name => nil)
27
+ transaction = Factory.build(:transaction, :debit_account => bad_account)
28
+ transaction.should_not be_valid
29
+ end
30
+
31
+ it "should not be valid without an amount" do
32
+ transaction = Factory.build(:transaction, :amount => nil)
33
+ transaction.should_not be_valid
34
+ end
35
+
36
+ it "should not be valid without a description" do
37
+ transaction = Factory.build(:transaction, :description => nil)
38
+ transaction.should_not be_valid
39
+ end
40
+
41
+ it "should have a polymorphic commercial document associations" do
42
+ mock_document = Factory(:transaction) # one would never do this, but it allows us to not require a migration for the test
43
+ transaction = Factory(:transaction, :commercial_document => mock_document)
44
+ saved_transaction = Transaction.find(transaction.id)
45
+ saved_transaction.commercial_document.should == mock_document
46
+ end
47
+
48
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe AccountsController do
4
+ describe "routing" do
5
+ it "recognizes and generates #index" do
6
+ { :get => "/accounts" }.should route_to(:controller => "accounts", :action => "index")
7
+ end
8
+
9
+ it "recognizes and generates #show" do
10
+ { :get => "/accounts/1" }.should route_to(:controller => "accounts", :action => "show", :id => "1")
11
+ end
12
+
13
+ it "recognizes and generates #edit" do
14
+ { :get => "/accounts/1/edit" }.should_not be_routable
15
+ end
16
+
17
+ it "recognizes and generates #create" do
18
+ { :post => "/accounts" }.should_not be_routable
19
+ end
20
+
21
+ it "recognizes and generates #update" do
22
+ { :put => "/accounts/1" }.should_not be_routable
23
+ end
24
+
25
+ it "recognizes and generates #destroy" do
26
+ { :delete => "/accounts/1" }.should_not be_routable
27
+ end
28
+ end
29
+ end