plutus 0.8.1 → 0.9.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +64 -41
  3. data/app/controllers/plutus/entries_controller.rb +44 -0
  4. data/app/models/plutus/account.rb +2 -2
  5. data/app/models/plutus/amount.rb +2 -2
  6. data/app/models/plutus/credit_amount.rb +2 -2
  7. data/app/models/plutus/debit_amount.rb +2 -2
  8. data/app/models/plutus/{transaction.rb → entry.rb} +16 -16
  9. data/app/views/plutus/accounts/index.html.erb +1 -1
  10. data/app/views/plutus/accounts/show.html.erb +8 -8
  11. data/app/views/plutus/{transactions → entries}/index.html.erb +8 -8
  12. data/app/views/plutus/{transactions → entries}/show.html.erb +6 -6
  13. data/config/routes.rb +1 -1
  14. data/lib/generators/plutus/USAGE +14 -3
  15. data/lib/generators/plutus/templates/migration.rb +6 -6
  16. data/lib/generators/plutus/templates/update_migration.rb +17 -0
  17. data/lib/generators/plutus/upgrade_plutus_generator.rb +28 -0
  18. data/lib/plutus/version.rb +1 -1
  19. data/spec/controllers/entries_controller_spec.rb +28 -0
  20. data/spec/factories/amount_factory.rb +3 -3
  21. data/spec/factories/entry_factory.rb +11 -0
  22. data/spec/models/account_spec.rb +7 -7
  23. data/spec/models/entry_spec.rb +91 -0
  24. data/spec/routing/{transactions_routing_spec.rb → entries_routing_spec.rb} +7 -7
  25. data/spec/support/account_shared_examples.rb +2 -2
  26. data/spec/support/amount_shared_examples.rb +2 -2
  27. metadata +17 -100
  28. data/app/assets/stylesheets/plutus/main.css.scss +0 -86
  29. data/app/controllers/plutus/transactions_controller.rb +0 -44
  30. data/spec/controllers/transactions_controller_spec.rb +0 -28
  31. data/spec/factories/transaction_factory.rb +0 -11
  32. data/spec/models/transaction_spec.rb +0 -91
@@ -1,5 +1,5 @@
1
1
  <div class="plutus_container">
2
- <h1>Transactions</h1>
2
+ <h1>Entries</h1>
3
3
 
4
4
  <table cellspacing="0">
5
5
  <thead>
@@ -12,15 +12,15 @@
12
12
  </tr>
13
13
  </thead>
14
14
  <tbody>
15
- <% @transactions.each do |transaction| %>
15
+ <% @entries.each do |entry| %>
16
16
  <tr class="<%= cycle("even", "odd") -%>">
17
- <td><%=link_to(transaction.id, transaction_path(transaction)) %></td>
18
- <td><%=h transaction.description %></td>
17
+ <td><%=link_to(entry.id, entry_path(entry)) %></td>
18
+ <td><%=h entry.description %></td>
19
19
  <td></td>
20
20
  <td></td>
21
- <td><%=h transaction.created_at %></td>
21
+ <td><%=h entry.created_at %></td>
22
22
  </tr>
23
- <% transaction.debit_amounts.each do |debit_amount| %>
23
+ <% entry.debit_amounts.each do |debit_amount| %>
24
24
  <tr class="<%= cycle("odd", "odd") -%>">
25
25
  <td></td>
26
26
  <td>&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{debit_amount.account.name}" %></td>
@@ -29,7 +29,7 @@
29
29
  <td></td>
30
30
  </tr>
31
31
  <% end %>
32
- <% transaction.credit_amounts.each do |credit_amount| %>
32
+ <% entry.credit_amounts.each do |credit_amount| %>
33
33
  <tr class="<%= cycle("odd", "odd") -%>">
34
34
  <td></td>
35
35
  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{credit_amount.account.name}" %></td>
@@ -45,4 +45,4 @@
45
45
  <br />
46
46
 
47
47
  <h3>Go to <%= link_to 'Accounts', accounts_path %></h3>
48
- </div>
48
+ </div>
@@ -1,5 +1,5 @@
1
1
  <div class="plutus_container">
