easy_rails_money 0.0.3 → 0.0.4

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.
@@ -1,250 +1,215 @@
1
1
  require 'spec_helper'
2
2
  require 'active_record_spec_helper'
3
3
  require 'tempfile'
4
-
5
- if defined? ActiveRecord
6
-
7
- require 'active_record/schema_dumper'
8
-
9
- # migrations used in tests. our factories/fixtures
10
- # their class names are the same if they are functionally
11
- # equivalent, but are organized in different modules depending on
12
- # whether it is implemented using
13
- # schema_statements, create_table or change_table
14
- module SchemaStatements
15
- class CreateLoanAndMoney < ActiveRecord::Migration
16
- def change
17
- suppress_messages do
18
- create_table :loans do |t|
19
- t.string :name
20
- end
21
- add_money :loans, :principal
22
- end
4
+ require 'active_record/schema_dumper'
5
+
6
+ # migrations used in tests. our factories/fixtures
7
+ # their class names are the same if they are functionally
8
+ # equivalent, but are organized in different modules depending on
9
+ # whether it is implemented using
10
+ # schema_statements, create_table or change_table
11
+ module SchemaStatements
12
+ class CreateLoanAndMoney < ActiveRecord::Migration
13
+ def change
14
+ suppress_messages do
15
+ create_table :loans do |t|
16
+ t.string :name
17
+ end
18
+ add_money :loans, :principal
23
19
  end
24
20
  end
21
+ end
25
22
 
26
- class CreateLoanWithCurrency < ActiveRecord::Migration
27
- def change
28
- suppress_messages do
29
- create_table :loans do |t|
30
- t.string :name
31
- t.currency
32
- end
33
- add_money :loans, :principal, :repaid, :npa
23
+ class CreateLoanWithCurrency < ActiveRecord::Migration
24
+ def change
25
+ suppress_messages do
26
+ create_table :loans do |t|
27
+ t.string :name
28
+ t.currency
34
29
  end
30
+ add_money :loans, :principal, :repaid, :npa
35
31
  end
36
32
  end
33
+ end
37
34
 
38
- class RemoveMoneyColumnsFromLoan < ActiveRecord::Migration
39
- def change
40
- suppress_messages do
41
- remove_money :loans, :principal, :repaid, :npa
42
- end
35
+ class RemoveMoneyColumnsFromLoan < ActiveRecord::Migration
36
+ def change
37
+ suppress_messages do
38
+ remove_money :loans, :principal, :repaid, :npa
43
39
  end
44
40
  end
41
+ end
45
42
 
46
- class RemoveMoneyColumnsExceptPrincipalFromLoan < ActiveRecord::Migration
47
- def change
48
- suppress_messages do
49
- remove_money :loans, :repaid, :npa
50
- end
43
+ class RemoveMoneyColumnsExceptPrincipalFromLoan < ActiveRecord::Migration
44
+ def change
45
+ suppress_messages do
46
+ remove_money :loans, :repaid, :npa
51
47
  end
52
48
  end
49
+ end
53
50
 
54
- class RemovePrincipalFromLoan < ActiveRecord::Migration
55
- def change
56
- suppress_messages do
57
- remove_money :loans, :principal
58
- end
51
+ class RemovePrincipalFromLoan < ActiveRecord::Migration
52
+ def change
53
+ suppress_messages do
54
+ remove_money :loans, :principal
59
55
  end
60
56
  end
57
+ end
61
58
 
62
- class RemoveCurrencyFromLoan < ActiveRecord::Migration
63
- def change
64
- suppress_messages do
65
- remove_currency :loans
66
- end
67
- end
68
- end
69
- end # module SchemaStatements
70
-
71
- module ChangeTable
72
- class AddPrincipalToLoan < ActiveRecord::Migration
73
- def change
74
- suppress_messages do
75
- change_table :loans do |t|
76
- t.money :principal
77
- end
78
- end
59
+ class RemoveCurrencyFromLoan < ActiveRecord::Migration
60
+ def change
61
+ suppress_messages do
62
+ remove_currency :loans
79
63
  end
