datashift 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +211 -0
- data/LICENSE.txt +27 -0
- data/README.markdown +286 -0
- data/README.rdoc +19 -0
- data/Rakefile +96 -0
- data/VERSION +5 -0
- data/bin/autospec +16 -0
- data/bin/convert_to_should_syntax +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/jeweler +16 -0
- data/bin/ldiff +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/spree +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/bin/tt +16 -0
- data/datashift.gemspec +178 -0
- data/lib/applications/jruby/jexcel_file.rb +397 -0
- data/lib/applications/jruby/word.rb +79 -0
- data/lib/datashift.rb +114 -0
- data/lib/datashift/exceptions.rb +12 -0
- data/lib/datashift/file_definitions.rb +353 -0
- data/lib/datashift/mapping_file_definitions.rb +88 -0
- data/lib/datashift/method_detail.rb +237 -0
- data/lib/datashift/method_mapper.rb +257 -0
- data/lib/generators/csv_generator.rb +36 -0
- data/lib/generators/excel_generator.rb +122 -0
- data/lib/generators/generator_base.rb +14 -0
- data/lib/helpers/core_ext/to_b.rb +24 -0
- data/lib/helpers/spree_helper.rb +131 -0
- data/lib/java/poi-3.7/._poi-3.7-20101029.jar5645100390082102460.tmp +0 -0
- data/lib/java/poi-3.7/LICENSE +507 -0
- data/lib/java/poi-3.7/NOTICE +21 -0
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -0
- data/lib/java/poi-3.7/lib/commons-logging-1.1.jar +0 -0
- data/lib/java/poi-3.7/lib/junit-3.8.1.jar +0 -0
- data/lib/java/poi-3.7/lib/log4j-1.2.13.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/dom4j-1.6.1.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar +0 -0
- data/lib/java/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar +0 -0
- data/lib/java/poi-3.7/poi-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-examples-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar +0 -0
- data/lib/java/poi-3.7/poi-scratchpad-3.7-20101029.jar +0 -0
- data/lib/loaders/csv_loader.rb +99 -0
- data/lib/loaders/excel_loader.rb +150 -0
- data/lib/loaders/loader_base.rb +332 -0
- data/lib/loaders/spreadsheet_loader.rb +137 -0
- data/lib/loaders/spree/image_loader.rb +46 -0
- data/lib/loaders/spree/product_loader.rb +225 -0
- data/spec/csv_loader_spec.rb +31 -0
- data/spec/datashift_spec.rb +27 -0
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -0
- data/spec/excel_generator_spec.rb +79 -0
- data/spec/excel_loader_spec.rb +177 -0
- data/spec/file_definitions.rb +141 -0
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xls +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/config/database.yml +25 -0
- data/spec/fixtures/interact_models_db.sqlite +0 -0
- data/spec/fixtures/interact_spree_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
- data/spec/fixtures/simple_export_spec.xls +0 -0
- data/spec/fixtures/simple_template_spec.xls +0 -0
- data/spec/fixtures/spree/SpreeProducts.csv +4 -0
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -0
- data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -0
- data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +57 -0
- data/spec/loader_spec.rb +121 -0
- data/spec/method_mapper_spec.rb +238 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/spree_generator_spec.rb +65 -0
- data/spec/spree_loader_spec.rb +311 -0
- data/spec/spree_method_mapping_spec.rb +215 -0
- data/tasks/config/seed_fu_product_template.erb +15 -0
- data/tasks/config/tidy_config.txt +13 -0
- data/tasks/db_tasks.rake +65 -0
- data/tasks/excel_generator.rake +79 -0
- data/tasks/file_tasks.rake +37 -0
- data/tasks/import/csv.rake +50 -0
- data/tasks/import/excel.rake +67 -0
- data/tasks/spree/image_load.rake +109 -0
- data/tasks/spree/product_loader.rake +44 -0
- data/tasks/word_to_seedfu.rake +167 -0
- data/test/helper.rb +18 -0
- data/test/test_interact.rb +7 -0
- metadata +301 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
# Author :: Tom Statter
|
2
|
+
# Date :: Aug 2011
|
3
|
+
# License:: MIT
|
4
|
+
#
|
5
|
+
# Details:: Migration to create a test database that exercises all aspects of Active Record models
|
6
|
+
#
|
7
|
+
|
8
|
+
class CreateTestBed < ActiveRecord::Migration
|
9
|
+
|
10
|
+
def self.up
|
11
|
+
|
12
|
+
# has many :milestones
|
13
|
+
create_table :projects do |t|
|
14
|
+
t.string :title
|
15
|
+
t.string :value_as_string
|
16
|
+
t.text :value_as_text
|
17
|
+
t.boolean :value_as_boolean, :default => false
|
18
|
+
t.datetime :value_as_datetime, :default => nil
|
19
|
+
t.integer :value_as_integer, :default => 0
|
20
|
+
t.decimal :value_as_double, :precision => 8, :scale => 2, :default => 0.0
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
|
24
|
+
# belongs_to :project, project => has_many
|
25
|
+
create_table :milestones do |t|
|
26
|
+
t.string :name
|
27
|
+
t.datetime :datetime, :default => nil
|
28
|
+
t.decimal :cost, :precision => 8, :scale => 2, :default => 0.0
|
29
|
+
t.references :project
|
30
|
+
t.timestamps
|
31
|
+
end
|
32
|
+
|
33
|
+
# belongs_to :project, project => has_one
|
34
|
+
create_table :owners do |t|
|
35
|
+
t.string :name
|
36
|
+
t.references :project
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
# has_belongs_to_many :project
|
41
|
+
create_table :categories do |t|
|
42
|
+
t.string :reference
|
43
|
+
t.timestamps
|
44
|
+
end
|
45
|
+
|
46
|
+
# testing has_belongs_to_many (hence no id)
|
47
|
+
create_table :categories_projects, :id => false do |t|
|
48
|
+
t.references :category
|
49
|
+
t.references :project
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :versions do |t|
|
53
|
+
t.string :name
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
|
57
|
+
# testing project has_many release + versions :through
|
58
|
+
create_table :loader_releases do |t|
|
59
|
+
t.string :name
|
60
|
+
t.references :project
|
61
|
+
t.references :version
|
62
|
+
t.timestamps
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
create_table :long_and_complex_table_linked_to_versions do |t|
|
67
|
+
t.references :version
|
68
|
+
end
|
69
|
+
|
70
|
+
create_table :empties do |t|
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.down
|
76
|
+
drop_table :projects
|
77
|
+
drop_table :categories
|
78
|
+
drop_table :loader_releases
|
79
|
+
drop_table :versions
|
80
|
+
drop_table :categories_projectss
|
81
|
+
drop_table :milestones
|
82
|
+
drop_table :long_and_complex_table_linked_to_versions
|
83
|
+
drop_table :empties
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for Excel aspect of Active Record Loader
|
7
|
+
#
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
+
|
10
|
+
if(Guards::jruby?)
|
11
|
+
require 'erb'
|
12
|
+
require 'excel_generator'
|
13
|
+
|
14
|
+
include DataShift
|
15
|
+
|
16
|
+
describe 'Excel Generator' do
|
17
|
+
|
18
|
+
before(:all) do
|
19
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
20
|
+
|
21
|
+
# load our test model definitions - Project etc
|
22
|
+
require File.join($DataShiftFixturePath, 'test_model_defs')
|
23
|
+
|
24
|
+
# handle migration changes or reset of test DB
|
25
|
+
migrate_up
|
26
|
+
|
27
|
+
db_clear() # todo read up about proper transactional fixtures
|
28
|
+
results_clear()
|
29
|
+
|
30
|
+
@klazz = Project
|
31
|
+
@assoc_klazz = Category
|
32
|
+
end
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
MethodMapper.clear
|
36
|
+
MethodMapper.find_operators( @klazz )
|
37
|
+
MethodMapper.find_operators( @assoc_klazz )
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to create a new excel generator" do
|
41
|
+
generator = ExcelGenerator.new( 'dummy.xls' )
|
42
|
+
|
43
|
+
generator.should_not be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should generate template .xls file from model" do
|
47
|
+
|
48
|
+
expect = result_file('project_template_spec.xls')
|
49
|
+
|
50
|
+
gen = ExcelGenerator.new( expect )
|
51
|
+
|
52
|
+
gen.generate(Project)
|
53
|
+
|
54
|
+
File.exists?(expect).should be_true
|
55
|
+
|
56
|
+
puts "Can manually check file @ #{expect}"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should export a simple model to .xls spreedsheet" do
|
60
|
+
|
61
|
+
Project.create( :value_as_string => 'Value as Text', :value_as_boolean => true, :value_as_double => 75.672)
|
62
|
+
#001 Demo string blah blah 2011-02-14 1.00 320.00
|
63
|
+
|
64
|
+
expect= result_file('simple_export_spec.xls')
|
65
|
+
|
66
|
+
gen = ExcelGenerator.new(expect)
|
67
|
+
|
68
|
+
items = Project.all
|
69
|
+
|
70
|
+
gen.export(items)
|
71
|
+
|
72
|
+
File.exists?(expect).should be_true
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
else
|
78
|
+
puts "WARNING: skipped excel_generator_spec : Requires JRUBY - JExcelFile requires JAVA"
|
79
|
+
end # jruby
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for Excel aspect of Active Record Loader
|
7
|
+
#
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
+
|
10
|
+
if(Guards::jruby?)
|
11
|
+
|
12
|
+
require 'erb'
|
13
|
+
require 'excel_loader'
|
14
|
+
|
15
|
+
include DataShift
|
16
|
+
|
17
|
+
describe 'Excel Loader' do
|
18
|
+
|
19
|
+
before(:all) do
|
20
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
21
|
+
|
22
|
+
# load our test model definitions - Project etc
|
23
|
+
require File.join($DataShiftFixturePath, 'test_model_defs')
|
24
|
+
|
25
|
+
# handle migration changes or reset of test DB
|
26
|
+
migrate_up
|
27
|
+
|
28
|
+
db_clear() # todo read up about proper transactional fixtures
|
29
|
+
|
30
|
+
|
31
|
+
@klazz = Project
|
32
|
+
@assoc_klazz = Category
|
33
|
+
end
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
|
37
|
+
Project.delete_all
|
38
|
+
|
39
|
+
%w{category_001 category_002 category_003}.each do |cat|
|
40
|
+
@assoc_klazz.find_or_create_by_reference(cat)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
MethodMapper.clear
|
45
|
+
MethodMapper.find_operators( @klazz )
|
46
|
+
MethodMapper.find_operators( @assoc_klazz )
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be able to create a new excel loader and load object" do
|
50
|
+
loader = ExcelLoader.new( @klazz)
|
51
|
+
|
52
|
+
loader.load_object.should_not be_nil
|
53
|
+
loader.load_object.should be_is_a(@klazz)
|
54
|
+
loader.load_object.new_record?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should process a simple .xls spreedsheet" do
|
58
|
+
|
59
|
+
loader = ExcelLoader.new(@klazz)
|
60
|
+
|
61
|
+
count = @klazz.count
|
62
|
+
loader.perform_load( $DataShiftFixturePath + '/SimpleProjects.xls')
|
63
|
+
|
64
|
+
loader.loaded_count.should == (@klazz.count - count)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should process multiple associationss from single column" do
|
69
|
+
|
70
|
+
@klazz.find_by_title('001').should be_nil
|
71
|
+
count = @klazz.count
|
72
|
+
|
73
|
+
loader = ExcelLoader.new(@klazz)
|
74
|
+
|
75
|
+
loader.perform_load( $DataShiftFixturePath + '/ProjectsSingleCategories.xls')
|
76
|
+
|
77
|
+
loader.loaded_count.should be > 3
|
78
|
+
loader.loaded_count.should == (@klazz.count - count)
|
79
|
+
|
80
|
+
{'001' => 2, '002' => 1, '003' => 3, '099' => 0 }.each do|title, expected|
|
81
|
+
project = @klazz.find_by_title(title)
|
82
|
+
|
83
|
+
project.should_not be_nil
|
84
|
+
puts "#{project.inspect} [#{project.categories.size}]"
|
85
|
+
|
86
|
+
project.should have(expected).categories
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should process multiple associations in excel spreedsheet" do
|
91
|
+
|
92
|
+
loader = ExcelLoader.new(Project)
|
93
|
+
|
94
|
+
count = Project.count
|
95
|
+
loader.perform_load( $DataShiftFixturePath + '/ProjectsMultiCategories.xls')
|
96
|
+
|
97
|
+
loader.loaded_count.should == (Project.count - count)
|
98
|
+
|
99
|
+
{'004' => 3, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
|
100
|
+
project = @klazz.find_by_title(title)
|
101
|
+
|
102
|
+
project.should_not be_nil
|
103
|
+
|
104
|
+
project.should have(expected).categories
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should process excel spreedsheet with extra undefined columns" do
|
110
|
+
loader = ExcelLoader.new(Project)
|
111
|
+
lambda {loader.perform_load( ifixture_file('BadAssociationName.xls') ) }.should_not raise_error
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should NOT process excel spreedsheet with extra undefined columns when strict mode" do
|
115
|
+
loader = ExcelLoader.new(Project)
|
116
|
+
expect {loader.perform_load( ifixture_file('BadAssociationName.xls'), :strict => true)}.to raise_error(MappingDefinitionError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise an error when mandatory columns missing" do
|
120
|
+
loader = ExcelLoader.new(Project)
|
121
|
+
expect {loader.perform_load($DataShiftFixturePath + '/ProjectsMultiCategories.xls', :mandatory => ['not_an_option', 'must_be_there'] )}.to raise_error(DataShift::MissingMandatoryError)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should provide facility to set default values", :focus => true do
|
125
|
+
loader = ExcelLoader.new(Project)
|
126
|
+
|
127
|
+
loader.set_default_value('value_as_string', 'some default text' )
|
128
|
+
loader.set_default_value('value_as_double', 45.467 )
|
129
|
+
loader.set_default_value('value_as_boolean', true )
|
130
|
+
|
131
|
+
texpected = Time.now.to_s(:db)
|
132
|
+
|
133
|
+
loader.set_default_value('value_as_datetime', texpected )
|
134
|
+
|
135
|
+
#value_as_string Value as Text value as datetime value_as_boolean value_as_double category
|
136
|
+
|
137
|
+
loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
|
138
|
+
|
139
|
+
p = Project.find_by_title( '099' )
|
140
|
+
|
141
|
+
p.should_not be_nil
|
142
|
+
|
143
|
+
p.value_as_string.should == 'some default text'
|
144
|
+
p.value_as_double.should == 45.467
|
145
|
+
p.value_as_boolean.should == true
|
146
|
+
p.value_as_datetime.should == texpected
|
147
|
+
|
148
|
+
p_no_defs = Project.first
|
149
|
+
|
150
|
+
p_no_defs.value_as_string.should_not == 'some default text'
|
151
|
+
p_no_defs.value_as_double.should_not == 45.467
|
152
|
+
p_no_defs.value_as_datetime.should_not == texpected
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should provide facility to set pre and post fix values", :focus => true do
|
157
|
+
loader = ExcelLoader.new(Project)
|
158
|
+
|
159
|
+
loader.set_prefix('value_as_string', 'myprefix' )
|
160
|
+
loader.set_postfix('value_as_string', 'my post fix' )
|
161
|
+
|
162
|
+
#value_as_string Value as Text value as datetime value_as_boolean value_as_double category
|
163
|
+
|
164
|
+
loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
|
165
|
+
|
166
|
+
p = Project.find_by_title( '001' )
|
167
|
+
|
168
|
+
p.should_not be_nil
|
169
|
+
|
170
|
+
p.value_as_string.should == 'myprefixDemo stringmy post fix'
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
else
|
176
|
+
puts "WARNING: skipped excel_loader_spec : Requires JRUBY - JExcelFile requires JAVA"
|
177
|
+
end # jruby
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib', 'engine')
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'file_definitions'
|
9
|
+
|
10
|
+
class File_definitions < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_fields_string
|
16
|
+
klass = Object.const_set('B', Class.new)
|
17
|
+
|
18
|
+
klass.module_eval do
|
19
|
+
include FileDefinitions
|
20
|
+
create_field_definition 'a_string'
|
21
|
+
|
22
|
+
create_field_attr_accessors
|
23
|
+
end
|
24
|
+
|
25
|
+
x = B.new '33'
|
26
|
+
assert_equal '33', x.a_string
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def test_fields_symbols
|
32
|
+
klass = Object.const_set('SymClass', Class.new)
|
33
|
+
klass.module_eval do
|
34
|
+
include FileDefinitions
|
35
|
+
create_field_definition [:a_symbol, :b_symbol]
|
36
|
+
|
37
|
+
create_field_attr_accessors
|
38
|
+
end
|
39
|
+
|
40
|
+
assert SymClass.new.respond_to? :a_symbol
|
41
|
+
assert SymClass.new.respond_to? :b_symbol
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_fields_strings
|
45
|
+
klass = Object.const_set('A', Class.new)
|
46
|
+
klass.module_eval do
|
47
|
+
include FileDefinitions
|
48
|
+
create_field_definition %w{abc def ghi jkl}
|
49
|
+
|
50
|
+
create_field_attr_accessors
|
51
|
+
end
|
52
|
+
|
53
|
+
x = A.new
|
54
|
+
|
55
|
+
assert_equal ["abc", "def", "ghi", "jkl"], A.field_definition.sort
|
56
|
+
|
57
|
+
A::add_field( "xyz" )
|
58
|
+
|
59
|
+
line = '1,2,3,4, 5'
|
60
|
+
x = A.new(line)
|
61
|
+
|
62
|
+
assert x.respond_to? 'abc'
|
63
|
+
assert x.respond_to? 'abc='
|
64
|
+
assert x.respond_to? :jkl
|
65
|
+
assert_equal x.current_line, line
|
66
|
+
assert_equal '1', x.abc
|
67
|
+
assert_equal 1.0, x.abc.to_f
|
68
|
+
assert_equal 1, x.abc.to_i
|
69
|
+
assert_equal '4', x.jkl
|
70
|
+
assert_equal ' 5', x.xyz
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_fixed_strings
|
75
|
+
|
76
|
+
klass = Object.const_set('AFixed', Class.new)
|
77
|
+
|
78
|
+
klass.module_eval do
|
79
|
+
include FileDefinitions
|
80
|
+
|
81
|
+
create_fixed_definition( 'value' => (0..7), 'date' => (8..15), :ccy => (16..18) )
|
82
|
+
|
83
|
+
create_field_attr_accessors
|
84
|
+
end
|
85
|
+
|
86
|
+
assert AFixed.respond_to?('fixed_definition')
|
87
|
+
assert AFixed.respond_to?('field_definition')
|
88
|
+
assert AFixed.respond_to?('add_field')
|
89
|
+
assert AFixed.respond_to?('file_set_field_by_map')
|
90
|
+
assert AFixed.respond_to?('split_on')
|
91
|
+
assert AFixed.respond_to?('split_on_write')
|
92
|
+
|
93
|
+
x = AFixed.new('0123456719990113EUR')
|
94
|
+
|
95
|
+
assert x.respond_to?('value')
|
96
|
+
assert x.respond_to?(:date)
|
97
|
+
assert x.respond_to?('ccy')
|
98
|
+
|
99
|
+
assert AFixed.field_definition.include?('ccy')
|
100
|
+
|
101
|
+
assert_equal 3, AFixed.field_definition.size
|
102
|
+
assert_equal 3, AFixed.fixed_definition.keys.size
|
103
|
+
|
104
|
+
assert_equal ["ccy", "date", "value"], AFixed.field_definition.sort
|
105
|
+
|
106
|
+
assert_equal AFixed.field_definition.sort, AFixed.fixed_definition.keys.sort
|
107
|
+
|
108
|
+
assert_instance_of Range, AFixed.fixed_definition.values[0]
|
109
|
+
|
110
|
+
assert_equal x.current_line, '0123456719990113EUR'
|
111
|
+
assert_equal x.value, '01234567'
|
112
|
+
assert_equal x.date, '19990113'
|
113
|
+
assert_equal x.ccy, 'EUR'
|
114
|
+
|
115
|
+
assert x.respond_to?(:parse)
|
116
|
+
|
117
|
+
x.parse('9876543220100630USD')
|
118
|
+
|
119
|
+
assert_equal x.current_line, '9876543220100630USD'
|
120
|
+
assert_equal x.value, '98765432'
|
121
|
+
assert_equal x.date, '20100630'
|
122
|
+
assert_equal x.ccy, 'USD'
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_bad_setup
|
127
|
+
klass = Object.const_set('ABadClass', Class.new)
|
128
|
+
begin
|
129
|
+
klass.module_eval do
|
130
|
+
include FileDefinitions
|
131
|
+
|
132
|
+
create_fixed_definition( 'abc' )
|
133
|
+
|
134
|
+
create_field_attr_accessors
|
135
|
+
end
|
136
|
+
flunk # We should never get here
|
137
|
+
rescue => e
|
138
|
+
assert e
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|