2
- <h1><%=h @transaction.description %> Transaction</h1>
2
+ <h1><%=h @entry.description %> Entry</h1>
3
3
 
4
4
  <table cellspacing="0">
5
5
  <thead>
@@ -13,13 +13,13 @@
13
13
  </thead>
14
14
  <tbody>
15
15
  <tr class="<%= cycle("even", "odd") -%>">
16
- <td><%=link_to(@transaction.id, transaction_path(@transaction)) %></td>
17
- <td><%=h @transaction.description %></td>
16
+ <td><%=link_to(@entry.id, entry_path(@entry)) %></td>
17
+ <td><%=h @entry.description %></td>
18
18
  <td></td>
19
19
  <td></td>
20
- <td><%=h @transaction.created_at %></td>
20
+ <td><%=h @entry.created_at %></td>
21
21
  </tr>
22
- <% @transaction.debit_amounts.each do |debit_amount| %>
22
+ <% @entry.debit_amounts.each do |debit_amount| %>
23
23
  <tr class="<%= cycle("odd", "odd") -%>">
24
24
  <td></td>
25
25
  <td>&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{debit_amount.account.name}" %></td>
@@ -28,7 +28,7 @@
28
28
  <td></td>
29
29
  </tr>
30
30
  <% end %>
31
- <% @transaction.credit_amounts.each do |credit_amount| %>
31
+ <% @entry.credit_amounts.each do |credit_amount| %>
32
32
  <tr class="<%= cycle("odd", "odd") -%>">
33
33
  <td></td>
34
34
  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=h "#{credit_amount.account.name}" %></td>
data/config/routes.rb CHANGED
@@ -2,5 +2,5 @@ Plutus::Engine.routes.draw do
2
2
  root :to => "accounts#index"
3
3
 
4
4
  resources :accounts
5
- resources :transactions
5
+ resources :entries
6
6
  end
@@ -1,11 +1,22 @@
1
1
  Description:
2
2
  Generator for Plutus Plugin
3
3
 
4
- Example:
4
+ Installation:
5
5
  rails g plutus
6
6
 
7
- This will create:
8
- Create a migration in the application for the "Account" and Transaction" tables.
7
+ This will:
8
+ Create a migration in the application for the "Account",
9
+ "Entry" and "Amount" tables.
10
+
11
+ Once generated, simply run:
12
+ rake db:migrate
13
+
14
+ Upgrade < 0.8 -> 0.9+:
15
+ rails g plutus:upgrade_plutus
16
+
17
+ This will:
18
+ Create a migration in the application for renaming the
19
+ "Transaction" table, columns and indexes to "Entry" tables.
9
20
 
10
21
  Once generated, simply run:
11
22
  rake db:migrate
@@ -9,29 +9,29 @@ class CreatePlutusTables < ActiveRecord::Migration
9
9
  end
10
10
  add_index :plutus_accounts, [:name, :type]
11
11
 
12
- create_table :plutus_transactions do |t|
12
+ create_table :plutus_entries do |t|
13
13
  t.string :description
14
14
  t.integer :commercial_document_id
15
15
  t.string :commercial_document_type
16
16
 
17
17
  t.timestamps
18
18
  end
19
- add_index :plutus_transactions, [:commercial_document_id, :commercial_document_type], :name => "index_transactions_on_commercial_doc"
19
+ add_index :plutus_entries, [:commercial_document_id, :commercial_document_type], :name => "index_entries_on_commercial_doc"
20
20
 
21
21
  create_table :plutus_amounts do |t|
22
22
  t.string :type
23
23
  t.references :account
24
- t.references :transaction
24
+ t.references :entry
25
25
  t.decimal :amount, :precision => 20, :scale => 10
26
26
  end
27
27
  add_index :plutus_amounts, :type
28
- add_index :plutus_amounts, [:account_id, :transaction_id]
29
- add_index :plutus_amounts, [:transaction_id, :account_id]
28
+ add_index :plutus_amounts, [:account_id, :entry_id]
29
+ add_index :plutus_amounts, [:entry_id, :account_id]
30
30
  end
31
31
 
32
32
  def self.down
33
33
  drop_table :plutus_accounts
34
- drop_table :plutus_transactions
34
+ drop_table :plutus_entries
35
35
  drop_table :plutus_amounts