80
64
  end
65
+ end
66
+ end # module SchemaStatements
81
67
 
82
- class RemoveCurrencyFromLoan < ActiveRecord::Migration
83
- def change
84
- suppress_messages do
85
- change_table :loans, force: true do |t|
86
- t.remove_currency
87
- end
68
+ module ChangeTable
69
+ class AddPrincipalToLoan < ActiveRecord::Migration
70
+ def change
71
+ suppress_messages do
72
+ change_table :loans do |t|
73
+ t.money :principal
88
74
  end
89
75
  end
90
76
  end
77
+ end
91
78
 
92
- class RemovePrincipalFromLoan < ActiveRecord::Migration
93
- def change
94
- suppress_messages do
95
- change_table :loans do |t|
96
- t.remove_money :principal
97
- end
98
- end
99
- end
100
- end
101
-
102
- class AddSingleCurrencyToLoan < ActiveRecord::Migration
103
- def change
104
- suppress_messages do
105
- change_table :loans, force: true do |t|
106
- t.currency
107
- end
79
+ class RemoveCurrencyFromLoan < ActiveRecord::Migration
80
+ def change
81
+ suppress_messages do
82
+ change_table :loans, force: true do |t|
83
+ t.remove_currency
108
84
  end
109
85
  end
110
86
  end
87
+ end
111
88
 
112
- class RemoveMoneyColumnsFromLoan < ActiveRecord::Migration
113
- def change
114
- suppress_messages do
115
- change_table :loans, force: true do |t|
116
- t.remove_money :principal, :repaid, :npa
117
- end
89
+ class RemovePrincipalFromLoan < ActiveRecord::Migration
90
+ def change
91
+ suppress_messages do
92
+ change_table :loans do |t|
93
+ t.remove_money :principal
118
94
  end
119
95
  end
120
96
  end
121
-
122
- class RemoveMoneyColumnsExceptPrincipalFromLoan < ActiveRecord::Migration
123
- def change
124
- suppress_messages do
125
- change_table :loans, force: true do |t|
126
- t.remove_money :repaid, :npa
127
- end
97
+ end
98
+
99
+ class AddSingleCurrencyToLoan < ActiveRecord::Migration
100
+ def change
101
+ suppress_messages do
102
+ change_table :loans, force: true do |t|
103
+ t.currency
128
104
  end
129
105
  end
130
106
  end
131
- end # module ChangeTable
132
-
133
- module CreateTableDefinition
134
- class CreateLoan < ActiveRecord::Migration
135
- def change
136
- suppress_messages do
137
- create_table :loans do |t|
138
- t.string :name
139
- end
107
+ end
108
+
109
+ class RemoveMoneyColumnsFromLoan < ActiveRecord::Migration
110
+ def change
111
+ suppress_messages do
112
+ change_table :loans, force: true do |t|
113
+ t.remove_money :principal, :repaid, :npa
140
114
  end
141
115
  end
142
116
  end
117
+ end
143
118
 
144
- class CreateLoanAndMoney < ActiveRecord::Migration
145
- def change
146
- suppress_messages do
147
- create_table :loans do |t|
148
- t.string :name
149
- t.money :principal
150
- end
119
+ class RemoveMoneyColumnsExceptPrincipalFromLoan < ActiveRecord::Migration
120
+ def change
121
+ suppress_messages do
122
+ change_table :loans, force: true do |t|
123
+ t.remove_money :repaid, :npa
151
124
  end
152
125
  end
153
126
  end
127
+ end
128
+ end # module ChangeTable
154
129
 
155
- class CreateLoanWithCurrency < ActiveRecord::Migration
156
- def change
157
- suppress_messages do
158
- create_table :loans, force: true do |t|
159
- t.string :name
160
- t.money :principal
161
- t.money :repaid
162
- t.money :npa
163
- t.currency
164
- end
130
+ module CreateTableDefinition
131
+ class CreateLoan < ActiveRecord::Migration
132
+ def change
133
+ suppress_messages do
134
+ create_table :loans do |t|
135
+ t.string :name
165
136
  end
