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
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<% adapter = 'sqlite3' %>
|
2
|
+
<% adapter = 'jdbcsqlite3' if(Guards::jruby? ) %>
|
3
|
+
|
4
|
+
test_mysql:
|
5
|
+
adapter: jdbcmysql
|
6
|
+
database: interact_test_db
|
7
|
+
username: test
|
8
|
+
password: test
|
9
|
+
host: localhost
|
10
|
+
|
11
|
+
test_memory:
|
12
|
+
adapter: <%= adapter %>
|
13
|
+
database: :memory
|
14
|
+
|
15
|
+
test_file:
|
16
|
+
adapter: <%= adapter %>
|
17
|
+
database: <%= File.join($DataShiftFixturePath, 'interact_models_db.sqlite') %>
|
18
|
+
encoding: utf8
|
19
|
+
host: localhost
|
20
|
+
|
21
|
+
test_spree_standalone:
|
22
|
+
adapter: <%= adapter %>
|
23
|
+
database: <%= File.join($DataShiftFixturePath, 'interact_spree_db.sqlite') %>
|
24
|
+
encoding: utf8
|
25
|
+
host: localhost
|
Binary file
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
"Name","Description","Available On"," Price","CostPrice","product_properties","count_on_hand","Taxons","Option Types"
|
2
|
+
"Demo Product for AR Loader","blah blah","2011-02-14",400.00,320.00,"name:test_pp_001",12,"Paintings","mime_type:jpeg, PDF,PNG"
|
3
|
+
"Demo Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,"name:test_pp_001",5,"Paintings","mime_type:jpeg, PDF,PNG"
|
4
|
+
"Demo third row in future","more blah blah","2012-07-01",50.34,23.34,"name:test_pp_002,test_pp_003",23,"Drawings","mime_type:jpeg,PDF,PNG|print_type:black_white,colour"
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
"SKU","Description","Available On","CostPrice","product_properties","count_on_hand","Taxons","Option Types"
|
2
|
+
"DEMO_001","blah blah","2011-02-14",320.00,"name:test_pp_001",12,"Paintings","mime_type:jpeg, PDF,PNG"
|
3
|
+
"DEMO_002","less blah","2011-05-14",30.00,"name:test_pp_001",5,"Paintings","mime_type:jpeg, PDF,PNG"
|
4
|
+
"DEMO_003","more blah blah","2012-07-01",23.34,"name:test_pp_002,test_pp_003",23,"Drawings","mime_type:jpeg,PDF,PNG|print_type:black_white,colour"
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
"SKU","Name","Description","Available On"," Price","CostPrice","product_properties","Taxons","Variants","count_on_hand"
|
2
|
+
"DEMO_001","Demo Product for AR Loader","blah blah","2011-02-14",399.99,320.00,"test_pp_001","Paintings|WaterColour","mime_type:jpeg,PDF,PNG","12|6|7"
|
3
|
+
"DEMO_002","Demo Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,"test_pp_003","Paintings|Landscape|Oils","mime_type:jpeg, PDF,PNG","5|4|2"
|
4
|
+
"DEMO_003","Demo third row in future","more blah blah","2012-07-01",50.34,23.34,"test_pp_002|test_pp_003:Example free value|yet_another_property","Drawings","mime_type:jpeg,PDF,PNG|print_type:black_white,colour","12|4|7|12|18"
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
"SKU","Name","Description","Available On"," Price","CostPrice","product_properties","product_properties","product_properties","Taxons","Taxons","Taxons","Option Types","Option Types","Variants","Variants","Variants","count_on_hand"
|
2
|
+
"DEMO_001","Demo Product for AR Loader","blah blah","2011-02-14",399.99,320.00,"test_pp_001",,,"Paintings","WaterColour",,"mime_type:jpeg","mime_type:PDF","mime_type:PNG",,,"12|6|7"
|
3
|
+
"DEMO_002","Demo Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,"test_pp_003",,,"Paintings","Landscape","Oils","mime_type:jpeg","mime_type:PDF","mime_type:PNG",,,"5|4|2"
|
4
|
+
"DEMO_003","Demo third row in future","more blah blah","2012-07-01",50.34,23.34,"test_pp_002","test_pp_003:Example free value","yet_another_property","Drawings",,,"mime_type:jpeg","mime_type:PDF","mime_type:PNG","print_type:black_white","print_type:colour","12|4|7|12|18"
|
Binary file
|
@@ -0,0 +1,4 @@
|
|
1
|
+
"SKU","Name","Description","Available On"," Price","CostPrice","count_on_hand","Option Types"
|
2
|
+
"SIMPLE_001","Simple Product for AR Loader","blah blah","2011-02-14",345.78,320.00,12,"mime_type"
|
3
|
+
"SIMPLE_002","Simple Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,5,"mime_type"
|
4
|
+
"SIMPLE_003","Simple third row avail in future","more blah blah","2012-07-01",50.34,23.34,23,"mime_type|print_type"
|
Binary file
|
Binary file
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
class Project < ActiveRecord::Base
|
3
|
+
|
4
|
+
has_one :owner
|
5
|
+
|
6
|
+
has_many :milestones
|
7
|
+
|
8
|
+
has_many :loader_releases
|
9
|
+
has_many :versions, :through => :loader_releases
|
10
|
+
|
11
|
+
|
12
|
+
#has_many :release_versions, :through => :loader_releases, :source => :versions
|
13
|
+
|
14
|
+
has_and_belongs_to_many :categories
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
class Owner < ActiveRecord::Base
|
19
|
+
belongs_to :project
|
20
|
+
end
|
21
|
+
|
22
|
+
class Milestone < ActiveRecord::Base
|
23
|
+
belongs_to :project
|
24
|
+
#validate the name, cost
|
25
|
+
|
26
|
+
delegate :title, :title=, :to => :project
|
27
|
+
end
|
28
|
+
|
29
|
+
# had_and_belongs to join table
|
30
|
+
class Category < ActiveRecord::Base
|
31
|
+
has_and_belongs_to_many :projects
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
class Version < ActiveRecord::Base
|
36
|
+
has_many :releases
|
37
|
+
|
38
|
+
has_one :long_and_complex_table_linked_to_version
|
39
|
+
end
|
40
|
+
|
41
|
+
# Join Table with additional columns
|
42
|
+
class LoaderRelease < ActiveRecord::Base
|
43
|
+
|
44
|
+
belongs_to :project
|
45
|
+
belongs_to :version
|
46
|
+
|
47
|
+
#validate the name
|
48
|
+
end
|
49
|
+
|
50
|
+
class Empty < ActiveRecord::Base
|
51
|
+
end
|
52
|
+
|
53
|
+
# Join Table with additional columns
|
54
|
+
class LongAndComplexTableLinkedToVersion < ActiveRecord::Base
|
55
|
+
|
56
|
+
belongs_to :version
|
57
|
+
end
|
data/spec/loader_spec.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for base class Loader
|
7
|
+
#
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
+
|
10
|
+
require 'erb'
|
11
|
+
|
12
|
+
describe 'Basic Loader' do
|
13
|
+
|
14
|
+
before(:all) do
|
15
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
16
|
+
|
17
|
+
# load our test model definitions - Project etc
|
18
|
+
require File.join($DataShiftFixturePath, 'test_model_defs')
|
19
|
+
|
20
|
+
migrate_up
|
21
|
+
@klazz = Project
|
22
|
+
end
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
MethodMapper.clear
|
26
|
+
MethodMapper.find_operators( @klazz )
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to create a new loader and load object" do
|
30
|
+
loader = LoaderBase.new( @klazz )
|
31
|
+
|
32
|
+
loader.load_object.should_not be_nil
|
33
|
+
loader.load_object.should be_is_a(@klazz)
|
34
|
+
loader.load_object.new_record?.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should process a string field against an assigment method detail" do
|
38
|
+
|
39
|
+
loader = LoaderBase.new(Project)
|
40
|
+
|
41
|
+
column = 'Value As String'
|
42
|
+
row = 'Another Lazy fox '
|
43
|
+
|
44
|
+
loader.find_and_process(column, row)
|
45
|
+
|
46
|
+
loader.load_object.value_as_string.should == row
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should process a text field against an assigment method detail" do
|
50
|
+
|
51
|
+
loader = LoaderBase.new(Project)
|
52
|
+
|
53
|
+
column = :value_as_text
|
54
|
+
row = "Another Lazy fox\nJumped over something and bumped,\nHis head"
|
55
|
+
|
56
|
+
loader.find_and_process(column, row)
|
57
|
+
|
58
|
+
loader.load_object.value_as_text.should == row
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should process a boolean field against an assigment method detail" do
|
63
|
+
|
64
|
+
loader = LoaderBase.new(Project)
|
65
|
+
|
66
|
+
column = :value_as_boolean
|
67
|
+
row = true
|
68
|
+
|
69
|
+
loader.find_and_process(column, row)
|
70
|
+
|
71
|
+
loader.load_object.value_as_boolean.should == row
|
72
|
+
|
73
|
+
row = 'false'
|
74
|
+
|
75
|
+
loader.find_and_process(column, row)
|
76
|
+
|
77
|
+
loader.load_object.value_as_boolean.should == false
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should process a double field against an assigment operator" do
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should process various date formats against a date assigment operator" do
|
86
|
+
|
87
|
+
loader = LoaderBase.new(Project)
|
88
|
+
|
89
|
+
column = :value_as_datetime
|
90
|
+
|
91
|
+
loader.find_and_process(column, Time.now)
|
92
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
93
|
+
|
94
|
+
loader.find_and_process(column, "2011-07-23")
|
95
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
96
|
+
|
97
|
+
loader.find_and_process(column, "Sat Jul 23 09:01:56 +0100 2011")
|
98
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
99
|
+
|
100
|
+
loader.find_and_process(column, Time.now.to_s(:db))
|
101
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
102
|
+
|
103
|
+
loader.find_and_process(column, "Jul 23 2011 23:02:59")
|
104
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
105
|
+
|
106
|
+
if(Guards.jruby?)
|
107
|
+
loader.find_and_process(column, "07/23/2011") # dd/mm/YYYY
|
108
|
+
loader.load_object.value_as_datetime.should_not be_nil
|
109
|
+
end
|
110
|
+
|
111
|
+
# bad casts - TODO - is this really an error needs raising ?
|
112
|
+
loader.find_and_process(column, "2011 07 23")
|
113
|
+
loader.load_object.value_as_datetime.should be_nil
|
114
|
+
|
115
|
+
|
116
|
+
loader.find_and_process(column, "2011-23-07")
|
117
|
+
loader.load_object.value_as_datetime.should be_nil
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for MethodMapper aspect of Active Record Loader
|
7
|
+
# MethodMapper provides the bridge between 'strings' e.g column headings
|
8
|
+
# and a classes different types of assignment operators
|
9
|
+
#
|
10
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
11
|
+
|
12
|
+
describe 'Method Mapping' do
|
13
|
+
|
14
|
+
before(:all) do
|
15
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
16
|
+
migrate_up
|
17
|
+
@klazz = Project
|
18
|
+
@assoc_klazz = Milestone
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
MethodMapper.clear
|
23
|
+
MethodMapper.find_operators( @klazz )
|
24
|
+
MethodMapper.find_operators( @assoc_klazz )
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should populate method map for a given AR model" do
|
28
|
+
|
29
|
+
MethodMapper.has_many.should_not be_empty
|
30
|
+
MethodMapper.has_many[Project].should include('milestones')
|
31
|
+
|
32
|
+
MethodMapper.assignments.should_not be_empty
|
33
|
+
MethodMapper.assignments[Project].should include('id')
|
34
|
+
MethodMapper.assignments[Project].should include('value_as_string')
|
35
|
+
MethodMapper.assignments[Project].should include('value_as_text')
|
36
|
+
|
37
|
+
MethodMapper.belongs_to.should_not be_empty
|
38
|
+
MethodMapper.belongs_to[Project].should be_empty
|
39
|
+
|
40
|
+
|
41
|
+
MethodMapper.column_types.should be_is_a(Hash)
|
42
|
+
MethodMapper.column_types.should_not be_empty
|
43
|
+
MethodMapper.column_types[Project].size.should == Project.columns.size
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should populate assigment members without the equivalent association names" do
|
49
|
+
|
50
|
+
# we should remove has-many & belongs_to from basic assignment set as they require a DB lookup
|
51
|
+
# or a Model.create call, not a simple assignment
|
52
|
+
|
53
|
+
MethodMapper.assignments_for(@klazz).should_not include( MethodMapper.belongs_to_for(@klazz) )
|
54
|
+
MethodMapper.assignments_for(@klazz).should_not include( MethodMapper.has_many_for(@klazz) )
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it "should populate assignment operators for method details for different forms of a column name" do
|
59
|
+
|
60
|
+
[:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
|
61
|
+
|
62
|
+
method_details = MethodMapper.find_method_detail( @klazz, format )
|
63
|
+
|
64
|
+
method_details.class.should == MethodDetail
|
65
|
+
|
66
|
+
method_details.name.should eq( format.to_s )
|
67
|
+
|
68
|
+
method_details.operator.should == 'value_as_string'
|
69
|
+
method_details.operator_for(:assignment).should == 'value_as_string'
|
70
|
+
|
71
|
+
method_details.operator?('value_as_string').should be_true
|
72
|
+
method_details.operator?('blah_as_string').should be_false
|
73
|
+
|
74
|
+
method_details.operator_for(:belongs_to).should be_nil
|
75
|
+
method_details.operator_for(:has_many).should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Note : Not all assignments will currently have a column type, for example
|
81
|
+
# those that are derived from a delegate_belongs_to
|
82
|
+
|
83
|
+
it "should populate column types for assignment operators in method details" do
|
84
|
+
|
85
|
+
[:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
|
86
|
+
|
87
|
+
method_details = MethodMapper.find_method_detail( @klazz, format )
|
88
|
+
|
89
|
+
method_details.class.should == MethodDetail
|
90
|
+
|
91
|
+
method_details.col_type.should_not be_nil
|
92
|
+
method_details.col_type.name.should == 'value_as_string'
|
93
|
+
method_details.col_type.default.should == nil
|
94
|
+
method_details.col_type.sql_type.should include 'varchar(255)' # db specific, sqlite
|
95
|
+
method_details.col_type.type.should == :string
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should populate required Class for assignment operators based on column type" do
|
100
|
+
|
101
|
+
[:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
|
102
|
+
|
103
|
+
method_details = MethodMapper.find_method_detail( Project, format )
|
104
|
+
|
105
|
+
method_details.operator_class_name.should == 'String'
|
106
|
+
method_details.operator_class.should be_is_a(Class)
|
107
|
+
method_details.operator_class.should == String
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should populate belongs_to operator for method details for different forms of a column name" do
|
113
|
+
|
114
|
+
# milestone.project = project.id
|
115
|
+
[:project, 'project', "PROJECT", "prOJECt"].each do |format|
|
116
|
+
|
117
|
+
method_details = MethodMapper.find_method_detail( Milestone, format )
|
118
|
+
|
119
|
+
method_details.should_not be_nil
|
120
|
+
|
121
|
+
method_details.operator.should == 'project'
|
122
|
+
method_details.operator_for(:belongs_to).should == 'project'
|
123
|
+
|
124
|
+
method_details.operator_for(:assignment).should be_nil
|
125
|
+
method_details.operator_for(:has_many).should be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should populate required Class for belongs_to operator method details" do
|
131
|
+
|
132
|
+
MethodMapper.find_operators( LoaderRelease )
|
133
|
+
MethodMapper.find_operators( LongAndComplexTableLinkedToVersion )
|
134
|
+
|
135
|
+
# release.project = project.id
|
136
|
+
[:project, 'project', "PROJECT", "prOJECt"].each do |format|
|
137
|
+
|
138
|
+
method_details = MethodMapper.find_method_detail( LoaderRelease, format )
|
139
|
+
|
140
|
+
method_details.operator_class_name.should == 'Project'
|
141
|
+
method_details.operator_class.should == Project
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
#LongAndComplexTableLinkedToVersion.version = version.id
|
146
|
+
|
147
|
+
[:version, "Version", "verSION"].each do |format|
|
148
|
+
method_details = MethodMapper.find_method_detail( LongAndComplexTableLinkedToVersion, format )
|
149
|
+
|
150
|
+
method_details.operator_type.should == :belongs_to
|
151
|
+
|
152
|
+
method_details.operator_class_name.should == 'Version'
|
153
|
+
method_details.operator_class.should == Version
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should populate required Class for has_one operator method details" do
|
158
|
+
|
159
|
+
MethodMapper.find_operators( Version )
|
160
|
+
|
161
|
+
# version.long_and_complex_table_linked_to_version = LongAndComplexTableLinkedToVersion.create()
|
162
|
+
|
163
|
+
[:long_and_complex_table_linked_to_version, 'LongAndComplexTableLinkedToVersion', "Long And Complex_Table_Linked To Version", "Long_And_Complex_Table_Linked_To_Version"].each do |format|
|
164
|
+
method_details = MethodMapper.find_method_detail( Version, format )
|
165
|
+
|
166
|
+
method_details.should_not be_nil
|
167
|
+
|
168
|
+
method_details.operator.should == 'long_and_complex_table_linked_to_version'
|
169
|
+
|
170
|
+
method_details.operator_type.should == :has_one
|
171
|
+
|
172
|
+
method_details.operator_class_name.should == 'LongAndComplexTableLinkedToVersion'
|
173
|
+
method_details.operator_class.should == LongAndComplexTableLinkedToVersion
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
it "should find has_many operator for method details" do
|
179
|
+
|
180
|
+
[:milestones, "Mile Stones", 'mileSTONES', 'MileStones'].each do |format|
|
181
|
+
|
182
|
+
method_details = MethodMapper.find_method_detail( Project, format )
|
183
|
+
|
184
|
+
method_details.class.should == MethodDetail
|
185
|
+
|
186
|
+
result = 'milestones'
|
187
|
+
method_details.operator.should == result
|
188
|
+
method_details.operator_for(:has_many).should == result
|
189
|
+
|
190
|
+
method_details.operator_for(:belongs_to).should be_nil
|
191
|
+
method_details.operator_for(:assignments).should be_nil
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
it "should return nil when non existent column name" do
|
198
|
+
["On sale", 'on_sale'].each do |format|
|
199
|
+
detail = MethodMapper.find_method_detail( @klazz, format )
|
200
|
+
|
201
|
+
detail.should be_nil
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
it "should find a set of methods based on a list of column names" do
|
207
|
+
|
208
|
+
mapper = MethodMapper.new
|
209
|
+
|
210
|
+
[:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |column_name_format|
|
211
|
+
|
212
|
+
method_details = MethodMapper.find_method_detail( @klazz, column_name_format )
|
213
|
+
|
214
|
+
method_details.class.should == MethodDetail
|
215
|
+
|
216
|
+
method_details.col_type.should_not be_nil
|
217
|
+
method_details.col_type.name.should == 'value_as_string'
|
218
|
+
method_details.col_type.default.should == nil
|
219
|
+
method_details.col_type.sql_type.should include 'varchar(255)' # db specific, sqlite
|
220
|
+
method_details.col_type.type.should == :string
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should not by default map setter methods", :fail => true do
|
225
|
+
MethodMapper.assignments[Milestone].should_not include('title')
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should support reload and inclusion of setter methods", :fail => true do
|
229
|
+
|
230
|
+
MethodMapper.assignments[Milestone].should_not include('title')
|
231
|
+
|
232
|
+
MethodMapper.find_operators( Milestone, :reload => true, :instance_methods => true )
|
233
|
+
|
234
|
+
# Milestone delegates :title to Project
|
235
|
+
MethodMapper.assignments[Milestone].should include('title')
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|