36
36
  end
37
37
  end
@@ -0,0 +1,17 @@
1
+ class UpdatePlutusTables < ActiveRecord::Migration
2
+ def change
3
+ # we have to remove these indexes because the temporary
4
+ # table index name is too long
5
+ remove_index :plutus_amounts, [:account_id, :transaction_id]
6
+ remove_index :plutus_amounts, [:transaction_id, :account_id]
7
+ remove_index :plutus_transactions, column: [:commercial_document_id, :commercial_document_type], :name => "index_transactions_on_commercial_doc"
8
+
9
+ rename_table :plutus_transactions, :plutus_entries
10
+ rename_column :plutus_amounts, :transaction_id, :entry_id
11
+
12
+ # adding the indexes back
13
+ add_index :plutus_amounts, [:account_id, :entry_id]
14
+ add_index :plutus_amounts, [:entry_id, :account_id]
15
+ add_index :plutus_entries, [:commercial_document_id, :commercial_document_type], :name => "index_entries_on_commercial_doc"
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # lib/generators/plutus/plutus_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ module Plutus
6
+ class UpgradePlutusGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ def self.source_root
10
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
11
+ end
12
+
13
+ # Implement the required interface for Rails::Generators::Migration.
14
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
15
+ def self.next_migration_number(dirname)
16
+ if ActiveRecord::Base.timestamped_migrations
17
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
18
+ else
19
+ "%.3d" % (current_migration_number(dirname) + 1)
20
+ end
21
+ end
22
+
23
+ def create_migration_file
24
+ migration_template 'update_migration.rb', 'db/migrate/update_plutus_tables.rb'
25
+ end
26
+
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Plutus
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Plutus
4
+ describe EntriesController do
5
+ # Run these tests if you enable routing in your rails app. See README
6
+
7
+ #def mock_entry(stubs={})
8
+ #@mock_entry ||= mock_model(Entry, stubs)
9
+ #end
10
+
11
+ #describe "GET index" do
12
+ #it "assigns all entries as @entries" do
13
+ #Entry.stub(:find).with(:all).and_return([mock_entry])
14
+ #get :index
15
+ #assigns[:entries].should == [mock_entry]
16
+ #end
17
+ #end
18
+
19
+ #describe "GET show" do
20
+ #it "assigns the requested entry as @entry" do
21
+ #Entry.stub(:find).with("37").and_return(mock_entry)
22
+ #get :show, :id => "37"
23
+ #assigns[:entry].should equal(mock_entry)
24
+ #end
25
+ #end
26
+
27
+ end
28
+ end
@@ -1,19 +1,19 @@
1
1
  FactoryGirl.define do
2
2
  factory :amount, :class => Plutus::Amount do |amount|
3
3
  amount.amount BigDecimal.new('473')
4
- amount.association :transaction, :factory => :transaction_with_credit_and_debit
4
+ amount.association :entry, :factory => :entry_with_credit_and_debit
5
5
  amount.association :account, :factory => :asset
6
6
  end
7
7
 
8
8
  factory :credit_amount, :class => Plutus::CreditAmount do |credit_amount|
9
9
  credit_amount.amount BigDecimal.new('473')
10
- credit_amount.association :transaction, :factory => :transaction_with_credit_and_debit
10
+ credit_amount.association :entry, :factory => :entry_with_credit_and_debit
11
11
  credit_amount.association :account, :factory => :revenue
12
12
  end
13
13
 
14
14
  factory :debit_amount, :class => Plutus::DebitAmount do |debit_amount|
15
15
  debit_amount.amount BigDecimal.new('473')
16
- debit_amount.association :transaction, :factory => :transaction_with_credit_and_debit
16
+ debit_amount.association :entry, :factory => :entry_with_credit_and_debit
17
17
  debit_amount.association :account, :factory => :asset
18
18
  end
19
19
  end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :entry, :class => Plutus::Entry do |entry|
3
+ entry.description 'factory description'
4
+ factory :entry_with_credit_and_debit, :class => Plutus::Entry do |entry_cd|
5
+ entry_cd.after_build do |t|
6
+ t.credit_amounts << FactoryGirl.build(:credit_amount, :entry => t)
7
+ t.debit_amounts << FactoryGirl.build(:debit_amount, :entry => t)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -24,11 +24,11 @@ module Plutus
24
24
  subject { Account.trial_balance }