166
137
  end
167
138
  end
139
+ end
168
140
 
169
- class CreateLoanWithoutCurrency < ActiveRecord::Migration
170
- def change
171
- suppress_messages do
172
- create_table :loans, force: true do |t|
173
- t.string :name
174
- t.money :principal
175
- t.money :repaid
176
- t.money :npa
177
- end
141
+ class CreateLoanAndMoney < ActiveRecord::Migration
142
+ def change
143
+ suppress_messages do
144
+ create_table :loans do |t|
145
+ t.string :name
146
+ t.money :principal
178
147
  end
179
148
  end
180
149
  end
181
-
182
- class CreateLoanWithCurrencySpecifiedFirst < ActiveRecord::Migration
183
- def change
184
- suppress_messages do
185
- create_table :loans, force: true do |t|
186
- t.string :name
187
- t.currency
188
- t.money :principal
189
- t.money :repaid
190
- t.money :npa
191
- end
150
+ end
151
+
152
+ class CreateLoanWithCurrencySpecifiedFirst < ActiveRecord::Migration
153
+ def change
154
+ suppress_messages do
155
+ create_table :loans, force: true do |t|
156
+ t.string :name
157
+ t.currency
158
+ t.money :principal
159
+ t.money :repaid
160
+ t.money :npa
192
161
  end
193
162
  end
194
163
  end
164
+ end
195
165
 
196
- class CreateLoanWithCurrencySpecifiedInBetween < ActiveRecord::Migration
197
- def change
198
- suppress_messages do
199
- create_table :loans, force: true do |t|
200
- t.string :name
201
- t.money :principal
202
- t.money :repaid
203
- t.currency
204
- t.money :npa
205
- end
166
+ class CreateLoanWithCurrencySpecifiedInBetween < ActiveRecord::Migration
167
+ def change
168
+ suppress_messages do
169
+ create_table :loans, force: true do |t|
170
+ t.string :name
171
+ t.money :principal
172
+ t.money :repaid
173
+ t.currency
174
+ t.money :npa
206
175
  end
207
176
  end
208
177
  end
209
- end # module CreateTableDefinition
210
-
211
- # class Loan < ActiveRecord::Base
212
- # attr_accessible :principal, :name
213
- # # money :principal
214
- # end
215
-
216
- describe "Migrating Money columns" do
178
+ end
179
+ end # module CreateTableDefinition
180
+
181
+ describe "Migrating Money columns" do
217
182
 
218
- let(:schema_with_principal) do
219
- <<-EOF.strip_spaces
183
+ let(:schema_with_principal) do
184
+ <<-EOF.strip_spaces
220
185
  create_table "loans", :force => true do |t|
221
186
  t.string "name"
222
187
  t.integer "principal_money"
223
188
  t.string "principal_currency"
224
189
  end
225
190
  EOF
226
- end
191
+ end
227
192
 
228
- let(:schema_with_principal_and_single_currency_column) do
229
- <<-EOF.strip_spaces
193
+ let(:schema_with_principal_and_single_currency_column) do
194
+ <<-EOF.strip_spaces
230
195
  create_table "loans", :force => true do |t|
231
196
  t.string "name"
232
197
  t.integer "principal_money"
233
198
  t.string "currency"
234
199
  end
235
200
  EOF
236
- end
201
+ end
237
202
 
238
- let(:schema_with_only_name) do
239
- <<-EOF.strip_spaces
203
+ let(:schema_with_only_name) do
204
+ <<-EOF.strip_spaces
240
205
  create_table "loans", :force => true do |t|
241
206
  t.string "name"
242
207
  end
243
208
  EOF
244
- end
209
+ end
245
210
 
246
- let(:schema_with_single_currency_column) do
247
- <<-EOF.strip_spaces
211
+ let(:schema_with_single_currency_column) do
212
+ <<-EOF.strip_spaces
248
213
  create_table "loans", :force => true do |t|
249
214
  t.string "name"
250
215
  t.integer "npa_money"
