invoicing 0.2.1 → 1.0.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.
- checksums.yaml +7 -0
- data/LICENSE +1 -0
- data/README.md +57 -0
- data/Rakefile +16 -37
- data/lib/invoicing.rb +20 -10
- data/lib/invoicing/cached_record.rb +9 -6
- data/lib/invoicing/class_info.rb +34 -34
- data/lib/invoicing/connection_adapter_ext.rb +4 -4
- data/lib/invoicing/countries/uk.rb +6 -6
- data/lib/invoicing/currency_value.rb +39 -32
- data/lib/invoicing/find_subclasses.rb +40 -15
- data/lib/invoicing/ledger_item.rb +166 -145
- data/lib/invoicing/ledger_item/pdf_generator.rb +108 -0
- data/lib/invoicing/ledger_item/render_html.rb +76 -73
- data/lib/invoicing/ledger_item/render_ubl.rb +37 -35
- data/lib/invoicing/line_item.rb +43 -38
- data/lib/invoicing/price.rb +1 -1
- data/lib/invoicing/tax_rate.rb +3 -6
- data/lib/invoicing/taxable.rb +37 -32
- data/lib/invoicing/time_dependent.rb +40 -40
- data/lib/invoicing/version.rb +4 -4
- data/lib/rails/generators/invoicing/invoicing_generator.rb +14 -0
- data/lib/rails/generators/invoicing/ledger_item/ledger_item_generator.rb +17 -0
- data/lib/rails/generators/invoicing/ledger_item/templates/migration.rb +25 -0
- data/lib/rails/generators/invoicing/ledger_item/templates/model.rb +5 -0
- data/lib/rails/generators/invoicing/line_item/line_item_generator.rb +17 -0
- data/lib/rails/generators/invoicing/line_item/templates/migration.rb +20 -0
- data/lib/rails/generators/invoicing/line_item/templates/model.rb +5 -0
- data/lib/rails/generators/invoicing/tax_rate/tax_rate_generator.rb +17 -0
- data/lib/rails/generators/invoicing/tax_rate/templates/migration.rb +14 -0
- data/lib/rails/generators/invoicing/tax_rate/templates/model.rb +3 -0
- metadata +110 -153
- data.tar.gz.sig +0 -1
- data/History.txt +0 -31
- data/Manifest.txt +0 -62
- data/PostInstall.txt +0 -10
- data/README.rdoc +0 -58
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/tasks/rcov.rake +0 -4
- data/test/cached_record_test.rb +0 -100
- data/test/class_info_test.rb +0 -253
- data/test/connection_adapter_ext_test.rb +0 -79
- data/test/currency_value_test.rb +0 -209
- data/test/find_subclasses_test.rb +0 -120
- data/test/fixtures/README +0 -7
- data/test/fixtures/cached_record.sql +0 -22
- data/test/fixtures/class_info.sql +0 -28
- data/test/fixtures/currency_value.sql +0 -29
- data/test/fixtures/find_subclasses.sql +0 -43
- data/test/fixtures/ledger_item.sql +0 -39
- data/test/fixtures/line_item.sql +0 -33
- data/test/fixtures/price.sql +0 -4
- data/test/fixtures/tax_rate.sql +0 -4
- data/test/fixtures/taxable.sql +0 -14
- data/test/fixtures/time_dependent.sql +0 -35
- data/test/ledger_item_test.rb +0 -444
- data/test/line_item_test.rb +0 -139
- data/test/models/README +0 -4
- data/test/models/test_subclass_in_another_file.rb +0 -3
- data/test/models/test_subclass_not_in_database.rb +0 -6
- data/test/price_test.rb +0 -9
- data/test/ref-output/creditnote3.html +0 -82
- data/test/ref-output/creditnote3.xml +0 -89
- data/test/ref-output/invoice1.html +0 -93
- data/test/ref-output/invoice1.xml +0 -111
- data/test/ref-output/invoice2.html +0 -86
- data/test/ref-output/invoice2.xml +0 -98
- data/test/ref-output/invoice_null.html +0 -36
- data/test/render_html_test.rb +0 -70
- data/test/render_ubl_test.rb +0 -44
- data/test/setup.rb +0 -37
- data/test/tax_rate_test.rb +0 -9
- data/test/taxable_test.rb +0 -180
- data/test/test_helper.rb +0 -72
- data/test/time_dependent_test.rb +0 -180
- metadata.gz.sig +0 -4
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
|
3
|
-
class ConnectionAdapterExtTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
# Don't run these tests in database transactions.
|
6
|
-
def setup
|
7
|
-
end
|
8
|
-
def teardown
|
9
|
-
end
|
10
|
-
|
11
|
-
def using_database(database_type)
|
12
|
-
if database_type.to_sym == database_used_for_testing
|
13
|
-
# If the test is for the main database type of this test suite, just run it
|
14
|
-
yield
|
15
|
-
|
16
|
-
elsif test_in_all_databases
|
17
|
-
# Run the test having connected to the requested database type, or skip it
|
18
|
-
# if we're not trying to test all database types
|
19
|
-
begin
|
20
|
-
ActiveRecord::Base.establish_connection(TEST_DB_CONFIG[database_type.to_sym])
|
21
|
-
yield
|
22
|
-
ensure
|
23
|
-
connect_to_testing_database
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_conditional_function_as_mysql
|
29
|
-
using_database :mysql do
|
30
|
-
assert_equal "IF(true, foo, bar)", Invoicing::ConnectionAdapterExt.conditional_function('true', 'foo', 'bar')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_conditional_function_as_postgresql
|
35
|
-
using_database :postgresql do
|
36
|
-
assert_equal "CASE WHEN true THEN foo ELSE bar END",
|
37
|
-
Invoicing::ConnectionAdapterExt.conditional_function('true', 'foo', 'bar')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_conditional_function_as_sqlite3
|
42
|
-
using_database :sqlite3 do
|
43
|
-
assert_raise RuntimeError do
|
44
|
-
Invoicing::ConnectionAdapterExt.conditional_function('true', 'foo', 'bar')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_group_by_all_columns_as_mysql
|
50
|
-
using_database :mysql do
|
51
|
-
assert_equal "`ledger_item_records`.`id2`",
|
52
|
-
Invoicing::ConnectionAdapterExt.group_by_all_columns(MyLedgerItem)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_group_by_all_columns_as_postgresql
|
57
|
-
using_database :postgresql do
|
58
|
-
assert_equal(
|
59
|
-
'"ledger_item_records"."id2", "ledger_item_records"."type2", "ledger_item_records"."sender_id2", ' +
|
60
|
-
'"ledger_item_records"."recipient_id2", "ledger_item_records"."identifier2", ' +
|
61
|
-
'"ledger_item_records"."issue_date2", "ledger_item_records"."currency2", ' +
|
62
|
-
'"ledger_item_records"."total_amount2", "ledger_item_records"."tax_amount2", ' +
|
63
|
-
'"ledger_item_records"."status2", "ledger_item_records"."period_start2", ' +
|
64
|
-
'"ledger_item_records"."period_end2", "ledger_item_records"."uuid2", ' +
|
65
|
-
'"ledger_item_records"."due_date2", "ledger_item_records"."created_at", ' +
|
66
|
-
'"ledger_item_records"."updated_at"',
|
67
|
-
Invoicing::ConnectionAdapterExt.group_by_all_columns(MyLedgerItem))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_group_by_all_columns_as_sqlite3
|
72
|
-
using_database :sqlite3 do
|
73
|
-
assert_raise RuntimeError do
|
74
|
-
Invoicing::ConnectionAdapterExt.group_by_all_columns(MyLedgerItem)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
data/test/currency_value_test.rb
DELETED
@@ -1,209 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
4
|
-
|
5
|
-
# Test extending the default list of currency codes: include the Zimbabwe Dollar.
|
6
|
-
# This also tests rounding and seriously large numbers. -- Sorry, you shouldn't make
|
7
|
-
# jokes about this sort of thing. The people are suffering badly.
|
8
|
-
Invoicing::CurrencyValue::CURRENCIES['ZWD'] = {:symbol => 'ZW$', :round => 5_000_000}
|
9
|
-
|
10
|
-
class CurrencyValueTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
class CurrencyValueRecord < ActiveRecord::Base
|
13
|
-
validates_numericality_of :amount
|
14
|
-
acts_as_currency_value :amount, :tax_amount, :currency => 'currency_code'
|
15
|
-
end
|
16
|
-
|
17
|
-
# In Finland and the Netherlands, Euro amounts are commonly rounded to the nearest 5 cents.
|
18
|
-
class EurosInFinlandRecord < ActiveRecord::Base
|
19
|
-
set_table_name 'no_currency_column_records'
|
20
|
-
acts_as_currency_value :amount, :currency_code => 'EUR', :round => 0.05, :space => true
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_format_small_number
|
24
|
-
assert_equal "€0.02", CurrencyValueRecord.find(2).tax_amount_formatted
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_format_thousands_separators
|
28
|
-
assert_equal "€98,765,432.00", CurrencyValueRecord.find(2).amount_formatted
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_format_no_decimal_point
|
32
|
-
assert_equal "¥8,888", CurrencyValueRecord.find(4).amount_formatted
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_format_suffix_unit
|
36
|
-
assert_equal "5,432.00 元", CurrencyValueRecord.find(3).amount_formatted
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_format_unknown_currency
|
40
|
-
assert_equal "123.00 XXX", CurrencyValueRecord.find(5).amount_formatted
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_format_with_custom_currency
|
44
|
-
record = CurrencyValueRecord.new(:currency_code => 'ZWD', :amount => BigDecimal('50000000000'))
|
45
|
-
assert_equal "ZW$50,000,000,000", record.amount_formatted # price of 1 egg on 18 July 2008
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_format_without_currency_column
|
49
|
-
assert_equal "€ 95.15", EurosInFinlandRecord.find(1).amount_formatted
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_format_with_options
|
53
|
-
assert_equal "0.02 €", CurrencyValueRecord.find(2).tax_amount_formatted(:suffix => true)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_format_custom_value
|
57
|
-
assert_equal "€1,357.90", CurrencyValueRecord.find(2).format_currency_value(BigDecimal('1357.9'))
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_format_negative_value_with_minus
|
61
|
-
assert_equal "−€1,357.90", CurrencyValueRecord.find(2).format_currency_value(BigDecimal('-1357.9'))
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_format_negative_value_with_hyphen
|
65
|
-
assert_equal "-€1,357.90", CurrencyValueRecord.find(2).format_currency_value(BigDecimal('-1357.9'), :negative => :hyphen)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_format_negative_value_with_brackets
|
69
|
-
assert_equal "(€1,357.90)", CurrencyValueRecord.find(2).format_currency_value(BigDecimal('-1357.9'), :negative => :brackets)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_load_from_database_and_format
|
73
|
-
assert_equal BigDecimal('123.45'), CurrencyValueRecord.find(1).amount
|
74
|
-
assert_equal "£123.45", CurrencyValueRecord.find(1).amount_formatted
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_new_record_from_string_and_format
|
78
|
-
record = CurrencyValueRecord.new(:amount => '44.44', :currency_code => 'USD')
|
79
|
-
assert_equal BigDecimal('44.44'), record.amount
|
80
|
-
assert_equal "$44.44", record.amount_formatted
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_new_record_from_big_decimal_and_format
|
84
|
-
record = CurrencyValueRecord.new(:amount => BigDecimal('3.33'), :currency_code => 'USD')
|
85
|
-
assert_equal BigDecimal('3.33'), record.amount
|
86
|
-
assert_equal "$3.33", record.amount_formatted
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_standalone_formatting
|
90
|
-
assert_equal "12.00 €", Invoicing::CurrencyValue::Formatter.format_value(:eur, 12, :suffix => true)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_standalone_currency_info
|
94
|
-
assert_equal({:code => 'USD', :symbol => '$', :round => 0.01, :suffix => false,
|
95
|
-
:space => false, :digits => 2}, Invoicing::CurrencyValue::Formatter.currency_info(:USD))
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_assign_float_to_new_record_and_format
|
99
|
-
record = CurrencyValueRecord.new
|
100
|
-
record.amount = 44.44
|
101
|
-
record.currency_code = 'USD'
|
102
|
-
assert_equal BigDecimal('44.44'), record.amount
|
103
|
-
assert_equal "$44.44", record.amount_formatted
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_assign_to_new_record_omitting_currency
|
107
|
-
record = CurrencyValueRecord.new
|
108
|
-
record.amount = 44.44
|
109
|
-
assert_equal BigDecimal('44.44'), record.amount
|
110
|
-
assert_equal "44.44", record.amount_formatted
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_assign_nothing_to_new_record_with_numericality_validation
|
114
|
-
record = CurrencyValueRecord.new(:currency_code => 'USD')
|
115
|
-
assert_nil record.amount
|
116
|
-
assert_equal '', record.amount_formatted
|
117
|
-
assert !record.valid?
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_assign_nothing_to_new_record_without_numericality_validation
|
121
|
-
record = CurrencyValueRecord.new(:amount => 1, :currency_code => 'USD')
|
122
|
-
assert_nil record.tax_amount
|
123
|
-
assert_equal '', record.tax_amount_formatted
|
124
|
-
assert record.valid?
|
125
|
-
record.save!
|
126
|
-
assert_equal([{'amount' => '1.0000', 'tax_amount' => nil}],
|
127
|
-
ActiveRecord::Base.connection.select_all("SELECT amount, tax_amount FROM currency_value_records WHERE id=#{record.id}"))
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_assign_invalid_value_to_new_record_with_numericality_validation
|
131
|
-
record = CurrencyValueRecord.new(:amount => 'plonk', :currency_code => 'USD')
|
132
|
-
assert_equal BigDecimal('0.00'), record.amount
|
133
|
-
assert_equal 'plonk', record.amount_before_type_cast
|
134
|
-
assert_equal '', record.amount_formatted
|
135
|
-
assert !record.valid?
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_assign_invalid_value_to_new_record_without_numericality_validation
|
139
|
-
record = CurrencyValueRecord.new(:amount => 1, :tax_amount => 'plonk', :currency_code => 'USD')
|
140
|
-
assert_equal BigDecimal('0.00'), record.tax_amount
|
141
|
-
assert_equal 'plonk', record.tax_amount_before_type_cast
|
142
|
-
assert_equal '', record.tax_amount_formatted
|
143
|
-
assert record.valid?
|
144
|
-
record.save!
|
145
|
-
assert_equal([{'amount' => '1.0000', 'tax_amount' => '0.0000'}],
|
146
|
-
ActiveRecord::Base.connection.select_all("SELECT amount, tax_amount FROM currency_value_records WHERE id=#{record.id}"))
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_overwrite_existing_record_with_valid_value
|
150
|
-
record = CurrencyValueRecord.find(4)
|
151
|
-
record.amount = '12.34'
|
152
|
-
record.currency_code = 'EUR'
|
153
|
-
assert_equal BigDecimal('12.34'), record.amount
|
154
|
-
assert_equal '12.34', record.amount_before_type_cast
|
155
|
-
assert_equal "€12.34", record.amount_formatted
|
156
|
-
record.save!
|
157
|
-
assert_equal([{'amount' => '12.3400', 'currency_code' => 'EUR'}],
|
158
|
-
ActiveRecord::Base.connection.select_all("SELECT amount, currency_code FROM currency_value_records WHERE id=#{record.id}"))
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_overwrite_existing_record_with_nil
|
162
|
-
record = CurrencyValueRecord.find(4)
|
163
|
-
record.tax_amount = nil
|
164
|
-
assert_nil record.tax_amount
|
165
|
-
assert_nil record.tax_amount_before_type_cast
|
166
|
-
assert_equal '', record.tax_amount_formatted
|
167
|
-
record.save!
|
168
|
-
assert_equal([{'amount' => '8888.0000', 'tax_amount' => nil, 'currency_code' => 'JPY'}],
|
169
|
-
ActiveRecord::Base.connection.select_all("SELECT amount, tax_amount, currency_code FROM currency_value_records WHERE id=#{record.id}"))
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_rounding_on_new_record_with_currency_column
|
173
|
-
record = CurrencyValueRecord.new(:amount => '1234.5678', :currency_code => 'JPY')
|
174
|
-
assert_equal BigDecimal('1235'), record.amount
|
175
|
-
assert_equal '1234.5678', record.amount_before_type_cast
|
176
|
-
record.save!
|
177
|
-
assert_equal([{'amount' => '1235.0000'}],
|
178
|
-
ActiveRecord::Base.connection.select_all("SELECT amount FROM currency_value_records WHERE id=#{record.id}"))
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_rounding_on_overwriting_record_with_currency_column
|
182
|
-
record = CurrencyValueRecord.find(1)
|
183
|
-
record.amount = 10.0/3.0
|
184
|
-
assert_equal BigDecimal('3.33'), record.amount
|
185
|
-
assert_equal 10.0/3.0, record.amount_before_type_cast
|
186
|
-
record.save!
|
187
|
-
assert_equal([{'amount' => '3.3300'}],
|
188
|
-
ActiveRecord::Base.connection.select_all("SELECT amount FROM currency_value_records WHERE id=1"))
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_rounding_on_new_record_with_default_currency
|
192
|
-
record = EurosInFinlandRecord.new(:amount => '1234.5678')
|
193
|
-
assert_equal BigDecimal('1234.55'), record.amount
|
194
|
-
assert_equal '1234.5678', record.amount_before_type_cast
|
195
|
-
record.save!
|
196
|
-
assert_equal([{'amount' => '1234.5500'}],
|
197
|
-
ActiveRecord::Base.connection.select_all("SELECT amount FROM no_currency_column_records WHERE id=#{record.id}"))
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_rounding_on_overwriting_record_with_default_currency
|
201
|
-
record = EurosInFinlandRecord.find(1)
|
202
|
-
record.amount = '98.7654321'
|
203
|
-
assert_equal BigDecimal('98.75'), record.amount
|
204
|
-
assert_equal '98.7654321', record.amount_before_type_cast
|
205
|
-
record.save!
|
206
|
-
assert_equal([{'amount' => '98.7500'}],
|
207
|
-
ActiveRecord::Base.connection.select_all("SELECT amount FROM no_currency_column_records WHERE id=1"))
|
208
|
-
end
|
209
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
|
3
|
-
# Associated with TestBaseclass
|
4
|
-
|
5
|
-
class FindSubclassesAssociate < ActiveRecord::Base
|
6
|
-
end
|
7
|
-
|
8
|
-
|
9
|
-
# Primary hierarchy of classes for testing.
|
10
|
-
|
11
|
-
class TestBaseclass < ActiveRecord::Base
|
12
|
-
set_table_name 'find_subclasses_records'
|
13
|
-
set_inheritance_column 'type_name' # usually left as default 'type'. rename to test renaming
|
14
|
-
belongs_to :associate, :foreign_key => 'associate_id', :class_name => 'FindSubclassesAssociate'
|
15
|
-
named_scope :with_coolness, lambda{|factor| {:conditions => {:coolness_factor => factor}}}
|
16
|
-
extend Invoicing::FindSubclasses
|
17
|
-
def self.coolness_factor; 3; end
|
18
|
-
end
|
19
|
-
|
20
|
-
class TestSubclass < TestBaseclass
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
class TestSubSubclass < TestSubclass
|
25
|
-
def self.coolness_factor; 5; end
|
26
|
-
end
|
27
|
-
|
28
|
-
module TestModule
|
29
|
-
class TestInsideModuleSubclass < TestBaseclass
|
30
|
-
def self.coolness_factor; nil; end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class TestOutsideModuleSubSubclass < TestModule::TestInsideModuleSubclass
|
35
|
-
def self.coolness_factor; 999; end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
# This class' table contains non-existent subclass names, to test errors
|
40
|
-
|
41
|
-
class SomeSillySuperclass < ActiveRecord::Base
|
42
|
-
extend Invoicing::FindSubclasses
|
43
|
-
set_table_name 'find_subclasses_non_existent'
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
#####################
|
48
|
-
|
49
|
-
class FindSubclassesTest < Test::Unit::TestCase
|
50
|
-
|
51
|
-
def test_known_subclasses
|
52
|
-
# All subclasses of TestBaseclass except for TestSubclassNotInDatabase
|
53
|
-
expected = ['TestBaseclass', 'TestModule::TestInsideModuleSubclass', 'TestOutsideModuleSubSubclass',
|
54
|
-
'TestSubSubclass', 'TestSubclass', 'TestSubclassInAnotherFile']
|
55
|
-
assert_equal expected, TestBaseclass.known_subclasses.map{|cls| cls.name}.sort
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_known_subclasses_for_subtype
|
59
|
-
expected = ['TestSubSubclass', 'TestSubclass']
|
60
|
-
assert_equal expected, TestSubclass.known_subclasses.map{|cls| cls.name}.sort
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_error_when_unknown_type_is_encountered
|
64
|
-
assert_raise ActiveRecord::SubclassNotFound do
|
65
|
-
SomeSillySuperclass.known_subclasses
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_class_method_condition_in_find
|
70
|
-
assert_equal [1, 2, 4], TestBaseclass.all(:conditions => {:coolness_factor => 3}).map{|r| r.id}.sort
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_class_method_condition_in_named_scope
|
74
|
-
assert_equal [6], TestBaseclass.with_coolness(999).map{|r| r.id}
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_class_method_condition_combined_with_column_condition_as_string_list
|
78
|
-
assert_equal [2, 4], TestBaseclass.with_coolness(3).all(:conditions => ["value LIKE ?", 'B%']).map{|r| r.id}.sort
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_class_method_condition_combined_with_column_condition_as_hash
|
82
|
-
assert_equal [1], TestBaseclass.scoped(:conditions => {:value => 'Mooo!', :coolness_factor => 3}).all.map{|r| r.id}
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_class_method_condition_combined_with_column_condition_on_joined_table_expressed_as_string
|
86
|
-
conditions = {'find_subclasses_associates.value' => 'Cool stuff', 'find_subclasses_records.coolness_factor' => 3}
|
87
|
-
assert_equal [1], TestBaseclass.all(:joins => :associate, :conditions => conditions).map{|r| r.id}
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_class_method_condition_combined_with_column_condition_on_joined_table_expressed_as_hash
|
91
|
-
conditions = {:find_subclasses_associates => {:value => 'Cool stuff'},
|
92
|
-
:find_subclasses_records => {:coolness_factor => 3}}
|
93
|
-
assert_equal [1], TestBaseclass.all(:joins => :associate, :conditions => conditions).map{|r| r.id}
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_class_method_condition_with_same_table_name
|
97
|
-
conditions = {'find_subclasses_records.value' => 'Baaa!', 'find_subclasses_records.coolness_factor' => 3}
|
98
|
-
assert_equal [2, 4], TestBaseclass.all(:conditions => conditions).map{|r| r.id}.sort
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_class_method_condition_with_list_of_alternatives
|
102
|
-
assert_equal [3, 6], TestBaseclass.all(:conditions => {:coolness_factor => [5, 999]}).map{|r| r.id}.sort
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_class_method_condition_with_range_of_alternatives
|
106
|
-
assert_equal [1, 2, 3, 4, 6], TestBaseclass.all(:conditions => {:coolness_factor => 1..1000}).map{|r| r.id}.sort
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_class_method_condition_invoked_on_subclass
|
110
|
-
assert_equal [2], TestSubclass.with_coolness(3).all.map{|r| r.id}
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_class_method_condition_false_type_coercion
|
114
|
-
assert_equal [5], TestBaseclass.find(:all, :conditions => {:coolness_factor => false}).map{|r| r.id}
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_class_method_condition_true_type_coercion
|
118
|
-
assert_equal [1, 2, 3, 4, 6], TestBaseclass.all(:conditions => {:coolness_factor => true}).map{|r| r.id}.sort
|
119
|
-
end
|
120
|
-
end
|
data/test/fixtures/README
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
The SQL files in this folder are executed once on the current ActiveRecord database connection
|
2
|
-
before the tests are run. Use them to set up a database schema and any contents (fixtures)
|
3
|
-
required by the tests. Tests are run in transactions and rolled back, so the database should
|
4
|
-
be restored back to the state defined in these files after each test.
|
5
|
-
|
6
|
-
It's important that all tables are created with option ENGINE=InnoDB, otherwise MySQL creates
|
7
|
-
MyISAM tables which do not support transactions.
|
@@ -1,22 +0,0 @@
|
|
1
|
-
DROP TABLE IF EXISTS cached_records;
|
2
|
-
|
3
|
-
CREATE TABLE cached_records (
|
4
|
-
id2 int primary key auto_increment,
|
5
|
-
value varchar(255)
|
6
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
7
|
-
|
8
|
-
INSERT INTO cached_records(id2, value) values(1, 'One'), (2, 'Two');
|
9
|
-
|
10
|
-
ALTER SEQUENCE cached_records_id2_seq start 1000;
|
11
|
-
|
12
|
-
|
13
|
-
DROP TABLE IF EXISTS refers_to_cached_records;
|
14
|
-
|
15
|
-
CREATE TABLE refers_to_cached_records (
|
16
|
-
id int primary key auto_increment,
|
17
|
-
cached_record_id int
|
18
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
19
|
-
|
20
|
-
INSERT INTO refers_to_cached_records(id, cached_record_id) values(1, 1), (2, 1), (3, NULL);
|
21
|
-
|
22
|
-
ALTER SEQUENCE refers_to_cached_records_id_seq start 1000;
|
@@ -1,28 +0,0 @@
|
|
1
|
-
DROP TABLE IF EXISTS class_info_test_records;
|
2
|
-
|
3
|
-
CREATE TABLE class_info_test_records (
|
4
|
-
id int primary key auto_increment,
|
5
|
-
value int,
|
6
|
-
type varchar(255)
|
7
|
-
);
|
8
|
-
|
9
|
-
INSERT INTO class_info_test_records (id, value, type) values
|
10
|
-
(1, 2, 'ClassInfoTestRecord'),
|
11
|
-
(2, 3, 'ClassInfoTestSubclass'),
|
12
|
-
(3, 3, 'ClassInfoTestSubclass2'),
|
13
|
-
(4, 3, 'ClassInfoTestSubSubclass');
|
14
|
-
|
15
|
-
ALTER SEQUENCE class_info_test_records_id_seq start 1000;
|
16
|
-
|
17
|
-
|
18
|
-
DROP TABLE IF EXISTS class_info_test2_records;
|
19
|
-
|
20
|
-
CREATE TABLE class_info_test2_records (
|
21
|
-
id int primary key auto_increment,
|
22
|
-
value int,
|
23
|
-
okapi varchar(255)
|
24
|
-
);
|
25
|
-
|
26
|
-
INSERT INTO class_info_test2_records(id, value, okapi) values(1, 1, 'OKAPI!');
|
27
|
-
|
28
|
-
ALTER SEQUENCE class_info_test2_records_id_seq start 1000;
|