25
25
  it { should be_kind_of BigDecimal }
26
26
 
27
- context "when given no transactions" do
27
+ context "when given no entries" do
28
28
  it { should == 0 }
29
29
  end
30
30
 
31
- context "when given correct transactions" do
31
+ context "when given correct entries" do
32
32
  before {
33
33
  # credit accounts
34
34
  liability = FactoryGirl.create(:liability)
@@ -56,11 +56,11 @@ module Plutus
56
56
  da4 = FactoryGirl.build(:debit_amount, :account => contra_equity, :amount => 2)
57
57
  da5 = FactoryGirl.build(:debit_amount, :account => contra_revenue, :amount => 333)
58
58
 
59
- FactoryGirl.create(:transaction, :credit_amounts => [ca1], :debit_amounts => [da1])
60
- FactoryGirl.create(:transaction, :credit_amounts => [ca2], :debit_amounts => [da2])
61
- FactoryGirl.create(:transaction, :credit_amounts => [ca3], :debit_amounts => [da3])
62
- FactoryGirl.create(:transaction, :credit_amounts => [ca4], :debit_amounts => [da4])
63
- FactoryGirl.create(:transaction, :credit_amounts => [ca5], :debit_amounts => [da5])
59
+ FactoryGirl.create(:entry, :credit_amounts => [ca1], :debit_amounts => [da1])
60
+ FactoryGirl.create(:entry, :credit_amounts => [ca2], :debit_amounts => [da2])
61
+ FactoryGirl.create(:entry, :credit_amounts => [ca3], :debit_amounts => [da3])
62
+ FactoryGirl.create(:entry, :credit_amounts => [ca4], :debit_amounts => [da4])
63
+ FactoryGirl.create(:entry, :credit_amounts => [ca5], :debit_amounts => [da5])
64
64
  }
65
65
 
66
66
  it { should == 0 }
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ module Plutus
4
+ describe Entry do
5
+ let(:entry) { FactoryGirl.build(:entry) }
6
+ subject { entry }
7
+
8
+ it { should_not be_valid }
9
+
10
+ context "with credit and debit" do
11
+ let(:entry) { FactoryGirl.build(:entry_with_credit_and_debit) }
12
+ it { should be_valid }
13
+
14
+ it "should require a description" do
15
+ entry.description = nil
16
+ entry.should_not be_valid
17
+ end
18
+ end
19
+
20
+ context "with a debit" do
21
+ before {
22
+ entry.debit_amounts << FactoryGirl.build(:debit_amount, entry: entry)
23
+ }
24
+ it { should_not be_valid }
25
+
26
+ context "with an invalid credit" do
27
+ before {
28
+ entry.credit_amounts << FactoryGirl.build(:credit_amount, entry: entry, amount: nil)
29
+ }
30
+ it { should_not be_valid }
31
+ end
32
+ end
33
+
34
+ context "with a credit" do
35
+ before {
36
+ entry.credit_amounts << FactoryGirl.build(:credit_amount, entry: entry)
37
+ }
38
+ it { should_not be_valid }
39
+
40
+ context "with an invalid debit" do
41
+ before {
42
+ entry.debit_amounts << FactoryGirl.build(:debit_amount, entry: entry, amount: nil)
43
+ }
44
+ it { should_not be_valid }
45
+ end
46
+ end
47
+
48
+ it "should require the debit and credit amounts to cancel" do
49
+ entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100, :entry => entry)
50
+ entry.debit_amounts << FactoryGirl.build(:debit_amount, :amount => 200, :entry => entry)
51
+ entry.should_not be_valid
52
+ entry.errors['base'].should == ["The credit and debit amounts are not equal"]
53
+ end
54
+
55
+ it "should require the debit and credit amounts to cancel even with fractions" do
56
+ entry = FactoryGirl.build(:entry)
57
+ entry.credit_amounts << FactoryGirl.build(:credit_amount, :amount => 100.1, :entry => entry)
58
+ entry.debit_amounts << FactoryGirl.build(:debit_amount, :amount => 100.2, :entry => entry)
59
+ entry.should_not be_valid
60
+ entry.errors['base'].should == ["The credit and debit amounts are not equal"]
61
+ end
62
+
63
+ it "should have a polymorphic commercial document associations" do
64
+ mock_document = FactoryGirl.create(:asset) # one would never do this, but it allows us to not require a migration for the test
65
+ entry = FactoryGirl.build(:entry_with_credit_and_debit, commercial_document: mock_document)
66
+ entry.save!
67
+ saved_entry = Entry.find(entry.id)
68
+ saved_entry.commercial_document.should == mock_document
69
+ end
70
+
71
+ it "should allow building an entry and credit and debits with a hash" do
72
+ FactoryGirl.create(:asset, name: "Accounts Receivable")
73
+ FactoryGirl.create(:revenue, name: "Sales Revenue")
74
+ FactoryGirl.create(:liability, name: "Sales Tax Payable")
75
+ mock_document = FactoryGirl.create(:asset)
76
+ entry = Entry.build(
77
+ description: "Sold some widgets",
78
+ commercial_document: mock_document,
79
+ debits: [
80
+ {account: "Accounts Receivable", amount: 50}],
81
+ credits: [
82
+ {account: "Sales Revenue", amount: 45},
83
+ {account: "Sales Tax Payable", amount: 5}])
84
+ entry.save!
85
+
86
+ saved_entry = Entry.find(entry.id)
87
+ saved_entry.commercial_document.should == mock_document
88
+ end
89
+
90
+ end
91
+ end
@@ -1,31 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Plutus
4
- describe TransactionsController do
4
+ describe EntriesController do
5
5
  # Run these tests if you enable routing in your rails app. See README