@@ -253,10 +218,10 @@ EOF
253
218
  t.string "currency"
254
219
  end
255
220
  EOF
256
- end
221
+ end
257
222
 
258
- let(:schema_with_multiple_currency_columns) do
259
- <<-EOF.strip_spaces
223
+ let(:schema_with_multiple_currency_columns) do
224
+ <<-EOF.strip_spaces
260
225
  create_table "loans", :force => true do |t|
261
226
  t.string "name"
262
227
  t.string "npa_currency"
@@ -267,134 +232,133 @@ EOF
267
232
  t.integer "repaid_money"
268
233
  end
269
234
  EOF
270
- end
271
-
272
- context "and testing schema statements", :schema_statements do
273
- context "which have one currency column for each money column" do
274
- before(:each) do
275
- migrate SchemaStatements::CreateLoanAndMoney
276
- end
235
+ end
277
236
 
278
- describe "#add_money" do
279
- it "creates two columns for each money attribute. one to store the lower denomination as an integer and the currency as a string" do
280
- expect(dump_schema).to eq schema_with_principal
281
- end
282
- end
283
-
284
- describe "#remove_money" do
285
- it "drops two columns for each money attribute. one which stored the lower denomination as an integer and the currency as a string" do
286
- expect { migrate SchemaStatements::RemovePrincipalFromLoan }.to change { dump_schema }.from(schema_with_principal).to(schema_with_only_name)
287
- end
288
- end
237
+ context "and testing schema statements", :schema_statements do
238
+ context "which have one currency column for each money column" do
239
+ before(:each) do
240
+ migrate SchemaStatements::CreateLoanAndMoney
289
241
  end
290
242
 
291
- context "which has a single currency", :single_currency do
292
- before(:each) do
293
- migrate SchemaStatements::CreateLoanWithCurrency
243
+ describe "#add_money" do
244
+ it "creates two columns for each money attribute. one to store the lower denomination as an integer and the currency as a string" do
245
+ expect(dump_schema).to eq schema_with_principal
294
246
  end
247
+ end
295
248
 
296
- describe "#add_money" do
297
- it "creates one column for each money attribute, to store the lower denomination as an integer. currency is stored in a common column" do
298
- expect(dump_schema).to eq schema_with_single_currency_column
299
- end
249
+ describe "#remove_money" do
250
+ it "drops two columns for each money attribute. one which stored the lower denomination as an integer and the currency as a string" do
251
+ expect { migrate SchemaStatements::RemovePrincipalFromLoan }.to change { dump_schema }.from(schema_with_principal).to(schema_with_only_name)
300
252
  end
253
+ end
254
+ end
301
255
 
302
- describe "#remove_money" do
303
- it "drops the money column for each money attribute and the common currency column as well", :fixme, :fixme_need_to_clear_table_cache do
304
- expect { migrate SchemaStatements::RemoveMoneyColumnsFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_only_name)
305
- end
256
+ context "which has a single currency", :single_currency do
257
+ before(:each) do
258
+ migrate SchemaStatements::CreateLoanWithCurrency
259
+ end
306
260
 
307
- it "drops the money column for each money attribute but keeps the common currency column because some money columns still remain" do
308
- expect { migrate SchemaStatements::RemoveMoneyColumnsExceptPrincipalFromLoan }.to change { dump_schema }.
309
- from(schema_with_single_currency_column).
310
- to(schema_with_principal_and_single_currency_column)
311
- end
261
+ describe "#add_money" do
262
+ it "creates one column for each money attribute, to store the lower denomination as an integer. currency is stored in a common column" do
263
+ expect(dump_schema).to eq schema_with_single_currency_column
312
264
  end
265
+ end
313
266
 
314
- describe "#remove_currency" do
315
- it "drops the common currency column and adds a currency columns to each of the existing money columns" do
316
- expect { migrate SchemaStatements::RemoveCurrencyFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_multiple_currency_columns)
317
- end
267
+ describe "#remove_money" do
268
+ it "drops the money column for each money attribute and the common currency column as well", :fixme, :fixme_need_to_clear_table_cache do
269
+ expect { migrate SchemaStatements::RemoveMoneyColumnsFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_only_name)
270
+ end
318
271
 
