plutus 0.5.2 → 0.7.0
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.
- data/README.markdown +116 -69
- data/Rakefile +7 -20
- data/app/assets/javascripts/plutus/application.js +15 -0
- data/app/assets/stylesheets/plutus/application.css +13 -0
- data/app/assets/stylesheets/plutus/main.css.scss +86 -0
- data/app/controllers/plutus/accounts_controller.rb +45 -0
- data/app/controllers/plutus/transactions_controller.rb +44 -0
- data/app/models/plutus/account.rb +60 -0
- data/app/models/plutus/amount.rb +16 -0
- data/app/models/plutus/asset.rb +83 -0
- data/app/models/plutus/credit_amount.rb +10 -0
- data/app/models/plutus/debit_amount.rb +10 -0
- data/app/models/plutus/equity.rb +84 -0
- data/app/models/plutus/expense.rb +83 -0
- data/app/models/plutus/liability.rb +78 -0
- data/app/models/plutus/revenue.rb +83 -0
- data/app/models/plutus/transaction.rb +83 -0
- data/app/views/{accounts → plutus/accounts}/index.html.erb +4 -2
- data/app/views/{accounts → plutus/accounts}/show.html.erb +8 -18
- data/app/views/plutus/transactions/index.html.erb +48 -0
- data/app/views/plutus/transactions/show.html.erb +46 -0
- data/config/database.yml +5 -0
- data/config/routes.rb +6 -0
- data/lib/generators/plutus/templates/migration.rb +17 -13
- data/lib/plutus.rb +3 -2
- data/lib/plutus/version.rb +3 -0
- data/spec/controllers/accounts_controller_spec.rb +22 -19
- data/spec/controllers/transactions_controller_spec.rb +23 -20
- data/spec/factories/account_factory.rb +30 -24
- data/spec/factories/amount_factory.rb +19 -0
- data/spec/factories/transaction_factory.rb +11 -6
- data/spec/models/account_spec.rb +61 -40
- data/spec/models/amount_spec.rb +12 -0
- data/spec/models/asset_spec.rb +46 -39
- data/spec/models/credit_amount_spec.rb +22 -0
- data/spec/models/debit_amount_spec.rb +22 -0
- data/spec/models/equity_spec.rb +51 -43
- data/spec/models/expense_spec.rb +49 -41
- data/spec/models/liability_spec.rb +48 -40
- data/spec/models/revenue_spec.rb +48 -41
- data/spec/models/transaction_spec.rb +77 -42
- data/spec/routing/accounts_routing_spec.rb +23 -20
- data/spec/routing/transactions_routing_spec.rb +23 -20
- data/spec/spec_helper.rb +3 -1
- metadata +208 -139
- data/.yardopts +0 -2
- data/VERSION.yml +0 -5
- data/app/controllers/accounts_controller.rb +0 -43
- data/app/controllers/transactions_controller.rb +0 -42
- data/app/models/account.rb +0 -57
- data/app/models/asset.rb +0 -81
- data/app/models/equity.rb +0 -82
- data/app/models/expense.rb +0 -81
- data/app/models/liability.rb +0 -76
- data/app/models/revenue.rb +0 -81
- data/app/models/transaction.rb +0 -27
- data/app/views/layouts/accounts.html.erb +0 -68
- data/app/views/layouts/transactions.html.erb +0 -68
- data/app/views/transactions/index.html.erb +0 -27
- data/app/views/transactions/show.html.erb +0 -24
- data/doc/Account.html +0 -300
- data/doc/AccountsController.html +0 -317
- data/doc/Asset.html +0 -610
- data/doc/CreatePlutusTables.html +0 -265
- data/doc/Equity.html +0 -610
- data/doc/Expense.html +0 -610
- data/doc/Liability.html +0 -588
- data/doc/Plutus.html +0 -91
- data/doc/Plutus/Engine.html +0 -100
- data/doc/PlutusGenerator.html +0 -312
- data/doc/Revenue.html +0 -610
- data/doc/Transaction.html +0 -156
- data/doc/TransactionsController.html +0 -317
- data/doc/_index.html +0 -204
- data/doc/class_list.html +0 -36
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -53
- data/doc/css/style.css +0 -310
- data/doc/file.README.html +0 -250
- data/doc/file_list.html +0 -38
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -250
- data/doc/js/app.js +0 -202
- data/doc/js/full_list.js +0 -149
- data/doc/js/jquery.js +0 -154
- data/doc/method_list.html +0 -275
- data/doc/top-level-namespace.html +0 -90
- data/fixture_rails_root/.gitignore +0 -4
- data/fixture_rails_root/Gemfile +0 -38
- data/fixture_rails_root/Gemfile.lock +0 -98
- data/fixture_rails_root/README +0 -256
- data/fixture_rails_root/Rakefile +0 -7
- data/fixture_rails_root/app/controllers/application_controller.rb +0 -3
- data/fixture_rails_root/app/helpers/application_helper.rb +0 -2
- data/fixture_rails_root/app/views/layouts/application.html.erb +0 -14
- data/fixture_rails_root/config.ru +0 -4
- data/fixture_rails_root/config/application.rb +0 -42
- data/fixture_rails_root/config/boot.rb +0 -13
- data/fixture_rails_root/config/database.yml +0 -22
- data/fixture_rails_root/config/environment.rb +0 -5
- data/fixture_rails_root/config/environments/development.rb +0 -26
- data/fixture_rails_root/config/environments/production.rb +0 -49
- data/fixture_rails_root/config/environments/test.rb +0 -35
- data/fixture_rails_root/config/initializers/backtrace_silencers.rb +0 -7
- data/fixture_rails_root/config/initializers/inflections.rb +0 -10
- data/fixture_rails_root/config/initializers/mime_types.rb +0 -5
- data/fixture_rails_root/config/initializers/secret_token.rb +0 -7
- data/fixture_rails_root/config/initializers/session_store.rb +0 -8
- data/fixture_rails_root/config/locales/en.yml +0 -5
- data/fixture_rails_root/config/routes.rb +0 -58
- data/fixture_rails_root/db/migrate/20101203193439_create_plutus_tables.rb +0 -33
- data/fixture_rails_root/db/schema.rb +0 -40
- data/fixture_rails_root/db/seeds.rb +0 -7
- data/fixture_rails_root/doc/README_FOR_APP +0 -2
- data/fixture_rails_root/lib/tasks/.gitkeep +0 -0
- data/fixture_rails_root/public/404.html +0 -26
- data/fixture_rails_root/public/422.html +0 -26
- data/fixture_rails_root/public/500.html +0 -26
- data/fixture_rails_root/public/favicon.ico +0 -0
- data/fixture_rails_root/public/images/rails.png +0 -0
- data/fixture_rails_root/public/index.html +0 -239
- data/fixture_rails_root/public/javascripts/application.js +0 -2
- data/fixture_rails_root/public/javascripts/controls.js +0 -965
- data/fixture_rails_root/public/javascripts/dragdrop.js +0 -974
- data/fixture_rails_root/public/javascripts/effects.js +0 -1123
- data/fixture_rails_root/public/javascripts/prototype.js +0 -6001
- data/fixture_rails_root/public/javascripts/rails.js +0 -175
- data/fixture_rails_root/public/robots.txt +0 -5
- data/fixture_rails_root/public/stylesheets/.gitkeep +0 -0
- data/fixture_rails_root/script/rails +0 -6
- data/fixture_rails_root/test/performance/browsing_test.rb +0 -9
- data/fixture_rails_root/test/test_helper.rb +0 -13
- data/fixture_rails_root/vendor/plugins/.gitkeep +0 -0
- data/plutus.gemspec +0 -176
- data/tasks/plutus_tasks.rake +0 -4
data/spec/models/expense_spec.rb
CHANGED
|
@@ -1,46 +1,54 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
expense
|
|
7
|
-
|
|
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
|
|
3
|
+
module Plutus
|
|
4
|
+
describe Expense do
|
|
5
|
+
|
|
6
|
+
it "should allow creating an expense account" do
|
|
7
|
+
expense = FactoryGirl.create(:expense)
|
|
8
|
+
end
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
it "should report a balance for the expense account" do
|
|
11
|
+
expense = FactoryGirl.create(:expense)
|
|
12
|
+
FactoryGirl.create(:debit_amount, :account => expense)
|
|
13
|
+
expense.balance.should > 0
|
|
14
|
+
expense.balance.should be_kind_of(BigDecimal)
|
|
15
|
+
end
|
|
37
16
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
it "should report a balance for the class of accounts" do
|
|
18
|
+
expense = FactoryGirl.create(:expense)
|
|
19
|
+
FactoryGirl.create(:debit_amount, :account => expense)
|
|
20
|
+
Expense.should respond_to(:balance)
|
|
21
|
+
Expense.balance.should > 0
|
|
22
|
+
Expense.balance.should be_kind_of(BigDecimal)
|
|
23
|
+
end
|
|
45
24
|
|
|
46
|
-
|
|
25
|
+
it "should not report a trial balance" do
|
|
26
|
+
lambda{Expense.trial_balance}.should raise_error(NoMethodError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should not be valid without a name" do
|
|
30
|
+
expense = FactoryGirl.build(:expense, :name => nil)
|
|
31
|
+
expense.should_not be_valid
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should have many credit transactions" do
|
|
35
|
+
expense = Factory(:expense)
|
|
36
|
+
expense.should respond_to(:credit_transactions)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should have many debit transactions" do
|
|
40
|
+
expense = Factory(:expense)
|
|
41
|
+
expense.should respond_to(:debit_transactions)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "a contra account should reverse the normal balance" do
|
|
45
|
+
expense = FactoryGirl.create(:expense)
|
|
46
|
+
contra_expense = Factory(:expense, :contra => true)
|
|
47
|
+
FactoryGirl.create(:debit_amount, :account => expense)
|
|
48
|
+
FactoryGirl.create(:credit_amount, :account => contra_expense)
|
|
49
|
+
contra_expense.balance.should > 0
|
|
50
|
+
Expense.balance.should == 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -1,46 +1,54 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
liability
|
|
7
|
-
|
|
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
|
|
3
|
+
module Plutus
|
|
4
|
+
describe Liability do
|
|
5
|
+
|
|
6
|
+
it "should allow creating an liability account" do
|
|
7
|
+
liability = FactoryGirl.create(:liability)
|
|
8
|
+
end
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
it "should report a balance for the liability account" do
|
|
11
|
+
liability = FactoryGirl.create(:liability)
|
|
12
|
+
FactoryGirl.create(:credit_amount, :account => liability)
|
|
13
|
+
liability.balance.should > 0
|
|
14
|
+
liability.balance.should be_kind_of(BigDecimal)
|
|
15
|
+
end
|
|
37
16
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
it "should report a balance for the class of accounts" do
|
|
18
|
+
liability = FactoryGirl.create(:liability)
|
|
19
|
+
FactoryGirl.create(:credit_amount, :account => liability)
|
|
20
|
+
Liability.should respond_to(:balance)
|
|
21
|
+
Liability.balance.should > 0
|
|
22
|
+
Liability.balance.should be_kind_of(BigDecimal)
|
|
23
|
+
end
|
|
45
24
|
|
|
25
|
+
it "should not report a trial balance" do
|
|
26
|
+
lambda{Liability.trial_balance}.should raise_error(NoMethodError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should not be valid without a name" do
|
|
30
|
+
liability = FactoryGirl.build(:liability, :name => nil)
|
|
31
|
+
liability.should_not be_valid
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should have many credit transactions" do
|
|
35
|
+
liability = Factory(:liability)
|
|
36
|
+
liability.should respond_to(:credit_transactions)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should have many debit transactions" do
|
|
40
|
+
liability = Factory(:liability)
|
|
41
|
+
liability.should respond_to(:debit_transactions)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "a contra account should reverse the normal balance" do
|
|
45
|
+
liability = FactoryGirl.create(:liability)
|
|
46
|
+
contra_liability = Factory(:liability, :contra => true)
|
|
47
|
+
FactoryGirl.create(:credit_amount, :account => liability)
|
|
48
|
+
FactoryGirl.create(:debit_amount, :account => contra_liability)
|
|
49
|
+
contra_liability.balance.should > 0
|
|
50
|
+
Liability.balance.should == 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
46
54
|
end
|
data/spec/models/revenue_spec.rb
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
revenue
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
revenue
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
3
|
+
module Plutus
|
|
4
|
+
describe Revenue do
|
|
5
|
+
|
|
6
|
+
it "should allow creating an revenue account" do
|
|
7
|
+
revenue = FactoryGirl.create(:revenue)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should report a balance for the revenue account" do
|
|
11
|
+
revenue = FactoryGirl.create(:revenue)
|
|
12
|
+
FactoryGirl.create(:credit_amount, :account => revenue)
|
|
13
|
+
revenue.balance.should > 0
|
|
14
|
+
revenue.balance.should be_kind_of(BigDecimal)
|
|
15
|
+
end
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
17
|
+
it "should report a balance for the class of accounts" do
|
|
18
|
+
revenue = FactoryGirl.create(:revenue)
|
|
19
|
+
FactoryGirl.create(:credit_amount, :account => revenue)
|
|
20
|
+
Revenue.should respond_to(:balance)
|
|
21
|
+
Revenue.balance.should > 0
|
|
22
|
+
Revenue.balance.should be_kind_of(BigDecimal)
|
|
23
|
+
end
|
|
45
24
|
|
|
25
|
+
it "should not report a trial balance" do
|
|
26
|
+
lambda{Revenue.trial_balance}.should raise_error(NoMethodError)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should not be valid without a name" do
|
|
30
|
+
revenue = FactoryGirl.build(:revenue, :name => nil)
|
|
31
|
+
revenue.should_not be_valid
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should have many credit transactions" do
|
|
35
|
+
revenue = Factory(:revenue)
|
|
36
|
+
revenue.should respond_to(:credit_transactions)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should have many debit transactions" do
|
|
40
|
+
revenue = Factory(:revenue)
|
|
41
|
+
revenue.should respond_to(:debit_transactions)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "a contra account should reverse the normal balance" do
|
|
45
|
+
contra_revenue = Factory(:revenue, :contra => true)
|
|
46
|
+
# the odd amount below is because factories create an revenue debit_amount
|
|
47
|
+
FactoryGirl.create(:debit_amount, :account => contra_revenue, :amount => 473)
|
|
48
|
+
contra_revenue.balance.should > 0
|
|
49
|
+
Revenue.balance.should == 0
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
46
53
|
end
|
|
@@ -1,48 +1,83 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module Plutus
|
|
4
|
+
describe Transaction do
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
it "should create a transaction" do
|
|
7
|
+
transaction = FactoryGirl.build(:transaction_with_credit_and_debit)
|
|
8
|
+
transaction.save!
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should not be valid without a credit amount" do
|
|
12
|
+
transaction = FactoryGirl.build(:transaction)
|
|
13
|
+
transaction.debit_amounts << FactoryGirl.build(:debit_amount, :transaction => transaction)
|
|
14
|
+
transaction.should_not be_valid
|
|
15
|
+
transaction.errors['base'].should include("Transaction must have at least one credit amount")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should not be valid with an invalid credit amount" do
|
|
19
|
+
transaction = FactoryGirl.build(:transaction)
|
|
20
|
+
transaction.debit_amounts << FactoryGirl.build(:debit_amount, :transaction => transaction)
|
|
21
|
+
transaction.credit_amounts << FactoryGirl.build(:credit_amount, :transaction => transaction, :amount => nil)
|
|
22
|
+
transaction.should_not be_valid
|
|
23
|
+
transaction.errors[:credit_amounts].should == ["is invalid"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should not be valid without a debit amount" do
|
|
27
|
+
transaction = FactoryGirl.build(:transaction)
|
|
28
|
+
transaction.credit_amounts << FactoryGirl.build(:credit_amount, :transaction => transaction)
|
|
29
|
+
transaction.should_not be_valid
|
|
30
|
+
transaction.errors['base'].should include("Transaction must have at least one debit amount")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should not be valid with an invalid debit amount" do
|
|
34
|
+
transaction = FactoryGirl.build(:transaction)
|
|
35
|
+
transaction.credit_amounts << FactoryGirl.build(:credit_amount, :transaction => transaction)
|
|
36
|
+
transaction.debit_amounts << FactoryGirl.build(:debit_amount, :transaction => transaction, :amount => nil)
|
|
37
|
+
transaction.should_not be_valid
|
|
38
|
+
transaction.errors[:debit_amounts].should == ["is invalid"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should not be valid without a description" do
|
|
42
|
+
transaction = FactoryGirl.build(:transaction_with_credit_and_debit, :description => nil)
|
|
43
|
+
transaction.should_not be_valid
|
|
44
|
+
transaction.errors[:description].should == ["can't be blank"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should require the debit and credit amounts to cancel" do
|
|
48
|
+
transaction = FactoryGirl.build(:transaction)
|
|
49
|
+
transaction.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100, :transaction => transaction)
|
|
50
|
+
transaction.debit_amounts << FactoryGirl.build(:debit_amount, :amount => 200, :transaction => transaction)
|
|
51
|
+
transaction.should_not be_valid
|
|
52
|
+
transaction.errors['base'].should == ["The credit and debit amounts are not equal"]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should have a polymorphic commercial document associations" do
|
|
56
|
+
mock_document = FactoryGirl.create(:asset) # one would never do this, but it allows us to not require a migration for the test
|
|
57
|
+
transaction = FactoryGirl.build(:transaction_with_credit_and_debit, :commercial_document => mock_document)
|
|
58
|
+
transaction.save
|
|
59
|
+
saved_transaction = Transaction.find(transaction.id)
|
|
60
|
+
saved_transaction.commercial_document.should == mock_document
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should allow building a transaction and credit and debits with a hash" do
|
|
64
|
+
FactoryGirl.create(:asset, :name => "Accounts Receivable")
|
|
65
|
+
FactoryGirl.create(:revenue, :name => "Sales Revenue")
|
|
66
|
+
FactoryGirl.create(:liability, :name => "Sales Tax Payable")
|
|
67
|
+
mock_document = FactoryGirl.create(:asset)
|
|
68
|
+
transaction = Transaction.build(
|
|
69
|
+
description: "Sold some widgets",
|
|
70
|
+
commercial_document: mock_document,
|
|
71
|
+
debits: [
|
|
72
|
+
{account: "Accounts Receivable", amount: 50}],
|
|
73
|
+
credits: [
|
|
74
|
+
{account: "Sales Revenue", amount: 45},
|
|
75
|
+
{account: "Sales Tax Payable", amount: 5}])
|
|
76
|
+
transaction.should be_valid
|
|
77
|
+
transaction.save
|
|
78
|
+
saved_transaction = Transaction.find(transaction.id)
|
|
79
|
+
saved_transaction.commercial_document.should == mock_document
|
|
80
|
+
end
|
|
35
81
|
|
|
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
82
|
end
|
|
47
|
-
|
|
48
83
|
end
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
describe
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module Plutus
|
|
4
|
+
describe AccountsController do
|
|
5
|
+
# Run these tests if you enable routing in your rails app. See README
|
|
6
|
+
#describe "routing" do
|
|
7
|
+
#it "recognizes and generates #index" do
|
|
8
|
+
#{ :get => "/accounts" }.should route_to(:controller => "accounts", :action => "index")
|
|
9
|
+
#end
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
#it "recognizes and generates #show" do
|
|
12
|
+
#{ :get => "/accounts/1" }.should route_to(:controller => "accounts", :action => "show", :id => "1")
|
|
13
|
+
#end
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
#it "recognizes and generates #edit" do
|
|
16
|
+
#{ :get => "/accounts/1/edit" }.should_not be_routable
|
|
17
|
+
#end
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
#it "recognizes and generates #create" do
|
|
20
|
+
#{ :post => "/accounts" }.should_not be_routable
|
|
21
|
+
#end
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
#it "recognizes and generates #update" do
|
|
24
|
+
#{ :put => "/accounts/1" }.should_not be_routable
|
|
25
|
+
#end
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
#it "recognizes and generates #destroy" do
|
|
28
|
+
#{ :delete => "/accounts/1" }.should_not be_routable
|
|
29
|
+
#end
|
|
30
|
+
#end
|
|
28
31
|
end
|
|
29
32
|
end
|