6
6
  #describe "routing" do
7
7
  #it "recognizes and generates #index" do
8
- #{ :get => "/transactions" }.should route_to(:controller => "transactions", :action => "index")
8
+ #{ :get => "/entries" }.should route_to(:controller => "entries", :action => "index")
9
9
  #end
10
10
 
11
11
  #it "recognizes and generates #show" do
12
- #{ :get => "/transactions/1" }.should route_to(:controller => "transactions", :action => "show", :id => "1")
12
+ #{ :get => "/entries/1" }.should route_to(:controller => "entries", :action => "show", :id => "1")
13
13
  #end
14
14
 
15
15
  #it "recognizes and generates #edit" do
16
- #{ :get => "/transactions/1/edit" }.should_not be_routable
16
+ #{ :get => "/entries/1/edit" }.should_not be_routable
17
17
  #end
18
18
 
19
19
  #it "recognizes and generates #create" do
20
- #{ :post => "/transactions" }.should_not be_routable
20
+ #{ :post => "/entries" }.should_not be_routable
21
21
  #end
22
22
 
23
23
  #it "recognizes and generates #update" do
24
- #{ :put => "/transactions/1" }.should_not be_routable
24
+ #{ :put => "/entries/1" }.should_not be_routable
25
25
  #end
26
26
 
27
27
  #it "recognizes and generates #destroy" do
28
- #{ :delete => "/transactions/1" }.should_not be_routable
28
+ #{ :delete => "/entries/1" }.should_not be_routable
29
29
  #end
30
30
  #end
31
31
  end
@@ -16,8 +16,8 @@ shared_examples_for 'a Plutus::Account subtype' do |elements|
16
16
  describe "instance methods" do
17
17
  its(:balance) { should be_kind_of(BigDecimal) }
18
18
 
19
- it { should respond_to(:credit_transactions) }
20
- it { should respond_to(:debit_transactions) }
19
+ it { should respond_to(:credit_entries) }
20
+ it { should respond_to(:debit_entries) }
21
21
  end
22
22
 
23
23
  it "requires a name" do
@@ -9,8 +9,8 @@ shared_examples_for 'a Plutus::Amount subtype' do |elements|
9
9
  amount.should_not be_valid
10
10
  end
11
11
 
12
- it "should require a transaction" do
13
- amount.transaction = nil
12
+ it "should require a entry" do
13
+ amount.entry = nil
14
14
  amount.should_not be_valid
15
15
  end
16
16