319
- pending "remove currency while side-by-side adding a money column"
272
+ it "drops the money column for each money attribute but keeps the common currency column because some money columns still remain" do
273
+ expect { migrate SchemaStatements::RemoveMoneyColumnsExceptPrincipalFromLoan }.to change { dump_schema }.
274
+ from(schema_with_single_currency_column).
275
+ to(schema_with_principal_and_single_currency_column)
320
276
  end
321
277
  end
322
- end # context "schema_statements"
323
278
 
324
- context "and testing table statements", :table_statements do
325
- context "which have one currency column for each money column" do
326
- before(:each) do
327
- migrate CreateTableDefinition::CreateLoanAndMoney
328
- end
329
-
330
- describe "#add_money" do
331
- it "creates two columns for each money attribute. one to store the lower denomination as an integer and the currency as a string" do
332
- expect(dump_schema).to eq schema_with_principal
333
- end
279
+ describe "#remove_currency" do
280
+ it "drops the common currency column and adds a currency columns to each of the existing money columns" do
281
+ expect { migrate SchemaStatements::RemoveCurrencyFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_multiple_currency_columns)
334
282
  end
335
283
 
336
- describe "#remove_money" do
337
- it "drops two columns for each money attribute. one which stored the lower denomination as an integer and the currency as a string" do
338
- expect { migrate ChangeTable::RemovePrincipalFromLoan }.to change { dump_schema }.from(schema_with_principal).to(schema_with_only_name)
339
- end
284
+ pending "remove currency while side-by-side adding a money column"
285
+ end
286
+ end
287
+ end # context "schema_statements"
288
+
289
+ context "and testing table statements", :table_statements do
290
+ context "which have one currency column for each money column" do
291
+ before(:each) do
292
+ migrate CreateTableDefinition::CreateLoanAndMoney
293
+ end
294
+
295
+ describe "#add_money" do
296
+ it "creates two columns for each money attribute. one to store the lower denomination as an integer and the currency as a string" do
297
+ expect(dump_schema).to eq schema_with_principal
340
298
  end
341
299
  end
342
300
 
343
- context "which has a single currency", :single_currency do
344
- describe "#add_money" do
345
- context "and tests that order of statements does not matter" do
346
- it "creates money and common currency cilumns when currency column is specified last" do
347
- migrate CreateTableDefinition::CreateLoanWithCurrency
348
- expect(dump_schema).to eq schema_with_single_currency_column
349
- end
350
-
351
- it "creates money and common currency cilumns when currency column is specified first" do
352
- migrate CreateTableDefinition::CreateLoanWithCurrencySpecifiedFirst
353
- expect(dump_schema).to eq schema_with_single_currency_column
354
- end
355
-
356
- it "creates money and common currency cilumns when currency column is specified in-between" do
357
- migrate CreateTableDefinition::CreateLoanWithCurrencySpecifiedInBetween
358
- expect(dump_schema).to eq schema_with_single_currency_column
359
- end
360
- end
301
+ describe "#remove_money" do
302
+ it "drops two columns for each money attribute. one which stored the lower denomination as an integer and the currency as a string" do
303
+ expect { migrate ChangeTable::RemovePrincipalFromLoan }.to change { dump_schema }.from(schema_with_principal).to(schema_with_only_name)
361
304
  end
305
+ end
306
+ end
362
307
 
363
- describe "#remove_money" do
364
- before(:each) do
308
+ context "which has a single currency", :single_currency do
309
+ describe "#add_money" do
310
+ context "and tests that order of statements does not matter" do
311
+ it "creates money and common currency cilumns when currency column is specified last" do
365
312
  migrate CreateTableDefinition::CreateLoanWithCurrency
313
+ expect(dump_schema).to eq schema_with_single_currency_column
366
314
  end
367
315
 
368
- it "drops the money column for each money attribute and the common currency column as well" do
369
- expect { migrate ChangeTable::RemoveMoneyColumnsFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_only_name)
316
+ it "creates money and common currency cilumns when currency column is specified first" do
317
+ migrate CreateTableDefinition::CreateLoanWithCurrencySpecifiedFirst
318
+ expect(dump_schema).to eq schema_with_single_currency_column
370
319
  end
371
-
372
- it "drops the money column for each money attribute but keeps the common currency column because some money columns still remain" do
373
- expect { migrate ChangeTable::RemoveMoneyColumnsExceptPrincipalFromLoan }.to change { dump_schema }.
374
- from(schema_with_single_currency_column).
375
- to(schema_with_principal_and_single_currency_column)
320
+
321
+ it "creates money and common currency cilumns when currency column is specified in-between" do
322
+ migrate CreateTableDefinition::CreateLoanWithCurrencySpecifiedInBetween
323
+ expect(dump_schema).to eq schema_with_single_currency_column
376
324
  end
377
325
  end
326
+ end
327
+
328
+ describe "#remove_money" do
329
+ before(:each) do
330
+ migrate CreateTableDefinition::CreateLoanWithCurrency
331
+ end
378
332
 
379
- describe "#remove_currency" do
380
- it "drops the common currency column and adds a currency columns to each of the existing money columns" do
381
- migrate CreateTableDefinition::CreateLoanWithCurrency
382
- expect { migrate ChangeTable::RemoveCurrencyFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_multiple_currency_columns)
383
- end
333
+ it "drops the money column for each money attribute and the common currency column as well" do
334
+ expect { migrate ChangeTable::RemoveMoneyColumnsFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_only_name)
384
335
  end
385
-
386
- it "can add a single currrency column later" do
387
- migrate CreateTableDefinition::CreateLoanWithoutCurrency
388
- expect { migrate ChangeTable::AddSingleCurrencyToLoan }.to change { dump_schema }.from(schema_with_multiple_currency_columns).to(schema_with_single_currency_column)
336
+
337
+ it "drops the money column for each money attribute but keeps the common currency column because some money columns still remain" do
338
+ expect { migrate ChangeTable::RemoveMoneyColumnsExceptPrincipalFromLoan }.to change { dump_schema }.
339
+ from(schema_with_single_currency_column).
340
+ to(schema_with_principal_and_single_currency_column)
341
+ end
342
+ end
343
+
344
+ describe "#remove_currency" do
345
+ it "drops the common currency column and adds a currency columns to each of the existing money columns" do
346
+ migrate CreateTableDefinition::CreateLoanWithCurrency
347
+ expect { migrate ChangeTable::RemoveCurrencyFromLoan }.to change { dump_schema }.from(schema_with_single_currency_column).to(schema_with_multiple_currency_columns)
389
348
  end
390
- end # context "which has a single currency"
391
- end # context "and testing table statements"
349
+ end
392
350
 
393
- it "can add a money column later" do
394
- migrate CreateTableDefinition::CreateLoan
395
- expect { migrate ChangeTable::AddPrincipalToLoan }.to change { dump_schema }.from(schema_with_only_name).to(schema_with_principal)
396
- end
351
+ it "can add a single currrency column later" do
352
+ migrate CreateTableDefinition::CreateLoanWithoutCurrency
353
+ expect { migrate ChangeTable::AddSingleCurrencyToLoan }.to change { dump_schema }.from(schema_with_multiple_currency_columns).to(schema_with_single_currency_column)
354
+ end
355
+ end # context "which has a single currency"
356
+ end # context "and testing table statements"
357
+
358
+ it "can add a money column later" do
359
+ migrate CreateTableDefinition::CreateLoan
360
+ expect { migrate ChangeTable::AddPrincipalToLoan }.to change { dump_schema }.from(schema_with_only_name).to(schema_with_principal)
361
+ end
397
362
 
398
- pending "separate up and down migration methods. using add_money and remove_money"
399
- end # describe "Migrating Money columns"
400
- end # if defined? ActiveRecord
363
+ pending "separate up and down migration methods. using add_money and remove_money"
364
+ end # describe "Migrating Money columns"